Skip to content

Commit

Permalink
module: fix check for package.json at volume root
Browse files Browse the repository at this point in the history
Fix package.json files at the volume root so that
when they contain {"type": "module"}, they behave
as documented, like such a package.json file in
any other folder.

Fixes: #33438

PR-URL: #33476
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Jan Krems <[email protected]>
  • Loading branch information
GeoffreyBooth authored and codebytere committed Jun 18, 2020
1 parent ee45b78 commit 78c5c4c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const {
SafeMap,
String,
StringPrototypeIndexOf,
StringPrototypeLastIndexOf,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeStartsWith,
Expand Down Expand Up @@ -286,12 +287,13 @@ function readPackageScope(checkPath) {
const rootSeparatorIndex = checkPath.indexOf(path.sep);
let separatorIndex;
while (
(separatorIndex = checkPath.lastIndexOf(path.sep)) > rootSeparatorIndex
(separatorIndex = StringPrototypeLastIndexOf(checkPath, path.sep)) >=
rootSeparatorIndex
) {
checkPath = checkPath.slice(0, separatorIndex);
if (checkPath.endsWith(path.sep + 'node_modules'))
return false;
const pjson = readPackage(checkPath);
const pjson = readPackage(checkPath + path.sep);
if (pjson) return {
path: checkPath,
data: pjson
Expand Down

0 comments on commit 78c5c4c

Please sign in to comment.