Skip to content

Commit 423a43b

Browse files
Keep dev watch alive on initial errors and harden env parsing
- Do not exit dev watch on first compilation error; only reject when BUILD_WATCH_ONCE is enabled. This preserves the previous DX of staying in watch mode to fix errors. - Add robust boolean env parsing for BUILD_WATCH_ONCE to treat '0', 'false', 'no', 'off', and empty as false. - Retain fast‑fail for early setup/packaging errors and for watch‑once. Why: Refactor introduced a Promise wrapper that caused dev to exit on initial compile errors. This change restores expected behavior while keeping deterministic exits for CI/watch‑once.
1 parent 1bda239 commit 423a43b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

build.mjs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ const __dirname = path.resolve()
1515
const isProduction = process.argv[2] !== '--development' // --production and --analyze are both production
1616
const isAnalyzing = process.argv[2] === '--analyze'
1717
const parallelBuild = process.env.BUILD_PARALLEL !== '0'
18-
const isWatchOnce = !!process.env.BUILD_WATCH_ONCE
18+
function parseBooleanEnv(val) {
19+
if (val == null) return false
20+
const s = String(val).trim().toLowerCase()
21+
return !(s === '' || s === '0' || s === 'false' || s === 'no' || s === 'off')
22+
}
23+
const isWatchOnce = parseBooleanEnv(process.env.BUILD_WATCH_ONCE)
1924
// Cache compression control: default none; allow override via env
2025
function parseCacheCompressionOption(envVal) {
2126
if (envVal == null) return undefined
@@ -598,18 +603,27 @@ async function build() {
598603

599604
await new Promise((resolve, reject) => {
600605
const ret = runWebpack(false, false, false, outdir, async (err, stats) => {
601-
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
606+
const hasErrors = !!(
607+
err ||
608+
(stats && typeof stats.hasErrors === 'function' && stats.hasErrors())
609+
)
610+
if (hasErrors) {
602611
console.error(err || stats.toString())
603-
reject(err || new Error('webpack error'))
612+
// In normal dev watch, keep process alive on initial errors; only fail when watch-once
613+
if (isWatchOnce) {
614+
reject(err || new Error('webpack error'))
615+
}
604616
return
605617
}
606618
try {
607619
await finishOutput('')
608620
resolve()
609621
} catch (e) {
622+
// Packaging failure should stop even in dev to avoid silent success
610623
reject(e)
611624
}
612625
})
626+
// Early setup failures (e.g., dynamic imports) should fail fast
613627
if (ret && typeof ret.then === 'function') ret.catch(reject)
614628
})
615629
}

0 commit comments

Comments
 (0)