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