-
-
Notifications
You must be signed in to change notification settings - Fork 593
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
fix(node-resolve): Fix package exports / imports resolution algorithm #1549
Conversation
d65e95e
to
99c413a
Compare
Thanks for the PR. @guybedford is our resident resolutions expert, hoping he sees this and offers thoughts. |
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 really looks massive and appears to contain many subtle improvements. It also appears you checked against the original algorithm, is that true?
Admittedly, the TypeScript conversion both is very useful and makes comparing the diff rather hard. For other reviewers, the relevant files to look at are resolvePackageImportsExports.ts and resolvePackageTarget.ts as only those contain major changes.
I do not feel confident to 100% judge the accuracy of the algorithm, but I would hope this feature can land as it seems to fix everything that might subtly differ from the Node algorithm.
// Assert: ends with "/" or contains only a single "*". | ||
.filter((k) => k.endsWith('/') || k.includes('*')) |
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.
You say you only want patterns that contain a single *
, but this will also keep patterns with multiple *
, is this intended?
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 how the algorithm is written - basically multiple **
are invalid, but we don't ban them outright in case it might be supported in future - so instead they are filtered out by omission since they can never be matched.
packages/node-resolve/src/package/resolvePackageImportsExports.ts
Outdated
Show resolved
Hide resolved
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.
Sorry didn't spot this at first. Great to have the spec comments in here - this is excellent work thank you!
packages/node-resolve/src/package/resolvePackageImportsExports.ts
Outdated
Show resolved
Hide resolved
// Assert: ends with "/" or contains only a single "*". | ||
.filter((k) => k.endsWith('/') || k.includes('*')) |
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 how the algorithm is written - basically multiple **
are invalid, but we don't ban them outright in case it might be supported in future - so instead they are filtered out by omission since they can never be matched.
@lukastaegert I'll leave this one up to you to merge when you're happy with the convo with @guybedford |
…orithm according to Node documentation This fixes the package exports and imports resolution algorithm by strictly following the Node API documentation. For backwards compatibility a new option `allowExportsFolderMapping` is introduced which will enable deprecated folder mappings. Test case included Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
99c413a
to
95b7671
Compare
@lukastaegert @guybedford Thank you very much for your review! |
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.
Looks good from my side
Rollup Plugin Name:
node-resolve
This PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
Description
Currently the implementation of package exports / imports resolution does not follow the Node documentation as the README implies.
So this fixes the package exports and imports resolution algorithm by strictly following the Node API documentation. For backwards compatibility a new option
allowExportsFolderMapping
is introduced which will enable deprecated folder mappings.This is required for packages that use export patterns with the asterisk in the middle not at the end, like this:
See included test file.