@@ -56,8 +56,8 @@ async function run() {
56
56
// --------------- End evaluation ---------------
57
57
58
58
/** 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 ) ;
61
61
62
62
const overallSize = [ ...pathOutput . values ( ) ] . reduce (
63
63
( acc , size ) => acc + size ,
@@ -106,17 +106,17 @@ async function run() {
106
106
107
107
markdown . push ( `<details>` , `<summary><b>Details</b></summary>` , "" ) ;
108
108
109
- sections . map ( ( { name, totalSize, totalDiffSize, fileMap } ) => {
109
+ sections . map ( ( { name, filePath , totalSize, totalDiffSize, hasChange , fileMap } ) => {
110
110
const md = [ "" , `#### ${ name } ` , "" ] ;
111
111
const data = [ name , bytesToSize ( totalDiffSize ) ] ;
112
112
113
- if ( totalDiffSize - totalSize === 0 ) return ;
113
+ if ( ! hasChange ) return ;
114
114
115
115
if ( hasDiff ) {
116
116
// If a diff path was provided and the component folder doesn't exist,
117
117
// report that the compiled assets were removed
118
118
if (
119
- ! existsSync ( join ( diffPath , "components" , name ) ) ||
119
+ ! existsSync ( join ( diffPath , filePath , name ) ) ||
120
120
( totalSize === 0 && totalDiffSize > 0 )
121
121
) {
122
122
data . push ( "🚨 deleted, moved, or renamed" ) ;
@@ -183,7 +183,7 @@ async function run() {
183
183
markdown . push (
184
184
"" ,
185
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/>" ,
186
+ "* <em>Size determined by adding together the size of the main file for all packages in the library.</em><br/>" ,
187
187
"* <em>Results are not gzipped or minified.</em><br/>" ,
188
188
"* <em>An ASCII character in UTF-8 is 8 bits or 1 byte.</em>" ,
189
189
"</small>"
@@ -265,15 +265,25 @@ const printPercentChange = function (delta) {
265
265
266
266
/**
267
267
*
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 }>}> }
270
272
*/
271
- const makeTable = function ( COMPONENTS ) {
273
+ const makeTable = function ( PACKAGES , filePath , path ) {
272
274
const sections = [ ] ;
273
275
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 ) ) ;
277
287
const totalSize = mainFileOnly . reduce (
278
288
( acc , filename ) => {
279
289
const { byteSize = 0 } = fileMap . get ( filename ) ;
@@ -296,7 +306,14 @@ const makeTable = function (COMPONENTS) {
296
306
*/
297
307
if ( totalSize === totalDiffSize ) return ;
298
308
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
+ } ) ;
300
317
} ) ;
301
318
302
319
return sections ;
@@ -305,20 +322,28 @@ const makeTable = function (COMPONENTS) {
305
322
/**
306
323
* Split out the data indexed by filename into groups by component
307
324
* @param {Map<string, number> } dataMap
325
+ * @param {string } path
308
326
* @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 }>>} }
310
328
*/
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 ;
313
333
[ ...dataMap . entries ( ) ] . forEach ( ( [ file , byteSize ] ) => {
314
334
// Determine the name of the component
315
335
const parts = file . split ( sep ) ;
316
336
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
+
318
343
const readableFilename = file . replace ( / ^ .* \/ d i s t \/ / , "" ) ;
319
344
320
- const fileMap = COMPONENTS . has ( componentName )
321
- ? COMPONENTS . get ( componentName )
345
+ const fileMap = PACKAGES . has ( packageName )
346
+ ? PACKAGES . get ( packageName )
322
347
: new Map ( ) ;
323
348
324
349
if ( ! fileMap . has ( readableFilename ) ) {
@@ -331,7 +356,8 @@ const splitDataByComponent = function (dataMap, diffMap = new Map()) {
331
356
}
332
357
333
358
/** Update the component's table data */
334
- COMPONENTS . set ( componentName , fileMap ) ;
359
+ PACKAGES . set ( packageName , fileMap ) ;
335
360
} ) ;
336
- return COMPONENTS ;
361
+
362
+ return { filePath, PACKAGES } ;
337
363
} ;
0 commit comments