diff --git a/.changeset/silver-melons-cheat.md b/.changeset/silver-melons-cheat.md new file mode 100644 index 0000000..3ffad78 --- /dev/null +++ b/.changeset/silver-melons-cheat.md @@ -0,0 +1,5 @@ +--- +"sonda": patch +--- + +Sort `inputs` and `outputs.inputs` in JSON report for easier diffing diff --git a/packages/sonda/src/report.ts b/packages/sonda/src/report.ts index 1940e4c..cad8eac 100644 --- a/packages/sonda/src/report.ts +++ b/packages/sonda/src/report.ts @@ -34,8 +34,8 @@ export function generateJsonReport( }, {} as Record ); return { - inputs, - outputs + inputs: sortObjectKeys( inputs ), + outputs: sortObjectKeys( outputs ) }; } @@ -71,17 +71,31 @@ function processAsset( const assetSizes = getSizes( code, options ); const bytes = getBytesPerSource( code, mapped, assetSizes, options ); - - return { - ...assetSizes, - inputs: Array.from( bytes ).reduce( ( carry, [ source, sizes ] ) => { + const outputInputs = Array + .from( bytes ) + .reduce( ( carry, [ source, sizes ] ) => { carry[ normalizePath( source ) ] = sizes; return carry; - }, {} as Record ) + }, {} as Record ); + + return { + ...assetSizes, + inputs: sortObjectKeys( outputInputs ) }; } function hasCodeAndMap( result: MaybeCodeMap ): result is Required { return Boolean( result && result.code && result.map ); } + +function sortObjectKeys( object: Record ): Record { + return Object + .keys( object ) + .sort() + .reduce( ( carry, key ) => { + carry[ key ] = object[ key ]; + + return carry; + }, {} as Record ); +}