* Load and parse the package map from a config path. * @param {string} configPath * @returns {PackageMap}
(configPath)
| 228 | * @returns {PackageMap} |
| 229 | */ |
| 230 | function 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. |
no test coverage detected
searching dependent graphs…