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 <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
  • Loading branch information
GeoffreyBooth authored and MylesBorins committed Jul 14, 2020
1 parent 3b26809 commit 3fd61ee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -41,6 +41,7 @@ const {
SafeMap,
String,
StringPrototypeIndexOf,
StringPrototypeLastIndexOf,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeStartsWith,
Expand Down Expand Up @@ -287,12 +288,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 3fd61ee

Please sign in to comment.