mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-14 19:46:01 -04:00
19 lines
411 B
JavaScript
19 lines
411 B
JavaScript
var cache = {}
|
|
|
|
/*
|
|
* Works identically to require('/path/to/file.json'), but safer.
|
|
*/
|
|
|
|
module.exports = function requireJson (path) {
|
|
path = require('path').resolve(path)
|
|
if (cache[path]) return cache[path]
|
|
try {
|
|
cache[path] = JSON.parse(require('fs').readFileSync(path, 'utf-8'))
|
|
} catch (e) {
|
|
console.error('')
|
|
console.error('' + e.stack)
|
|
process.exit(1)
|
|
}
|
|
return cache[path]
|
|
}
|