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
+1
View File
@@ -0,0 +1 @@
export {};
+14
View File
@@ -0,0 +1,14 @@
import startServer from "../../functions/server/start-server";
import { log } from "../../utils/log";
import bunextInit from "../../functions/bunext-init";
import grabDirNames from "../../utils/grab-dir-names";
import { rmSync } from "fs";
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
log.info("Running development server ...");
try {
rmSync(HYDRATION_DST_DIR, { recursive: true });
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
}
catch (error) { }
await bunextInit();
await startServer();
+22 -14
View File
@@ -1,22 +1,30 @@
import { Command } from "commander";
import startServer from "../../functions/server/start-server";
import { log } from "../../utils/log";
import bunextInit from "../../functions/bunext-init";
import path from "path";
import grabDirNames from "../../utils/grab-dir-names";
import { rmSync } from "fs";
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNX_CWD_MODULE_CACHE_DIR, } = grabDirNames();
import writeErrorFile from "../../functions/write-error-file";
export default function () {
return new Command("dev")
.description("Run development server")
.action(async () => {
process.env.NODE_ENV = "development";
log.info("Running development server ...");
try {
rmSync(HYDRATION_DST_DIR, { recursive: true });
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
}
catch (error) { }
await bunextInit();
await startServer();
await dev();
});
}
async function dev() {
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
const spawn_options = {
cmd: ["bun", dev_spawn_file],
stdio: ["inherit", "inherit", "inherit"],
onExit(subprocess, exitCode, signalCode, error) {
writeErrorFile({ exitCode, error });
},
env: {
...process.env,
NODE_ENV: "development",
},
};
let dev_process = Bun.spawn(spawn_options);
const exited = await dev_process.exited;
if (exited) {
return await dev();
}
}