Skip to content

Commit

Permalink
module: runtime deprecate subpath folder mappings
Browse files Browse the repository at this point in the history
PR-URL: #37215
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
  • Loading branch information
aduh95 committed Mar 20, 2021
1 parent d4693ff commit 3cc9aec
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
16 changes: 7 additions & 9 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2697,24 +2697,22 @@ Use `fs.rm(path, { recursive: true, force: true })`,
### DEP0148: Folder mappings in `"exports"` (trailing `"/"`)
<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/37215
description: Runtime deprecation.
- version: v15.1.0
pr-url: https://github.com/nodejs/node/pull/35747
description: Runtime deprecation.
description: Runtime deprecation for self-referencing imports.
- version: v14.13.0
pr-url: https://github.com/nodejs/node/pull/34718
description: Documentation-only deprecation.
-->

Type: Runtime (supports [`--pending-deprecation`][])
Type: Runtime

Prior to [subpath patterns][] support, it was possible to define
Using a trailing `"/"` to define
[subpath folder mappings][] in the [subpath exports][] or
[subpath imports][] fields using a trailing `"/"`.

Without `--pending-deprecation`, runtime warnings occur only for exports
resolutions not in `node_modules`. This means there will not be deprecation
warnings for `"exports"` in dependencies. With `--pending-deprecation`, a
runtime warning results no matter where the `"exports"` usage occurs.
[subpath imports][] fields is deprecated. Use [subpath patterns][] instead.

### DEP0149: `http.IncomingMessage#connection`
<!-- YAML
Expand Down
7 changes: 5 additions & 2 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,12 @@ targets, this expansion is dependent on only the files of the package itself.
### Subpath folder mappings
<!-- YAML
changes:
- version: v15.1.0
pr-url: https://github.com/nodejs/node/pull/35746
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/37215
description: Runtime deprecation.
- version: v15.1.0
pr-url: https://github.com/nodejs/node/pull/35747
description: Runtime deprecation for self-referencing imports.
- version:
- v14.13.0
- v12.20.0
Expand Down
16 changes: 1 addition & 15 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const {
String,
StringPrototypeEndsWith,
StringPrototypeIndexOf,
StringPrototypeLastIndexOf,
StringPrototypeReplace,
StringPrototypeSlice,
StringPrototypeSplit,
Expand Down Expand Up @@ -60,23 +59,10 @@ const userConditions = getOptionValue('--conditions');
const DEFAULT_CONDITIONS = ObjectFreeze(['node', 'import', ...userConditions]);
const DEFAULT_CONDITIONS_SET = new SafeSet(DEFAULT_CONDITIONS);

const pendingDeprecation = getOptionValue('--pending-deprecation');
const emittedPackageWarnings = new SafeSet();
function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) {
const pjsonPath = fileURLToPath(pjsonUrl);
if (!pendingDeprecation) {
const nodeModulesIndex =
StringPrototypeLastIndexOf(pjsonPath, sep + 'node_modules' + sep);
if (nodeModulesIndex !== -1) {
const afterNodeModulesPath =
StringPrototypeSlice(pjsonPath, nodeModulesIndex + 14, -13);
try {
const { packageSubpath } = parsePackageName(afterNodeModulesPath);
if (packageSubpath === '.')
return;
} catch {}
}
}

if (emittedPackageWarnings.has(pjsonPath + '|' + match))
return;
emittedPackageWarnings.add(pjsonPath + '|' + match);
Expand Down
3 changes: 2 additions & 1 deletion test/es-module/test-esm-local-deprecations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const deprecatedFoldersIgnore =

const expectedWarnings = [
'"./" in the "exports" field',
'"#self/" in the "imports" field'
'"#self/" in the "imports" field',
'"./folder/" in the "exports" field',
];

process.addListener('warning', (warning) => {
Expand Down

0 comments on commit 3cc9aec

Please sign in to comment.