module: Refine and unify exports resolution error handling#31625
Closed
guybedford wants to merge 9 commits intonodejs:masterfrom
Closed
module: Refine and unify exports resolution error handling#31625guybedford wants to merge 9 commits intonodejs:masterfrom
guybedford wants to merge 9 commits intonodejs:masterfrom
Conversation
db65846 to
888fae1
Compare
Contributor
Author
|
//cc @nodejs/modules-active-members |
ljharb
reviewed
Feb 3, 2020
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
addaleax
reviewed
Feb 7, 2020
Contributor
Author
|
Thanks @addaleax for the review here, would appreciate your advice re how to properly do the check handling. |
Contributor
Author
|
@addaleax I've added all the checks you mentioned here now. Better docs / info around how exactly to these sorts of cases properly would definitely be useful for future reference. |
7f9c775 to
d2f5a07
Compare
d2f5a07 to
f6d4dac
Compare
hybrist
approved these changes
Feb 10, 2020
Collaborator
Collaborator
guybedford
added a commit
that referenced
this pull request
Feb 18, 2020
PR-URL: #31625 Reviewed-By: Jan Krems <jan.krems@gmail.com>
Contributor
Author
|
Landed in 58de9b4. |
4 tasks
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
The CITGM failures were tracked down to causes unrelated to this PR in nodejs/citgm#785 (comment). |
codebytere
pushed a commit
that referenced
this pull request
Feb 27, 2020
PR-URL: #31625 Reviewed-By: Jan Krems <jan.krems@gmail.com>
Merged
MylesBorins
added a commit
to MylesBorins/node
that referenced
this pull request
Mar 6, 2020
Member
|
@guybedford if this is something that should be in |
4 tasks
Contributor
Author
|
@codebytere thanks for letting me know about this - backport PR at #32287. |
tetsuharuohzeki
added a commit
to tetsuharuohzeki/option-t
that referenced
this pull request
Mar 26, 2020
This error happens by this change in [Node,js v13.10](nodejs/node#31625) and I think we can regard this problem as the regression of this library. For the future, we should wait nodejs/node#32107 but it is still in progress. This patch will try to workaround for it. ## Reference * nodejs/node#31625 * nodejs/node#32107 * babel/babel#11216
tetsuharuohzeki
added a commit
to tetsuharuohzeki/option-t
that referenced
this pull request
Mar 26, 2020
This error happens by this change in [Node,js v13.10](nodejs/node#31625) and I think we can regard this problem as the regression of this library. For the future, we should wait nodejs/node#32107 but it is still in progress. This patch will try to workaround for it. * nodejs/node#31625 * nodejs/node#32107 * babel/babel#11216
guybedford
added a commit
to guybedford/node
that referenced
this pull request
Apr 1, 2020
PR-URL: nodejs#31625 Reviewed-By: Jan Krems <jan.krems@gmail.com>
MylesBorins
pushed a commit
to MylesBorins/node
that referenced
this pull request
Apr 3, 2020
PR-URL: nodejs#31625 Reviewed-By: Jan Krems <jan.krems@gmail.com>
Merged
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR includes a number of refinements to the error handling of exports resolutions in the ES module resolver:
imported from ...part since they don't have natural error stacks likerequire()does.invalid:urlor backtrack below the package boundary like../../../outside."exports": { "./sub/": "./sub/" }where the user attempts to require egpkg/sub/../../../asdforpkg/sub/node_modules/...etc. The error thus distinguishes that the fault is with the requestor, not the package.json itself.The main semantic changes in this PR are then the following:
"exports": { "node": { "node": "not:valid" }, "default": "./valid.js" }would before this PR always return thevalid.jspath, but after this PR always throw an ERR_INVALID_PACKAGE_TARGET error for thenot:validpath. On the other hand,"exports": { "node": { "never": "./never.js" }, "default": "./valid.js" }would fall through the "never" path fine. Array fallbacks continue to fall back on the validation errors though as designed."."entry, or because there is no conditional resolution for the"."entry (eg"exports": { "never": "./never.js" }), the ERR_PACKAGE_PATH_NOT_EXPORTED error will immediately throw without doing any"main"or"index.js"lookups. This makes "exports" exhaustive in its definition of the package resolution, and simplifies the error handling consistency for exports in turn.Since its original proposal,
"exports"has very much turned into a full replacement for"main". Having self-resolve entirely reliant on this field being set is also in line with this. I understand (2) may be the most controversial part of this PR with the biggest user-facing consequences, so I expect we should discuss this further in the next meeting. This PR can be adjusted further based on any resolutions. The logic connects around the error handling hence the monolith here.In addition, this PR fixes #31510 and the incorrect use of XOR instead of bit shift described in #31008 (review).
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes