Skip to content

Add an exports map to package.json #183

Open
@dzearing

Description

@dzearing

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions