This repository was archived by the owner on Apr 16, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
[Do not merge] doc: Add pkg-exports proposal to resolve spec #14
Closed
jkrems
wants to merge
1
commit into
esm-resolver-spec
from
jkrems/feature/esm-resolver-spec/resource-resolver
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 mentioned when we discussed, I still worry a little about this in cases where packages do not have a package.json file, as in theory it should still be possible to resolve subpaths in these cases (for eg legacy package backwards compatibility)?
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.
The case would be:
Is this something we should allow via
import
? It would continue to work for.js
and viarequire
for people who truly need it.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.
And also where
node_modules/pkg/x.js
exists without anode_modules/pkg/package.json
I think? Or is that ok?Uh oh!
There was an error while loading. Please reload this page.
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.
Any package installed via
npm
/yarn
would have apackage.json
afaik. Manually created package-less files innode_modules
feel like a hack that exploited the previous design space to get a specific result. I don't believe too many people who know node would be able to understand why it's working (or expect to find it in a project).If we do want to support this for power users, I believe it should be opt-in (e.g. via loader or config), not the default.
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 think having this kind of manual public entrypoint specification probably has value for cjs just as much as esm, tbh. And for cjs, this would need to be opt-in, so it'd make sense for esm to be the same.
Uh oh!
There was an error while loading. Please reload this page.
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.
That's well and good, but I'd rather that not be tethered to
esm
just because it seems like a sneaky way to introduce changes without them obviously being breaks. And like I said and you agreed, this has equal value describing what people want to be able to accomplish with plain ole cjs - which leads me to the conclusion that this aughta be a core cjs loader feature that is replicated in the esm loader, rather than going the other way and trying to "backport" the feature to cjs in the future. Heck, it's an argument for designing explicitly with cjs in mind to ensure it works for it. And as an added bonus, if you propose this for cjs proper, it could start getting worked on being merged into core right away if people agree.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 think that's an overly negative way of portraying it. It's not about sneaking in changes, it's about being able to clean up the API. CJS has a lot of assumptions built in, e.g. how it's tied to a specific file system layout. I don't think it's realistic to remove those assumptions (or even just loosen them) but maybe I'm wrong.
From observing what people are doing in practice, I assume CJS as implemented in node core will be more and more a system that people just wholesale replace. Yes, landing features in core for CJS might be possible. But then we'd just have to reimplement it each replacement again until node-CJS becomes usable as-is. And I'd be (positively) surprised if node core would be prepared to take on the potential perf regression of a more flexible CJS system that still preserves full compatibility with all existing code.
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.
Can't you bill this as potentially improving perf by allowing the resolver to skip disk hits for fallback locations when exact mappings are provided?
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 is about the more general thing: Being able to not even hit the disk for resolution and storing packages outside of an on-disk hierarchy in
node_modules
. That is the reason why people replace the whole CJS system and/or shim around FS (see source oftink
oryarn pnp
). That implies adding hooks into the resolution pipeline which might affect out-of-the-box performance.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'm not saying the end result when using the npm or yarn resolver would be slower. It would be faster. But at the expense of using node without those resolvers. Which is what node core would realistically benchmark. If node core doesn't add those hooks, I'm not sure it's super relevant if it adds
exports
support because nothing would actually hit that code.