-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Update esm loader hooks API #1457
Conversation
Codecov Report
|
Thanks for the PR. I'm swamped with work, so I'll do my best to review in a timely manner, but it might drag a bit. However, anyone who wants to use this PR before it is merged and published can install directly from git. npm's documentation explains how to install dependencies directly from a git branch instead npmjs.com. Our CI also uploads a package tarball as an artifact, which anyone can download and install locally. Re the warnings from node about deprecated hooks: I think we can detect the node version and conditionally export only the hooks expected by that version of node. We can export Lines 43 to 62 in aaf6052
|
Should we add node's nightly builds to our test matrix? We already test against nightly typescript. |
Linking to actions/setup-node#80 re testing against node nightlies. If they don't have a good solution, we can roll our own I guess. |
I've added node nightly to the test matrix which is causing some failures. It also looks like stack traces are not showing correct line numbers for the errors. I don't know if this is a ts-node bug, a node nightly bug, or if those stack traces have never been correct. |
According to the docs it seems |
Well, it seemed to fix all the tests but one :-). |
That's great; do you know what's up with the remaining failing test? |
I'm pretty sure the remaining test failures can be fixed by updating |
Thanks, I'll try to get some time to look into the last test failure. FYI, I'm also working towards a more complete solution for the resolve hook in a new package called ts-resolve. It is still in an early stage but it would of course be interesting to know if something like this package would be considered useful for ts-node? |
The fix was a one-line change; tests are passing now. 63c0618
Possibly, yeah. We want to do both CJS and ESM resolution so that projects "just work," so if we support project references for ESM it should also work with CJS. And since we already resolve the user's configuration, we'd want it to accept a pre-parsed config or set of multiple project-referenced configs, share FS cache, stuff like that. We'll also need to be able to hook into format determination to override as dictated by https://typestrong.org/ts-node/docs/module-type-overrides Glancing at the readme, looks like it ticks at least a few of those boxes. |
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.
Looks good to go. Follow-up PRs can fill in the appropriate version numbers once the new loader API lands in node.
Does esbuild's sync API still have that per-call process spawning overhead? That's why I implemented swc support for ts-node, but I want to add esbuild as well once that process-spawning limitation goes away. |
Nice :-)
The initial goal for ts-esm-resolve is for ESM resolution. Not sure how much work it would be to add CJS resolution. A lot of the logic is of course similar so it might be rather easy.
Yes, currently it is accepting a path to a tsconfig file and resolving it to an internal
That should be possible since all FS calls are done through callback functions passed to the resolve function. I currently use this to mock the filesystem in the test-cases but it should also be possible to use it for cached FS calls. |
AFAIK the resolve process does not need to know the format, that is only needed later when executing the module? |
Oh yeah, you're right: format only needed for
We allow ts-node-specific overrides to the |
I haven't dug deep into the transpilers for load. I was investigating using snowpack or vitejs and they both use esbuild. However they do not resolve typescript files fully for project references. In the end I would like to have a full-stack typescript ESM setup with both node and snowpack/vitejs supporting full typescript resolving for references/workspaces. I've been experimenting with such a setup in this repo. Currently it uses the ts-node esm loader and snowpack. |
Noting that I was concerned about some sourcemaps, but I can't remember why or if they're fixed or covered by tests. This is still an experimental API surface so I feel good merging now. |
This is an attempt to fix #1372.
Link to docs for the new hooks API:
https://github.com/nodejs/node/blob/master/doc/api/esm.md#loaders
EDIT from @cspotcode:
createEsmHooks
to expose the new hooks