-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: Use ES modules for internal runtime code #17648
Conversation
@@ -0,0 +1,4 @@ | |||
error: Uncaught (in promise) TypeError: Cannot load internal module from external code |
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.
How does CLI get to the point of this error? This error is thrown by the internal module loader, not the cli loader. What is up with that?
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.
That's a good point @crowlKats, we shouldn't get an error from the CLI loader, not the internal loader.
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.
Why was this resolved? AFAICT, the error is still coming from the internal loader. Why is the internal loader used at runtime in CLI?
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.
@lucacasonato it's not coming from internal loader - I disabled dynamic imports of internal modules completely in core/bindings.rs
- so we're not even hitting module system, nor any of the loaders.
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.
Can we do the same for resolution in static loading?
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.
static loading is erroring before currently, because the FileFetcher is erroring with invalid scheme
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.
I think we could do that somewhere in core/modules.rs
- essentially you're asking to hard disable loading of internal modules in cases where we are running from a snapshot?
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.
essentially you're asking to hard disable loading of internal modules in cases where we are running from a snapshot?
we already are doing that though, no? the InternalModuleLoader isnt used by cli; its not used if one is loading a snapshot but not creating one
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.
Please do the enforcement at core level in a follow up as Bartek described. CLI is not the only loader implementation. Not all loaders enforce a given scheme during resolution.
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.
There will be several clean ups needed after landing this PR, but this is a major effort that brings us very close to be able to snapshot TypeScript modules.
We should land it ASAP, to catch any potential problems and have time to fix them before the next release.
LGTM!
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.
Great work @crowlKats and @bartlomieju !
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.
Partial review but +1 from me for landing. Awesome work!
…17694) Addressing Luca concerns from #17648 (comment)
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This PR refactors all internal js files (except core) to be written as ES modules.
__bootstrap
has been mostly replaced with static imports in form ininternal:[path to file from repo root]
.To specify if files are ESM, an
esm
method has been added toExtension
, similar to thejs
method.A new ModuleLoader called
InternalModuleLoader
has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it.