1'use strict'; 2 3const { SafeMap } = primordials; 4const { internalModuleReadJSON } = internalBinding('fs'); 5const { pathToFileURL } = require('url'); 6const { toNamespacedPath } = require('path'); 7 8const cache = new SafeMap(); 9 10/** 11 * 12 * @param {string} jsonPath 13 */ 14function read(jsonPath) { 15 if (cache.has(jsonPath)) { 16 return cache.get(jsonPath); 17 } 18 19 const [string, containsKeys] = internalModuleReadJSON( 20 toNamespacedPath(jsonPath) 21 ); 22 const result = { string, containsKeys }; 23 const { getOptionValue } = require('internal/options'); 24 if (string !== undefined) { 25 const manifest = getOptionValue('--experimental-policy') ? 26 require('internal/process/policy').manifest : 27 null; 28 if (manifest) { 29 const jsonURL = pathToFileURL(jsonPath); 30 manifest.assertIntegrity(jsonURL, string); 31 } 32 } 33 cache.set(jsonPath, result); 34 return result; 35} 36 37module.exports = { read }; 38