@@ -3,8 +3,8 @@ import { findPackageRoot } from 'workspace-tools';
33
44import { getChangedEntriesInReport } from '../utils/getChangedEntriesInReport.mjs' ;
55import { formatBytes } from '../utils/helpers.mjs' ;
6- import type { ComparedReport } from '../utils/compareResultsInReports.mjs' ;
76import type { DiffByMetric } from '../utils/calculateDiffByMetric.mjs' ;
7+ import type { Reporter } from './shared.mjs' ;
88
99const icons = { increase : 'increase.png' , decrease : 'decrease.png' } ;
1010
@@ -31,29 +31,25 @@ function formatDelta(diff: DiffByMetric): string {
3131 return `\`${ formatBytes ( diff . delta ) } \` ${ getDirectionSymbol ( diff . delta ) } ` ;
3232}
3333
34- export async function markdownReporter ( result : ComparedReport , commitSHA : string , repository : string , quiet : boolean ) {
35- const dirname = fileURLToPath ( new URL ( '.' , import . meta . url ) ) ;
36- const packageRoot = findPackageRoot ( dirname ) ;
34+ export const markdownReporter : Reporter = ( report , options ) => {
35+ const { commitSHA , repository , showUnchanged } = options ;
36+ const footer = `<sub>🤖 This report was generated against <a href=' ${ repository } /commit/ ${ commitSHA } '> ${ commitSHA } </a></sub>` ;
3737
38- if ( ! packageRoot ) {
39- throw new Error (
40- [
41- 'Failed to find a package root (directory that contains "package.json" file)' ,
42- `Lookup start in: ${ dirname } ` ,
43- ] . join ( '\n' ) ,
44- ) ;
45- }
38+ assertPackageRoot ( ) ;
4639
47- const report = [ ] ;
40+ const { changedEntries , unchangedEntries } = getChangedEntriesInReport ( report ) ;
4841
49- report . push ( '## 📊 Bundle size report' ) ;
50- report . push ( '' ) ;
42+ const reportOutput = [ '## 📊 Bundle size report' , '' ] ;
5143
52- const { changedEntries, unchangedEntries } = getChangedEntriesInReport ( result ) ;
44+ if ( changedEntries . length === 0 ) {
45+ reportOutput . push ( `✅ No changes found` ) ;
46+ console . log ( reportOutput . join ( '\n' ) ) ;
47+ return ;
48+ }
5349
5450 if ( changedEntries . length > 0 ) {
55- report . push ( '| Package & Exports | Baseline (minified/GZIP) | PR | Change |' ) ;
56- report . push ( '| :---------------- | -----------------------: | ----: | ---------: |' ) ;
51+ reportOutput . push ( '| Package & Exports | Baseline (minified/GZIP) | PR | Change |' ) ;
52+ reportOutput . push ( '| :---------------- | -----------------------: | ----: | ---------: |' ) ;
5753
5854 changedEntries . forEach ( entry => {
5955 const title = `<samp>${ entry . packageName } </samp> <br /> <abbr title='${ entry . path } '>${ entry . name } </abbr>` ;
@@ -71,36 +67,48 @@ export async function markdownReporter(result: ComparedReport, commitSHA: string
7167 ? '🆕 New entry'
7268 : [ `${ formatDelta ( entry . diff . minified ) } ` , '<br />' , `${ formatDelta ( entry . diff . gzip ) } ` ] . join ( '' ) ;
7369
74- report . push ( `| ${ title } | ${ before } | ${ after } | ${ difference } |` ) ;
70+ reportOutput . push ( `| ${ title } | ${ before } | ${ after } | ${ difference } |` ) ;
7571 } ) ;
7672
77- report . push ( '' ) ;
73+ reportOutput . push ( '' ) ;
7874 }
7975
80- if ( unchangedEntries . length > 0 ) {
81- report . push ( '<details>' ) ;
82- report . push ( '<summary>Unchanged fixtures</summary>' ) ;
83- report . push ( '' ) ;
76+ if ( showUnchanged && unchangedEntries . length > 0 ) {
77+ reportOutput . push ( '<details>' ) ;
78+ reportOutput . push ( '<summary>Unchanged fixtures</summary>' ) ;
79+ reportOutput . push ( '' ) ;
8480
85- report . push ( '| Package & Exports | Size (minified/GZIP) |' ) ;
86- report . push ( '| ----------------- | -------------------: |' ) ;
81+ reportOutput . push ( '| Package & Exports | Size (minified/GZIP) |' ) ;
82+ reportOutput . push ( '| ----------------- | -------------------: |' ) ;
8783
8884 unchangedEntries . forEach ( entry => {
8985 const title = `<samp>${ entry . packageName } </samp> <br /> <abbr title='${ entry . path } '>${ entry . name } </abbr>` ;
9086 const size = [ `\`${ formatBytes ( entry . minifiedSize ) } \`` , '<br />' , `\`${ formatBytes ( entry . gzippedSize ) } \`` ] . join (
9187 '' ,
9288 ) ;
9389
94- report . push ( `| ${ title } | ${ size } |` ) ;
90+ reportOutput . push ( `| ${ title } | ${ size } |` ) ;
9591 } ) ;
9692
97- report . push ( '</details>' ) ;
93+ reportOutput . push ( '</details>' ) ;
9894 }
9995
10096 // TODO: use repo settings
101- report . push (
102- `<sub>🤖 This report was generated against <a href='${ repository } /commit/${ commitSHA } '>${ commitSHA } </a></sub>` ,
103- ) ;
97+ reportOutput . push ( footer ) ;
98+
99+ console . log ( reportOutput . join ( '\n' ) ) ;
100+ } ;
104101
105- console . log ( report . join ( '\n' ) ) ;
102+ function assertPackageRoot ( ) {
103+ const dirname = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
104+ const packageRoot = findPackageRoot ( dirname ) ;
105+
106+ if ( ! packageRoot ) {
107+ throw new Error (
108+ [
109+ 'Failed to find a package root (directory that contains "package.json" file)' ,
110+ `Lookup start in: ${ dirname } ` ,
111+ ] . join ( '\n' ) ,
112+ ) ;
113+ }
106114}
0 commit comments