MCPcopy
hub / github.com/webpack/webpack / printData

Function printData

tooling/print-cache-file.js:52–165  ·  view source on GitHub ↗
(data, indent)

Source from the content-addressed store, hash-verified

50 * @returns {Promise<void>} promise
51 */
52const printData = async (data, indent) => {
53 if (!Array.isArray(data)) throw new Error("Not an array");
54 if (Buffer.isBuffer(data[0])) {
55 for (const b of data) {
56 if (typeof b === "function") {
57 const innerData = await b();
58 const info = /** @type {SizeInfo} */ (lazySizes.shift());
59 const sizeInfo = `${(info.size / 1048576).toFixed(2)} MiB + ${(
60 info.lazySize / 1048576
61 ).toFixed(2)} lazy MiB`;
62 console.log(`${indent}= lazy ${sizeInfo} {`);
63 await printData(innerData, `${indent} `);
64 console.log(`${indent}}`);
65 } else {
66 console.log(`${indent}= ${b.toString("hex")}`);
67 }
68 }
69 return;
70 }
71 const referencedValues = new Map();
72 const referencedValuesCounters = new Map();
73 const referencedTypes = new Map();
74 let currentReference = 0;
75 let currentTypeReference = 0;
76 let i = 0;
77 const read = () => data[i++];
78 /**
79 * @param {string} content content
80 */
81 const printLine = (content) => {
82 console.log(`${indent}${content}`);
83 };
84 printLine(`Version: ${read()}`);
85 while (i < data.length) {
86 const item = read();
87 if (item === ESCAPE) {
88 const nextItem = read();
89 if (nextItem === ESCAPE_ESCAPE_VALUE) {
90 printLine("null");
91 } else if (nextItem === ESCAPE_UNDEFINED) {
92 printLine("undefined");
93 } else if (nextItem === ESCAPE_END_OBJECT) {
94 indent = indent.slice(0, -2);
95 printLine(`} = #${currentReference++}`);
96 } else if (typeof nextItem === "number" && nextItem < 0) {
97 const ref = currentReference + nextItem;
98 const value = referencedValues.get(ref);
99 referencedValuesCounters.set(
100 ref,
101 (referencedValuesCounters.get(ref) || 0) + 1
102 );
103 if (value) {
104 printLine(
105 `Reference ${nextItem} => ${JSON.stringify(value)} #${ref}`
106 );
107 } else {
108 printLine(`Reference ${nextItem} => #${ref}`);
109 }

Callers 1

Calls 11

printLineFunction · 0.85
isArrayMethod · 0.80
logMethod · 0.80
sliceMethod · 0.80
sortMethod · 0.80
readFunction · 0.70
bFunction · 0.50
toStringMethod · 0.45
getMethod · 0.45
setMethod · 0.45
isLazyMethod · 0.45

Tested by

no test coverage detected