Skip to content

Commit 6c89d29

Browse files
Harden watch-once callback handling and document symlink behavior
- Normalize watcher callback to a Promise to catch sync throws and ensure finalize always runs before exit in watch-once - Add inline note for resolve.symlinks: false to align with docs This reduces the chance of partial outputs or silent crashes in single-run dev builds while preserving existing behavior
1 parent abfc14d commit 6c89d29

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

build.mjs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
203203
],
204204
resolve: {
205205
extensions: ['.jsx', '.mjs', '.js'],
206+
// Disable symlink resolution for consistent behavior/perf; note this can
207+
// affect `npm link`/pnpm workspaces during local development
206208
symlinks: false,
207209
alias: {
208210
parse5: path.resolve(__dirname, 'node_modules/parse5'),
@@ -400,7 +402,8 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
400402
err ||
401403
(stats && typeof stats.hasErrors === 'function' && stats.hasErrors())
402404
)
403-
const ret = callback(err, stats)
405+
// Normalize callback return into a Promise to catch synchronous throws
406+
const ret = Promise.resolve().then(() => callback(err, stats))
404407
if (isWatchOnce) {
405408
const finalize = (callbackFailed = false) =>
406409
watching.close((closeErr) => {
@@ -410,12 +413,10 @@ async function runWebpack(isWithoutKatex, isWithoutTiktoken, minimal, sourceBuil
410413
const shouldFail = hasErrors || closeErr || callbackFailed
411414
process.exit(shouldFail ? 1 : 0)
412415
})
413-
if (ret && typeof ret.then === 'function')
414-
ret.then(
415-
() => finalize(false),
416-
() => finalize(true),
417-
)
418-
else finalize(false)
416+
ret.then(
417+
() => finalize(false),
418+
() => finalize(true),
419+
)
419420
}
420421
})
421422
}

0 commit comments

Comments
 (0)