@@ -56,8 +56,8 @@ async function run() {
5656 // --------------- End evaluation ---------------
5757
5858 /** Split the data by component package */
59- const COMPONENTS = splitDataByComponent ( pathOutput , diffOutput ) ;
60- const sections = makeTable ( COMPONENTS ) ;
59+ const { filePath , PACKAGES } = splitDataByPackage ( pathOutput , path , diffOutput ) ;
60+ const sections = makeTable ( PACKAGES , filePath , path ) ;
6161
6262 const overallSize = [ ...pathOutput . values ( ) ] . reduce (
6363 ( acc , size ) => acc + size ,
@@ -106,17 +106,17 @@ async function run() {
106106
107107 markdown . push ( `<details>` , `<summary><b>Details</b></summary>` , "" ) ;
108108
109- sections . map ( ( { name, totalSize, totalDiffSize, fileMap } ) => {
109+ sections . map ( ( { name, filePath , totalSize, totalDiffSize, hasChange , fileMap } ) => {
110110 const md = [ "" , `#### ${ name } ` , "" ] ;
111111 const data = [ name , bytesToSize ( totalDiffSize ) ] ;
112112
113- if ( totalDiffSize - totalSize === 0 ) return ;
113+ if ( ! hasChange ) return ;
114114
115115 if ( hasDiff ) {
116116 // If a diff path was provided and the component folder doesn't exist,
117117 // report that the compiled assets were removed
118118 if (
119- ! existsSync ( join ( diffPath , "components" , name ) ) ||
119+ ! existsSync ( join ( diffPath , filePath , name ) ) ||
120120 ( totalSize === 0 && totalDiffSize > 0 )
121121 ) {
122122 data . push ( "🚨 deleted, moved, or renamed" ) ;
@@ -183,7 +183,7 @@ async function run() {
183183 markdown . push (
184184 "" ,
185185 "<small>" ,
186- "* <em>Size determined by adding together the size of the main file (index.css) for all packages in the library.</em><br/>" ,
186+ "* <em>Size determined by adding together the size of the main file for all packages in the library.</em><br/>" ,
187187 "* <em>Results are not gzipped or minified.</em><br/>" ,
188188 "* <em>An ASCII character in UTF-8 is 8 bits or 1 byte.</em>" ,
189189 "</small>"
@@ -265,15 +265,25 @@ const printPercentChange = function (delta) {
265265
266266/**
267267 *
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 }>}> }
268+ * @param {Map<string, Map<string, { byteSize: number, diffByteSize: number }>> } PACKAGES
269+ * @param {string } filePath - The path to the component's dist folder from the root of the repo
270+ * @param {string } path - The path from the github workspace to the root of the repo
271+ * @returns {Array<{ name: string, filePath: string, totalSize: number, totalDiffSize: number, hasChange: boolean, fileMap: Map<string, { byteSize: number, diffByteSize: number }>}> }
270272 */
271- const makeTable = function ( COMPONENTS ) {
273+ const makeTable = function ( PACKAGES , filePath , path ) {
272274 const sections = [ ] ;
273275
274- /** Next convert that component data into a comment */
275- COMPONENTS . forEach ( ( fileMap , componentName ) => {
276- const mainFileOnly = [ ...fileMap . keys ( ) ] . filter ( ( file ) => file . endsWith ( "index.css" ) ) ;
276+ /** Next convert that component data into a detailed object for reporting */
277+ PACKAGES . forEach ( ( fileMap , packageName ) => {
278+ // Read in the main asset file from the package.json
279+ const packagePath = join ( path , filePath , packageName , "package.json" ) ;
280+
281+ let mainFile = "index.css" ;
282+ if ( existsSync ( packagePath ) ) {
283+ mainFile = require ( join ( path , filePath , packageName , "package.json" ) ) ?. main ;
284+ }
285+
286+ const mainFileOnly = [ ...fileMap . keys ( ) ] . filter ( ( file ) => file . endsWith ( mainFile ) ) ;
277287 const totalSize = mainFileOnly . reduce (
278288 ( acc , filename ) => {
279289 const { byteSize = 0 } = fileMap . get ( filename ) ;
@@ -296,7 +306,14 @@ const makeTable = function (COMPONENTS) {
296306 */
297307 if ( totalSize === totalDiffSize ) return ;
298308
299- sections . push ( { name : componentName , totalSize, totalDiffSize, hasChange, fileMap } ) ;
309+ sections . push ( {
310+ name : packageName ,
311+ filePath,
312+ totalSize,
313+ totalDiffSize,
314+ hasChange,
315+ fileMap
316+ } ) ;
300317 } ) ;
301318
302319 return sections ;
@@ -305,20 +322,28 @@ const makeTable = function (COMPONENTS) {
305322/**
306323 * Split out the data indexed by filename into groups by component
307324 * @param {Map<string, number> } dataMap
325+ * @param {string } path
308326 * @param {Map<string, number> } diffMap
309- * @returns {Map<string, Map<string, { byteSize: number, diffByteSize: number }>> }
327+ * @returns {{ filePath: string, PACKAGES: Map<string, Map<string, { byteSize: number, diffByteSize: number }>>} }
310328 */
311- const splitDataByComponent = function ( dataMap , diffMap = new Map ( ) ) {
312- const COMPONENTS = new Map ( ) ;
329+ const splitDataByPackage = function ( dataMap , path , diffMap = new Map ( ) ) {
330+ const PACKAGES = new Map ( ) ;
331+
332+ let filePath ;
313333 [ ...dataMap . entries ( ) ] . forEach ( ( [ file , byteSize ] ) => {
314334 // Determine the name of the component
315335 const parts = file . split ( sep ) ;
316336 const componentIdx = parts . findIndex ( ( part ) => part === "dist" ) - 1 ;
317- const componentName = parts [ componentIdx ] ;
337+ const packageName = parts [ componentIdx ] ;
338+
339+ if ( ! filePath ) {
340+ filePath = `${ file . replace ( path , "" ) } /${ parts . slice ( componentIdx + 1 , - 1 ) . join ( sep ) } ` ;
341+ }
342+
318343 const readableFilename = file . replace ( / ^ .* \/ d i s t \/ / , "" ) ;
319344
320- const fileMap = COMPONENTS . has ( componentName )
321- ? COMPONENTS . get ( componentName )
345+ const fileMap = PACKAGES . has ( packageName )
346+ ? PACKAGES . get ( packageName )
322347 : new Map ( ) ;
323348
324349 if ( ! fileMap . has ( readableFilename ) ) {
@@ -331,7 +356,8 @@ const splitDataByComponent = function (dataMap, diffMap = new Map()) {
331356 }
332357
333358 /** Update the component's table data */
334- COMPONENTS . set ( componentName , fileMap ) ;
359+ PACKAGES . set ( packageName , fileMap ) ;
335360 } ) ;
336- return COMPONENTS ;
361+
362+ return { filePath, PACKAGES } ;
337363} ;
0 commit comments