@@ -31,12 +31,27 @@ class SizeLimit {
31
31
return bytes . format ( size , { unitSeparator : ' ' } ) ;
32
32
}
33
33
34
- formatTime ( seconds ) {
35
- if ( seconds >= 1 ) {
36
- return `${ Math . ceil ( seconds * 10 ) / 10 } s` ;
34
+ formatPercentageChange ( base = 0 , current = 0 ) {
35
+ if ( base === 0 ) {
36
+ return 'added' ;
37
+ }
38
+
39
+ if ( current === 0 ) {
40
+ return 'removed' ;
41
+ }
42
+
43
+ const value = ( ( current - base ) / base ) * 100 ;
44
+ const formatted = ( Math . sign ( value ) * Math . ceil ( Math . abs ( value ) * 100 ) ) / 100 ;
45
+
46
+ if ( value > 0 ) {
47
+ return `+${ formatted } %` ;
37
48
}
38
49
39
- return `${ Math . ceil ( seconds * 1000 ) } ms` ;
50
+ if ( value === 0 ) {
51
+ return '-' ;
52
+ }
53
+
54
+ return `${ formatted } %` ;
40
55
}
41
56
42
57
formatChange ( base = 0 , current = 0 ) {
@@ -48,75 +63,50 @@ class SizeLimit {
48
63
return 'removed' ;
49
64
}
50
65
51
- const value = ( ( current - base ) / base ) * 100 ;
52
- const formatted = ( Math . sign ( value ) * Math . ceil ( Math . abs ( value ) * 100 ) ) / 100 ;
66
+ const value = current - base ;
67
+ const formatted = this . formatBytes ( value ) ;
53
68
54
69
if ( value > 0 ) {
55
- return `+${ formatted } % 🔺` ;
70
+ return `+${ formatted } 🔺` ;
56
71
}
57
72
58
73
if ( value === 0 ) {
59
- return ` ${ formatted } %` ;
74
+ return '-' ;
60
75
}
61
76
62
- return `${ formatted } % 🔽` ;
77
+ return `${ formatted } 🔽` ;
63
78
}
64
79
65
80
formatLine ( value , change ) {
66
81
return `${ value } (${ change } )` ;
67
82
}
68
83
69
84
formatSizeResult ( name , base , current ) {
70
- return [ name , this . formatLine ( this . formatBytes ( current . size ) , this . formatChange ( base . size , current . size ) ) ] ;
71
- }
72
-
73
- formatTimeResult ( name , base , current ) {
74
85
return [
75
86
name ,
76
- this . formatLine ( this . formatBytes ( current . size ) , this . formatChange ( base . size , current . size ) ) ,
77
- this . formatLine ( this . formatTime ( current . loading ) , this . formatChange ( base . loading , current . loading ) ) ,
78
- this . formatLine ( this . formatTime ( current . running ) , this . formatChange ( base . running , current . running ) ) ,
79
- this . formatTime ( current . total ) ,
87
+ this . formatBytes ( current . size ) ,
88
+ this . formatPercentageChange ( base . size , current . size ) ,
89
+ this . formatChange ( base . size , current . size ) ,
80
90
] ;
81
91
}
82
92
83
93
parseResults ( output ) {
84
94
const results = JSON . parse ( output ) ;
85
95
86
96
return results . reduce ( ( current , result ) => {
87
- let time = { } ;
88
-
89
- if ( result . loading !== undefined && result . running !== undefined ) {
90
- const loading = + result . loading ;
91
- const running = + result . running ;
92
-
93
- time = {
94
- running,
95
- loading,
96
- total : loading + running ,
97
- } ;
98
- }
99
-
100
97
return {
101
98
// biome-ignore lint/performance/noAccumulatingSpread: <explanation>
102
99
...current ,
103
100
[ result . name ] : {
104
101
name : result . name ,
105
102
size : + result . size ,
106
- ...time ,
107
103
} ,
108
104
} ;
109
105
} , { } ) ;
110
106
}
111
107
112
108
hasSizeChanges ( base , current , threshold = 0 ) {
113
109
const names = [ ...new Set ( [ ...( base ? Object . keys ( base ) : [ ] ) , ...Object . keys ( current ) ] ) ] ;
114
- const isSize = names . some ( name => current [ name ] && current [ name ] . total === undefined ) ;
115
-
116
- // Always return true if time results are present
117
- if ( ! isSize ) {
118
- return true ;
119
- }
120
110
121
111
return ! ! names . find ( name => {
122
112
const baseResult = base ?. [ name ] || EmptyResult ;
@@ -132,16 +122,12 @@ class SizeLimit {
132
122
133
123
formatResults ( base , current ) {
134
124
const names = [ ...new Set ( [ ...( base ? Object . keys ( base ) : [ ] ) , ...Object . keys ( current ) ] ) ] ;
135
- const isSize = names . some ( name => current [ name ] && current [ name ] . total === undefined ) ;
136
- const header = isSize ? SIZE_RESULTS_HEADER : TIME_RESULTS_HEADER ;
125
+ const header = SIZE_RESULTS_HEADER ;
137
126
const fields = names . map ( name => {
138
127
const baseResult = base ?. [ name ] || EmptyResult ;
139
128
const currentResult = current [ name ] || EmptyResult ;
140
129
141
- if ( isSize ) {
142
- return this . formatSizeResult ( name , baseResult , currentResult ) ;
143
- }
144
- return this . formatTimeResult ( name , baseResult , currentResult ) ;
130
+ return this . formatSizeResult ( name , baseResult , currentResult ) ;
145
131
} ) ;
146
132
147
133
return [ header , ...fields ] ;
@@ -165,15 +151,12 @@ async function execSizeLimit() {
165
151
return { status, output } ;
166
152
}
167
153
168
- const SIZE_RESULTS_HEADER = [ 'Path' , 'Size' ] ;
169
- const TIME_RESULTS_HEADER = [ 'Path' , 'Size' , 'Loading time (3g)' , 'Running time (snapdragon)' , 'Total time' ] ;
154
+ const SIZE_RESULTS_HEADER = [ 'Path' , 'Size' , 'Change' ] ;
170
155
171
156
const EmptyResult = {
172
157
name : '-' ,
173
158
size : 0 ,
174
- running : 0 ,
175
- loading : 0 ,
176
- total : 0 ,
159
+ change : 0 ,
177
160
} ;
178
161
179
162
async function run ( ) {
0 commit comments