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

New Entry Points #238

Closed
8 tasks done
evanplaice opened this issue Jan 27, 2020 · 1 comment
Closed
8 tasks done

New Entry Points #238

evanplaice opened this issue Jan 27, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@evanplaice
Copy link
Member

evanplaice commented Jan 27, 2020

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

@evanplaice evanplaice added the enhancement New feature or request label Jan 27, 2020
@evanplaice evanplaice changed the title Breaking Change - pkg.exports Breaking Change - New Entry Points Jan 27, 2020
@evanplaice evanplaice changed the title Breaking Change - New Entry Points Marking ESM Use in Node as Experimental Feb 2, 2020
@evanplaice evanplaice changed the title Marking ESM Use in Node as Experimental New Entry Points Feb 4, 2020
@evanplaice
Copy link
Member Author

evanplaice commented Feb 4, 2020

Added in v1.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant