diff options
author | Guy Bedford <guybedford@gmail.com> | 2021-05-18 19:39:06 +0300 |
---|---|---|
committer | Richard Lau <rlau@redhat.com> | 2021-07-20 14:11:18 +0300 |
commit | 8049b69b7f067ae72ce66ec865d760b9359b2048 (patch) | |
tree | 5a0b7b73a49600fbb527b88bea9757f7174a9e19 /doc/api/packages.md | |
parent | e265d8ee1b10ddfe0fdddf2287c295d71c5c2530 (diff) |
doc: document null target pattern
PR-URL: https://github.com/nodejs/node/pull/38724
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/packages.md')
-rw-r--r-- | doc/api/packages.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/doc/api/packages.md b/doc/api/packages.md index 6f7fbf64cab..35ed4d4f024 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -357,6 +357,9 @@ For these use cases, subpath export patterns can be used instead: } ``` +**`*` maps expose nested subpaths as it is a string replacement syntax +only.** + The left hand matching pattern must always end in `*`. All instances of `*` on the right hand side will then be replaced with this value, including if it contains any `/` separators. @@ -382,6 +385,26 @@ treating the right hand side target pattern as a `**` glob against the list of 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. +To exclude private subfolders from patterns, `null` targets can be used: + +```json +// ./node_modules/es-module-package/package.json +{ + "exports": { + "./features/*": "./src/features/*.js", + "./features/private-internal/*": null + } +} +``` + +```js +import featureInternal from 'es-module-package/features/private-internal/m'; +// Throws: ERR_PACKAGE_PATH_NOT_EXPORTED + +import featureX from 'es-module-package/features/x'; +// Loads ./node_modules/es-module-package/src/features/x.js +``` + ### Exports sugar <!--YAML added: v12.11.0 |