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

[Native ES Modules] Support for exports subpath aliasing #9565

Closed
aldeed opened this issue Feb 12, 2020 · 4 comments
Closed

[Native ES Modules] Support for exports subpath aliasing #9565

aldeed opened this issue Feb 12, 2020 · 4 comments

Comments

@aldeed
Copy link

aldeed commented Feb 12, 2020

@SimenB Great to see the list in #9430 and progress being made on it. Lots of complicated issues.

I don't see an explicit mention of handling exports object from a package when resolving package identifiers.

For example, given this in package.json:

"exports": {
    "./": "./lib/"
  },

Assuming the ESM package has a file located at /lib/foo.js, you would instead import from "package-name/foo.js" and then Node transforms that to add /lib layer.

Currently latest Jest (using Babel for parsing) does not respect this exports mapping so we have to add a matching Jest config for every dependency package that uses it:

moduleNameMapper: {
  "^package-name/(.*)$": "package-name/lib/$1"
},

Will this "just work" when native ESM support lands? If so, great, you can close this.

If not I think it should be added to your list. Thanks!

Ref: https://nodejs.org/dist/latest-v12.x/docs/api/esm.html#esm_package_exports

@SimenB
Copy link
Member

SimenB commented Feb 12, 2020

Thanks, I'd forgotten to add it 👍 Updated the post now with this:

Node supports package exports, which sorta maps to Jest's moduleNameMapper, but also provides encapsulation features. Hopefully resolve will implement this, but if they do not we'll need to do something. Might be enough to use the pathFilter option? Unsure.

This would have been fine as a comment in that issue, btw 🙂 I'll close this as I've added the tracking item over there

@aldeed
Copy link
Author

aldeed commented Feb 12, 2020

Thanks @SimenB !

I opened a new issue because of

Any comments added to this issue not related to how we can implement support for the below enumerated features (or to tell me I'm missing something) will be marked as spam

I see now that that sentence can be read in two different ways, and I read it the wrong way ("comments to tell me I'm missing something will be marked as spam"). Hopefully you're not missing anything else, but if I think of anything, I'll leave a comment next time. 😄

@SimenB
Copy link
Member

SimenB commented Feb 12, 2020

Fair enough! I rephrased it now so hopefully we're down to only a single interpretation 👍

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants