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

Function loadPackageMap

lib/internal/modules/package_map.js:230–254  ·  view source on GitHub ↗

* Load and parse the package map from a config path. * @param {string} configPath * @returns {PackageMap}

(configPath)

Source from the content-addressed store, hash-verified

228 * @returns {PackageMap}
229 */
230function loadPackageMap(configPath) {
231 let content;
232 try {
233 content = fs.readFileSync(configPath);
234 } catch (err) {
235 const error = new ERR_PACKAGE_MAP_INVALID(configPath, 'failed to read');
236 setOwnProperty(error, 'cause', err);
237 throw error;
238 }
239
240 // Resolve symlinks so that stored paths match the realpath'd module paths
241 // that Node.js uses during resolution.
242 configPath = fs.realpathSync(configPath);
243
244 let data;
245 try {
246 data = JSONParse(content);
247 } catch (err) {
248 const error = new ERR_PACKAGE_MAP_INVALID(configPath, `invalid JSON`);
249 setOwnProperty(error, 'cause', err);
250 throw error;
251 }
252
253 return new PackageMap(configPath, data);
254}
255
256/**
257 * Get the singleton package map, initializing on first call.

Callers 1

getPackageMapFunction · 0.85

Calls 3

setOwnPropertyFunction · 0.85
readFileSyncMethod · 0.45
realpathSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…