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

Function read

lib/internal/modules/package_json_reader.js:122–140  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

120 * @returns {PackageConfig}
121 */
122function 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.

Callers

nothing calls this directly

Calls 2

deserializePackageJSONFunction · 0.85
readPackageJSONMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…