Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e4a0e5b

Browse filesBrowse files
Derek LewisBethGriggs
authored andcommitted
module: fix check for package.json at volume root
This patch converts the "read package scope" algorithm's while loop into a do-while loop enabling items at the filesystem root dir to be considered within the scope of a sibling package.json also at the filesystem root dir. Fixes: #33438 Co-authored-by: Guy Bedford <guybedford@gmail.com> PR-URL: #34595 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Mary Marchini <oss@mmarchini.me>
1 parent 2781f64 commit e4a0e5b
Copy full SHA for e4a0e5b

File tree

Expand file treeCollapse file tree

2 files changed

+13
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-10
lines changed
Open diff view settings
Collapse file

‎doc/api/esm.md‎

Copy file name to clipboardExpand all lines: doc/api/esm.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1864,11 +1864,11 @@ _conditions_)
18641864

18651865
> 1. Let _scopeURL_ be _url_.
18661866
> 1. While _scopeURL_ is not the file system root,
1867+
> 1. Set _scopeURL_ to the parent URL of _scopeURL_.
18671868
> 1. If _scopeURL_ ends in a _"node_modules"_ path segment, return **null**.
18681869
> 1. Let _pjson_ be the result of **READ_PACKAGE_JSON**(_scopeURL_).
18691870
> 1. If _pjson_ is not **null**, then
18701871
> 1. Return _pjson_.
1871-
> 1. Set _scopeURL_ to the parent URL of _scopeURL_.
18721872
> 1. Return **null**.
18731873

18741874
**READ_PACKAGE_JSON**(_packageURL_)
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const {
4545
RegExpPrototypeTest,
4646
SafeMap,
4747
String,
48+
StringPrototypeEndsWith,
49+
StringPrototypeIndexOf,
50+
StringPrototypeLastIndexOf,
4851
StringPrototypeMatch,
4952
StringPrototypeSlice,
5053
StringPrototypeStartsWith,
@@ -62,6 +65,7 @@ const assert = require('internal/assert');
6265
const fs = require('fs');
6366
const internalFS = require('internal/fs/utils');
6467
const path = require('path');
68+
const { sep } = path;
6569
const { emitWarningSync } = require('internal/process/warning');
6670
const { internalModuleStat } = internalBinding('fs');
6771
const packageJsonReader = require('internal/modules/package_json_reader');
@@ -282,20 +286,19 @@ function readPackage(requestPath) {
282286
}
283287

284288
function readPackageScope(checkPath) {
285-
const rootSeparatorIndex = checkPath.indexOf(path.sep);
289+
const rootSeparatorIndex = StringPrototypeIndexOf(checkPath, sep);
286290
let separatorIndex;
287-
while (
288-
(separatorIndex = checkPath.lastIndexOf(path.sep)) > rootSeparatorIndex
289-
) {
290-
checkPath = checkPath.slice(0, separatorIndex);
291-
if (checkPath.endsWith(path.sep + 'node_modules'))
291+
do {
292+
separatorIndex = StringPrototypeLastIndexOf(checkPath, sep);
293+
checkPath = StringPrototypeSlice(checkPath, 0, separatorIndex);
294+
if (StringPrototypeEndsWith(checkPath, sep + 'node_modules'))
292295
return false;
293-
const pjson = readPackage(checkPath);
296+
const pjson = readPackage(checkPath + sep);
294297
if (pjson) return {
298+
data: pjson,
295299
path: checkPath,
296-
data: pjson
297300
};
298-
}
301+
} while (separatorIndex > rootSeparatorIndex);
299302
return false;
300303
}
301304

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.