Skip to content

Commit 36e2ffe

Browse files
committed
module: subpath folder mappings EOL
PR-URL: #40121 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 0991dfc commit 36e2ffe

File tree

11 files changed

+81
-237
lines changed

11 files changed

+81
-237
lines changed

doc/api/deprecations.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,9 @@ Use `fs.rm(path, { recursive: true, force: true })`,
27072707
### DEP0148: Folder mappings in `"exports"` (trailing `"/"`)
27082708
<!-- YAML
27092709
changes:
2710+
- version: REPLACEME
2711+
pr-url: https://github.com/nodejs/node/pull/40121
2712+
description: End-of-Life.
27102713
- version: v16.0.0
27112714
pr-url: https://github.com/nodejs/node/pull/37215
27122715
description: Runtime deprecation.
@@ -2720,9 +2723,9 @@ changes:
27202723

27212724
Type: Runtime
27222725

2723-
Using a trailing `"/"` to define
2724-
[subpath folder mappings][] in the [subpath exports][] or
2725-
[subpath imports][] fields is deprecated. Use [subpath patterns][] instead.
2726+
Using a trailing `"/"` to define subpath folder mappings in the
2727+
[subpath exports][] or [subpath imports][] fields is deprecated. Use
2728+
[subpath patterns][] instead.
27262729

27272730
### DEP0149: `http.IncomingMessage#connection`
27282731
<!-- YAML
@@ -2965,6 +2968,5 @@ for package `"exports"` and `"imports"` pattern resolutions.
29652968
[legacy `urlObject`]: url.md#legacy-urlobject
29662969
[static methods of `crypto.Certificate()`]: crypto.md#class-certificate
29672970
[subpath exports]: packages.md#subpath-exports
2968-
[subpath folder mappings]: packages.md#subpath-folder-mappings
29692971
[subpath imports]: packages.md#subpath-imports
29702972
[subpath patterns]: packages.md#subpath-patterns

doc/api/esm.md

+31-51
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,8 @@ The resolver can throw the following errors:
10681068
> 1. Set _resolved_ to the URL resolution of _specifier_ relative to
10691069
> _parentURL_.
10701070
> 1. Otherwise, if _specifier_ starts with _"#"_, then
1071-
> 1. Set _resolved_ to the destructured value of the result of
1072-
> **PACKAGE_IMPORTS_RESOLVE**(_specifier_, _parentURL_,
1073-
> _defaultConditions_).
1071+
> 1. Set _resolved_ to the result of **PACKAGE_IMPORTS_RESOLVE**(_specifier_,
1072+
> _parentURL_, _defaultConditions_).
10741073
> 1. Otherwise,
10751074
> 1. Note: _specifier_ is now a bare specifier.
10761075
> 1. Set _resolved_ the result of
@@ -1103,7 +1102,7 @@ The resolver can throw the following errors:
11031102
> 1. If _packageName_ starts with _"."_ or contains _"\\"_ or _"%"_, then
11041103
> 1. Throw an _Invalid Module Specifier_ error.
11051104
> 1. Let _packageSubpath_ be _"."_ concatenated with the substring of
1106-
> _packageSpecifier_ from the position at the length of _packageName_.
1105+
> _packageSpecifier_ from the position at the length of _packageName_.
11071106
> 1. Let _selfUrl_ be the result of
11081107
> **PACKAGE_SELF_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
11091108
> 1. If _selfUrl_ is not **undefined**, return _selfUrl_.
@@ -1121,11 +1120,10 @@ The resolver can throw the following errors:
11211120
> 1. If _pjson_ is not **null** and _pjson_._exports_ is not **null** or
11221121
> **undefined**, then
11231122
> 1. Let _exports_ be _pjson.exports_.
1124-
> 1. Return the _resolved_ destructured value of the result of
1125-
> **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packageSubpath_,
1126-
> _pjson.exports_, _defaultConditions_).
1123+
> 1. Return the result of **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
1124+
> _packageSubpath_, _pjson.exports_, _defaultConditions_).
11271125
> 1. Otherwise, if _packageSubpath_ is equal to _"."_, then
1128-
> 1. Return the result applying the legacy **LOAD_AS_DIRECTORY**
1126+
> 1. Return the result of applying the legacy **LOAD_AS_DIRECTORY**
11291127
> CommonJS resolver to _packageURL_, throwing a _Module Not Found_
11301128
> error for no resolution.
11311129
> 1. Otherwise,
@@ -1142,13 +1140,14 @@ The resolver can throw the following errors:
11421140
> **undefined**, then
11431141
> 1. Return **undefined**.
11441142
> 1. If _pjson.name_ is equal to _packageName_, then
1145-
> 1. Return the _resolved_ destructured value of the result of
1146-
> **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, _pjson.exports_,
1147-
> _defaultConditions_).
1143+
> 1. Return the result of **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
1144+
> _subpath_, _pjson.exports_, _defaultConditions_).
11481145
> 1. Otherwise, return **undefined**.
11491146

11501147
**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_)
11511148

1149+
> 1. If _subpath_ ends in _"/"_, then
1150+
> 1. Throw an _Invalid Module Specifier_ error.
11521151
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
11531152
> starting with _"."_, throw an _Invalid Package Configuration_ error.
11541153
> 1. If _subpath_ is equal to _"."_, then
@@ -1162,53 +1161,45 @@ The resolver can throw the following errors:
11621161
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
11631162
> _packageURL_, _mainExport_, _""_, **false**, **false**,
11641163
> _conditions_).
1165-
> 1. If _resolved_ is not **null** or **undefined**, then
1166-
> 1. Return _resolved_.
1164+
> 1. If _resolved_ is not **null** or **undefined**, return _resolved_.
11671165
> 1. Otherwise, if _exports_ is an Object and all keys of _exports_ start with
11681166
> _"."_, then
11691167
> 1. Let _matchKey_ be the string _"./"_ concatenated with _subpath_.
1170-
> 1. Let _resolvedMatch_ be result of **PACKAGE_IMPORTS_EXPORTS_RESOLVE**(
1168+
> 1. Let _resolved_ be the result of **PACKAGE_IMPORTS_EXPORTS_RESOLVE**(
11711169
> _matchKey_, _exports_, _packageURL_, **false**, _conditions_).
1172-
> 1. If _resolvedMatch_._resolve_ is not **null** or **undefined**, then
1173-
> 1. Return _resolvedMatch_.
1170+
> 1. If _resolved_ is not **null** or **undefined**, return _resolved_.
11741171
> 1. Throw a _Package Path Not Exported_ error.
11751172

11761173
**PACKAGE_IMPORTS_RESOLVE**(_specifier_, _parentURL_, _conditions_)
11771174

11781175
> 1. Assert: _specifier_ begins with _"#"_.
1179-
> 1. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
1176+
> 1. If _specifier_ is exactly equal to _"#"_, starts with _"#/"_, or ends in
1177+
> _"/"_, then
11801178
> 1. Throw an _Invalid Module Specifier_ error.
11811179
> 1. Let _packageURL_ be the result of **READ_PACKAGE_SCOPE**(_parentURL_).
11821180
> 1. If _packageURL_ is not **null**, then
11831181
> 1. Let _pjson_ be the result of **READ_PACKAGE_JSON**(_packageURL_).
11841182
> 1. If _pjson.imports_ is a non-null Object, then
1185-
> 1. Let _resolvedMatch_ be the result of
1186-
> **PACKAGE_IMPORTS_EXPORTS_RESOLVE**(_specifier_, _pjson.imports_,
1187-
> _packageURL_, **true**, _conditions_).
1188-
> 1. If _resolvedMatch_._resolve_ is not **null** or **undefined**, then
1189-
> 1. Return _resolvedMatch_.
1183+
> 1. Let _resolved_ be the result of **PACKAGE_IMPORTS_EXPORTS_RESOLVE**(
1184+
> _specifier_, _pjson.imports_, _packageURL_, **true**, _conditions_).
1185+
> 1. If _resolved_ is not **null** or **undefined**, return _resolved_.
11901186
> 1. Throw a _Package Import Not Defined_ error.
11911187

11921188
**PACKAGE_IMPORTS_EXPORTS_RESOLVE**(_matchKey_, _matchObj_, _packageURL_,
11931189
_isImports_, _conditions_)
11941190

1195-
> 1. If _matchKey_ is a key of _matchObj_ and does not end in _"/"_ or contain
1196-
> _"*"_, then
1191+
> 1. Assert: _matchKey_ does not end in _"/"_.
1192+
> 1. If _matchKey_ is a key of _matchObj_ and does not contain _"*"_, then
11971193
> 1. Let _target_ be the value of _matchObj_\[_matchKey_\].
1198-
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1199-
> _packageURL_, _target_, _""_, **false**, _isImports_, _conditions_).
1200-
> 1. Return the object _{ resolved, exact: **true** }_.
1201-
> 1. Let _expansionKeys_ be the list of keys of _matchObj_ either ending in
1202-
> _"/"_ or containing only a single _"*"_, sorted by the sorting function
1203-
> **PATTERN_KEY_COMPARE** which orders in descending order of specificity.
1194+
> 1. Return the result of **PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_,
1195+
> _""_, **false**, _isImports_, _conditions_).
1196+
> 1. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a
1197+
> single _"*"_, sorted by the sorting function **PATTERN_KEY_COMPARE** which
1198+
> orders in descending order of specificity.
12041199
> 1. For each key _expansionKey_ in _expansionKeys_, do
1205-
> 1. Let _patternBase_ be **null**.
1206-
> 1. If _expansionKey_ contains _"*"_, set _patternBase_ to the substring of
1207-
> _expansionKey_ up to but excluding the first _"*"_ character.
1208-
> 1. If _patternBase_ is not **null** and _matchKey_ starts with but is not
1209-
> equal to _patternBase_, then
1210-
> 1. If _matchKey_ ends with _"/"_, throw an _Invalid Module Specifier_
1211-
> error.
1200+
> 1. Let _patternBase_ be the substring of _expansionKey_ up to but excluding
1201+
> the first _"*"_ character.
1202+
> 1. If _matchKey_ starts with but is not equal to _patternBase_, then
12121203
> 1. Let _patternTrailer_ be the substring of _expansionKey_ from the
12131204
> index after the first _"*"_ character.
12141205
> 1. If _patternTrailer_ has zero length, or if _matchKey_ ends with
@@ -1218,20 +1209,9 @@ _isImports_, _conditions_)
12181209
> 1. Let _subpath_ be the substring of _matchKey_ starting at the
12191210
> index of the length of _patternBase_ up to the length of
12201211
> _matchKey_ minus the length of _patternTrailer_.
1221-
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1222-
> _packageURL_, _target_, _subpath_, **true**, _isImports_,
1223-
> _conditions_).
1224-
> 1. Return the object _{ resolved, exact: **true** }_.
1225-
> 1. Otherwise if _patternBase_ is **null** and _matchKey_ starts with
1226-
> _expansionKey_, then
1227-
> 1. Let _target_ be the value of _matchObj_\[_expansionKey_\].
1228-
> 1. Let _subpath_ be the substring of _matchKey_ starting at the
1229-
> index of the length of _expansionKey_.
1230-
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
1231-
> _packageURL_, _target_, _subpath_, **false**, _isImports_,
1232-
> _conditions_).
1233-
> 1. Return the object _{ resolved, exact: **false** }_.
1234-
> 1. Return the object _{ resolved: **null**, exact: **true** }_.
1212+
> 1. Return the result of **PACKAGE_TARGET_RESOLVE**(_packageURL_,
1213+
> _target_, _subpath_, **true**, _isImports_, _conditions_).
1214+
> 1. Return **null**.
12351215

12361216
**PATTERN_KEY_COMPARE**(_keyA_, _keyB_)
12371217

doc/api/packages.md

-45
Original file line numberDiff line numberDiff line change
@@ -422,50 +422,6 @@ import featureX from 'es-module-package/features/x';
422422
// Loads ./node_modules/es-module-package/src/features/x.js
423423
```
424424

425-
### Subpath folder mappings
426-
<!-- YAML
427-
changes:
428-
- version: v16.0.0
429-
pr-url: https://github.com/nodejs/node/pull/37215
430-
description: Runtime deprecation.
431-
- version: v15.1.0
432-
pr-url: https://github.com/nodejs/node/pull/35747
433-
description: Runtime deprecation for self-referencing imports.
434-
- version:
435-
- v14.13.0
436-
- v12.20.0
437-
pr-url: https://github.com/nodejs/node/pull/34718
438-
description: Documentation-only deprecation.
439-
-->
440-
441-
> Stability: 0 - Deprecated: Use subpath patterns instead.
442-
443-
Before subpath patterns were supported, a trailing `"/"` suffix was used to
444-
support folder mappings:
445-
446-
```json
447-
{
448-
"exports": {
449-
"./features/": "./features/"
450-
}
451-
}
452-
```
453-
454-
_This feature will be removed in a future release._
455-
456-
Instead, use direct [subpath patterns][]:
457-
458-
```json
459-
{
460-
"exports": {
461-
"./features/*": "./features/*.js"
462-
}
463-
}
464-
```
465-
466-
The benefit of patterns over folder exports is that packages can always be
467-
imported by consumers without subpath file extensions being necessary.
468-
469425
### Exports sugar
470426
<!-- YAML
471427
added: v12.11.0
@@ -1270,7 +1226,6 @@ This field defines [subpath imports][] for the current package.
12701226
[self-reference]: #self-referencing-a-package-using-its-name
12711227
[subpath exports]: #subpath-exports
12721228
[subpath imports]: #subpath-imports
1273-
[subpath patterns]: #subpath-patterns
12741229
[supported package managers]: corepack.md#supported-package-managers
12751230
[the dual CommonJS/ES module packages section]: #dual-commonjses-module-packages
12761231
[the full specifier path]: esm.md#mandatory-file-extensions

lib/internal/modules/cjs/loader.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ function trySelf(parentPath, request) {
457457
try {
458458
return finalizeEsmResolution(packageExportsResolve(
459459
pathToFileURL(pkgPath + '/package.json'), expansion, pkg,
460-
pathToFileURL(parentPath), cjsConditions), request, parentPath, pkgPath);
460+
pathToFileURL(parentPath), cjsConditions), parentPath, pkgPath);
461461
} catch (e) {
462462
if (e.code === 'ERR_MODULE_NOT_FOUND')
463463
throw createEsmNotFoundErr(request, pkgPath + '/package.json');
@@ -481,7 +481,7 @@ function resolveExports(nmPath, request) {
481481
try {
482482
return finalizeEsmResolution(packageExportsResolve(
483483
pathToFileURL(pkgPath + '/package.json'), '.' + expansion, pkg, null,
484-
cjsConditions), request, null, pkgPath);
484+
cjsConditions), null, pkgPath);
485485
} catch (e) {
486486
if (e.code === 'ERR_MODULE_NOT_FOUND')
487487
throw createEsmNotFoundErr(request, pkgPath + '/package.json');
@@ -894,7 +894,7 @@ Module._resolveFilename = function(request, parent, isMain, options) {
894894
try {
895895
return finalizeEsmResolution(
896896
packageImportsResolve(request, pathToFileURL(parent.filename),
897-
cjsConditions), request, parent.filename,
897+
cjsConditions), parent.filename,
898898
pkg.path);
899899
} catch (e) {
900900
if (e.code === 'ERR_MODULE_NOT_FOUND')
@@ -936,18 +936,12 @@ Module._resolveFilename = function(request, parent, isMain, options) {
936936
throw err;
937937
};
938938

939-
function finalizeEsmResolution(match, request, parentPath, pkgPath) {
940-
const { resolved, exact } = match;
939+
function finalizeEsmResolution(resolved, parentPath, pkgPath) {
941940
if (RegExpPrototypeTest(encodedSepRegEx, resolved))
942941
throw new ERR_INVALID_MODULE_SPECIFIER(
943942
resolved, 'must not include encoded "/" or "\\" characters', parentPath);
944943
const filename = fileURLToPath(resolved);
945-
let actual = tryFile(filename);
946-
if (!exact && !actual) {
947-
const exts = ObjectKeys(Module._extensions);
948-
actual = tryExtensions(filename, exts, false) ||
949-
tryPackage(filename, exts, false, request);
950-
}
944+
const actual = tryFile(filename);
951945
if (actual)
952946
return actual;
953947
const err = createEsmNotFoundErr(filename,

0 commit comments

Comments
 (0)