Bugfix catch all page renaming bundler error
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import allPagesBundler from "../bundler/all-pages-bundler";
|
||||
import serverPostBuildFn from "./server-post-build-fn";
|
||||
|
||||
export default async function rebuildBundler() {
|
||||
try {
|
||||
global.ROUTER.reload();
|
||||
|
||||
await global.BUNDLER_CTX?.dispose();
|
||||
global.BUNDLER_CTX = undefined;
|
||||
|
||||
await allPagesBundler({
|
||||
watch: true,
|
||||
post_build_fn: serverPostBuildFn,
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,15 @@
|
||||
import { watch, existsSync } from "fs";
|
||||
import path from "path";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import serverParamsGen from "./server-params-gen";
|
||||
import allPagesBundler from "../bundler/all-pages-bundler";
|
||||
import serverPostBuildFn from "./server-post-build-fn";
|
||||
import refreshRouter from "../../utils/refresh-router";
|
||||
import rebuildBundler from "./rebuild-bundler";
|
||||
|
||||
const { PAGES_DIR } = grabDirNames();
|
||||
const { SRC_DIR } = grabDirNames();
|
||||
|
||||
const PAGE_FILE_RE = /\.(tsx?|jsx?)$/;
|
||||
const PAGE_FILE_RE = /\.(tsx?|jsx?|css)$/;
|
||||
|
||||
export default function watcher() {
|
||||
watch(
|
||||
PAGES_DIR,
|
||||
SRC_DIR,
|
||||
{
|
||||
recursive: true,
|
||||
persistent: true,
|
||||
@@ -28,7 +25,7 @@ export default function watcher() {
|
||||
|
||||
if (global.RECOMPILING) return;
|
||||
|
||||
const fullPath = path.join(PAGES_DIR, filename);
|
||||
const fullPath = path.join(SRC_DIR, filename);
|
||||
const action = existsSync(fullPath) ? "created" : "deleted";
|
||||
|
||||
clearTimeout(global.WATCHER_TIMEOUT);
|
||||
@@ -38,15 +35,7 @@ export default function watcher() {
|
||||
|
||||
console.log(`Page ${action}: ${filename}. Rebuilding ...`);
|
||||
|
||||
global.ROUTER.reload();
|
||||
|
||||
await global.BUNDLER_CTX?.dispose();
|
||||
global.BUNDLER_CTX = undefined;
|
||||
|
||||
await allPagesBundler({
|
||||
watch: true,
|
||||
post_build_fn: serverPostBuildFn,
|
||||
});
|
||||
await rebuildBundler();
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
@@ -55,46 +44,4 @@ export default function watcher() {
|
||||
}, 150);
|
||||
},
|
||||
);
|
||||
|
||||
// watch(BUNX_HYDRATION_SRC_DIR, async (event, filename) => {
|
||||
// if (!filename) return;
|
||||
|
||||
// const targetFile = path.join(BUNX_HYDRATION_SRC_DIR, filename);
|
||||
|
||||
// await Bun.build({
|
||||
// entrypoints: [targetFile],
|
||||
// outdir: HYDRATION_DST_DIR,
|
||||
// minify: true,
|
||||
// target: "browser",
|
||||
// format: "esm",
|
||||
// });
|
||||
|
||||
// global.SERVER?.publish("__bun_hmr", "update");
|
||||
|
||||
// setTimeout(() => {
|
||||
// global.RECOMPILING = false;
|
||||
// }, 200);
|
||||
// });
|
||||
|
||||
// watch(HYDRATION_DST_DIR, async (event, filename) => {
|
||||
// const encoder = new TextEncoder();
|
||||
// global.HMR_CONTROLLER?.enqueue(encoder.encode(`event: update\ndata: reload\n\n`));
|
||||
// global.RECOMPILING = false;
|
||||
// });
|
||||
|
||||
// let cmd = `bun build`;
|
||||
|
||||
// cmd += ` ${BUNX_HYDRATION_SRC_DIR}/*.tsx --outdir ${HYDRATION_DST_DIR}`;
|
||||
// cmd += ` --watch --minify`;
|
||||
|
||||
// execSync(cmd, { stdio: "inherit" });
|
||||
}
|
||||
|
||||
async function reloadServer() {
|
||||
const serverParams = await serverParamsGen();
|
||||
|
||||
console.log(`Reloading Server ...`);
|
||||
|
||||
global.SERVER?.stop();
|
||||
global.SERVER = Bun.serve(serverParams);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user