Skip to content

Migrate to TS#278

Merged
marnusw merged 10 commits into
marnusw:masterfrom
brettwillis:master
Apr 15, 2024
Merged

Migrate to TS#278
marnusw merged 10 commits into
marnusw:masterfrom
brettwillis:master

Conversation

@brettwillis

@brettwillis brettwillis commented Apr 9, 2024

Copy link
Copy Markdown
Contributor

Thought I'd help you out while I had a moment. I depend on this projects so it's only right to contribute back 🙏🏼 . Took a few liberties in terms of the build scripts so I'm not sure how you'll feel about it, but at least this could be a starting point. Significant reduction in code size.

  • Migrate to TypeScript source
  • Use TS for CJS and ESM builds, remove all dynamic code generation (for the size of the library, the build scripts are an order of magnitude or two larger than the code itself)
  • Review TS build targets (language feature support) for CJS and ESM targets
  • Adapt tests and webpack config

@brettwillis

Copy link
Copy Markdown
Contributor Author

Don't know why but two tests fail on my machine that aren't failing here:

Screenshot 2024-04-10 at 2 34 25 PM

@brettwillis brettwillis marked this pull request as ready for review April 10, 2024 08:54
@marnusw

marnusw commented Apr 10, 2024

Copy link
Copy Markdown
Owner

This is amazing, thank you!! I will review asap, including the build scripts. In the past I've mostly copied the scripts from date-fns to minimize effort, but as long as it gets the job done...

@marnusw

marnusw commented Apr 12, 2024

Copy link
Copy Markdown
Owner

@brettwillis when I ran the tests I got the error for each test file: Module parse failed: 'import' and 'export' may appear only with 'sourceType: module'. I changed the src folder to type: module to fix this and switched to full path imports in the test files. (It looks like top level package.json has to stay type: commonjs to support Karma.) I also make a few other minor tweaks.

I see you said above two tests were failing locally for you, but I guess you fixed that in the two subsequent commits? Are all the tests running fine for you locally now and does it all look good?

I'll just compare the TS build targets to what date-fns is doing still, and then I think we can release a beta and then publish.

@brettwillis

Copy link
Copy Markdown
Contributor Author

@marnusw no those two tests are still failing on my machine same as before. Is it something to do with the MacOS plaform?

Also just wondering why you removed all the documentation comments? They're not unused because that is what TS uses to export to the .d.ts files which documents the code for users.

@brettwillis

Copy link
Copy Markdown
Contributor Author

@marnusw btw those same two tests also fail in the same way on v3.0.0, seems it is not new to the TS branch.

@marnusw

marnusw commented Apr 15, 2024

Copy link
Copy Markdown
Owner

Also just wondering why you removed all the documentation comments? They're not unused because that is what TS uses to export to the .d.ts files which documents the code for users.

Are they used though? The old build scripts used them to create the types, but now that it's rewritten in TS the d.ts files will just be derived from the actual code won't it?

I removed them because they cluttered the code files (especially format and other long ones) and weren't used to build the actual documentation which is in the README. I'm fine with putting it back if there is a reason/preference for it.

Would you mind checking whether those tests fail on the latest v2 release? Either way, if it's already failing in 3.0.0 it doesn't have to prevent merging this.

@brettwillis

Copy link
Copy Markdown
Contributor Author

Would you mind checking whether those tests fail on the latest v2 release?

Confirmed same tests fail on v2.0.1.

...now that it's rewritten in TS the d.ts files will just be derived from the actual code won't it? I removed them because they cluttered the code files (especially format and other long ones) and weren't used to build the actual documentation which is in the README.

Correct the d.ts are now derived from the ts source directly. The JSDoc-style annotations in the d.ts is what drives the inline documentation powered by the IDE, which is quite powerful, without having to look up separate documentation. Of course the typings are now defined by the TS annotations which is why I removed the type annotations from JSDoc, but the descriptions/documentation still applies. We previously had no inline docs because the d.ts generated by the build script was void of documentation.

Now we can get that inline documentation for free. So I would recommend adding it back imho.

@marnusw

marnusw commented Apr 15, 2024

Copy link
Copy Markdown
Owner

That's good to know. I didn't realize that. I'll definitely add it back in, and then we can merge and release this.

Thank you for the feedback. 👍🏻

@marnusw marnusw merged commit 31a42ad into marnusw:master Apr 15, 2024
@marnusw

marnusw commented Apr 15, 2024

Copy link
Copy Markdown
Owner

Thanks again for the great work! v3.1.0.

@brettwillis

Copy link
Copy Markdown
Contributor Author

Great! And thanks for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants