-
Notifications
You must be signed in to change notification settings - Fork 79
fix(compartment-mapper): mapNodeModules should not crawl ESM modules from CJS entrypoints #3003
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
base: master
Are you sure you want to change the base?
Conversation
…from CJS entrypoints This changes the logic in mapNodeModules() so that when it reads the `package.json` of the entrypoint, it checks for `type === 'module'`. If this is set, then `import` is added to the `conditions`. If it is not set, then `require` is added to the conditions. The conditions always contain `default`; this has not changed. This prevents CJS modules from referencing modules in the `CompartmentMapDescriptor` which they would not otherwise load (and in fact _cannot_ load for some value of "_cannot_").
c972ee6 to
d99f0a4
Compare
| @@ -0,0 +1,2 @@ | |||
| module.exports = { value: 'dual-esm' }; | |||
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.
did you mean dual-cjs?
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.
idk, doesn't really matter
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've created an exploratory e2e test to see how the nested trees of cjs vs esm would work
there's a few more permutations to try.
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.
Comparing against node.js is one thgin, but do we also want to compare against some bundlers and tsc?
|
For the sake of capturing notes, I think this is interesting. Node.js, unlike Endo-as-writ, supports two concurrent module systems. The legacy, bottom tier module system is always synchronous and only hosts CJS. The top tier, like Endo, hosts both CJS and ESM. The ramp up is dynamic import, with a fully qualified module specifier (module- and package-relative imports won’t work). The ramp down is I believe the top tier always has |
|
Yeah, based on talking it over with @kriskowal and his comments here, I am not really convinced this is "correct", nor am I convinced it actually "fixes" anything. The current behavior seems kind of weird to me, so I think Something should be done. This is likely not the Something that should be done. |
Description
This changes the logic in
mapNodeModules()so that when it reads thepackage.jsonof the entrypoint, it checks fortype === 'module'. If this is set, thenimportis added to theconditions. If it is not set, thenrequireis added to the conditions. The conditions always containdefault; this has not changed.This prevents CJS modules from referencing modules in the
CompartmentMapDescriptorwhich they would not otherwise load (and in fact cannot load for some value of "cannot").Security Considerations
n/a
Scaling Considerations
n/a
Documentation Considerations
This may impact users, but it is a bug fix.
Testing Considerations
The tests verify this is working for both module systems.
Compatibility Considerations
n/a
Upgrade Considerations
Updated
NEWS.md.