| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
//cc @nodejs/modules-active-members |
Sorry, something went wrong.
|
I'm not sure that we should change the resolve order between ESM + CJS. This could result in unexpected behavior. |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
It'll behave strangely any time a package gets installed in its own node_modules folder (as the esm resolver will resolve to the local copy, while the cjs resolver will resolve to the node_modules copy). This used to happen when developing typescript, as typescript had a devDependency of tslint which had a dependency of typescript (which npm then flattens), so is a situation that happens in the real world. They probably shouldn't diverge. |
Sorry, something went wrong.
It needs to check the fs to look for the enclosing package.jsons already - the node_modules folder state isn't that much more, once you're already hitting disk. W.R.T. the sigil stuff, I, at least, forsee writing a {
"name": "~",
"type": "module",
"private": true
}package.json file in my src folders, under my primary package.json. So you could say that the current implementation just allows choice of sigil, if you're so inclined. So if people are taking issue with the "meaning" of a sigil, I'm not sure the argument holds once this kind of "custom sigil" is possible. it may be better to just pick one, any one, just to save work in both resolvers. |
Sorry, something went wrong.
|
@weswigham it will check node_modules/[name] folders all the way to the root of the file system, is the issue. When applying tooling for eg import maps generation, a root-level node_modules install affecting self-resolution isn't ideal. |
Sorry, something went wrong.
Are the discovered folder contents cached, like how package.json results are cached? If so, it shouldn't be too bad, since resolution will already be forced to generate that list for literally any other non-relative specifier. |
Sorry, something went wrong.
Using a sigil does unfortunately not really change this: Any sigil would be a valid sub-directory of node_modules and we're back to the same order concern for require. Afaik we haven't found any syntax that is backwards compatible with existing CJS resolution without checking node_modules first. The only solution would be an explicit opt-in like a useSelfReference in package.json which would work for both name and sigil. |
Sorry, something went wrong.
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 npm); meanwhile if using the package's actual name, if you change the behavior, you change a scenario that actually crops up in real installations. |
Sorry, something went wrong.
|
Could we potentially tease the ordering change out of this PR and land the fixes? Or are they entangled? |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
There was a problem hiding this comment.
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!
Sorry, something went wrong.
|
In line with the suggestion by @jkrems I've made self-resolution always-opt-in on "exports" being present for both. |
Sorry, something went wrong.
There was a problem hiding this comment.
Nice! I think there's some traces left in the algorithm of the previous variant.
Sorry, something went wrong.
|
Wait, does this mean that self-export only works inside a package using "exports"? |
Sorry, something went wrong.
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. |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
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>
PR-URL: #31009 Reviewed-By: Jan Krems <jan.krems@gmail.com>
| Back | FazBrowse Home | New Git URL |
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