import isCleanWorkingDir from "./lib/isCleanWorkingDir.js";
const VERSION = 1;
+const lastRunBranch = " last run";
const gzip = promisify( zlib.gzip );
const exec = promisify( nodeExec );
return {};
}
- const lastRun = cache[ " last run" ];
+ const lastRun = cache[ lastRunBranch ];
if ( !lastRun || !lastRun.meta || lastRun.meta.version !== VERSION ) {
console.log( "Compare cache version mismatch. Rewriting..." );
return {};
return chalk.green( `${delta}`.padStart( padLength ) );
}
+function sortBranches( a, b ) {
+ if ( a === lastRunBranch ) {
+ return 1;
+ }
+ if ( b === lastRunBranch ) {
+ return -1;
+ }
+ if ( a < b ) {
+ return -1;
+ }
+ if ( a > b ) {
+ return 1;
+ }
+ return 0;
+}
+
export async function compareSize( { cache = ".sizecache.json", files } = {} ) {
if ( !files || !files.length ) {
throw new Error( "No files specified" );
return `${rawSize} ${gzSize} ${result.filename}`;
} );
- const comparisons = Object.keys( sizeCache ).map( function( branch ) {
+ const comparisons = Object.keys( sizeCache ).sort( sortBranches ).map( function( branch ) {
const meta = sizeCache[ branch ].meta || {};
const commit = meta.commit;
// Always save the last run
// Save version under last run
- sizeCache[ " last run" ] = {
+ sizeCache[ lastRunBranch ] = {
meta: { version: VERSION },
files: cacheResults( results )
};