@@ -6,6 +6,7 @@ import { exec as nodeExec } from "node:child_process";
66import isCleanWorkingDir from "./lib/isCleanWorkingDir.js" ;
77
88const VERSION = 1 ;
9+ const lastRunBranch = " last run" ;
910
1011const gzip = promisify ( zlib . gzip ) ;
1112const exec = promisify ( nodeExec ) ;
@@ -39,7 +40,7 @@ async function getCache( loc ) {
3940 return { } ;
4041 }
4142
42- const lastRun = cache [ " last run" ] ;
43+ const lastRun = cache [ lastRunBranch ] ;
4344 if ( ! lastRun || ! lastRun . meta || lastRun . meta . version !== VERSION ) {
4445 console . log ( "Compare cache version mismatch. Rewriting..." ) ;
4546 return { } ;
@@ -73,6 +74,22 @@ function compareSizes( existing, current, padLength ) {
7374 return chalk . green ( `${ delta } ` . padStart ( padLength ) ) ;
7475}
7576
77+ function sortBranches ( a , b ) {
78+ if ( a === lastRunBranch ) {
79+ return 1 ;
80+ }
81+ if ( b === lastRunBranch ) {
82+ return - 1 ;
83+ }
84+ if ( a < b ) {
85+ return - 1 ;
86+ }
87+ if ( a > b ) {
88+ return 1 ;
89+ }
90+ return 0 ;
91+ }
92+
7693export async function compareSize ( { cache = ".sizecache.json" , files } = { } ) {
7794 if ( ! files || ! files . length ) {
7895 throw new Error ( "No files specified" ) ;
@@ -116,7 +133,7 @@ export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
116133 return `${ rawSize } ${ gzSize } ${ result . filename } ` ;
117134 } ) ;
118135
119- const comparisons = Object . keys ( sizeCache ) . map ( function ( branch ) {
136+ const comparisons = Object . keys ( sizeCache ) . sort ( sortBranches ) . map ( function ( branch ) {
120137 const meta = sizeCache [ branch ] . meta || { } ;
121138 const commit = meta . commit ;
122139
@@ -153,7 +170,7 @@ export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
153170
154171 // Always save the last run
155172 // Save version under last run
156- sizeCache [ " last run" ] = {
173+ sizeCache [ lastRunBranch ] = {
157174 meta : { version : VERSION } ,
158175 files : cacheResults ( results )
159176 } ;
0 commit comments