Refactor Bundler. Fix bugs.

This commit is contained in:
2026-03-24 22:03:55 +01:00
parent 336fa812a5
commit 321c8ebb89
25 changed files with 387 additions and 167 deletions
@@ -30,6 +30,7 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
const tsx = await grabClientHydrationScript({
page_local_path: page.local_path,
});
if (!tsx) continue;
const entryFile = path.join(
@@ -28,6 +28,28 @@ export default async function grabClientHydrationScript({
// ? pagePathTransform({ page_path: root_file_path })
// : undefined;
if (!existsSync(page_local_path)) {
return undefined;
}
if (root_file_path) {
if (!existsSync(root_file_path)) {
return undefined;
}
const root_content = await Bun.file(root_file_path).text();
if (!root_content.match(/^export default/m)) {
return undefined;
}
}
const page_content = await Bun.file(page_local_path).text();
if (!page_content.match(/^export default/m)) {
return undefined;
}
let txt = ``;
txt += `import { hydrateRoot } from "react-dom/client";\n`;
@@ -52,8 +52,6 @@ export default async function watcherEsbuildCTX() {
if (global.RECOMPILING) return;
global.RECOMPILING = true;
log.info(`Rebuilding CTX ...`);
await global.BUNDLER_CTX?.rebuild();
if (filename.match(/(404|500)\.tsx?/)) {
@@ -107,28 +105,21 @@ async function fullRebuild(params?: { msg?: string }) {
log.watch(msg);
}
log.info(`Reloading Router ...`);
global.ROUTER.reload();
log.info(`Disposing Bundler CTX ...`);
await global.BUNDLER_CTX?.dispose();
global.BUNDLER_CTX = undefined;
global.BUNDLER_CTX_MAP = {};
log.info(`Rebuilding Modules ...`);
allPagesESBuildContextBundler({
post_build_fn: serverPostBuildFn,
});
} catch (error: any) {
log.error(error);
} finally {
global.RECOMPILING = false;
}
if (global.PAGES_SRC_WATCHER) {
log.info(`Restarting watcher ...`);
global.PAGES_SRC_WATCHER.close();
watcherEsbuildCTX();
}