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

add exports field to package.json #659

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bschlenk
Copy link

@bschlenk bschlenk commented Apr 16, 2024

fixes #646

Left some inline comments on what each part is for. Mostly I'm being defensive, so that if any of these import patterns are already in use, they'll still work and this can be a minor version bump.

I'd recommend at some point locking this down to just the . and the package.json entries and making that a major version bump.

@@ -8,6 +8,21 @@
"main": "dist/a11y-dialog.js",
"module": "dist/a11y-dialog.esm.js",
"types": "dist/a11y-dialog.d.ts",
"exports": {
".": {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you do import A11yDialog from 'a11y-dialog' you get ./dist/a11y-dialog.esm.js, and when you do const A11yDialog = require('a11y-dialog) you get ./dist/a11y-dialog.js

Comment on lines +17 to +18
"dist/*.esm.js": "./dist/*.esm.js",
"dist/*.js": "./dist/*.js",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone is importing using an exact extension, give them what they asked for

Comment on lines +19 to +23
"dist/*": {
"import": "./dist/*.esm.js",
"require": "./dist/*.js",
"types": "./dist/*.d.ts"
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise if the extension is omitted, use the appropriate extension depending on import or require

"require": "./dist/*.js",
"types": "./dist/*.d.ts"
},
"package.json": "./package.json"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

general best practice to allow importing your package.json

@KittyGiraudel
Copy link
Owner

Thank you so much for the PR and the explanations! Do you think we should do that in v9 or is it safe to ship as is? Is there any import that could potentially break when setting this up?

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 this pull request may close these issues.

Package.json has type: module but main still points at commonjs
2 participants