Refactor start and dev commands. Start in child processes. Handle errors better

This commit is contained in:
2026-04-17 08:47:36 +01:00
parent a5f25d522e
commit 9a427412f3
38 changed files with 706 additions and 224 deletions
@@ -5,10 +5,17 @@ import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-resu
import buildOnstartErrorHandler from "../build-on-start-error-handler";
import _ from "lodash";
import pagesSSRBundler from "../pages-ssr-bundler";
import grabDirNames from "../../../utils/grab-dir-names";
import { cpSync, existsSync, mkdirSync, rmSync } from "fs";
import fullRebuild from "../../server/full-rebuild";
import path from "path";
import cleanupLogsDirs from "../../cleanup-logs-dir";
const { BUNX_BUNDLER_ERROR_EXIT_FILE, BUNX_ERROR_LOGS_DIR } = grabDirNames();
let build_start = 0;
let build_starts = 0;
const MAX_BUILD_STARTS = 5;
const MAX_BUILD_STARTS = 2;
type Params = {
entryToPage: Map<
@@ -31,8 +38,16 @@ export default function esbuildCTXArtifactTracker({
build_starts++;
build_start = performance.now();
if (build_starts == MAX_BUILD_STARTS) {
const does_error_file_exist = existsSync(
BUNX_BUNDLER_ERROR_EXIT_FILE,
);
if (
build_starts == MAX_BUILD_STARTS &&
!does_error_file_exist
) {
await buildOnstartErrorHandler();
process.exit(1);
}
});
@@ -69,7 +84,22 @@ export default function esbuildCTXArtifactTracker({
build_starts = 0;
pagesSSRBundler();
const does_error_file_exist = existsSync(
BUNX_BUNDLER_ERROR_EXIT_FILE,
);
if (does_error_file_exist) {
mkdirSync(BUNX_ERROR_LOGS_DIR, { recursive: true });
cpSync(
BUNX_BUNDLER_ERROR_EXIT_FILE,
path.join(BUNX_ERROR_LOGS_DIR, `${Date.now()}.log`),
);
rmSync(BUNX_BUNDLER_ERROR_EXIT_FILE, { force: true });
cleanupLogsDirs();
fullRebuild();
} else {
pagesSSRBundler();
}
// if (global.SSR_BUNDLER_CTX) {
// global.SSR_BUNDLER_CTX.rebuild();