Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: runtime deprecate subpath folder mappings #37215

Merged
merged 1 commit into from
Mar 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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