@@ -13,16 +13,37 @@ const props = defineProps<{
13
13
b: ArtifactDescription ;
14
14
}>();
15
15
16
+ interface ComponentSize {
17
+ name: string ;
18
+ before: number ;
19
+ after: number ;
20
+ }
21
+
22
+ const allComponents: ComponentSize [] = [
23
+ ... new Set ([
24
+ ... Object .keys (props .a .component_sizes ),
25
+ ... Object .keys (props .b .component_sizes ),
26
+ ]),
27
+ ].map ((name ) => {
28
+ const before = props .a .component_sizes [name ] ?? 0 ;
29
+ const after = props .b .component_sizes [name ] ?? 0 ;
30
+ return {
31
+ name ,
32
+ before ,
33
+ after ,
34
+ };
35
+ });
36
+
16
37
// Sort binaries first, libraries later. Then within each category, sort alphabetically.
17
- const components = Object . keys ( props . a . component_sizes ) .sort ((a , b ) => {
18
- const aLib = a . startsWith ( " lib " );
19
- const bLib = b . startsWith ( " lib " );
38
+ const components = allComponents .sort ((a , b ) => {
39
+ const aLib = isLibrary ( a . name );
40
+ const bLib = isLibrary ( b . name );
20
41
if (aLib && ! bLib ) {
21
42
return 1 ;
22
43
} else if (! aLib && bLib ) {
23
44
return - 1 ;
24
45
} else {
25
- return a .localeCompare (b );
46
+ return a .name . localeCompare (b . name );
26
47
}
27
48
});
28
49
@@ -37,27 +58,25 @@ function formatName(component: string): string {
37
58
return component ;
38
59
}
39
60
40
- function formatValue(value : number | undefined ): string {
41
- if (! isValidValue ( value ) ) {
61
+ function formatValue(value : number ): string {
62
+ if (value === 0 ) {
42
63
return " -" ;
43
64
}
44
65
return formatSize (value );
45
66
}
46
67
47
- function formatChangeTitle(
48
- a : number | undefined ,
49
- b : number | undefined
50
- ): string {
51
- if (! isValidValue (a ) || ! isValidValue (b )) {
52
- return " " ;
53
- }
68
+ function formatChangeTitle(a : number , b : number ): string {
54
69
return (b - a ).toLocaleString ();
55
70
}
56
71
57
- function formatChange( a : number | undefined , b : number | undefined ): string {
58
- if (! isValidValue ( a ) || ! isValidValue ( b ) ) {
59
- return " - " ;
72
+ function formatTitle( value : number ): string {
73
+ if (value === 0 ) {
74
+ return " Missing value " ;
60
75
}
76
+ return value .toLocaleString ();
77
+ }
78
+
79
+ function formatChange(a : number , b : number ): string {
61
80
const diff = b - a ;
62
81
const formatted = formatSize (Math .abs (diff ));
63
82
if (diff < 0 ) {
@@ -66,8 +85,8 @@ function formatChange(a: number | undefined, b: number | undefined): string {
66
85
return formatted ;
67
86
}
68
87
69
- function getClass(a : number | undefined , b : number | undefined ): string {
70
- if (! isValidValue ( a ) || ! isValidValue ( b ) || a == b ) {
88
+ function getClass(a : number , b : number ): string {
89
+ if (a = == b ) {
71
90
return " " ;
72
91
}
73
92
return diffClass (b - a );
@@ -111,68 +130,33 @@ function generateTitle(component: string): string {
111
130
<tbody >
112
131
<tr v-for =" component in components" >
113
132
<td class =" component" >
114
- {{ formatName(component) }}
115
- <Tooltip >{{ generateTitle(component) }}</Tooltip >
133
+ {{ formatName(component.name ) }}
134
+ <Tooltip >{{ generateTitle(component.name ) }}</Tooltip >
116
135
</td >
117
136
<td >
118
- {{ isLibrary(component) ? "Library" : "Binary" }}
137
+ {{ isLibrary(component.name ) ? "Library" : "Binary" }}
119
138
</td >
120
139
<td >
121
- <div
122
- class =" aligned"
123
- :title =" a.component_sizes[component].toLocaleString()"
124
- >
125
- {{ formatValue(a.component_sizes[component]) }}
140
+ <div class =" aligned" :title =" formatTitle(component.before)" >
141
+ {{ formatValue(component.before) }}
126
142
</div >
127
143
</td >
128
144
<td >
129
- <div
130
- class =" aligned"
131
- :title =" b.component_sizes[component].toLocaleString()"
132
- >
133
- {{ formatValue(b.component_sizes[component]) }}
145
+ <div class =" aligned" :title =" formatTitle(component.after)" >
146
+ {{ formatValue(component.after) }}
134
147
</div >
135
148
</td >
136
- <td
137
- :class ="
138
- getClass(
139
- a.component_sizes[component],
140
- b.component_sizes[component]
141
- )
142
- "
143
- >
149
+ <td :class =" getClass(component.before, component.after)" >
144
150
<div
145
151
class =" aligned"
146
- :title ="
147
- formatChangeTitle(
148
- a.component_sizes[component],
149
- b.component_sizes[component]
150
- )
151
- "
152
+ :title =" formatChangeTitle(component.before, component.after)"
152
153
>
153
- {{
154
- formatChange(
155
- a.component_sizes[component],
156
- b.component_sizes[component]
157
- )
158
- }}
154
+ {{ formatChange(component.before, component.after) }}
159
155
</div >
160
156
</td >
161
- <td
162
- :class ="
163
- getClass(
164
- a.component_sizes[component],
165
- b.component_sizes[component]
166
- )
167
- "
168
- >
157
+ <td :class =" getClass(component.before, component.after)" >
169
158
<div class =" aligned" >
170
- {{
171
- formatPercentChange(
172
- a.component_sizes[component],
173
- b.component_sizes[component]
174
- )
175
- }}
159
+ {{ formatPercentChange(component.before, component.after) }}
176
160
</div >
177
161
</td >
178
162
</tr >
0 commit comments