From 332521e3109451de3de6b208002806e0aef2741b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 9 Feb 2021 11:42:18 +0100 Subject: [PATCH] doc: add version metadata for packages features PR-URL: https://github.com/nodejs/node/pull/37289 Reviewed-By: Guy Bedford Reviewed-By: Luigi Pinca --- doc/api/packages.md | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/doc/api/packages.md b/doc/api/packages.md index 658e74af15551c..6c99e1e0a4175a 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -9,7 +9,9 @@ changes: - v12.20.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: @@ -136,6 +138,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 @@ -253,6 +258,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 @@ -283,6 +291,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 @@ -320,6 +333,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 @@ -407,6 +425,9 @@ The benefit of patterns over folder exports is that packages can always be imported by consumers without subpath file extensions being necessary. ### Exports sugar + If the `"."` export is the only export, the [`"exports"`][] field provides sugar for this case being the direct [`"exports"`][] field value. @@ -431,6 +452,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. @@ -529,6 +561,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: @@ -590,6 +627,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.