vanillaes/absurdum

New Entry Points

evanplaice opened this issue · 1 comments

Node 13.7 introduced the new pkg.exports proposal

This will simplify the workflow for Node consumers. Instead of CJS (CommonJS) directly importing the CJS bundle, they can use a regular bare import. Ex const absurdum = require('absurdum').

BREAKING Experimental
This changes the meaning of pkg.main. Instead of pointing to the ESM entry-point, it can be reassigned to the CJS bundle for backward compat with <13.2 Node.

New Entry Points
The new pkg.exports rollout also includes the ability to assign Conditional Exports. In short, entry points can be defined to allow importing of the arrays, objects, strings groups directly.

Why? A limitation or Webpack's tree-shaking is that it doesn't work with export * as ns style re-exports. It won't eliminate unused parts when the main entry point is used.

This will also enable named exports from each group in ESM

import { without } from 'absurdum/arrays';

Changes

1.x

  • add pkg.engines -> node >= 13.2
  • add CHANGELOG.md

2.x

  • remove pkg.module
  • change pkg.engines -> node >= 13.7
  • remove 'CommonJS' section from README.md
  • add *.cjs bundles for arrays, objects, strings
  • update CHANGELOG.md with notes on the breaking change
  • add 'Webpack' section to README.md
  • add 'Legacy' section to README.md
  • Add namespace-specific exports for ESM
  • Update README.md w/ an notice for Node users?
  • Update tests to rely on self-referencing import specifiers

Notes

package.json

{
  "type": "module",
  "main": "index.cjs",
  "exports": {
    ".": {
      "import": "./index.js",
      "require": "./index.cjs"
    },
    "./arrays": {
      "import": "./src/arrays/index.js",
      "require": "./src/arrays/index.cjs"
    },
    "./objects": {
      "import": "./src/objects/index.js",
      "require": "./src/objects/index.cjs"
    },
    "./strings": {
      "import": "./src/strings/index.js",
      "require": "./src/strings/index.cjs"
    }
  }
}

References

Added in v1.1.0