-
Notifications
You must be signed in to change notification settings - Fork 363
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
feat: Support customizing the modern output via "exports" #784
Conversation
🦋 Changeset detectedLatest commit: 3ccfefd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
src/index.js
Outdated
@@ -280,7 +280,10 @@ function getMain({ options, entry, format }) { | |||
mainNoExtension, | |||
); | |||
mainsByFormat.modern = replaceName( | |||
(pkg.syntax && pkg.syntax.esmodules) || pkg.esmodule || 'x.modern.js', | |||
(typeof pkg.exports === 'string' && pkg.exports) || |
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 works for the main case. I'm wondering - maybe we could walk the exports object to find matching import
entries?
function walk(exports) {
if (typeof exports === 'string') return exports;
return walk(exports['.'] || exports.import || exports.module);
}
walk(pkg.exports)
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.
Certainly could. I started to think about this but had reservations on whether or not users would expect all keys (or at least the ones in the spec?) to be supported. If they have a "require"
, would they then expect a matching output file? Not sure.
Co-authored-by: Jason Miller <[email protected]>
Summary
Closes #783
Allows users to customize modern output file name with
exports
like they can withesmodules
.