MCPcopy Index your code
hub / github.com/nodejs/node / getPackageJSONURL

Function getPackageJSONURL

lib/internal/modules/package_json_reader.js:267–302  ·  view source on GitHub ↗
(specifier, base)

Source from the content-addressed store, hash-verified

265}
266
267function getPackageJSONURL(specifier, base) {
268 const { packageName, packageSubpath, isScoped } = parsePackageName(specifier, base);
269
270 // ResolveSelf
271 const packageConfig = getPackageScopeConfig(base);
272 if (packageConfig.exists) {
273 if (packageConfig.exports != null && packageConfig.name === packageName) {
274 const packageJSONPath = packageConfig.pjsonPath;
275 return { packageJSONUrl: pathToFileURL(packageJSONPath), packageJSONPath, packageSubpath };
276 }
277 }
278
279 let packageJSONUrl = new URL(`./node_modules/${packageName}/package.json`, base);
280 let packageJSONPath = fileURLToPath(packageJSONUrl);
281 let lastPath;
282 do {
283 const stat = internalFsBinding.internalModuleStat(
284 StringPrototypeSlice(packageJSONPath, 0, packageJSONPath.length - 13),
285 );
286 // Check for !stat.isDirectory()
287 if (stat !== 1) {
288 lastPath = packageJSONPath;
289 packageJSONUrl = new URL(
290 `${isScoped ? '../' : ''}../../../node_modules/${packageName}/package.json`,
291 packageJSONUrl,
292 );
293 packageJSONPath = fileURLToPath(packageJSONUrl);
294 continue;
295 }
296
297 // Package match.
298 return { packageJSONUrl, packageJSONPath, packageSubpath };
299 } while (packageJSONPath.length !== lastPath.length);
300
301 throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
302}
303
304/** @type {import('./esm/resolve.js').defaultResolve} */
305let defaultResolve;

Callers 1

findPackageJSONFunction · 0.85

Calls 4

getPackageScopeConfigFunction · 0.85
fileURLToPathFunction · 0.85
parsePackageNameFunction · 0.70
pathToFileURLFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…