-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Description
Affected URL(s)
https://nodejs.org/api/packages.html#subpath-patterns
Description of the problem
The current documentation for subpath patterns gives this example for preventing export of a private path:
// ./node_modules/es-module-package/package.json
{
"exports": {
"./features/*.js": "./src/features/*.js",
"./features/private-internal/*": null
}
}
//// Consuming code
import featureInternal from 'es-module-package/features/private-internal/m.js';
// Throws: ERR_PACKAGE_PATH_NOT_EXPORTEDThis is somewhat confusing in the context of the following section about conditional exports, which says that
Within the "exports" object, key order is significant. During condition matching, earlier entries have higher priority and take precedence over later entries. The general rule is that conditions should be from most specific to least specific in object order.
The documented behavior suggests that conditional matching stops when it finds the first matching entry, while subpath pattern matching reads all paths and somehow chooses one. Does null value (preventing export) override any other matches? What if two paths match and don't have a null value? Should null-value patterns always be specified last? If not, is there a suggested or canonical ordering? The docs should explain this, possibly with more subath-pattern examples.