@@ -33,22 +33,13 @@ function formatBytes(bytes) {
33
33
return ( bytes / 1024 ) . toFixed ( 2 ) ;
34
34
}
35
35
36
- function formatPercent ( percent ) {
37
- if ( ! isFinite ( percent ) ) return "0.0" ;
38
- return Math . abs ( percent ) . toFixed ( 1 ) ;
39
- }
40
-
41
36
function formatDiff ( diff , showSign = true ) {
42
37
const sign = showSign && diff > 0 ? "+" : "" ;
43
38
return `${ sign } ${ formatBytes ( diff ) } ` ;
44
39
}
45
40
46
41
function getStatusIcon ( status , sizeDiff ) {
47
42
switch ( status ) {
48
- case "added" :
49
- return "✨" ;
50
- case "removed" :
51
- return "❌" ;
52
43
case "changed" :
53
44
return sizeDiff > 0 ? "📈" : sizeDiff < 0 ? "📉" : "➡️" ;
54
45
case "unchanged" :
@@ -71,33 +62,7 @@ function analyzeBundleChanges(prReport, targetReport) {
71
62
const prResult = prMap . get ( component ) ;
72
63
const targetResult = targetMap . get ( component ) ;
73
64
74
- if ( ! prResult && targetResult ) {
75
- changes . push ( {
76
- component,
77
- status : "removed" ,
78
- sizeDiff : - targetResult . size ,
79
- gzipSizeDiff : - targetResult . gzipSize ,
80
- sizePercent : - 100 ,
81
- gzipSizePercent : - 100 ,
82
- currentSize : 0 ,
83
- currentGzipSize : 0 ,
84
- targetSize : targetResult . size ,
85
- targetGzipSize : targetResult . gzipSize ,
86
- } ) ;
87
- } else if ( prResult && ! targetResult ) {
88
- changes . push ( {
89
- component,
90
- status : "added" ,
91
- sizeDiff : prResult . size ,
92
- gzipSizeDiff : prResult . gzipSize ,
93
- sizePercent : Infinity ,
94
- gzipSizePercent : Infinity ,
95
- currentSize : prResult . size ,
96
- currentGzipSize : prResult . gzipSize ,
97
- targetSize : 0 ,
98
- targetGzipSize : 0 ,
99
- } ) ;
100
- } else if ( prResult && targetResult ) {
65
+ if ( prResult && targetResult ) {
101
66
const sizeDiff = prResult . size - targetResult . size ;
102
67
const gzipSizeDiff = prResult . gzipSize - targetResult . gzipSize ;
103
68
const sizePercent = targetResult . size > 0 ? ( sizeDiff / targetResult . size ) * 100 : 0 ;
@@ -136,12 +101,12 @@ function generateComment(changes, hasBaseline = true) {
136
101
137
102
if ( changes . length > 0 ) {
138
103
comment += "### 📊 Current Component Sizes\n\n" ;
139
- comment += "| Component | Size | Gzipped | \n" ;
140
- comment += "|-----------|------|----------| \n" ;
104
+ comment += "| Component | Size |\n" ;
105
+ comment += "|-----------|------|\n" ;
141
106
142
107
const sortedComponents = changes . sort ( ( a , b ) => a . component . localeCompare ( b . component ) ) ;
143
108
for ( const comp of sortedComponents ) {
144
- comment += `| \`${ comp . component } \` | ${ formatBytes ( comp . currentSize ) } KB | ${ formatBytes ( comp . currentGzipSize ) } KB |\n` ;
109
+ comment += `| \`${ comp . component } \` | ${ formatBytes ( comp . currentSize ) } KB <sub>gzipped: ( ${ formatBytes ( comp . currentGzipSize ) } KB)</sub> |\n` ;
145
110
}
146
111
comment += "\n" ;
147
112
}
@@ -154,59 +119,23 @@ function generateComment(changes, hasBaseline = true) {
154
119
return comment ;
155
120
}
156
121
157
- // Summary stats
158
- const totalSizeDiff = changedComponents . reduce ( ( sum , c ) => sum + c . sizeDiff , 0 ) ;
159
- const totalGzipDiff = changedComponents . reduce ( ( sum , c ) => sum + c . gzipSizeDiff , 0 ) ;
160
-
161
- const summaryIcon = totalSizeDiff > 0 ? "📈" : totalSizeDiff < 0 ? "📉" : "➡️" ;
162
- comment += `### ${ summaryIcon } Summary\n\n` ;
163
- comment += `**Total bundle size change**: ${ formatDiff ( totalSizeDiff ) } KB (${ formatDiff ( totalGzipDiff ) } KB gzipped)\n\n` ;
164
-
165
- // Group changes by status
166
- const addedComponents = changedComponents . filter ( ( c ) => c . status === "added" ) ;
167
- const removedComponents = changedComponents . filter ( ( c ) => c . status === "removed" ) ;
168
122
const modifiedComponents = changedComponents . filter ( ( c ) => c . status === "changed" ) ;
169
123
170
- if ( addedComponents . length > 0 ) {
171
- comment += "### ✨ New Components\n\n" ;
172
- comment += "| Component | Size | Gzipped |\n" ;
173
- comment += "|-----------|------|----------|\n" ;
174
- for ( const comp of addedComponents ) {
175
- comment += `| \`${ comp . component } \` | +${ formatBytes ( comp . currentSize ) } KB | +${ formatBytes ( comp . currentGzipSize ) } KB |\n` ;
176
- }
177
- comment += "\n" ;
178
- }
179
-
180
- if ( removedComponents . length > 0 ) {
181
- comment += "### ❌ Removed Components\n\n" ;
182
- comment += "| Component | Size | Gzipped |\n" ;
183
- comment += "|-----------|------|----------|\n" ;
184
- for ( const comp of removedComponents ) {
185
- comment += `| \`${ comp . component } \` | -${ formatBytes ( comp . targetSize ) } KB | -${ formatBytes ( comp . targetGzipSize ) } KB |\n` ;
186
- }
187
- comment += "\n" ;
188
- }
189
-
190
124
if ( modifiedComponents . length > 0 ) {
191
125
comment += "### 📊 Modified Components\n\n" ;
192
- comment += "| Component | Size Change | Gzipped Change | % Change |\n" ;
193
- comment += "|-----------|------------- |----------------|-- --------|\n" ;
126
+ comment += "| Component | Current | New | Change |\n" ;
127
+ comment += "|-----------|---------|-----| --------|\n" ;
194
128
195
129
for ( const comp of modifiedComponents ) {
196
130
const icon = getStatusIcon ( comp . status , comp . sizeDiff ) ;
197
- const sizeChange = `${ formatDiff ( comp . sizeDiff ) } KB` ;
198
- const gzipChange = `${ formatDiff ( comp . gzipSizeDiff ) } KB` ;
199
- const percentChange =
200
- comp . sizeDiff !== 0
201
- ? `${ comp . sizeDiff > 0 ? "+" : "" } ${ formatPercent ( comp . sizePercent ) } %`
202
- : "0.0%" ;
203
-
204
- comment += `| ${ icon } \`${ comp . component } \` | ${ sizeChange } | ${ gzipChange } | ${ percentChange } |\n` ;
131
+ const currentSize = `${ formatBytes ( comp . targetSize ) } KB <sub>gzipped: (${ formatBytes ( comp . targetGzipSize ) } KB)</sub>` ;
132
+ const newSize = `${ formatBytes ( comp . currentSize ) } KB <sub>gzipped: (${ formatBytes ( comp . currentGzipSize ) } KB)</sub>` ;
133
+ const sizeChange = `${ formatDiff ( comp . sizeDiff ) } KB <sub>gzipped: (${ formatDiff ( comp . gzipSizeDiff ) } KB)</sub>` ;
134
+ comment += `| ${ icon } \`${ comp . component } \` | ${ currentSize } | ${ newSize } | ${ sizeChange } |\n` ;
205
135
}
206
136
comment += "\n" ;
207
137
}
208
138
209
- // Add helpful context
210
139
comment += "---\n\n" ;
211
140
comment += "<details>\n" ;
212
141
comment += "<summary>📋 Understanding Bundle Analysis</summary>\n\n" ;
@@ -260,7 +189,7 @@ function main() {
260
189
261
190
const comment = generateComment ( changes , hasBaseline ) ;
262
191
263
- writeFileSync ( "./ bundle-analysis-temp /comment.md" , comment ) ;
192
+ writeFileSync ( "/tmp/ bundle-analysis/comment.md" , comment ) ;
264
193
265
194
console . log ( "✅ Bundle analysis comment generated successfully" ) ;
266
195
if ( hasBaseline ) {
0 commit comments