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 10let manifest; 11 12/** 13 * 14 * @param {string} jsonPath 15 */ 16function read(jsonPath) { 17 if (cache.has(jsonPath)) { 18 return cache.get(jsonPath); 19 } 20 21 const [string, containsKeys] = internalModuleReadJSON( 22 toNamespacedPath(jsonPath) 23 ); 24 const result = { string, containsKeys }; 25 const { getOptionValue } = require('internal/options'); 26 if (string !== undefined) { 27 if (manifest === undefined) { 28 manifest = getOptionValue('--experimental-policy') ? 29 require('internal/process/policy').manifest : 30 null; 31 } 32 if (manifest !== null) { 33 const jsonURL = pathToFileURL(jsonPath); 34 manifest.assertIntegrity(jsonURL, string); 35 } 36 } 37 cache.set(jsonPath, result); 38 return result; 39} 40 41module.exports = { read }; 42