@@ -33,22 +33,13 @@ function formatBytes(bytes) {
3333 return ( bytes / 1024 ) . toFixed ( 2 ) ;
3434}
3535
36- function formatPercent ( percent ) {
37- if ( ! isFinite ( percent ) ) return "0.0" ;
38- return Math . abs ( percent ) . toFixed ( 1 ) ;
39- }
40-
4136function formatDiff ( diff , showSign = true ) {
4237 const sign = showSign && diff > 0 ? "+" : "" ;
4338 return `${ sign } ${ formatBytes ( diff ) } ` ;
4439}
4540
4641function getStatusIcon ( status , sizeDiff ) {
4742 switch ( status ) {
48- case "added" :
49- return "✨" ;
50- case "removed" :
51- return "❌" ;
5243 case "changed" :
5344 return sizeDiff > 0 ? "📈" : sizeDiff < 0 ? "📉" : "➡️" ;
5445 case "unchanged" :
@@ -71,33 +62,7 @@ function analyzeBundleChanges(prReport, targetReport) {
7162 const prResult = prMap . get ( component ) ;
7263 const targetResult = targetMap . get ( component ) ;
7364
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 ) {
10166 const sizeDiff = prResult . size - targetResult . size ;
10267 const gzipSizeDiff = prResult . gzipSize - targetResult . gzipSize ;
10368 const sizePercent = targetResult . size > 0 ? ( sizeDiff / targetResult . size ) * 100 : 0 ;
@@ -136,12 +101,12 @@ function generateComment(changes, hasBaseline = true) {
136101
137102 if ( changes . length > 0 ) {
138103 comment += "### 📊 Current Component Sizes\n\n" ;
139- comment += "| Component | Size | Gzipped | \n" ;
140- comment += "|-----------|------|----------| \n" ;
104+ comment += "| Component | Size |\n" ;
105+ comment += "|-----------|------|\n" ;
141106
142107 const sortedComponents = changes . sort ( ( a , b ) => a . component . localeCompare ( b . component ) ) ;
143108 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` ;
145110 }
146111 comment += "\n" ;
147112 }
@@ -154,59 +119,23 @@ function generateComment(changes, hasBaseline = true) {
154119 return comment ;
155120 }
156121
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" ) ;
168122 const modifiedComponents = changedComponents . filter ( ( c ) => c . status === "changed" ) ;
169123
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-
190124 if ( modifiedComponents . length > 0 ) {
191125 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" ;
194128
195129 for ( const comp of modifiedComponents ) {
196130 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` ;
205135 }
206136 comment += "\n" ;
207137 }
208138
209- // Add helpful context
210139 comment += "---\n\n" ;
211140 comment += "<details>\n" ;
212141 comment += "<summary>📋 Understanding Bundle Analysis</summary>\n\n" ;
@@ -260,7 +189,7 @@ function main() {
260189
261190 const comment = generateComment ( changes , hasBaseline ) ;
262191
263- writeFileSync ( "./ bundle-analysis-temp /comment.md" , comment ) ;
192+ writeFileSync ( "/tmp/ bundle-analysis/comment.md" , comment ) ;
264193
265194 console . log ( "✅ Bundle analysis comment generated successfully" ) ;
266195 if ( hasBaseline ) {
0 commit comments