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

doc: esm: improve dual package hazard docs #30345

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
doc: esm: give "main" a heading, mention other entry points
  • Loading branch information
GeoffreyBooth committed Nov 13, 2019
commit c9b6df34e59ef3ce402c83a6c6167d5d3d5982d1
10 changes: 9 additions & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ unspecified.

### Package Entry Points

#### <code>package.json</code> <code>"main"</code>

The `package.json` `"main"` field defines the entry point for a package,
whether the package is included into CommonJS via `require` or into an ES
module via `import`.
Expand Down Expand Up @@ -219,7 +221,12 @@ The `"main"` field can point to exactly one file, regardless of whether the
package is referenced via `require` (in a CommonJS context) or `import` (in an
ES module context).

### Package Exports
[Package Exports][] provide an alternative to `"main"` where the package main
entry point can be defined while also encapsulating the package, preventing any
other entry points besides those defined in `"exports"`. If package entry points
are defined in both `"main"` and `"exports"`, the latter takes precedence.

#### Package Exports

By default, all subpaths from a package can be imported (`import 'pkg/x.js'`).
Custom subpath aliasing and encapsulation can be provided through the
Expand Down Expand Up @@ -1385,6 +1392,7 @@ success!
[ECMAScript-modules implementation]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
[ES Module Integration Proposal for Web Assembly]: https://github.com/webassembly/esm-integration
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
[Package Exports]: #esm_package_exports
[Terminology]: #esm_terminology
[WHATWG JSON modules specification]: https://html.spec.whatwg.org/#creating-a-json-module-script
[`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
Expand Down