@@ -17,21 +17,15 @@ const isAnalyzing = process.argv[2] === '--analyze'
1717const parallelBuild = process . env . BUILD_PARALLEL !== '0'
1818const isWatchOnce = ! ! process . env . BUILD_WATCH_ONCE
1919// Cache compression control: default none; allow override via env
20- const cacheCompressionEnv = process . env . BUILD_CACHE_COMPRESSION
21- let cacheCompressionOption
22- if ( cacheCompressionEnv != null ) {
23- const v = String ( cacheCompressionEnv ) . trim ( ) . toLowerCase ( )
24- if ( v === '' || v === '0' || v === 'false' || v === 'none' ) {
25- cacheCompressionOption = false
26- } else if ( v === 'gzip' || v === 'brotli' ) {
27- cacheCompressionOption = v
28- } else {
29- console . warn (
30- `[build] Unknown BUILD_CACHE_COMPRESSION="${ cacheCompressionEnv } ", defaulting to no compression` ,
31- )
32- cacheCompressionOption = false
33- }
20+ function parseCacheCompressionOption ( envVal ) {
21+ if ( envVal == null ) return undefined
22+ const v = String ( envVal ) . trim ( ) . toLowerCase ( )
23+ if ( v === '' || v === '0' || v === 'false' || v === 'none' ) return false
24+ if ( v === 'gzip' || v === 'brotli' ) return v
25+ console . warn ( `[build] Unknown BUILD_CACHE_COMPRESSION="${ envVal } ", defaulting to no compression` )
26+ return false
3427}
28+ const cacheCompressionOption = parseCacheCompressionOption ( process . env . BUILD_CACHE_COMPRESSION )
3529let cpuCount = 1
3630try {
3731 const cpuInfo = os . cpus && os . cpus ( )
@@ -40,26 +34,25 @@ try {
4034} catch {
4135 cpuCount = 1
4236}
43- const rawWorkers = process . env . BUILD_THREAD_WORKERS
44- ? parseInt ( process . env . BUILD_THREAD_WORKERS , 10 )
45- : undefined
46- let threadWorkers
47- if ( Number . isInteger ( rawWorkers ) && rawWorkers > 0 ) {
37+ function parseThreadWorkerCount ( envValue , cpuCount ) {
4838 const maxWorkers = Math . max ( 1 , cpuCount )
49- if ( rawWorkers > maxWorkers ) {
50- console . warn (
51- `[build] BUILD_THREAD_WORKERS=${ rawWorkers } exceeds CPU count (${ cpuCount } ); capping to ${ maxWorkers } ` ,
52- )
53- }
54- threadWorkers = Math . min ( rawWorkers , maxWorkers )
55- } else {
56- if ( process . env . BUILD_THREAD_WORKERS ) {
39+ if ( envValue !== undefined && envValue !== null ) {
40+ const raw = parseInt ( envValue , 10 )
41+ if ( Number . isInteger ( raw ) && raw > 0 ) {
42+ if ( raw > maxWorkers ) {
43+ console . warn (
44+ `[build] BUILD_THREAD_WORKERS=${ raw } exceeds CPU count (${ cpuCount } ); capping to ${ maxWorkers } ` ,
45+ )
46+ }
47+ return Math . min ( raw , maxWorkers )
48+ }
5749 console . warn (
58- `[build] Invalid BUILD_THREAD_WORKERS="${ process . env . BUILD_THREAD_WORKERS } ", defaulting to CPU count (${ cpuCount } )` ,
50+ `[build] Invalid BUILD_THREAD_WORKERS="${ envValue } ", defaulting to CPU count (${ cpuCount } )` ,
5951 )
6052 }
61- threadWorkers = cpuCount
53+ return maxWorkers
6254}
55+ const threadWorkers = parseThreadWorkerCount ( process . env . BUILD_THREAD_WORKERS , cpuCount )
6356// Thread-loader pool timeout constants (allow override via env)
6457let PRODUCTION_POOL_TIMEOUT_MS = 2000
6558if ( process . env . BUILD_POOL_TIMEOUT ) {
0 commit comments