-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
module: link module with a module request record #58886
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
Conversation
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58886 +/- ##
==========================================
- Coverage 90.10% 90.08% -0.03%
==========================================
Files 640 640
Lines 188493 188502 +9
Branches 36971 36977 +6
==========================================
- Hits 169843 169805 -38
- Misses 11358 11428 +70
+ Partials 7292 7269 -23
🚀 New features to boost your workflow:
|
a8faeb0
to
5ea8994
Compare
That's not how I interpret the spec, AFAICT the spec says nothing about what the behavior should if they are different. If |
The spec didn't say the two specifier may be mapped to a single module. The issue is that, if a loader resolves a single specifier with different import attributes, to two modules, the current implementation take the latter because the cache is keyed by specifier only. If a loader interprets additional attributes, like: import * as secret1 from 'a-json-package' with { type: 'json', integrity: 'frozen' };
import * as secret2 from 'a-json-package' with { type: 'json' }; This will be problematic because both namespaces |
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.
This definitely better aligns with the specification, thanks for doing this work.
@@ -0,0 +1,52 @@ | |||
import '../common/index.mjs'; | |||
import assert from 'node:assert'; | |||
import Module from 'node:module'; |
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 wasn't aware of a convention to import Module
instead of module
here. What makes Module
different from other core libs here? Seems it should use the same casing unless there is a good reason.
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.
It's just my preference lasted from CJS that to prevent name collision with CJS module
.
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.
In node:module
, module.exports = Module
, so the default export is also the Module
constructor.
6a8b7e7
to
1abf30b
Compare
1abf30b
to
f7185b1
Compare
f7185b1
to
008345a
Compare
@aduh95 @guybedford @joyeecheung updated PR to use hash+equality caching. PTAL again, thanks! |
I think we might still be able to avoid the extra string storage & transcoding with cppgc-managed wrappers; but that's probably a task for another PR. |
When a module is being statically linked with module requests, if two module requests with a same specifier but different attributes are resolved to two modules, the module requests should be linked to these two modules.
008345a
to
ed81a84
Compare
Landed in cc856b3 |
When a module is being statically linked with module requests, if two module requests with a same specifier but different attributes are resolved to two modules, the module requests should be linked to these two modules. PR-URL: #58886 Refs: https://tc39.es/ecma262/#sec-HostLoadImportedModule Refs: https://github.com/tc39/proposal-import-attributes?tab=readme-ov-file#how-would-this-proposal-work-with-caching Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
This doesn't land cleanly on v22.x-staging |
When a module is being statically linked with module requests, if two module requests with a same specifier but different attributes are resolved to two modules, the module requests should be linked to these two modules. PR-URL: #58886 Backport-PR-URL: #60000 Refs: https://tc39.es/ecma262/#sec-HostLoadImportedModule Refs: https://github.com/tc39/proposal-import-attributes?tab=readme-ov-file#how-would-this-proposal-work-with-caching Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
When a module is being statically linked with module requests, if two
module requests with a same specifier but different attributes are
resolved to two modules, the module requests should be linked to these
two modules.
For example,
should result in two different module instances, if the second import
is been evaluated as a CommonJS/ESM module by a loader.
ECMA-262 requires that in
HostLoadImportedModule
, if the operation is calledmultiple times with two (referrer, moduleRequest) pairs, it should return the same
result. But if the moduleRequest is different, and the module loader resolves to
different module instances, it should return different module instances.
Refs: https://tc39.es/ecma262/#sec-HostLoadImportedModule
Refs: https://github.com/tc39/proposal-import-attributes?tab=readme-ov-file#how-would-this-proposal-work-with-caching