44// Measure: node scripts/bundle-size-report.mjs --output sizes.json [--packages-dir packages]
55// Compare: node scripts/bundle-size-report.mjs --compare base.json --current current.json --output stats.txt
66
7- import { readFileSync , writeFileSync , readdirSync , statSync , existsSync } from 'fs' ;
7+ import {
8+ readFileSync ,
9+ writeFileSync ,
10+ readdirSync ,
11+ statSync ,
12+ existsSync ,
13+ } from 'fs' ;
814import { join , resolve , relative } from 'path' ;
915import { gzipSync } from 'zlib' ;
1016
@@ -88,7 +94,10 @@ function findEsmEntry(pkgDir) {
8894 const dot = pkg . exports [ '.' ] ;
8995 const importPath = typeof dot === 'string' ? dot : dot . import ;
9096 if ( importPath ) {
91- const entry = typeof importPath === 'string' ? importPath : importPath . default || importPath ;
97+ const entry =
98+ typeof importPath === 'string'
99+ ? importPath
100+ : importPath . default || importPath ;
92101 if ( typeof entry === 'string' ) {
93102 const resolved = join ( pkgDir , entry ) ;
94103 if ( existsSync ( resolved ) ) return resolved ;
@@ -183,7 +192,10 @@ function measure(packagesDir) {
183192// ── Compare ──────────────────────────────────────────────────────────────────
184193
185194function compare ( baseData , currentData ) {
186- const allPackages = new Set ( [ ...Object . keys ( baseData ) , ...Object . keys ( currentData ) ] ) ;
195+ const allPackages = new Set ( [
196+ ...Object . keys ( baseData ) ,
197+ ...Object . keys ( currentData ) ,
198+ ] ) ;
187199 const changed = [ ] ;
188200 let unchangedCount = 0 ;
189201 let totalDistBase = 0 ;
@@ -219,7 +231,9 @@ function compare(baseData, currentData) {
219231 lines . push ( 'No bundle size changes detected.' ) ;
220232 lines . push ( '' ) ;
221233 } else {
222- lines . push ( `${ changed . length } package(s) changed, ${ unchangedCount } unchanged.` ) ;
234+ lines . push (
235+ `${ changed . length } package(s) changed, ${ unchangedCount } unchanged.` ,
236+ ) ;
223237 lines . push ( '' ) ;
224238 lines . push ( '| Package | Total dist | Delta | ESM gzip | Delta |' ) ;
225239 lines . push ( '|---------|-----------|-------|----------|-------|' ) ;
@@ -242,8 +256,12 @@ function compare(baseData, currentData) {
242256 lines . push ( '' ) ;
243257 }
244258
245- lines . push ( `**Total dist:** ${ formatBytes ( totalDistCurrent ) } (${ formatDelta ( totalDistCurrent , totalDistBase ) } )` ) ;
246- lines . push ( `**Total ESM gzip:** ${ formatBytes ( totalEsmCurrent ) } (${ formatDelta ( totalEsmCurrent , totalEsmBase ) } )` ) ;
259+ lines . push (
260+ `**Total dist:** ${ formatBytes ( totalDistCurrent ) } (${ formatDelta ( totalDistCurrent , totalDistBase ) } )` ,
261+ ) ;
262+ lines . push (
263+ `**Total ESM gzip:** ${ formatBytes ( totalEsmCurrent ) } (${ formatDelta ( totalEsmCurrent , totalEsmBase ) } )` ,
264+ ) ;
247265 lines . push ( '' ) ;
248266
249267 return lines . join ( '\n' ) ;
@@ -294,9 +312,13 @@ function main() {
294312 for ( const [ name , data ] of Object . entries ( results ) ) {
295313 totalDist += data . totalDist ;
296314 totalEsm += data . esmGzip ;
297- console . log ( ` ${ name } : dist=${ formatBytes ( data . totalDist ) } , esm-gzip=${ formatBytes ( data . esmGzip ) } ` ) ;
315+ console . log (
316+ ` ${ name } : dist=${ formatBytes ( data . totalDist ) } , esm-gzip=${ formatBytes ( data . esmGzip ) } ` ,
317+ ) ;
298318 }
299- console . log ( `Total dist: ${ formatBytes ( totalDist ) } , Total ESM gzip: ${ formatBytes ( totalEsm ) } ` ) ;
319+ console . log (
320+ `Total dist: ${ formatBytes ( totalDist ) } , Total ESM gzip: ${ formatBytes ( totalEsm ) } ` ,
321+ ) ;
300322 }
301323}
302324
0 commit comments