-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
properly support watch mode when transforming .ts files #249
properly support watch mode when transforming .ts files #249
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this looks very good!
I released this as Interesting that dogfooding this for the plugins own type definitions, the changes to use TBH this is the first time I saw |
the changes to use I'm all for exposing the main plugin with an explicit typedef if you don't want to have the public side of things to have those inferred typings, but at least for the inner transform plugin, it was hugely helpful to be able to have more explicit typings that mirrored the actual code tysm for getting this released! |
The `generateDtsFromTs` path expects cases where `!module.source` but since Swatinem#249 `getModule` does not actually return it as it fails trying to use it for gathering `code`.
The `generateDtsFromTs` path expects cases where `!module.source` but since #249 `getModule` does not actually return it as it fails trying to use it for gathering `code`.
closes #248
while the diff looks noisy, these changes preserve the codepaths 1:1 while making the actual logic involved much more digestible
the main big change is in resolving modules, where we now resolve both the
code
as well as the typescript-compiler-specificsource
&program
values. this makes the logic inside oftransform()
way simpler, where we can just check thatresolveModule
actually returned something, and if so we know we can pass the code straight along to the inner transform pluginI also did my best to remove a lot of mutability in variables as it was making it hard to follow the logic, as well as make the types a little stricter/more explicit
if this PR is too heavy-handed, I am happy to restore some of the original structure (e.x. re-inlining getModule so we don't need to pass around a context object) while preserving the main core changes that enabled better watch mode support. however, as you mentioned in #248 that this repo is mostly in maintenance mode, I am hoping that these changes will be welcome as I feel they greatly improve the readability & robustness of the code :3
all tests pass :)