module: fix check for package.json at volume root

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: https://github.com/nodejs/node/issues/33438

PR-URL: https://github.com/nodejs/node/pull/33476
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
This commit is contained in:
Geoffrey Booth 2020-05-19 21:47:31 -07:00
parent 979ec425bd
commit 51af89fe45

View File

@ -41,6 +41,7 @@ const {
SafeMap,
String,
StringPrototypeIndexOf,
StringPrototypeLastIndexOf,
StringPrototypeMatch,
StringPrototypeSlice,
StringPrototypeStartsWith,
@ -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