5555 cpuCount = 1
5656}
5757function parseThreadWorkerCount ( envValue , cpuCount ) {
58- const maxWorkers = Math . max ( 1 , cpuCount - 1 )
58+ const maxWorkers = Math . max ( 1 , cpuCount )
5959 if ( envValue !== undefined && envValue !== null ) {
6060 const rawStr = String ( envValue ) . trim ( )
6161 if ( / ^ [ 1 - 9 ] \d * $ / . test ( rawStr ) ) {
@@ -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
@@ -683,6 +674,10 @@ async function build() {
683674 } catch ( e ) {
684675 // Packaging failure should stop even in dev to avoid silent success
685676 reject ( e )
677+ if ( isWatchOnce ) {
678+ // Re-throw to surface an error and exit non-zero even if rejection isn't awaited
679+ throw e
680+ }
686681 }
687682 } )
688683 // Early setup failures (e.g., dynamic imports) should fail fast
0 commit comments