Skip to content

Commit 78c5c4c

Browse files
GeoffreyBoothcodebytere
authored andcommitted
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: #33438 PR-URL: #33476 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Jan Krems <[email protected]>
1 parent ee45b78 commit 78c5c4c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/internal/modules/cjs/loader.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const {
4141
SafeMap,
4242
String,
4343
StringPrototypeIndexOf,
44+
StringPrototypeLastIndexOf,
4445
StringPrototypeMatch,
4546
StringPrototypeSlice,
4647
StringPrototypeStartsWith,
@@ -286,12 +287,13 @@ function readPackageScope(checkPath) {
286287
const rootSeparatorIndex = checkPath.indexOf(path.sep);
287288
let separatorIndex;
288289
while (
289-
(separatorIndex = checkPath.lastIndexOf(path.sep)) > rootSeparatorIndex
290+
(separatorIndex = StringPrototypeLastIndexOf(checkPath, path.sep)) >=
291+
rootSeparatorIndex
290292
) {
291293
checkPath = checkPath.slice(0, separatorIndex);
292294
if (checkPath.endsWith(path.sep + 'node_modules'))
293295
return false;
294-
const pjson = readPackage(checkPath);
296+
const pjson = readPackage(checkPath + path.sep);
295297
if (pjson) return {
296298
path: checkPath,
297299
data: pjson

0 commit comments

Comments
 (0)