7
7
*/
8
8
9
9
import { WebpackLoggingCallback } from '@angular-devkit/build-webpack' ;
10
- import { logging , tags } from '@angular-devkit/core' ;
10
+ import { logging } from '@angular-devkit/core' ;
11
11
import assert from 'node:assert' ;
12
12
import * as path from 'node:path' ;
13
13
import { Configuration , StatsCompilation } from 'webpack' ;
@@ -75,18 +75,73 @@ function generateBundleStats(info: {
75
75
} ;
76
76
}
77
77
78
+ export function generateEsbuildBuildStatsTable (
79
+ [ browserStats , serverStats ] : [ browserStats : BundleStats [ ] , serverStats : BundleStats [ ] ] ,
80
+ colors : boolean ,
81
+ showTotalSize : boolean ,
82
+ showEstimatedTransferSize : boolean ,
83
+ budgetFailures ?: BudgetCalculatorResult [ ] ,
84
+ ) : string {
85
+ const bundleInfo = generateBuildStatsData (
86
+ browserStats ,
87
+ colors ,
88
+ showTotalSize ,
89
+ showEstimatedTransferSize ,
90
+ budgetFailures ,
91
+ ) ;
92
+
93
+ if ( serverStats . length ) {
94
+ const m = ( x : string ) => ( colors ? ansiColors . magenta ( x ) : x ) ;
95
+ if ( browserStats . length ) {
96
+ bundleInfo . unshift ( [ m ( 'Browser bundles' ) ] ) ;
97
+ // Add seperators between browser and server logs
98
+ bundleInfo . push ( [ ] , [ ] ) ;
99
+ }
100
+
101
+ bundleInfo . push (
102
+ [ m ( 'Server bundles' ) ] ,
103
+ ...generateBuildStatsData ( serverStats , colors , false , false , undefined ) ,
104
+ ) ;
105
+ }
106
+
107
+ return generateTableText ( bundleInfo , colors ) ;
108
+ }
109
+
78
110
export function generateBuildStatsTable (
79
111
data : BundleStats [ ] ,
80
112
colors : boolean ,
81
113
showTotalSize : boolean ,
82
114
showEstimatedTransferSize : boolean ,
83
115
budgetFailures ?: BudgetCalculatorResult [ ] ,
84
116
) : string {
85
- const g = ( x : string ) => ( colors ? ansiColors . greenBright ( x ) : x ) ;
86
- const c = ( x : string ) => ( colors ? ansiColors . cyanBright ( x ) : x ) ;
117
+ const bundleInfo = generateBuildStatsData (
118
+ data ,
119
+ colors ,
120
+ showTotalSize ,
121
+ showEstimatedTransferSize ,
122
+ budgetFailures ,
123
+ ) ;
124
+
125
+ return generateTableText ( bundleInfo , colors ) ;
126
+ }
127
+
128
+ function generateBuildStatsData (
129
+ data : BundleStats [ ] ,
130
+ colors : boolean ,
131
+ showTotalSize : boolean ,
132
+ showEstimatedTransferSize : boolean ,
133
+ budgetFailures ?: BudgetCalculatorResult [ ] ,
134
+ ) : ( string | number ) [ ] [ ] {
135
+ if ( data . length === 0 ) {
136
+ return [ ] ;
137
+ }
138
+
139
+ const g = ( x : string ) => ( colors ? ansiColors . green ( x ) : x ) ;
140
+ const c = ( x : string ) => ( colors ? ansiColors . cyan ( x ) : x ) ;
87
141
const r = ( x : string ) => ( colors ? ansiColors . redBright ( x ) : x ) ;
88
142
const y = ( x : string ) => ( colors ? ansiColors . yellowBright ( x ) : x ) ;
89
143
const bold = ( x : string ) => ( colors ? ansiColors . bold ( x ) : x ) ;
144
+ const dim = ( x : string ) => ( colors ? ansiColors . dim ( x ) : x ) ;
90
145
91
146
const getSizeColor = ( name : string , file ?: string , defaultColor = c ) => {
92
147
const severity = budgets . get ( name ) || ( file && budgets . get ( file ) ) ;
@@ -138,7 +193,7 @@ export function generateBuildStatsTable(
138
193
if ( showEstimatedTransferSize ) {
139
194
data = [
140
195
g ( files ) ,
141
- names ,
196
+ dim ( names ) ,
142
197
getRawSizeColor ( typeof rawSize === 'number' ? formatSize ( rawSize ) : rawSize ) ,
143
198
c (
144
199
typeof estimatedTransferSize === 'number'
@@ -149,7 +204,7 @@ export function generateBuildStatsTable(
149
204
} else {
150
205
data = [
151
206
g ( files ) ,
152
- names ,
207
+ dim ( names ) ,
153
208
getRawSizeColor ( typeof rawSize === 'number' ? formatSize ( rawSize ) : rawSize ) ,
154
209
'' ,
155
210
] ;
@@ -172,25 +227,25 @@ export function generateBuildStatsTable(
172
227
}
173
228
174
229
const bundleInfo : ( string | number ) [ ] [ ] = [ ] ;
175
- const baseTitles = [ 'Names' , 'Raw Size ' ] ;
230
+ const baseTitles = [ 'Names' , 'Raw size ' ] ;
176
231
const tableAlign : ( 'l' | 'r' ) [ ] = [ 'l' , 'l' , 'r' ] ;
177
232
178
233
if ( showEstimatedTransferSize ) {
179
- baseTitles . push ( 'Estimated Transfer Size ' ) ;
234
+ baseTitles . push ( 'Estimated transfer size ' ) ;
180
235
tableAlign . push ( 'r' ) ;
181
236
}
182
237
183
238
// Entry chunks
184
239
if ( changedEntryChunksStats . length ) {
185
- bundleInfo . push ( [ 'Initial Chunk Files ' , ...baseTitles ] . map ( bold ) , ...changedEntryChunksStats ) ;
240
+ bundleInfo . push ( [ 'Initial chunk files ' , ...baseTitles ] . map ( bold ) , ...changedEntryChunksStats ) ;
186
241
187
242
if ( showTotalSize ) {
188
243
bundleInfo . push ( [ ] ) ;
189
244
190
245
const initialSizeTotalColor = getSizeColor ( 'bundle initial' , undefined , ( x ) => x ) ;
191
246
const totalSizeElements = [
192
247
' ' ,
193
- 'Initial Total ' ,
248
+ 'Initial total ' ,
194
249
initialSizeTotalColor ( formatSize ( initialTotalRawSize ) ) ,
195
250
] ;
196
251
if ( showEstimatedTransferSize ) {
@@ -211,10 +266,10 @@ export function generateBuildStatsTable(
211
266
212
267
// Lazy chunks
213
268
if ( changedLazyChunksStats . length ) {
214
- bundleInfo . push ( [ 'Lazy Chunk Files ' , ...baseTitles ] . map ( bold ) , ...changedLazyChunksStats ) ;
269
+ bundleInfo . push ( [ 'Lazy chunk files ' , ...baseTitles ] . map ( bold ) , ...changedLazyChunksStats ) ;
215
270
}
216
271
217
- return generateTableText ( bundleInfo , colors ) ;
272
+ return bundleInfo ;
218
273
}
219
274
220
275
function generateTableText ( bundleInfo : ( string | number ) [ ] [ ] , colors : boolean ) : string {
@@ -255,12 +310,6 @@ function generateTableText(bundleInfo: (string | number)[][], colors: boolean):
255
310
return outputTable . join ( '\n' ) ;
256
311
}
257
312
258
- function generateBuildStats ( hash : string , time : number , colors : boolean ) : string {
259
- const w = ( x : string ) => ( colors ? ansiColors . bold . white ( x ) : x ) ;
260
-
261
- return `Build at: ${ w ( new Date ( ) . toISOString ( ) ) } - Hash: ${ w ( hash ) } - Time: ${ w ( '' + time ) } ms` ;
262
- }
263
-
264
313
// We use this cache because we can have multiple builders running in the same process,
265
314
// where each builder has different output path.
266
315
@@ -279,6 +328,7 @@ function statsToString(
279
328
280
329
const colors = statsConfig . colors ;
281
330
const rs = ( x : string ) => ( colors ? ansiColors . reset ( x ) : x ) ;
331
+ const w = ( x : string ) => ( colors ? ansiColors . bold . white ( x ) : x ) ;
282
332
283
333
const changedChunksStats : BundleStats [ ] = [ ] ;
284
334
let unchangedChunkNumber = 0 ;
@@ -330,30 +380,13 @@ function statsToString(
330
380
// In some cases we do things outside of webpack context
331
381
// Such us index generation, service worker augmentation etc...
332
382
// This will correct the time and include these.
333
-
334
383
const time = getBuildDuration ( json ) ;
335
384
336
- if ( unchangedChunkNumber > 0 ) {
337
- return (
338
- '\n' +
339
- rs ( tags . stripIndents `
340
- ${ statsTable }
341
-
342
- ${ unchangedChunkNumber } unchanged chunks
343
-
344
- ${ generateBuildStats ( json . hash || '' , time , colors ) }
345
- ` )
346
- ) ;
347
- } else {
348
- return (
349
- '\n' +
350
- rs ( tags . stripIndents `
351
- ${ statsTable }
352
-
353
- ${ generateBuildStats ( json . hash || '' , time , colors ) }
354
- ` )
355
- ) ;
356
- }
385
+ return rs (
386
+ `\n${ statsTable } \n\n` +
387
+ ( unchangedChunkNumber > 0 ? `${ unchangedChunkNumber } unchanged chunks\n\n` : '' ) +
388
+ `Build at: ${ w ( new Date ( ) . toISOString ( ) ) } - Hash: ${ w ( json . hash || '' ) } - Time: ${ w ( '' + time ) } ms` ,
389
+ ) ;
357
390
}
358
391
359
392
export function statsWarningsToString (
0 commit comments