mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
module: simplify findPackageJSON
implementation
PR-URL: https://github.com/nodejs/node/pull/55543 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
This commit is contained in:
parent
10cce655ca
commit
c0db893f04
@ -7,7 +7,6 @@ const {
|
||||
RegExpPrototypeExec,
|
||||
StringPrototypeIndexOf,
|
||||
StringPrototypeSlice,
|
||||
StringPrototypeStartsWith,
|
||||
} = primordials;
|
||||
const {
|
||||
fileURLToPath,
|
||||
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user