Skip to content
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

Merged
merged 67 commits into from
Feb 7, 2023

Conversation

crowlKats
Copy link
Member

@crowlKats crowlKats commented Feb 4, 2023

This PR refactors all internal js files (except core) to be written as ES modules.
__bootstraphas 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.

core/02_error.js Outdated Show resolved Hide resolved
core/modules.rs Outdated Show resolved Hide resolved
core/00_primordials.js Outdated Show resolved Hide resolved
core/extensions.rs Outdated Show resolved Hide resolved
core/ops_builtin_v8.rs Outdated Show resolved Hide resolved
core/runtime.rs Outdated Show resolved Hide resolved
ext/broadcast_channel/lib.rs Show resolved Hide resolved
@@ -0,0 +1,4 @@
error: Uncaught (in promise) TypeError: Cannot load internal module from external code
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@bartlomieju bartlomieju left a 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!

core/modules.rs Show resolved Hide resolved
Copy link
Member

@ry ry left a 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 !

Copy link
Member

@ry ry left a 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!

@crowlKats crowlKats merged commit b4aa153 into denoland:main Feb 7, 2023
@crowlKats crowlKats deleted the es_builtins branch February 7, 2023 19:23
bartlomieju added a commit that referenced this pull request Feb 8, 2023
sido378 pushed a commit to dynatrace-oss-contrib/deno that referenced this pull request Feb 13, 2023
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants