MCPcopy Index your code
hub / github.com/nodejs/node / deserializePackageJSON

Function deserializePackageJSON

lib/internal/modules/package_json_reader.js:44–105  ·  view source on GitHub ↗

* @param {URL['pathname']} path * @param {SerializedPackageConfig} contents * @returns {DeserializedPackageConfig}

(path, contents)

Source from the content-addressed store, hash-verified

42 * @returns {DeserializedPackageConfig}
43 */
44function deserializePackageJSON(path, contents) {
45 if (contents === undefined) {
46 return {
47 data: {
48 __proto__: null,
49 type: 'none', // Ignore unknown types for forwards compatibility
50 },
51 exists: false,
52 path,
53 };
54 }
55
56 const {
57 0: name,
58 1: main,
59 2: type,
60 3: plainImports,
61 4: plainExports,
62 5: optionalFilePath,
63 } = contents;
64
65 const pjsonPath = optionalFilePath ?? path;
66
67 const data = {
68 __proto__: null,
69 ...(name != null && { name }),
70 ...(main != null && { main }),
71 ...(type != null && { type }),
72 };
73
74 if (plainExports !== null) {
75 ObjectDefineProperty(data, 'exports', {
76 __proto__: null,
77 configurable: true,
78 enumerable: true,
79 get() {
80 const value = requiresJSONParse(plainExports) ? JSONParse(plainExports) : plainExports;
81 ObjectDefineProperty(data, 'exports', { __proto__: null, enumerable: true, value });
82 return value;
83 },
84 });
85 }
86
87 if (plainImports !== null) {
88 ObjectDefineProperty(data, 'imports', {
89 __proto__: null,
90 configurable: true,
91 enumerable: true,
92 get() {
93 const value = requiresJSONParse(plainImports) ? JSONParse(plainImports) : plainImports;
94 ObjectDefineProperty(data, 'imports', { __proto__: null, enumerable: true, value });
95 return value;
96 },
97 });
98 }
99
100 return {
101 data,

Callers 3

readFunction · 0.85
getPackageScopeConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…