11<script setup lang="ts">
22import {ArtifactDescription } from " ../types" ;
3- import {
4- diffClass ,
5- formatPercentChange ,
6- formatSize ,
7- isValidValue ,
8- } from " ../shared" ;
3+ import {diffClass , formatPercentChange , formatSize } from " ../shared" ;
94import Tooltip from " ../tooltip.vue" ;
105
116const props = defineProps <{
127 a: ArtifactDescription ;
138 b: ArtifactDescription ;
149}>();
1510
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+
1632// 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 );
2036 if (aLib && ! bLib ) {
2137 return 1 ;
2238 } else if (! aLib && bLib ) {
2339 return - 1 ;
2440 } else {
25- return a .localeCompare (b );
41+ return a .name . localeCompare (b . name );
2642 }
2743});
2844
@@ -37,27 +53,25 @@ function formatName(component: string): string {
3753 return component ;
3854}
3955
40- function formatValue(value : number | undefined ): string {
41- if (! isValidValue ( value ) ) {
56+ function formatValue(value : number ): string {
57+ if (value === 0 ) {
4258 return " -" ;
4359 }
4460 return formatSize (value );
4561}
4662
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 {
5464 return (b - a ).toLocaleString ();
5565}
5666
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 " ;
6070 }
71+ return value .toLocaleString ();
72+ }
73+
74+ function formatChange(a : number , b : number ): string {
6175 const diff = b - a ;
6276 const formatted = formatSize (Math .abs (diff ));
6377 if (diff < 0 ) {
@@ -66,8 +80,8 @@ function formatChange(a: number | undefined, b: number | undefined): string {
6680 return formatted ;
6781}
6882
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 ) {
7185 return " " ;
7286 }
7387 return diffClass (b - a );
@@ -111,68 +125,33 @@ function generateTitle(component: string): string {
111125 <tbody >
112126 <tr v-for =" component in components" >
113127 <td class =" component" >
114- {{ formatName(component) }}
115- <Tooltip >{{ generateTitle(component) }}</Tooltip >
128+ {{ formatName(component.name ) }}
129+ <Tooltip >{{ generateTitle(component.name ) }}</Tooltip >
116130 </td >
117131 <td >
118- {{ isLibrary(component) ? "Library" : "Binary" }}
132+ {{ isLibrary(component.name ) ? "Library" : "Binary" }}
119133 </td >
120134 <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) }}
126137 </div >
127138 </td >
128139 <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) }}
134142 </div >
135143 </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)" >
144145 <div
145146 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)"
152148 >
153- {{
154- formatChange(
155- a.component_sizes[component],
156- b.component_sizes[component]
157- )
158- }}
149+ {{ formatChange(component.before, component.after) }}
159150 </div >
160151 </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)" >
169153 <div class =" aligned" >
170- {{
171- formatPercentChange(
172- a.component_sizes[component],
173- b.component_sizes[component]
174- )
175- }}
154+ {{ formatPercentChange(component.before, component.after) }}
176155 </div >
177156 </td >
178157 </tr >
0 commit comments