Skip to content

Commit c1c0880

Browse files
Simplify CPU count detection
Use Math.max(1, os.cpus()?.length || 1) to replace try/catch + manual guards while keeping behavior equivalent on Node 20 environments.
1 parent 82c4c57 commit c1c0880

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

build.mjs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ if (cacheCompressionEnv != null) {
3232
cacheCompressionOption = false
3333
}
3434
}
35-
let cpuCount = 1
36-
try {
37-
const cpuInfo = os.cpus && os.cpus()
38-
const len = Array.isArray(cpuInfo) ? cpuInfo.length : 0
39-
cpuCount = Number.isInteger(len) && len > 0 ? len : 1
40-
} catch {
41-
cpuCount = 1
42-
}
35+
const cpuCount = Math.max(1, os.cpus()?.length || 1)
4336
const rawWorkers = process.env.BUILD_THREAD_WORKERS
4437
? parseInt(process.env.BUILD_THREAD_WORKERS, 10)
4538
: undefined

0 commit comments

Comments
 (0)