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

Function getNearestParentPackageJSON

lib/internal/modules/package_json_reader.js:167–185  ·  view source on GitHub ↗

* Get the nearest parent package.json file from a given path. * Return the package.json data and the path to the package.json file, or undefined. * @param {string} checkPath The path to start searching from. * @returns {undefined | DeserializedPackageConfig}

(checkPath)

Source from the content-addressed store, hash-verified

165 * @returns {undefined | DeserializedPackageConfig}
166 */
167function getNearestParentPackageJSON(checkPath) {
168 const parentPackageJSONPath = moduleToParentPackageJSONCache.get(checkPath);
169 if (parentPackageJSONPath !== undefined) {
170 return deserializedPackageJSONCache.get(parentPackageJSONPath);
171 }
172
173 const result = modulesBinding.getNearestParentPackageJSON(checkPath);
174 const packageConfig = deserializePackageJSON(checkPath, result);
175
176 moduleToParentPackageJSONCache.set(checkPath, packageConfig.path);
177
178 const maybeCachedPackageConfig = deserializedPackageJSONCache.get(packageConfig.path);
179 if (maybeCachedPackageConfig !== undefined) {
180 return maybeCachedPackageConfig;
181 }
182
183 deserializedPackageJSONCache.set(packageConfig.path, packageConfig);
184 return packageConfig;
185}
186
187/**
188 * Returns the package configuration for the given resolved URL.

Callers 1

findPackageJSONFunction · 0.85

Calls 4

deserializePackageJSONFunction · 0.85
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…