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