@@ -110,23 +110,26 @@ async function run() {
110110 const md = [ "" , `#### ${ name } ` , "" ] ;
111111 const data = [ name , bytesToSize ( totalDiffSize ) ] ;
112112
113+ if ( totalDiffSize - totalSize === 0 ) return ;
114+
113115 if ( hasDiff ) {
114116 // If a diff path was provided and the component folder doesn't exist,
115117 // report that the compiled assets were removed
116118 if (
117119 ! existsSync ( join ( diffPath , "components" , name ) ) ||
118120 ( totalSize === 0 && totalDiffSize > 0 )
119121 ) {
120- data . push ( "🚨 package deleted/moved/renamed" ) ;
122+ data . push ( "🚨 deleted, moved, or renamed" ) ;
123+ summaryTable . push ( data ) ;
121124 } else if ( totalSize > 0 && totalDiffSize === 0 ) {
122- data . push ( "🎉 new package" ) ;
123- } else {
125+ data . push ( "🎉 new" ) ;
126+ summaryTable . push ( data ) ;
127+ } else if ( bytesToSize ( Math . abs ( totalDiffSize - totalSize ) ) !== "< 0.01 KB" ) {
124128 data . push ( printChange ( totalDiffSize - totalSize ) ) ;
129+ summaryTable . push ( data ) ;
125130 }
126131 }
127132
128- summaryTable . push ( data ) ;
129-
130133 md . push (
131134 ...[
132135 [ "File" , "Size" , ...( hasDiff ? [ "Base" , "Δ" ] : [ ] ) ] ,
@@ -137,7 +140,7 @@ async function run() {
137140 ...( hasDiff
138141 ? [
139142 bytesToSize ( totalDiffSize ) ,
140- `${ printChange ( totalDiffSize - totalSize ) } (${ printPercentChange ( ( totalDiffSize - totalSize ) / totalSize ) } )` ,
143+ `${ printChange ( totalDiffSize - totalSize ) } ${ totalDiffSize - totalSize !== 0 ? ` (${ printPercentChange ( ( totalDiffSize - totalSize ) / totalSize ) } )` : "" } ` ,
141144 ]
142145 : [ ] ) ,
143146 ] ,
@@ -157,7 +160,7 @@ async function run() {
157160 byteSize === 0 && diffByteSize > 0 ? "**removed**" : bytesToSize ( byteSize ) ,
158161 ...( hasDiff ? [
159162 bytesToSize ( diffByteSize ) ,
160- `${ printChange ( diffByteSize - byteSize ) } (${ printPercentChange ( ( diffByteSize - byteSize ) / byteSize ) } )` ,
163+ `${ printChange ( diffByteSize - byteSize ) } ${ diffByteSize - byteSize !== 0 ? ` (${ printPercentChange ( ( diffByteSize - byteSize ) / byteSize ) } )` : "" } ` ,
161164 ] : [ ] ) ,
162165 ]
163166 ] ;
@@ -177,7 +180,14 @@ async function run() {
177180 summary . push ( ...summaryTable . map ( ( row ) => `| ${ row . join ( " | " ) } |` ) ) ;
178181 }
179182
180- markdown . push ( "" , `<small><sup>*</sup> <em>An ASCII character in UTF-8 is 8 bits or 1 byte.</em></small>` ) ;
183+ markdown . push (
184+ "" ,
185+ "<small>" ,
186+ "* <em>Size determined by adding together the size of the main file (index.css) for all packages in the library.</em><br/>" ,
187+ "* <em>Results are not gzipped or minified.</em><br/>" ,
188+ "* <em>An ASCII character in UTF-8 is 8 bits or 1 byte.</em>" ,
189+ "</small>"
190+ ) ;
181191
182192 // --------------- Start Comment ---------------
183193 if ( shouldAddComment ) {
@@ -255,30 +265,38 @@ const printPercentChange = function (delta) {
255265
256266/**
257267 *
258- * @param {Map<string, number> } pathMap
259- * @param {Map<string, number> } diffMap
260- * @returns {string }
268+ * @param {Map<string, Map<string, { byteSize: number, diffByteSize: number }>> } COMPONENTS
269+ * @returns {Array<{ name: string, totalSize: number, totalDiffSize: number, hasChange: boolean, fileMap: Map<string, { byteSize: number, diffByteSize: number }>}> }
261270 */
262271const makeTable = function ( COMPONENTS ) {
263272 const sections = [ ] ;
264273
265274 /** Next convert that component data into a comment */
266275 COMPONENTS . forEach ( ( fileMap , componentName ) => {
267- const totalSize = [ ...fileMap . values ( ) ] . reduce (
268- ( acc , { byteSize } ) => acc + byteSize ,
276+ const mainFileOnly = [ ...fileMap . keys ( ) ] . filter ( ( file ) => file . endsWith ( "index.css" ) ) ;
277+ const totalSize = mainFileOnly . reduce (
278+ ( acc , filename ) => {
279+ const { byteSize = 0 } = fileMap . get ( filename ) ;
280+ return acc + byteSize ;
281+ } ,
269282 0
270283 ) ;
271- const totalDiffSize = [ ...fileMap . values ( ) ] . reduce (
272- ( acc , { diffByteSize = 0 } ) => acc + diffByteSize ,
284+ const totalDiffSize = mainFileOnly . reduce (
285+ ( acc , filename ) => {
286+ const { diffByteSize = 0 } = fileMap . get ( filename ) ;
287+ return acc + diffByteSize ;
288+ } ,
273289 0
274290 ) ;
275291
292+ const hasChange = fileMap . size > 0 && [ ...fileMap . values ( ) ] . some ( ( { byteSize, diffByteSize } ) => byteSize !== diffByteSize ) ;
293+
276294 /**
277295 * We don't need to report on components that haven't changed unless they're new or removed
278296 */
279297 if ( totalSize === totalDiffSize ) return ;
280298
281- sections . push ( { name : componentName , totalSize, totalDiffSize, fileMap } ) ;
299+ sections . push ( { name : componentName , totalSize, totalDiffSize, hasChange , fileMap } ) ;
282300 } ) ;
283301
284302 return sections ;
0 commit comments