@@ -90,16 +90,6 @@ function formatDiff(absoluteChange, relativeChange) {
9090 ) } )`;
9191}
9292
93- function computeBundleLabel ( bundleId ) {
94- if ( bundleId === 'packages/material-ui/build/umd/material-ui.production.min.js' ) {
95- return '@material-ui/core[umd]' ;
96- }
97- if ( bundleId === '@material-ui/core/Textarea' ) {
98- return 'TextareaAutosize' ;
99- }
100- return bundleId . replace ( / ^ @ m a t e r i a l - u i \/ c o r e \/ / , '' ) . replace ( / \. e s m $ / , '' ) ;
101- }
102-
10393/**
10494 * Generates a Markdown table
10595 * @param {{ label: string, align: 'left' | 'center' | 'right'}[] } headers
@@ -129,6 +119,74 @@ function generateEmphasizedChange([bundle, { parsed, gzip }]) {
129119 return `**${ bundle } **: parsed: ${ changeParsed } , gzip: ${ changeGzip } ` ;
130120}
131121
122+ /**
123+ *
124+ * @param {[string, object][] } entries
125+ * @param {object } options
126+ * @param {function (string): string } options.computeBundleLabel
127+ */
128+ function createComparisonTable ( entries , options ) {
129+ const { computeBundleLabel } = options ;
130+
131+ return generateMDTable (
132+ [
133+ { label : 'bundle' } ,
134+ { label : 'Size Change' , align : 'right' } ,
135+ { label : 'Size' , align : 'right' } ,
136+ { label : 'Gzip Change' , align : 'right' } ,
137+ { label : 'Gzip' , align : 'right' } ,
138+ ] ,
139+ entries
140+ . map ( ( [ bundleId , size ] ) => [ computeBundleLabel ( bundleId ) , size ] )
141+ // orderBy(|parsedDiff| DESC, |gzipDiff| DESC, name ASC)
142+ . sort ( ( [ labelA , statsA ] , [ labelB , statsB ] ) => {
143+ const compareParsedDiff =
144+ Math . abs ( statsB . parsed . absoluteDiff ) - Math . abs ( statsA . parsed . absoluteDiff ) ;
145+ const compareGzipDiff =
146+ Math . abs ( statsB . gzip . absoluteDiff ) - Math . abs ( statsA . gzip . absoluteDiff ) ;
147+ const compareName = labelA . localeCompare ( labelB ) ;
148+
149+ if ( compareParsedDiff === 0 && compareGzipDiff === 0 ) {
150+ return compareName ;
151+ }
152+ if ( compareParsedDiff === 0 ) {
153+ return compareGzipDiff ;
154+ }
155+ return compareParsedDiff ;
156+ } )
157+ . map ( ( [ label , { parsed, gzip } ] ) => {
158+ return [
159+ label ,
160+ formatDiff ( parsed . absoluteDiff , parsed . relativeDiff ) ,
161+ prettyBytes ( parsed . current ) ,
162+ formatDiff ( gzip . absoluteDiff , gzip . relativeDiff ) ,
163+ prettyBytes ( gzip . current ) ,
164+ ] ;
165+ } ) ,
166+ ) ;
167+ }
168+
169+ /**
170+ * Puts results in different buckets wh
171+ * @param {* } results
172+ */
173+ function sieveResults ( results ) {
174+ const main = [ ] ;
175+ const pages = [ ] ;
176+
177+ results . forEach ( entry => {
178+ const [ bundleId ] = entry ;
179+
180+ if ( bundleId . startsWith ( 'docs:' ) ) {
181+ pages . push ( entry ) ;
182+ } else {
183+ main . push ( entry ) ;
184+ }
185+ } ) ;
186+
187+ return { all : results , main, pages } ;
188+ }
189+
132190async function run ( ) {
133191 // Use git locally to grab the commit which represents the place
134192 // where the branches differ
@@ -145,11 +203,14 @@ async function run() {
145203 const commitRange = `${ mergeBaseCommit } ...${ danger . github . pr . head . sha } ` ;
146204
147205 const comparison = await loadComparison ( mergeBaseCommit , upstreamRef ) ;
148- const results = Object . entries ( comparison . bundles ) ;
149- const anyResultsChanges = results . filter ( createComparisonFilter ( 1 , 1 ) ) ;
206+
207+ const { all : allResults , main : mainResults , pages : pageResults } = sieveResults (
208+ Object . entries ( comparison . bundles ) ,
209+ ) ;
210+ const anyResultsChanges = allResults . filter ( createComparisonFilter ( 1 , 1 ) ) ;
150211
151212 if ( anyResultsChanges . length > 0 ) {
152- const importantChanges = results
213+ const importantChanges = mainResults
153214 . filter ( createComparisonFilter ( parsedSizeChangeThreshold , gzipSizeChangeThreshold ) )
154215 . filter ( isPackageComparison )
155216 . map ( generateEmphasizedChange ) ;
@@ -159,50 +220,44 @@ async function run() {
159220 markdown ( importantChanges . join ( '\n' ) ) ;
160221 }
161222
162- const detailsTable = generateMDTable (
163- [
164- { label : 'bundle' } ,
165- { label : 'Size Change' , align : 'right' } ,
166- { label : 'Size' , align : 'right' } ,
167- { label : 'Gzip Change' , align : 'right' } ,
168- { label : 'Gzip' , align : 'right' } ,
169- ] ,
170- results
171- . map ( ( [ bundleId , size ] ) => [ computeBundleLabel ( bundleId ) , size ] )
172- // orderBy(|parsedDiff| DESC, |gzipDiff| DESC, name ASC)
173- . sort ( ( [ labelA , statsA ] , [ labelB , statsB ] ) => {
174- const compareParsedDiff =
175- Math . abs ( statsB . parsed . absoluteDiff ) - Math . abs ( statsA . parsed . absoluteDiff ) ;
176- const compareGzipDiff =
177- Math . abs ( statsB . gzip . absoluteDiff ) - Math . abs ( statsA . gzip . absoluteDiff ) ;
178- const compareName = labelA . localeCompare ( labelB ) ;
179-
180- if ( compareParsedDiff === 0 && compareGzipDiff === 0 ) {
181- return compareName ;
182- }
183- if ( compareParsedDiff === 0 ) {
184- return compareGzipDiff ;
185- }
186- return compareParsedDiff ;
187- } )
188- . map ( ( [ label , { parsed, gzip } ] ) => {
189- return [
190- label ,
191- formatDiff ( parsed . absoluteDiff , parsed . relativeDiff ) ,
192- prettyBytes ( parsed . current ) ,
193- formatDiff ( gzip . absoluteDiff , gzip . relativeDiff ) ,
194- prettyBytes ( gzip . current ) ,
195- ] ;
196- } ) ,
197- ) ;
223+ const mainDetailsTable = createComparisonTable ( mainResults , {
224+ computeBundleLabel : bundleId => {
225+ if ( bundleId === 'packages/material-ui/build/umd/material-ui.production.min.js' ) {
226+ return '@material-ui/core[umd]' ;
227+ }
228+ if ( bundleId === '@material-ui/core/Textarea' ) {
229+ return 'TextareaAutosize' ;
230+ }
231+ if ( bundleId === 'docs.main' ) {
232+ return 'docs:/_app' ;
233+ }
234+ if ( bundleId === 'docs.landing' ) {
235+ return 'docs:/' ;
236+ }
237+ return bundleId . replace ( / ^ @ m a t e r i a l - u i \/ c o r e \/ / , '' ) . replace ( / \. e s m $ / , '' ) ;
238+ } ,
239+ } ) ;
240+ const pageDetailsTable = createComparisonTable ( pageResults , {
241+ computeBundleLabel : bundleId => {
242+ const host = `https://deploy-preview-${ danger . github . pr . number } --material-ui.netlify.com` ;
243+ const page = bundleId . replace ( / ^ d o c s : / , '' ) ;
244+ return `[${ page } ](${ host } ${ page } )` ;
245+ } ,
246+ } ) ;
198247
199248 const details = `
200249 <details>
201250 <summary>Details of bundle changes.</summary>
202251
203252 <p>Comparing: ${ commitRange } </p>
204253
205- ${ detailsTable }
254+ <details>
255+ <summary>Details of page changes</summary>
256+
257+ ${ pageDetailsTable }
258+ </details>
259+
260+ ${ mainDetailsTable }
206261
207262 </details>` ;
208263
0 commit comments