Skip to content

Commit 9ce694c

Browse files
Simplify webpack error checks
1 parent 085fd6c commit 9ce694c

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

build.mjs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,7 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
413413
if (isProduction) {
414414
// Ensure compiler is properly closed after production runs
415415
compiler.run((err, stats) => {
416-
const hasErrors = !!(
417-
err ||
418-
(stats && typeof stats.hasErrors === 'function' && stats.hasErrors())
419-
)
416+
const hasErrors = !!(err || stats?.hasErrors?.())
420417
let callbackFailed = false
421418
const finishClose = () =>
422419
compiler.close((closeErr) => {
@@ -445,10 +442,7 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
445442
})
446443
} else {
447444
const watching = compiler.watch({}, (err, stats) => {
448-
const hasErrors = !!(
449-
err ||
450-
(stats && typeof stats.hasErrors === 'function' && stats.hasErrors())
451-
)
445+
const hasErrors = !!(err || stats?.hasErrors?.())
452446
// Normalize callback return into a Promise to catch synchronous throws
453447
const ret = Promise.resolve().then(() => callback(err, stats))
454448
if (isWatchOnce) {
@@ -626,7 +620,7 @@ async function build() {
626620
minimal,
627621
tmpDir,
628622
async (err, stats) => {
629-
if (err || (stats && typeof stats.hasErrors === 'function' && stats.hasErrors())) {
623+
if (err || stats?.hasErrors?.()) {
630624
console.error(err || stats.toString())
631625
reject(err || new Error('webpack error'))
632626
return
@@ -665,10 +659,7 @@ async function build() {
665659

666660
await new Promise((resolve, reject) => {
667661
const ret = runWebpack(false, false, false, outdir, async (err, stats) => {
668-
const hasErrors = !!(
669-
err ||
670-
(stats && typeof stats.hasErrors === 'function' && stats.hasErrors())
671-
)
662+
const hasErrors = !!(err || stats?.hasErrors?.())
672663
if (hasErrors) {
673664
console.error(err || stats.toString())
674665
// In normal dev watch, keep process alive on initial errors; only fail when watch-once

0 commit comments

Comments
 (0)