Skip to content

Commit

Permalink
module: simplify findPackageJSON implementation
Browse files Browse the repository at this point in the history
PR-URL: #55543
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
aduh95 authored Nov 2, 2024
1 parent 10cce65 commit c0db893
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/internal/modules/package_json_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
RegExpPrototypeExec,
StringPrototypeIndexOf,
StringPrototypeSlice,
StringPrototypeStartsWith,
} = primordials;
const {
fileURLToPath,
Expand Down Expand Up @@ -285,22 +284,14 @@ function findPackageJSON(specifier, base = 'data:') {
validateString(specifier, 'specifier');
}

let parentURL;
if (isURL(base)) {
parentURL = new URL(base);
} else {
let parentURL = base;
if (!isURL(base)) {
validateString(base, 'base');
if (
path.isAbsolute(base) ||
(URLCanParse(base) && !StringPrototypeStartsWith(base, 'file:'))
) {
parentURL = pathToFileURL(path.toNamespacedPath(base));
} else {
parentURL = URL.parse(base) || pathToFileURL(base);
}
parentURL = path.isAbsolute(base) ? pathToFileURL(base) : new URL(base);
}

if (specifier && specifier[0] !== '.' && specifier[0] !== '/' && !URLCanParse(specifier)) {
// If `specifier` is a bare specifier.
const { packageJSONPath } = getPackageJSONURL(specifier, parentURL);
return packageJSONPath;
}
Expand Down

0 comments on commit c0db893

Please sign in to comment.