diff --git a/doc/api/packages.md b/doc/api/packages.md index 00285bd6157e54..5f6f1e78edc33c 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -8,7 +8,9 @@ changes: - v14.13.0 pr-url: https://github.com/nodejs/node/pull/34718 description: Add support for `"exports"` patterns. - - version: v14.6.0 + - version: + - v14.6.0 + - v12.19.0 pr-url: https://github.com/nodejs/node/pull/34117 description: Add package `"imports"` field. - version: @@ -135,6 +137,9 @@ package: `"commonjs"` package). ### `--input-type` flag + Strings passed in as an argument to `--eval` (or `-e`), or piped to `node` via `STDIN`, are treated as [ES modules][] when the `--input-type=module` flag @@ -252,6 +257,9 @@ absolute subpath of the package such as `require('/path/to/node_modules/pkg/subpath.js')` will still load `subpath.js`. ### Subpath exports + When using the [`"exports"`][] field, custom subpaths can be defined along with the main entry point by treating the main entry point as the @@ -282,6 +290,11 @@ import submodule from 'es-module-package/private-module.js'; ``` ### Subpath imports + In addition to the [`"exports"`][] field, it is possible to define internal package import maps that only apply to import specifiers from within the package @@ -319,6 +332,11 @@ The resolution rules for the imports field are otherwise analogous to the exports field. ### Subpath patterns + For packages with a small number of exports or imports, we recommend explicitly listing each exports subpath entry. But for packages that have @@ -365,6 +383,9 @@ files within the package. Because `node_modules` paths are forbidden in exports targets, this expansion is dependent on only the files of the package itself. ### Exports sugar + If the `"."` export is the only export, the [`"exports"`][] field provides sugar for this case being the direct [`"exports"`][] field value. @@ -389,6 +410,17 @@ can be written: ``` ### Conditional exports + Conditional exports provide a way to map to different paths depending on certain conditions. They are supported for both CommonJS and ES module imports. @@ -487,6 +519,11 @@ the remaining conditions of the parent condition. In this way nested conditions behave analogously to nested JavaScript `if` statements. ### Resolving user conditions + When running Node.js, custom user conditions can be added with the `--conditions` flag: @@ -548,6 +585,17 @@ The above definitions may be moved to a dedicated conditions registry in due course. ### Self-referencing a package using its name + Within a package, the values defined in the package’s `package.json` [`"exports"`][] field can be referenced via the package’s name.