File tree Expand file tree Collapse file tree 4 files changed +131
-23
lines changed
Expand file tree Collapse file tree 4 files changed +131
-23
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ---
Original file line number Diff line number Diff line change 1+ import { writeFile } from 'node:fs/promises' ;
2+ import bundlewatch from 'bundlewatch' ;
3+ import { minimatch } from 'minimatch' ;
4+ import { format } from 'prettier' ;
5+ import { $ } from 'zx' ;
6+ import bundlewatchConfig from './bundlewatch.config.json' with { type : 'json' } ;
7+
8+ const { fullResults } = await bundlewatch . default ( bundlewatchConfig ) ;
9+ const failedFiles = fullResults . filter ( result => result . status === 'fail' ) ;
10+
11+ for ( const file of failedFiles ) {
12+ const matchingFileIndex = bundlewatchConfig . files . findIndex ( f => {
13+ return minimatch ( file . filePath , f . path ) ;
14+ } ) ;
15+ if ( matchingFileIndex !== - 1 ) {
16+ // update maxSize to the file size plus 1KB, rounded up to the nearest KB
17+ bundlewatchConfig . files [ matchingFileIndex ] . maxSize = `${ Math . ceil ( ( file . size + 1024 ) / 1024 ) } KB` ;
18+ }
19+ }
20+
21+ const formattedConfig = await format ( JSON . stringify ( bundlewatchConfig ) , { parser : 'json' } ) ;
22+ await writeFile ( './bundlewatch.config.json' , formattedConfig ) ;
23+ // print the git diff of the bundlewatch.config.json file
24+ const diff = await $ `git -c color.ui=always --no-pager diff bundlewatch.config.json` . then ( res => res . stdout ) ;
25+ console . log ( diff ) ;
26+ console . log ( 'Bundlewatch config updated!' ) ;
Original file line number Diff line number Diff line change 3838 "build:declarations" : " tsc -p tsconfig.declarations.json" ,
3939 "build:sandbox" : " rspack build --config rspack.config.js --env production --env sandbox" ,
4040 "build:stats" : " rspack build --config rspack.config.js --env production --json=stats.json --env variant=\" clerk.browser\" " ,
41- "bundlewatch" : " pnpm --package=bundlewatch -c dlx \" FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json\" " ,
41+ "bundlewatch" : " FORCE_COLOR=1 bundlewatch --config bundlewatch.config.json" ,
42+ "bundlewatch:fix" : " node bundlewatch-fix.mjs" ,
4243 "clean" : " rimraf ./dist" ,
4344 "dev" : " rspack serve --config rspack.config.js" ,
4445 "dev:chips" : " rspack serve --config rspack.config.js --env variant=\" clerk.chips.browser\" " ,
100101 "@types/cloudflare-turnstile" : " ^0.2.2" ,
101102 "@types/node" : " ^22.18.1" ,
102103 "@types/webpack-env" : " ^1.18.8" ,
104+ "bundlewatch" : " ^0.4.1" ,
103105 "jsdom" : " ^24.1.3" ,
106+ "minimatch" : " ^10.0.3" ,
104107 "webpack-merge" : " ^5.10.0"
105108 },
106109 "peerDependencies" : {
You can’t perform that action at this time.
0 commit comments