* 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)
| 165 | * @returns {undefined | DeserializedPackageConfig} |
| 166 | */ |
| 167 | function 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. |
no test coverage detected
searching dependent graphs…