MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / reportDiff

Function reportDiff

apps/site/scripts/compare-size/index.mjs:77–142  ·  view source on GitHub ↗

* Compares old and new assets and returns a markdown report

({ assets: oldAssets }, { assets: newAssets })

Source from the content-addressed store, hash-verified

75 * Compares old and new assets and returns a markdown report
76 */
77function reportDiff({ assets: oldAssets }, { assets: newAssets }) {
78 const changes = categorizeChanges(oldAssets, newAssets);
79
80 const oldTotal = oldAssets.reduce((sum, a) => sum + a.size, 0);
81 const newTotal = newAssets.reduce((sum, a) => sum + a.size, 0);
82 const totalDelta = newTotal - oldTotal;
83
84 // Summary table
85 let report = `## 📦 Build Size Comparison\n\n### Summary\n\n| Metric | Value |\n|--------|-------|\n`;
86 report += `| Old Total Size | ${formatBytes(oldTotal)} |\n`;
87 report += `| New Total Size | ${formatBytes(newTotal)} |\n`;
88 report += `| Delta | ${formatBytes(totalDelta)} (${formatPercent(
89 oldTotal,
90 newTotal
91 )}) |\n\n`;
92
93 // Changes
94 if (
95 changes.added.length ||
96 changes.removed.length ||
97 changes.modified.length
98 ) {
99 report += `### Changes\n\n`;
100
101 // Asset tables
102 report += tableSection(
103 'Added Assets',
104 changes.added,
105 [
106 { label: 'Name', format: a => `\`${a.name}\`` },
107 { label: 'Size', format: a => formatBytes(a.size) },
108 ],
109 '➕'
110 );
111
112 report += tableSection(
113 'Removed Assets',
114 changes.removed,
115 [
116 { label: 'Name', format: a => `\`${a.name}\`` },
117 { label: 'Size', format: a => formatBytes(a.size) },
118 ],
119 '➖'
120 );
121
122 report += tableSection(
123 'Modified Assets',
124 changes.modified,
125 [
126 { label: 'Name', format: a => `\`${a.name}\`` },
127 { label: 'Old Size', format: a => formatBytes(a.oldSize) },
128 { label: 'New Size', format: a => formatBytes(a.newSize) },
129 {
130 label: 'Delta',
131 format: a =>
132 `${a.delta > 0 ? '📈' : '📉'} ${formatBytes(
133 a.delta
134 )} (${formatPercent(a.oldSize, a.newSize)})`,

Callers 1

compareFunction · 0.85

Calls 4

categorizeChangesFunction · 0.85
formatBytesFunction · 0.85
formatPercentFunction · 0.85
tableSectionFunction · 0.85

Tested by

no test coverage detected