@@ -16,7 +16,8 @@ import { fetchSnapshot } from './fetchSnapshot.js';
1616 * @typedef {import('./sizeDiff.js').SizeSnapshot } SizeSnapshot
1717 */
1818
19- const MAX_CONCURRENCY = Math . min ( 8 , os . cpus ( ) . length ) ;
19+ // Default concurrency is set to the number of available CPU cores
20+ const DEFAULT_CONCURRENCY = os . availableParallelism ( ) ;
2021
2122const rootDir = process . cwd ( ) ;
2223
@@ -56,7 +57,7 @@ function normalizeEntries(entries) {
5657async function getWebpackSizes ( args , config ) {
5758 const worker = new Piscina ( {
5859 filename : new URL ( './worker.js' , import . meta. url ) . href ,
59- maxThreads : MAX_CONCURRENCY ,
60+ maxThreads : args . concurrency || DEFAULT_CONCURRENCY ,
6061 } ) ;
6162 // Clean and recreate the build directory
6263 const buildDir = path . join ( rootDir , 'build' ) ;
@@ -108,14 +109,16 @@ async function getWebpackSizes(args, config) {
108109 * @param {CommandLineArgs } argv - Command line arguments
109110 */
110111async function run ( argv ) {
111- const { analyze , accurateBundles , output, verbose , filter } = argv ;
112+ const { output, concurrency } = argv ;
112113
113114 const snapshotDestPath = output ? path . resolve ( output ) : path . join ( rootDir , 'size-snapshot.json' ) ;
114115
115116 const config = await loadConfig ( rootDir ) ;
116117
117- // Pass the filter patterns to getWebpackSizes if provided
118- const webpackSizes = await getWebpackSizes ( { analyze, accurateBundles, verbose, filter } , config ) ;
118+ // eslint-disable-next-line no-console
119+ console . log ( `Starting bundle size snapshot creation with ${ concurrency } workers...` ) ;
120+
121+ const webpackSizes = await getWebpackSizes ( argv , config ) ;
119122 const bundleSizes = Object . fromEntries ( webpackSizes . sort ( ( a , b ) => a [ 0 ] . localeCompare ( b [ 0 ] ) ) ) ;
120123
121124 // Ensure output directory exists
@@ -382,6 +385,12 @@ yargs(process.argv.slice(2))
382385 alias : 'F' ,
383386 describe : 'Filter entry points by glob pattern(s) applied to their IDs' ,
384387 type : 'array' ,
388+ } )
389+ . option ( 'concurrency' , {
390+ alias : 'c' ,
391+ describe : 'Number of workers to use for parallel processing' ,
392+ type : 'number' ,
393+ default : DEFAULT_CONCURRENCY ,
385394 } ) ;
386395 } ,
387396 handler : run ,
0 commit comments