-
-
Notifications
You must be signed in to change notification settings - Fork 544
fix: Add globalPreload to ts-node/esm for node 20 #2009
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
Open
isaacs
wants to merge
14
commits into
TypeStrong:main
Choose a base branch
from
isaacs:isaacs/node-20-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
670d0ea
remove swc experimental options
isaacs afbd4b6
fix: Add globalPreload to ts-node/esm for node 20
isaacs 71e319c
loader: return empty globalPreload when not using off-thread loader
isaacs 8b4be1d
fix: ts-node --esm on Node v20
isaacs a7aa440
WIP fix tests for off-thread loader
cspotcode 9346c54
Pushing my local changes
cspotcode db1fdf9
test: fix node defaultLoad error message check
isaacs d68a150
loader: TSError that survives thread comms channel
isaacs 04d9419
loader: Set default 'pretty' option properly
isaacs fba2006
use built-in source map support in node v20
isaacs 5c83838
test: line numbers in eval are not reliably source mapped
isaacs 49c74a0
add support for '--import ts-node/import'
isaacs ed07dd9
test: allow windows line endings, node-version-specific path displays
isaacs b614b1b
test: allow win32 line endings, path displays
isaacs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Add globalPreload to ts-node/esm for node 20
As of node v20, loader hooks are executed in a separate isolated thread environment. As a result, they are unable to register the `require.extensions` hooks in a way that would (in other node versions) make both CJS and ESM work as expected. By adding a `globalPreload` method, which *does* execute in the main script environment (but with very limited capabilities), these hooks can be attached properly, and `--loader=ts-node/esm` will once again make both cjs and esm typescript programs work properly.
- Loading branch information
commit afbd4b69fc039864c73fd5de60a33eb58fc8d699
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this hook be included in the return value of https://typestrong.org/ts-node/api/index.html#createEsmHooks?
That API is meant for anyone wanting to wrap our loader in their own logic. They'd do
--loader my-loader.mjswith theirmy-loader.mjsexporting all the functions they get from callingcreateEsmHooks(), perhaps wrapping them to implement new behavior.This API predates support for multiple loaders, but also it should be possible to compose loaders in code so that end-users don't have to pass
--loadertwice.Uh oh!
There was an error while loading. Please reload this page.
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.
Everything is just as composable as it was, with the exception that
globalPreloadis a bit weird to stack. (You have to append all the strings together wrapped in IIFE's so they don't clobber each others' vars.)But multiple loaders have been supported longer than
globalPreloadwas needed, so that might not matter.