Skip to content
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

Order of paths in exports object shouldn't matter #7

Closed
bgotink opened this issue Feb 4, 2021 · 3 comments
Closed

Order of paths in exports object shouldn't matter #7

bgotink opened this issue Feb 4, 2021 · 3 comments

Comments

@bgotink
Copy link

bgotink commented Feb 4, 2021

The following two exports objects are equivalent for Node, but resolve.exports only works correctly for the first. This can be verified by swapping lines 401 and 402 in test/resolve.js

{
  "./data/*": "./data/*.json",
  "./": "./"
}

{
  "./": "./",
  "./data/*": "./data/*.json"
}

Looking at the ESM resolution algorithm in node's documentation (PACKAGE_IMPORTS_EXPORTS_RESOLVE here), node sorts the keys by key length before looking for a match.

@lukeed
Copy link
Owner

lukeed commented Feb 4, 2021

Thanks, missed that. Can't quite get to this right now, but should be very easy to implement.

@bgotink
Copy link
Author

bgotink commented Feb 4, 2021

I hope you don't mind I gave it a go.

Rather than actually sorting as mentioned in the node docs I've chosen to loop through the entire object, as sorting would get slower for larger export objects.

@unional
Copy link

unional commented Jan 1, 2023

btw I have released pattern-key-compare for resolve.imports, in case you want to use it.

@lukeed lukeed closed this as completed in 7e41d63 Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants