-
Notifications
You must be signed in to change notification settings - Fork 30k
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
module: self resolve bug fixes and esm ordering #31009
Conversation
//cc @nodejs/modules-active-members |
I'm not sure that we should change the resolve order between ESM + CJS. This could result in unexpected behavior. |
@MylesBorins the alternatives here are:
I find this is enough of an edge case that the compat doesn't concern me personally, while the full encapsulation going forward I do think is important. Happy either way here though. |
It'll behave strangely any time a package gets installed in its own |
It needs to check the fs to look for the enclosing W.R.T. the sigil stuff, I, at least, forsee writing a {
"name": "~",
"type": "module",
"private": true
}
|
@weswigham it will check When applying tooling for eg import maps generation, a root-level |
Are the discovered folder contents cached, like how |
Using a sigil does unfortunately not really change this: Any sigil would be a valid sub-directory of |
I think the idea behind picking a sigil is that you can make the cjs loader pick the sigil first, and it's probably not a really breaking change, since you generally can't use sigils as a package name (especially if they can't be package names on |
Could we potentially tease the ordering change out of this PR and land the fixes? Or are they entangled? |
Further to the discussion from the meeting today I've gone ahead and pushed the following change:
The approach for this is basically to inject the self resolve method twice - once before and once after package resolution, with a flag to indicate if it must check for exports. @jkrems does that alleviate your original concerns here? Would appreciate re-review when you can. |
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.
As discussed out-of-band: LGTM in general although I'd like to see the 2nd attempt removed. Having a safe way of using this feature (set exports) and a default way that isn't as safe (post-node_modules lookup) seems dangerous. Thanks for working through this!
In line with the suggestion by @jkrems I've made self-resolution always-opt-in on |
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.
Nice! I think there's some traces left in the algorithm of the previous variant.
Wait, does this mean that self-export only works inside a package using "exports"? |
As added in ff11612, yes. The first iteration before this commit was a bit messier, but allowed it without exports too. The diff is in #31009 (comment) to see what I mean. Since "exports" is the new main which also offers encapsulation this approach seems to make the most sense. I'd advise checking the meeting notes on the discussion to avoid rehashing too much here, but happy to discuss further. |
PR-URL: #31009 Reviewed-By: Jan Krems <jan.krems@gmail.com>
Landed in 8a96d05. |
PR-URL: #31009 Reviewed-By: Jan Krems <jan.krems@gmail.com>
PR-URL: #31009 Reviewed-By: Jan Krems <jan.krems@gmail.com>
PR-URL: #31009 Reviewed-By: Jan Krems <jan.krems@gmail.com>
This resolves the self-resolve bugs #30633 and #30602. In addition the ESM implementation of self-resolve is slightly adjusted to apply before the node_modules lookup for better encapsulation, while the CJS implementation is left after the node_modules lookup for backwards compatibility.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes