nodejs/lib/internal/modules/package_json_reader.js
Kirill Shatskiy 8f10bb2da5 esm: share package.json cache between ESM and CJS loaders
Refs: https://github.com/nodejs/node/issues/30674

PR-URL: https://github.com/nodejs/node/pull/33229
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2020-05-24 16:22:31 -07:00

24 lines
432 B
JavaScript

'use strict';
const { SafeMap } = primordials;
const { internalModuleReadJSON } = internalBinding('fs');
const cache = new SafeMap();
/**
*
* @param {string} path
*/
function read(path) {
if (cache.has(path)) {
return cache.get(path);
}
const [string, containsKeys] = internalModuleReadJSON(path);
const result = { string, containsKeys };
cache.set(path, result);
return result;
}
module.exports = { read };