browserify / browserify/resolve
Support ESM resolution
- Dominant language
- JavaScript
- Stars
- 796
- Forks
- 188
- PR merge metrics
- No merged PRs in 30d
Description
Hiya! 👋
We've discussed this briefly on Slack, but I thought an issue would be easier to keep track of.
I'm not sure what it would entail, so I'll just list out (i.e. do a brain dump of) the features I think would be needed.
- Should file be interpreted as CJS or ESM
- Currently, `resolve` will only ever return a single string, which is the absolute path to the resolved file. I think in addition to this, we'd need to know if the file should be interpreted as CJS or ESM
- Related, should `resolve` taken an option what the caller would prefer? Should it be a static option in, or some callback?
- Support `exports` field in package.json
- Docs: https://nodejs.org/api/esm.html#esm_packages
- Again, should the caller be able to define which they want? EDIT: Ish, via `conditions`
- Support promise for async resolution
- This is admittedly not a requirement, but it matches the Node APIs making it cleaner to use `resolve` when implementing custom loaders or using the VM APIs.
- #210
- Support URLs. Mostly because `import()` supports it. It probably makes more sense for resolve to return URLs than an absolute path for ESM?
- Preserve query strings
- Makes sense, but just adding it here as a point
There is also a flagged API in Node for this, `import.meta.resolve`: https://github.com/nodejs/node/pull/31032. Not sure if we should care too much about it, though?
I _think_ that covers it, but you know way more about this subject than I do, so feel free to either close this to open up your own, or edit this OP as you see fit 👍
---
For background, Jest uses `resolve` as the default implementation in `jest-resolve`, although the user can swap it out. I'm currently working on [support for ESM natively in Jest](https://github.com/facebook/jest/issues/9430), and while we have a version today that sorta works, it's not a compliant implementation. Most of the (known) issues are due to resolution logic. I'd be happy to help implement support here in `resolve`.
Contributor guide
Assessment
This issue has not been assessed yet.