From 01213c71b9f1120b86ee584ed61a8f0f09bc9db2 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 9 Jan 2021 20:32:40 -0500 Subject: [PATCH] module: fix Windows folder exports deprecation warning PR-URL: https://github.com/nodejs/node/pull/36859 Reviewed-By: Antoine du Hamel Reviewed-By: James M Snell Reviewed-By: Geoffrey Booth Reviewed-By: Myles Borins --- lib/internal/modules/esm/resolve.js | 9 ++++----- test/es-module/test-esm-local-deprecations.mjs | 4 ++++ .../es-modules/deprecated-folders-ignore/main.js | 1 + .../deprecated-folders-ignore/node_modules/pkg/m.js | 1 + .../node_modules/pkg/package.json | 7 +++++++ .../es-modules/deprecated-folders-ignore/package.json | 4 ++++ 6 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/es-modules/deprecated-folders-ignore/main.js create mode 100644 test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/m.js create mode 100644 test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/package.json create mode 100644 test/fixtures/es-modules/deprecated-folders-ignore/package.json diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 8a5bc841ada22a..98683441586784 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -65,12 +65,11 @@ const emittedPackageWarnings = new SafeSet(); function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) { const pjsonPath = fileURLToPath(pjsonUrl); if (!pendingDeprecation) { - const nodeModulesIndex = StringPrototypeLastIndexOf(pjsonPath, - '/node_modules/'); + const nodeModulesIndex = + StringPrototypeLastIndexOf(pjsonPath, sep + 'node_modules' + sep); if (nodeModulesIndex !== -1) { - const afterNodeModulesPath = StringPrototypeSlice(pjsonPath, - nodeModulesIndex + 14, - -13); + const afterNodeModulesPath = + StringPrototypeSlice(pjsonPath, nodeModulesIndex + 14, -13); try { const { packageSubpath } = parsePackageName(afterNodeModulesPath); if (packageSubpath === '.') diff --git a/test/es-module/test-esm-local-deprecations.mjs b/test/es-module/test-esm-local-deprecations.mjs index 96d8cd1c8af735..5a6638d1d90e5a 100644 --- a/test/es-module/test-esm-local-deprecations.mjs +++ b/test/es-module/test-esm-local-deprecations.mjs @@ -6,6 +6,9 @@ import { pathToFileURL } from 'url'; const selfDeprecatedFolders = fixtures.path('/es-modules/self-deprecated-folders/main.js'); +const deprecatedFoldersIgnore = + fixtures.path('/es-modules/deprecated-folders-ignore/main.js'); + let curWarning = 0; const expectedWarnings = [ '"./" in the "exports" field', @@ -18,5 +21,6 @@ process.addListener('warning', mustCall((warning) => { (async () => { await import(pathToFileURL(selfDeprecatedFolders)); + await import(pathToFileURL(deprecatedFoldersIgnore)); })() .catch((err) => console.error(err)); diff --git a/test/fixtures/es-modules/deprecated-folders-ignore/main.js b/test/fixtures/es-modules/deprecated-folders-ignore/main.js new file mode 100644 index 00000000000000..88ffe3fe34a5a0 --- /dev/null +++ b/test/fixtures/es-modules/deprecated-folders-ignore/main.js @@ -0,0 +1 @@ +import 'pkg/folder/m.js'; diff --git a/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/m.js b/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/m.js new file mode 100644 index 00000000000000..7646bbd17d04a0 --- /dev/null +++ b/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/m.js @@ -0,0 +1 @@ +export default null; diff --git a/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/package.json b/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/package.json new file mode 100644 index 00000000000000..c3baf35ea96736 --- /dev/null +++ b/test/fixtures/es-modules/deprecated-folders-ignore/node_modules/pkg/package.json @@ -0,0 +1,7 @@ +{ + "exports": { + "./folder/": "./" + }, + "type": "module" +} + diff --git a/test/fixtures/es-modules/deprecated-folders-ignore/package.json b/test/fixtures/es-modules/deprecated-folders-ignore/package.json new file mode 100644 index 00000000000000..52a3a1e8a8b787 --- /dev/null +++ b/test/fixtures/es-modules/deprecated-folders-ignore/package.json @@ -0,0 +1,4 @@ +{ + "type": "module" +} +