-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Convert into TypeScript #23
Conversation
Attempting to clean up imports a bit
What a massive work you did! Thank you! Regarding:
That's the thing I want to avoid because tree-shaking doesn't always work properly. Sometimes it doesn't work at all. For example, Parcel bundler still doesn't have a stable version of the tree-shaking feature. |
Sorry, didn't clarify. Any use of |
As I mentioned, there are a few issues with the current build system, resulting in Microbundle never generating types for the non-default modules. This very well might be a bug, and I'll raise an issue. Regardless though, I've been thinking about rewriting it in a form that would most closely resemble Preact's setup for a few reasons. Using the current system is quite limiting as Microbundle has some options that are only configured via a Moving to what I suggest not only opens up a couple more Microbundle options but would also allow for targeted builds (rebuilding just We would simply track Might whip up a quick demo using the current state of master (so non-ts). This PR certainly doesn't need more things being done in it. |
@omgovich I updated the build process, everything seems to be good. I did switch it over to use ESModules, as I figure that better matches the repository with the ES6 import syntax and the like. Let me know if you'd rather keep it as CommonJS though, no problem. Thought I'd give it a shot. I did have to enable an experimental flag to import from a Edit: Didn't notice this failed for older Node. I'll fix tomorrow. |
Also, something you may notice is that TSC/Microbundle will output types for all files, even those that are not actually public interfaces. Unfortunately there's no way to stop this besides manual pruning. TS can't yet distinguish between external and internal typings. So in our bundle for say Maybe this only bothers me though. Don't know. Thought it worth mentioning that, yes, technically it is working as intended. |
Should be good to go now. Of course still review away if I've missed something. |
@molefrog Could you join us here? Fresh eyes would be good) |
Works and looks good! @ryanchristian4427 Could I ask you to fix conflicts? In my opinion, this is how our plan should look like:
@ryanchristian4427 Sounds good? |
Sorry, conflicts? Not seeing any on my side. But rather than publish a whole beta version, we could just use npm/yarn link and test that way? That's what I've been doing as I've went along, testing the components/intellisense typings in Preact TS project. I should still do another full run through, but I don't think there's a need for a beta? |
Guess you're right. We could just use |
Oh, sorry. Everything is okay — there are no conflicts. |
I'm wondering if we should add Edit: To expound, TS does not have any ability to alias. While most Preact applications will alias React to Preact, ensuring this library works just as well in Preact, when it comes to TS, there's no way around it. If they don't want to skip lib checks then a Preact application will need to have |
Also, I know next to nothing about HSL/HSV so while things look a bit weird to me they might not be? Might just be the wheel -> square conversion, but values don't seem to increase/decrease like I'd expect. |
Additionally, how do you feel about maybe doing named exports with the types? For example:
They could otherwise import the type like |
@ryanchristian4427 Merged. Thank you again! P.S. I love the idea of the named color types export! |
I'm going to actually fix our external/internal definitions for the three (RGB, HSL, HSV) first. I realized exporting those types would make it a bit more obvious that any string key could actually be added and would work fine (i.e., As of now the user has to more or less dig to find out what HSV is strictly defined as, which almost is a benefit as most wouldn't think of adding extra keys to an HSV object. Not the best situation but I'll try to straighten it out. Should just be able to cast to a different object when doing our color object comparisons, and keep otherwise correct types throughout. |
I'm still thinking the output should be combined and user can use named exports to get the parts of the library that they want. While multiple separate inputs -> outputs is on Microbundle's roadmap I don't see any related PRs open (or closed) relating to it. Just old issues. To continue using the current solution would just be a nightmare I think, especially as time goes on. Every extra output that gets added means more duplicated The current worst case scenario is if user wants to use only As was said more than a year ago now, the popular bundlers will all handle tree-shaking. If Parcel/another bundler can't work this out I think that's an issue for them, and not something we should really worry about. Majority of users use Webpack, and it can tree-shake quite well. The move to named exports will see:
Working with this library more since I originally asked that question only convinces me further that it is the right path. It is such a pain to work with currently due to the combination of build times and junk output. Don't get me wrong, I understand the value and virtue of a small output but trying to save a rather insignificant amount of bytes for a small minority of users just seems silly. The efforts are totally lost extremely quickly. Only noticeable if someone really cares, and if they care that much, they'd probably be using a build tool that can tree-shake. I thought I'd bring this up again as I was reading through Microbundle's and some other bundlers' documentation trying to find an easy solution but I couldn't help but think back to this. |
Hey @ryanchristian4427. I was also thinking about that recently and moving to tree-shakable named exports seems the right decision. So we are on the same page here) I think we should consider it as our v3 since those are breaking changes. |
Currently just a first draft of a TS conversion, mentioned first here. Currently still a few issues, some of which just need time, some which will require a few changes.
How would you feel about merging much of the files in
utils/
into a single file, sayconversions.ts
? As of now it's quite tedious to go through the dozen or so files. Named exports would vastly reduce the amount of files making for a much better developer experience IMO.The build config has a few problems revolving around type generation, not entirely sure how to fix that yet, if possible. Microbundle is really fighting on type definition generation. Adding the
types
field to thepackage.json
ensures the main export (dist
) has generated files and all users can use them. But for some reason that stops all the other exports from generating any types whatsoever. Not sure what's going on there, will have to look into it more.Have you thought about not splitting up your library into a bunch of separate modules? With modern tree-shaking, I think it could be beneficial to just export one bundle of named components and have users import the ones they want to use. That would result in the following Microbundle output:
With the following API:
Bit bigger, but whatever you don't use will be shaken out with modern build tools.
It would vastly reduce your build process complexity and package size in exchange for some bundle size for the users not using build tools. Just a thought.