mirror of
https://github.com/nodejs/node.git
synced 2025-04-30 23:56:58 +00:00

PR-URL: https://github.com/nodejs/node/pull/46629 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
42 lines
984 B
JavaScript
42 lines
984 B
JavaScript
'use strict';
|
|
|
|
const { SafeMap } = primordials;
|
|
const { internalModuleReadJSON } = internalBinding('fs');
|
|
const { pathToFileURL } = require('url');
|
|
const { toNamespacedPath } = require('path');
|
|
|
|
const cache = new SafeMap();
|
|
|
|
let manifest;
|
|
|
|
/**
|
|
*
|
|
* @param {string} jsonPath
|
|
*/
|
|
function read(jsonPath) {
|
|
if (cache.has(jsonPath)) {
|
|
return cache.get(jsonPath);
|
|
}
|
|
|
|
const { 0: string, 1: containsKeys } = internalModuleReadJSON(
|
|
toNamespacedPath(jsonPath),
|
|
);
|
|
const result = { string, containsKeys };
|
|
const { getOptionValue } = require('internal/options');
|
|
if (string !== undefined) {
|
|
if (manifest === undefined) {
|
|
manifest = getOptionValue('--experimental-policy') ?
|
|
require('internal/process/policy').manifest :
|
|
null;
|
|
}
|
|
if (manifest !== null) {
|
|
const jsonURL = pathToFileURL(jsonPath);
|
|
manifest.assertIntegrity(jsonURL, string);
|
|
}
|
|
}
|
|
cache.set(jsonPath, result);
|
|
return result;
|
|
}
|
|
|
|
module.exports = { read };
|