Skip to content

Commit 3fd61ee

Browse files
GeoffreyBoothMylesBorins
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 3b26809 commit 3fd61ee

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 4 additions & 2 deletions
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,
@@ -287,12 +288,13 @@ function readPackageScope(checkPath) {
287288
const rootSeparatorIndex = checkPath.indexOf(path.sep);
288289
let separatorIndex;
289290
while (
290-
(separatorIndex = checkPath.lastIndexOf(path.sep)) > rootSeparatorIndex
291+
(separatorIndex = StringPrototypeLastIndexOf(checkPath, path.sep)) >=
292+
rootSeparatorIndex
291293
) {
292294
checkPath = checkPath.slice(0, separatorIndex);
293295
if (checkPath.endsWith(path.sep + 'node_modules'))
294296
return false;
295-
const pjson = readPackage(checkPath);
297+
const pjson = readPackage(checkPath + path.sep);
296298
if (pjson) return {
297299
path: checkPath,
298300
data: pjson

0 commit comments

Comments
 (0)