MCPcopy Create free account
hub / github.com/doesdev/rollup-plugin-analyzer / reporter

Function reporter

index.js:34–91  ·  view source on GitHub ↗
(analysis, opts)

Source from the content-addressed store, hash-verified

32};
33
34const reporter = (analysis, opts) => {
35 const { hideDeps, root, showExports, summaryOnly } = opts || {};
36
37 let formatted = '' +
38 `${borderX}` +
39 'Rollup File Analysis\n' +
40 `${borderX}` +
41 `bundle size: ${formatBytes(analysis.bundleSize)}\n` +
42 `original size: ${formatBytes(analysis.bundleOrigSize)}\n` +
43 `code reduction: ${analysis.bundleReduction} %\n` +
44 `module count: ${analysis.moduleCount}\n` +
45 '\n';
46
47 analysis.modules.forEach((m, i) => {
48 const id = m.id.replace(/\\/g, '/');
49 const size = formatBytes(m.size);
50 const percentInt = parseInt(m.percent, 10);
51 const percentFilled = (percentInt ? parseInt(percentInt / 2, 10) : 0) + 1;
52 const percentEmpty = 52 - percentFilled;
53 const barFilled = `${Array(percentFilled).join('\u2588')}`;
54 const barEmpty = `${Array(percentEmpty).join('\u2591')}`;
55 const rawBar = `${barFilled}${barEmpty}`;
56 const summaryBar = `${id}\n${rawBar} ${m.percent} % (${size})`;
57 const bar = !summaryOnly ? rawBar : summaryBar;
58
59 const detailed = !summaryOnly && '' +
60 `${bar}\n` +
61 `file: ${buf}${id}\n` +
62 `bundle space: ${buf}${m.percent} %\n` +
63 `rendered size: ${buf}${size}\n` +
64 `original size: ${buf}${formatBytes(m.origSize || 'unknown')}\n` +
65 `code reduction: ${buf}${m.reduction} %\n` +
66 `dependents: ${buf}${m.dependents.length}\n`;
67
68 formatted += summaryOnly ? `${bar}\n` : detailed;
69
70 if (!hideDeps && !summaryOnly) {
71 m.dependents.forEach((d) => {
72 formatted += `${tab}-${buf}${d.replace(root, '').replace(/\\/g, '/')}\n`;
73 });
74 }
75
76 if (showExports && m.renderedExports && m.removedExports && !summaryOnly) {
77 formatted += `used exports: ${buf}${m.renderedExports.length}\n`;
78 m.renderedExports.forEach((e) => {
79 formatted += `${tab}-${buf}${e}\n`;
80 });
81 formatted += `unused exports: ${buf}${m.removedExports.length}\n`;
82 m.removedExports.forEach((e) => {
83 formatted += `${tab}-${buf}${e}\n`;
84 });
85 }
86
87 formatted += summaryOnly ? '' : '\n';
88 });
89
90 return formatted
91};

Callers 2

formattedFunction · 0.70
onAnalysisFunction · 0.70

Calls 1

formatBytesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…