Skip to content

Commit

Permalink
Sort inputs and outputs.inputs in JSON report
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsobol committed Oct 24, 2024
1 parent f8b5f6e commit 05de327
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-melons-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sonda": patch
---

Sort `inputs` and `outputs.inputs` in JSON report for easier diffing
28 changes: 21 additions & 7 deletions packages/sonda/src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export function generateJsonReport(
}, {} as Record<string, ReportOutput> );

return {
inputs,
outputs
inputs: sortObjectKeys( inputs ),
outputs: sortObjectKeys( outputs )
};
}

Expand Down Expand Up @@ -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<string, ReportOutputInput> )
}, {} as Record<string, ReportOutputInput> );

return {
...assetSizes,
inputs: sortObjectKeys( outputInputs )
};
}

function hasCodeAndMap( result: MaybeCodeMap ): result is Required<CodeMap> {
return Boolean( result && result.code && result.map );
}

function sortObjectKeys<T extends unknown>( object: Record<string, T> ): Record<string, T> {
return Object
.keys( object )
.sort()
.reduce( ( carry, key ) => {
carry[ key ] = object[ key ];

return carry;
}, {} as Record<string, T> );
}

0 comments on commit 05de327

Please sign in to comment.