Skip to content

Commit

Permalink
doc: document null target pattern
Browse files Browse the repository at this point in the history
PR-URL: #38724
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Derek Lewis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
guybedford authored and richardlau committed Jul 16, 2021
1 parent 4ecf9b0 commit 21a306d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 21a306d

Please sign in to comment.