From 96fa38708224025a04890c5ffbeaa5f967ea87c0 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 18 May 2021 18:39:06 +0200 Subject: [PATCH] doc: document null target pattern PR-URL: https://github.com/nodejs/node/pull/38724 Reviewed-By: Antoine du Hamel Reviewed-By: Derek Lewis Reviewed-By: James M Snell --- doc/api/packages.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/doc/api/packages.md b/doc/api/packages.md index f91184208af43e..6e87336a0095c6 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -358,6 +358,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. @@ -383,6 +386,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 +``` + ### Subpath folder mappings