We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
findPackageJSON
1 parent 7af76ef commit 869e88cCopy full SHA for 869e88c
1 file changed
lib/internal/modules/package_json_reader.js
@@ -7,7 +7,6 @@ const {
7
RegExpPrototypeExec,
8
StringPrototypeIndexOf,
9
StringPrototypeSlice,
10
- StringPrototypeStartsWith,
11
} = primordials;
12
const {
13
fileURLToPath,
@@ -285,22 +284,14 @@ function findPackageJSON(specifier, base = 'data:') {
285
284
validateString(specifier, 'specifier');
286
}
287
288
- let parentURL;
289
- if (isURL(base)) {
290
- parentURL = new URL(base);
291
- } else {
+ let parentURL = base;
+ if (!isURL(base)) {
292
validateString(base, 'base');
293
- if (
294
- path.isAbsolute(base) ||
295
- (URLCanParse(base) && !StringPrototypeStartsWith(base, 'file:'))
296
- ) {
297
- parentURL = pathToFileURL(path.toNamespacedPath(base));
298
299
- parentURL = URL.parse(base) || pathToFileURL(base);
300
- }
+ parentURL = path.isAbsolute(base) ? pathToFileURL(base) : new URL(base);
301
302
303
if (specifier && specifier[0] !== '.' && specifier[0] !== '/' && !URLCanParse(specifier)) {
+ // If `specifier` is a bare specifier.
304
const { packageJSONPath } = getPackageJSONURL(specifier, parentURL);
305
return packageJSONPath;
306
0 commit comments