Skip to content

Commit

Permalink
module: fix Windows folder exports deprecation warning
Browse files Browse the repository at this point in the history
PR-URL: #36859
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
  • Loading branch information
guybedford authored and danielleadams committed Jan 12, 2021
1 parent 17a5233 commit 01213c7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '.')
Expand Down
4 changes: 4 additions & 0 deletions test/es-module/test-esm-local-deprecations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -18,5 +21,6 @@ process.addListener('warning', mustCall((warning) => {

(async () => {
await import(pathToFileURL(selfDeprecatedFolders));
await import(pathToFileURL(deprecatedFoldersIgnore));
})()
.catch((err) => console.error(err));
1 change: 1 addition & 0 deletions test/fixtures/es-modules/deprecated-folders-ignore/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'pkg/folder/m.js';

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "module"
}

0 comments on commit 01213c7

Please sign in to comment.