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 an exports map to package.json #183

Open
dzearing opened this issue Mar 29, 2024 · 0 comments
Open

Add an exports map to package.json #183

dzearing opened this issue Mar 29, 2024 · 0 comments

Comments

@dzearing
Copy link

dzearing commented Mar 29, 2024

TLDR: this package is missing an exports map in package.json and needs one.

When deep imports like dom-helpers/addClass are allowed, we would like them to be explicitly specified in the package.json exports map. This provides some safety features:

  • Consumers can't import something you don't expect to be an api surface
  • You can safely reorganize your package (move things around, rename things, change filename casing) without breaking consumers, since exports maps allow the producer to map how the import resolves.
  • You can provide both commonjs and esm entry points without requiring the consumer to remap things in webpack config should that want to use another module format
  • It becomes possible to ditch the nested package.jsons, reducing complexity of understanding how imports resolve to source files.

Example exports map:

{
  "exports": {
    ".": {
      "types": "./lib/index.d.ts",
      "require": "./lib-commonjs/index.cjs",
      "import": "./lib/index.js"
    },
    "./addClass": {
      "types": "./lib/addClass.d.ts",
      "require": "./lib-commonjs/addClass.cjs",
      "import": "./lib/addClass.js",
   },
   // etc
}
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

No branches or pull requests

1 participant