Error handling bugfix: pass #1
This commit is contained in:
+40
-6
@@ -6,7 +6,33 @@ import { AppData } from "../../data/app-data";
|
||||
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
||||
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
||||
import { log } from "../../utils/log";
|
||||
import { logBuildErrorsOnce } from "../../utils/build-error-log";
|
||||
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||
// Tracks the last watcher re-creation so the 5s watchdog in start-server
|
||||
// doesn't fight fullRebuild (which also restarts the watcher after a rebuild).
|
||||
let last_watcher_restart = 0;
|
||||
/**
|
||||
* Closes and re-creates the FS watcher. Deduped: callers that restart the
|
||||
* watcher around the same time (fullRebuild, reloadWatcher, watchdog) only
|
||||
* trigger a single re-creation.
|
||||
*/
|
||||
export function restartWatcher() {
|
||||
if (!global.BUNEXT_PAGES_SRC_WATCHER)
|
||||
return;
|
||||
if (Date.now() - last_watcher_restart < 1000)
|
||||
return;
|
||||
global.BUNEXT_PAGES_SRC_WATCHER.close();
|
||||
global.BUNEXT_PAGES_SRC_WATCHER = undefined;
|
||||
last_watcher_restart = Date.now();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
/**
|
||||
* True when the watcher was last (re)created long enough ago that the
|
||||
* watchdog should consider re-creating it again.
|
||||
*/
|
||||
export function watcherRestartAvailable() {
|
||||
return Date.now() - last_watcher_restart > 6000;
|
||||
}
|
||||
export default async function watcherEsbuildCTX() {
|
||||
const pages_src_watcher = watch(ROOT_DIR, {
|
||||
recursive: true,
|
||||
@@ -85,9 +111,16 @@ export default async function watcherEsbuildCTX() {
|
||||
if (filename.match(/.*\.server\.tsx?/)) {
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = true;
|
||||
}
|
||||
if (global.BUNEXT_BUNDLER_CTX) {
|
||||
if (global.BUNEXT_BUNDLER_CTX &&
|
||||
!global.BUNEXT_BUNDLER_CTX_DISPOSED) {
|
||||
await global.BUNEXT_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
else if (global.BUNEXT_BUNDLER_CTX_DISPOSED) {
|
||||
await fullRebuild({
|
||||
msg: `Restarting Bundler ...`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (filename.match(/(404|500)\.tsx?/)) {
|
||||
for (let i = global.BUNEXT_HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||
const controller = global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
@@ -129,7 +162,11 @@ export default async function watcherEsbuildCTX() {
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`Watcher rebuild failed: ${error}`);
|
||||
logBuildErrorsOnce([
|
||||
{
|
||||
text: `Watcher rebuild failed: ${error?.message || String(error)}`,
|
||||
},
|
||||
], (line) => log.error(line));
|
||||
}
|
||||
finally {
|
||||
if (owns_recompile) {
|
||||
@@ -141,8 +178,5 @@ export default async function watcherEsbuildCTX() {
|
||||
global.BUNEXT_PAGES_SRC_WATCHER = pages_src_watcher;
|
||||
}
|
||||
function reloadWatcher() {
|
||||
if (global.BUNEXT_PAGES_SRC_WATCHER) {
|
||||
global.BUNEXT_PAGES_SRC_WATCHER.close();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
restartWatcher();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user