* Reads a package.json file and returns the parsed contents. * @param {string} jsonPath * @param {{ * base?: URL | string, * specifier?: URL | string, * isESM?: boolean, * }} options * @returns {PackageConfig}
(jsonPath, { base, specifier, isESM } = kEmptyObject)
| 120 | * @returns {PackageConfig} |
| 121 | */ |
| 122 | function read(jsonPath, { base, specifier, isESM } = kEmptyObject) { |
| 123 | // This function will be called by both CJS and ESM, so we need to make sure |
| 124 | // non-null attributes are converted to strings. |
| 125 | const parsed = modulesBinding.readPackageJSON( |
| 126 | jsonPath, |
| 127 | isESM, |
| 128 | base == null ? undefined : `${base}`, |
| 129 | specifier == null ? undefined : `${specifier}`, |
| 130 | ); |
| 131 | |
| 132 | const result = deserializePackageJSON(jsonPath, parsed); |
| 133 | |
| 134 | return { |
| 135 | __proto__: null, |
| 136 | ...result.data, |
| 137 | exists: result.exists, |
| 138 | pjsonPath: result.path, |
| 139 | }; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * A cache mapping a module's path to its parent `package.json` file's path. |
nothing calls this directly
no test coverage detected
searching dependent graphs…