-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
vm: add support for import assertions in dynamic imports #40249
Conversation
Ping @nodejs/vm @nodejs/modules for reviews. |
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.
Assert enforcement of spec for "type": "json" isn't in place but this is still experimental and I honestly don't have a clean way to enforce it even if we wanted to. We could treat this as a power/debugging tool which often lies outside of the spec? Seems fine for now but should revisit decision before unflagging.
In #40250 (comment) I asked if this could wait until that PR lands, or if this could land as part of that PR. There’s an unresolved discussion there about when and whether import assertions should be passed around between internal functions, which is what this PR adds; so it seems premature to land this until we’ve settled that question. |
@GeoffreyBooth I've opened this PR to separate the changes in
That being said, of course I'm OK waiting if there are concerns, but if there are none, I'd rather have it landed, and a future PR can change the implementation again if it turns out being necessary. |
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.
Seems like a nice simple change, and since VM doesn't relate to cache keying questions at all I don't see any reason not to land this.
src/module_wrap.cc
Outdated
Local<Object> assertions = | ||
Object::New(isolate, v8::Null(env->isolate()), nullptr, nullptr, 0); | ||
for (int i = 0; i < import_assertions->Length(); i += 2) { | ||
assertions | ||
->Set(env->context(), | ||
Local<String>::Cast(import_assertions->Get(env->context(), i)), | ||
Local<Value>::Cast(import_assertions->Get(env->context(), i + 1))) | ||
.ToChecked(); | ||
} |
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.
if possible it might be good to dedupe this code with the static import path so they stay consistent
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.
Done in adf6993.
9c2964f
to
adf6993
Compare
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 discussed with @aduh95; my concern about the function signature was whether the assertions would become part of the cache key. He tells me that he thinks that won’t be the case, in this PR at least. So I think this should be fine to land.
Landed in 879ff77...08ffbd1 |
PR-URL: #40249 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
PR-URL: #40249 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Notable Changes: Experimental ESM Loader Hooks API: Node.js ESM Loader hooks have been consolidated to represent the steps involved needed to facilitate future loader chaining: 1. `resolve`: `resolve` [+ `getFormat`] 2. `load`: `getFormat` + `getSource` + `transformSource` For consistency, `getGlobalPreloadCode` has been renamed to `globalPreload`. A loader exporting obsolete hook(s) will trigger a single deprecation warning (per loader) listing the errant hooks. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias - #37468 Other Notable Changes: deps: * upgrade npm to 8.1.0 (npm team) #40463 doc: * deprecate (doc-only) http abort related (dr-js) #36670 vm: * (SEMVER-MINOR) add support for import assertions in dynamic imports (Antoine du Hamel) #40249 PR-URL: #40504
Notable Changes: Experimental ESM Loader Hooks API: Node.js ESM Loader hooks have been consolidated to represent the steps involved needed to facilitate future loader chaining: 1. `resolve`: `resolve` [+ `getFormat`] 2. `load`: `getFormat` + `getSource` + `transformSource` For consistency, `getGlobalPreloadCode` has been renamed to `globalPreload`. A loader exporting obsolete hook(s) will trigger a single deprecation warning (per loader) listing the errant hooks. Contributed by Jacob Smith, Geoffrey Booth, and Bradley Farias - #37468 Other Notable Changes: deps: * upgrade npm to 8.1.0 (npm team) #40463 doc: * deprecate (doc-only) http abort related (dr-js) #36670 vm: * (SEMVER-MINOR) add support for import assertions in dynamic imports (Antoine du Hamel) #40249 PR-URL: #40504
Running Node 16.13.2, I see the following when I try to specify an import assertion on a dynamic
I think Node 16.3.2 includes this commit, but I'm guessing there's another one that's necessary in order for this to work? Thanks in advance for any response, and sorry for pinging the PR like this. |
You need to use the |
No description provided.