Compare commits
3
Commits
1d0ac4aa80
...
a19863b3e9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a19863b3e9 | ||
|
|
a9cd51d71c | ||
|
|
e3a0f5fbeb |
Vendored
+13
-2
@@ -4,11 +4,22 @@ import bunextInit from "../../functions/bunext-init";
|
|||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import { rmSync } from "fs";
|
import { rmSync } from "fs";
|
||||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||||
|
process.on("uncaughtException", (error) => {
|
||||||
|
log.error(`Uncaught exception: ${error}`);
|
||||||
|
});
|
||||||
|
process.on("unhandledRejection", (reason) => {
|
||||||
|
log.error(`Unhandled rejection: ${reason}`);
|
||||||
|
});
|
||||||
log.info("Running development server ...");
|
log.info("Running development server ...");
|
||||||
try {
|
try {
|
||||||
rmSync(HYDRATION_DST_DIR, { recursive: true });
|
rmSync(HYDRATION_DST_DIR, { recursive: true });
|
||||||
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
|
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
|
||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
await bunextInit();
|
try {
|
||||||
await startServer();
|
await bunextInit();
|
||||||
|
await startServer();
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
log.error(`Failed to start development server: ${error}`);
|
||||||
|
}
|
||||||
|
|||||||
+2
-2
@@ -4,8 +4,8 @@ export default async function buildOnstartErrorHandler(params) {
|
|||||||
if (global.BUNDLER_CTX_DISPOSED) {
|
if (global.BUNDLER_CTX_DISPOSED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(`Killing Bundler ...`);
|
// console.log(`Killing Bundler ...`);
|
||||||
console.log(`global.BUNDLER_CTX_DISPOSED`, global.BUNDLER_CTX_DISPOSED);
|
// console.log(`global.BUNDLER_CTX_DISPOSED`, global.BUNDLER_CTX_DISPOSED);
|
||||||
global.BUNDLER_CTX_DISPOSED = true;
|
global.BUNDLER_CTX_DISPOSED = true;
|
||||||
global.RECOMPILING = false;
|
global.RECOMPILING = false;
|
||||||
global.IS_SERVER_COMPONENT = false;
|
global.IS_SERVER_COMPONENT = false;
|
||||||
|
|||||||
+42
-37
@@ -48,41 +48,46 @@ export default async function pagesSSRBundler(params) {
|
|||||||
writeFileSync(path.join(BUNX_TMP_DIR, "ssr-entrypoints.json"), JSON.stringify(entryPoints, null, 4));
|
writeFileSync(path.join(BUNX_TMP_DIR, "ssr-entrypoints.json"), JSON.stringify(entryPoints, null, 4));
|
||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
await esbuild.build({
|
try {
|
||||||
entryPoints,
|
await esbuild.build({
|
||||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
entryPoints,
|
||||||
bundle: true,
|
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||||
minify: !dev,
|
bundle: true,
|
||||||
format: "esm",
|
minify: !dev,
|
||||||
target: "esnext",
|
format: "esm",
|
||||||
platform: "node",
|
target: "esnext",
|
||||||
define: {
|
platform: "node",
|
||||||
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
|
define: {
|
||||||
},
|
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
|
||||||
entryNames: "[dir]/[hash]",
|
},
|
||||||
metafile: true,
|
entryNames: "[dir]/[hash]",
|
||||||
plugins: [
|
metafile: true,
|
||||||
tailwindEsbuildPlugin,
|
plugins: [
|
||||||
ssrVirtualFilesPlugin({
|
tailwindEsbuildPlugin,
|
||||||
entryToPage,
|
ssrVirtualFilesPlugin({
|
||||||
}),
|
entryToPage,
|
||||||
ssrCTXArtifactTracker({
|
}),
|
||||||
entryToPage,
|
ssrCTXArtifactTracker({
|
||||||
post_build_fn: params?.post_build_fn,
|
entryToPage,
|
||||||
}),
|
post_build_fn: params?.post_build_fn,
|
||||||
],
|
}),
|
||||||
jsx: "automatic",
|
],
|
||||||
external: [
|
jsx: "automatic",
|
||||||
"react",
|
external: [
|
||||||
"react-dom",
|
"react",
|
||||||
"react/jsx-runtime",
|
"react-dom",
|
||||||
"react/jsx-dev-runtime",
|
"react/jsx-runtime",
|
||||||
"bun:*",
|
"react/jsx-dev-runtime",
|
||||||
"sqlite-vec",
|
"bun:*",
|
||||||
"better-sqlite3",
|
"sqlite-vec",
|
||||||
...(config.ssr_compiler_excludes || []),
|
"better-sqlite3",
|
||||||
],
|
...(config.ssr_compiler_excludes || []),
|
||||||
splitting: true,
|
],
|
||||||
// logLevel: "silent",
|
splitting: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||||
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,15 +56,13 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
|||||||
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
|
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
post_build_fn?.({ artifacts });
|
|
||||||
}
|
}
|
||||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||||
log.success(`[Built] in ${elapsed}ms`);
|
log.success(`[Built] in ${elapsed}ms`);
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
global.MAIN_CTX_BUILD_STARTS = 0;
|
global.MAIN_CTX_BUILD_STARTS = 0;
|
||||||
global.BUNDLER_CTX_DISPOSED = false;
|
global.BUNDLER_CTX_DISPOSED = false;
|
||||||
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||||
|
// SSR must finish before HMR so server props are fresh
|
||||||
if (build_only) {
|
if (build_only) {
|
||||||
try {
|
try {
|
||||||
await pagesSSRBundler();
|
await pagesSSRBundler();
|
||||||
@@ -82,17 +80,22 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
pagesSSRBundler();
|
await pagesSSRBundler();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
log.error(`SSR Bundler Error: ${error}`);
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
}
|
}
|
||||||
|
if (artifacts?.[0] && artifacts.length > 0) {
|
||||||
|
try {
|
||||||
|
await post_build_fn?.({ artifacts });
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
log.error(`Post-build Error: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// if (global.SSR_BUNDLER_CTX) {
|
global.RECOMPILING = false;
|
||||||
// global.SSR_BUNDLER_CTX.rebuild();
|
global.IS_SERVER_COMPONENT = false;
|
||||||
// } else {
|
|
||||||
// pagesSSRContextBundler();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -23,9 +23,15 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
|
|||||||
build.onEnd(async (result) => {
|
build.onEnd(async (result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||||
await global.SSR_BUNDLER_CTX?.dispose();
|
try {
|
||||||
|
await global.SSR_BUNDLER_CTX?.dispose();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
build_starts = 0;
|
build_starts = 0;
|
||||||
console.log("SSR Build errors:", result.errors);
|
for (const err of result.errors) {
|
||||||
|
console.error(`SSR Build error: ${err.text}${err.location ? ` (${err.location.file}:${err.location.line}:${err.location.column})` : ""}`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const artifacts = grabArtifactsFromBundledResults({
|
const artifacts = grabArtifactsFromBundledResults({
|
||||||
|
|||||||
Vendored
+2
-2
@@ -40,8 +40,8 @@ export default async function bunextInit(params) {
|
|||||||
else if (is_dev) {
|
else if (is_dev) {
|
||||||
log.build(`Building Modules ...`);
|
log.build(`Building Modules ...`);
|
||||||
await allPagesESBuildContextBundler({
|
await allPagesESBuildContextBundler({
|
||||||
post_build_fn: () => {
|
post_build_fn: async () => {
|
||||||
serverPostBuildFn();
|
await serverPostBuildFn();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
watcherEsbuildCTX();
|
watcherEsbuildCTX();
|
||||||
|
|||||||
+89
-71
@@ -1,17 +1,17 @@
|
|||||||
import chokidar from "chokidar";
|
import chokidar from "chokidar";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { existsSync, statSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import fullRebuild from "./full-rebuild";
|
import fullRebuild from "./full-rebuild";
|
||||||
import { AppData } from "../../data/app-data";
|
import { AppData } from "../../data/app-data";
|
||||||
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
||||||
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
||||||
|
import { log } from "../../utils/log";
|
||||||
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
export default async function chokadirWatcherEsbuildCTX() {
|
export default async function chokadirWatcherEsbuildCTX() {
|
||||||
// Define ignored patterns directly in Chokidar for better performance
|
|
||||||
const watcher = chokidar.watch(ROOT_DIR, {
|
const watcher = chokidar.watch(ROOT_DIR, {
|
||||||
ignored: [
|
ignored: [
|
||||||
/(^|[\/\\])\../, // ignore dotfiles
|
/(^|[\/\\])\../,
|
||||||
/node_modules/,
|
/node_modules/,
|
||||||
/public/,
|
/public/,
|
||||||
/\.bunext/,
|
/\.bunext/,
|
||||||
@@ -25,78 +25,97 @@ export default async function chokadirWatcherEsbuildCTX() {
|
|||||||
depth: 99,
|
depth: 99,
|
||||||
});
|
});
|
||||||
const handleEvent = async (event, filePath) => {
|
const handleEvent = async (event, filePath) => {
|
||||||
const filename = path.relative(ROOT_DIR, filePath);
|
let owns_recompile = false;
|
||||||
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
try {
|
||||||
await fullRebuild();
|
const filename = path.relative(ROOT_DIR, filePath);
|
||||||
return;
|
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
||||||
}
|
await fullRebuild();
|
||||||
if (global.BUNDLER_CTX_DISPOSED) {
|
return;
|
||||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
}
|
||||||
}
|
if (global.BUNDLER_CTX_DISPOSED) {
|
||||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||||
pagesSSRBundler();
|
}
|
||||||
}
|
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||||
if (filename.match(/\/styles$/) || filename === "styles") {
|
await pagesSSRBundler().catch((error) => {
|
||||||
global.RECOMPILING = true;
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
await Bun.sleep(1000);
|
});
|
||||||
await fullRebuild({
|
}
|
||||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
if (filename.match(/\/styles$/) || filename === "styles") {
|
||||||
});
|
owns_recompile = true;
|
||||||
return;
|
global.RECOMPILING = true;
|
||||||
}
|
await Bun.sleep(1000);
|
||||||
if (filename.match(/bunext.config\.ts/)) {
|
await fullRebuild({
|
||||||
await fullRebuild({
|
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||||
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
});
|
||||||
});
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (filename.match(/bunext.config\.ts/)) {
|
||||||
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
await fullRebuild({
|
||||||
if (event === "change") {
|
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
||||||
if (filename.match(target_files_match)) {
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
||||||
|
if (event === "change") {
|
||||||
|
if (filename.match(target_files_match)) {
|
||||||
|
if (global.RECOMPILING)
|
||||||
|
return;
|
||||||
|
owns_recompile = true;
|
||||||
|
global.RECOMPILING = true;
|
||||||
|
if (filename.match(/.*\.server\.tsx?/)) {
|
||||||
|
global.IS_SERVER_COMPONENT = true;
|
||||||
|
}
|
||||||
|
if (global.BUNDLER_CTX) {
|
||||||
|
await global.BUNDLER_CTX.rebuild();
|
||||||
|
}
|
||||||
|
if (filename.match(/(404|500)\.tsx?/)) {
|
||||||
|
for (let i = global.HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||||
|
const controller = global.HMR_CONTROLLERS[i];
|
||||||
|
try {
|
||||||
|
controller?.controller?.enqueue(`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (["add", "unlink", "addDir", "unlinkDir"].includes(event)) {
|
||||||
|
const is_file_of_interest = !!filename.match(target_files_match) ||
|
||||||
|
event.includes("Dir");
|
||||||
|
if (!is_file_of_interest)
|
||||||
|
return;
|
||||||
|
if (!filename.match(/^src\/pages\/|\.css$/) ||
|
||||||
|
checkExcludedPatterns({ path: filename }) ||
|
||||||
|
filename.includes(" ")) {
|
||||||
|
return reloadWatcher();
|
||||||
|
}
|
||||||
if (global.RECOMPILING)
|
if (global.RECOMPILING)
|
||||||
return;
|
return;
|
||||||
global.RECOMPILING = true;
|
owns_recompile = true;
|
||||||
if (filename.match(/.*\.server\.tsx?/)) {
|
const action = event.startsWith("add") ? "created" : "deleted";
|
||||||
global.IS_SERVER_COMPONENT = true;
|
const type = filename.match(/\.css$/)
|
||||||
}
|
? "Stylesheet"
|
||||||
if (global.BUNDLER_CTX) {
|
: event.includes("Dir")
|
||||||
await global.BUNDLER_CTX.rebuild();
|
? "Directory"
|
||||||
}
|
: filename.match(/\/pages\/api\//)
|
||||||
// HMR for error pages
|
? "API Route"
|
||||||
if (filename.match(/(404|500)\.tsx?/)) {
|
: "Page";
|
||||||
global.HMR_CONTROLLERS.forEach((controller) => {
|
await fullRebuild({
|
||||||
controller?.controller?.enqueue(`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`);
|
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
// Handle Structural Changes (Add/Delete)
|
catch (error) {
|
||||||
if (["add", "unlink", "addDir", "unlinkDir"].includes(event)) {
|
log.error(`Watcher rebuild failed: ${error}`);
|
||||||
const is_file_of_interest = !!filename.match(target_files_match) || event.includes("Dir");
|
}
|
||||||
if (!is_file_of_interest)
|
finally {
|
||||||
return;
|
if (owns_recompile) {
|
||||||
// Validation logic
|
global.RECOMPILING = false;
|
||||||
if (!filename.match(/^src\/pages\/|\.css$/) ||
|
global.IS_SERVER_COMPONENT = false;
|
||||||
checkExcludedPatterns({ path: filename }) ||
|
|
||||||
filename.includes(" ")) {
|
|
||||||
// With chokidar, you rarely need to "reload" the whole watcher.
|
|
||||||
// But we keep the logic for consistency.
|
|
||||||
return reloadWatcher();
|
|
||||||
}
|
}
|
||||||
if (global.RECOMPILING)
|
|
||||||
return;
|
|
||||||
const action = event.startsWith("add") ? "created" : "deleted";
|
|
||||||
const type = filename.match(/\.css$/)
|
|
||||||
? "Stylesheet"
|
|
||||||
: event.includes("Dir")
|
|
||||||
? "Directory"
|
|
||||||
: filename.match(/\/pages\/api\//)
|
|
||||||
? "API Route"
|
|
||||||
: "Page";
|
|
||||||
await fullRebuild({
|
|
||||||
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
watcher
|
watcher
|
||||||
@@ -105,7 +124,6 @@ export default async function chokadirWatcherEsbuildCTX() {
|
|||||||
.on("unlink", (path) => handleEvent("unlink", path))
|
.on("unlink", (path) => handleEvent("unlink", path))
|
||||||
.on("addDir", (path) => handleEvent("addDir", path))
|
.on("addDir", (path) => handleEvent("addDir", path))
|
||||||
.on("unlinkDir", (path) => handleEvent("unlinkDir", path));
|
.on("unlinkDir", (path) => handleEvent("unlinkDir", path));
|
||||||
// global.PAGES_SRC_WATCHER = watcher;
|
|
||||||
}
|
}
|
||||||
function reloadWatcher() {
|
function reloadWatcher() {
|
||||||
if (global.PAGES_SRC_WATCHER) {
|
if (global.PAGES_SRC_WATCHER) {
|
||||||
|
|||||||
+5
-4
@@ -17,17 +17,18 @@ export default async function fullRebuild(params) {
|
|||||||
global.SSR_BUNDLER_CTX = undefined;
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
}
|
}
|
||||||
catch (error) { }
|
catch (error) { }
|
||||||
// await pagesSSRBundler();
|
|
||||||
await allPagesESBuildContextBundler({
|
await allPagesESBuildContextBundler({
|
||||||
post_build_fn: () => {
|
post_build_fn: async () => {
|
||||||
serverPostBuildFn();
|
await serverPostBuildFn();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
log.error(error);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
global.RECOMPILING = false;
|
global.RECOMPILING = false;
|
||||||
global.IS_SERVER_COMPONENT = false;
|
global.IS_SERVER_COMPONENT = false;
|
||||||
log.error(error);
|
|
||||||
}
|
}
|
||||||
if (global.PAGES_SRC_WATCHER) {
|
if (global.PAGES_SRC_WATCHER) {
|
||||||
global.PAGES_SRC_WATCHER.close();
|
global.PAGES_SRC_WATCHER.close();
|
||||||
|
|||||||
+22
-14
@@ -22,28 +22,37 @@ export default async function serverPostBuildFn(params) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (params?.reload_all_controllers) {
|
if (params?.reload_all_controllers) {
|
||||||
controller.controller.enqueue(reload_enqueue);
|
try {
|
||||||
|
controller.controller.enqueue(reload_enqueue);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const target_artifact = global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
const target_artifact = global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
||||||
if (!target_artifact.local_path) {
|
if (!target_artifact?.local_path) {
|
||||||
controller.controller.enqueue(reload_enqueue);
|
try {
|
||||||
|
controller.controller.enqueue(reload_enqueue);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const mock_req = target_artifact.req_url
|
const mock_req = target_artifact.req_url
|
||||||
? new Request(target_artifact.req_url)
|
? new Request(target_artifact.req_url)
|
||||||
: new Request(controller.page_url);
|
: new Request(controller.page_url);
|
||||||
const page_component = global.IS_SERVER_COMPONENT
|
// Always re-run server fns so fixed errors clear on the first HMR
|
||||||
? await grabPageComponent({
|
const page_component = await grabPageComponent({
|
||||||
req: mock_req,
|
req: mock_req,
|
||||||
return_server_res_only: true,
|
return_server_res_only: true,
|
||||||
is_hydration: true,
|
is_hydration: true,
|
||||||
})
|
});
|
||||||
: {};
|
|
||||||
if (page_component instanceof Response) {
|
if (page_component instanceof Response) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const { serverRes } = page_component;
|
const { serverRes } = page_component || {};
|
||||||
const final_artifact = {
|
const final_artifact = {
|
||||||
..._.omit(controller, ["controller"]),
|
..._.omit(controller, ["controller"]),
|
||||||
target_map: target_artifact,
|
target_map: target_artifact,
|
||||||
@@ -51,9 +60,8 @@ export default async function serverPostBuildFn(params) {
|
|||||||
if (!target_artifact) {
|
if (!target_artifact) {
|
||||||
delete final_artifact.target_map;
|
delete final_artifact.target_map;
|
||||||
}
|
}
|
||||||
if (serverRes) {
|
// Always replace so prior error props cannot linger
|
||||||
final_artifact.page_props = serverRes;
|
final_artifact.page_props = serverRes || {};
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
let final_data = {};
|
let final_data = {};
|
||||||
if (global.ROOT_FILE_UPDATED) {
|
if (global.ROOT_FILE_UPDATED) {
|
||||||
|
|||||||
+103
-81
@@ -5,99 +5,121 @@ import fullRebuild from "./full-rebuild";
|
|||||||
import { AppData } from "../../data/app-data";
|
import { AppData } from "../../data/app-data";
|
||||||
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
||||||
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
||||||
|
import { log } from "../../utils/log";
|
||||||
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
export default async function watcherEsbuildCTX() {
|
export default async function watcherEsbuildCTX() {
|
||||||
const pages_src_watcher = watch(ROOT_DIR, {
|
const pages_src_watcher = watch(ROOT_DIR, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
}, async (event, filename) => {
|
}, async (event, filename) => {
|
||||||
if (!filename)
|
let owns_recompile = false;
|
||||||
return;
|
try {
|
||||||
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
if (!filename)
|
||||||
await fullRebuild();
|
return;
|
||||||
return;
|
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
||||||
}
|
await fullRebuild();
|
||||||
if (filename.match(/^\.\w+/)) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
if (filename.match(/^\.\w+/)) {
|
||||||
if (global.BUNDLER_CTX_DISPOSED) {
|
return;
|
||||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
}
|
||||||
return;
|
if (global.BUNDLER_CTX_DISPOSED) {
|
||||||
}
|
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
return;
|
||||||
pagesSSRBundler();
|
}
|
||||||
}
|
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||||
if (filename.endsWith(AppData["BunextTmpFileExt"])) {
|
await pagesSSRBundler().catch((error) => {
|
||||||
return;
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
}
|
});
|
||||||
const full_file_path = path.join(ROOT_DIR, filename);
|
}
|
||||||
const does_file_exist = existsSync(full_file_path);
|
if (filename.endsWith(AppData["BunextTmpFileExt"])) {
|
||||||
const file_stat = does_file_exist
|
return;
|
||||||
? statSync(full_file_path)
|
}
|
||||||
: undefined;
|
const full_file_path = path.join(ROOT_DIR, filename);
|
||||||
if (full_file_path.match(/\/styles$/)) {
|
const does_file_exist = existsSync(full_file_path);
|
||||||
global.RECOMPILING = true;
|
const file_stat = does_file_exist
|
||||||
await Bun.sleep(1000);
|
? statSync(full_file_path)
|
||||||
await fullRebuild({
|
: undefined;
|
||||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
if (full_file_path.match(/\/styles$/)) {
|
||||||
});
|
owns_recompile = true;
|
||||||
return;
|
|
||||||
}
|
|
||||||
const excluded_match = /node_modules\/|^public\/|^\.bunext\/|^\.git\/|^\.?dist\/|bun\.lockb$/;
|
|
||||||
if (filename.match(excluded_match))
|
|
||||||
return;
|
|
||||||
if (filename.match(/bunext.config\.ts/)) {
|
|
||||||
await fullRebuild({
|
|
||||||
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
|
||||||
// const rebuild_skip_paths = /\/pages\/api\//;
|
|
||||||
if (event !== "rename") {
|
|
||||||
if (filename.match(target_files_match)) {
|
|
||||||
if (global.RECOMPILING)
|
|
||||||
return;
|
|
||||||
global.RECOMPILING = true;
|
global.RECOMPILING = true;
|
||||||
if (filename.match(/.*\.server\.tsx?/)) {
|
await Bun.sleep(1000);
|
||||||
global.IS_SERVER_COMPONENT = true;
|
await fullRebuild({
|
||||||
}
|
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||||
if (global.BUNDLER_CTX) {
|
});
|
||||||
await global.BUNDLER_CTX.rebuild();
|
return;
|
||||||
}
|
}
|
||||||
if (filename.match(/(404|500)\.tsx?/)) {
|
const excluded_match = /node_modules\/|^public\/|^\.bunext\/|^\.git\/|^\.?dist\/|bun\.lockb$/;
|
||||||
for (let i = global.HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
if (filename.match(excluded_match))
|
||||||
const controller = global.HMR_CONTROLLERS[i];
|
return;
|
||||||
controller?.controller?.enqueue(`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`);
|
if (filename.match(/bunext.config\.ts/)) {
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
||||||
|
if (event !== "rename") {
|
||||||
|
if (filename.match(target_files_match)) {
|
||||||
|
if (global.RECOMPILING)
|
||||||
|
return;
|
||||||
|
owns_recompile = true;
|
||||||
|
global.RECOMPILING = true;
|
||||||
|
if (filename.match(/.*\.server\.tsx?/)) {
|
||||||
|
global.IS_SERVER_COMPONENT = true;
|
||||||
|
}
|
||||||
|
if (global.BUNDLER_CTX) {
|
||||||
|
await global.BUNDLER_CTX.rebuild();
|
||||||
|
}
|
||||||
|
if (filename.match(/(404|500)\.tsx?/)) {
|
||||||
|
for (let i = global.HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||||
|
const controller = global.HMR_CONTROLLERS[i];
|
||||||
|
try {
|
||||||
|
controller?.controller?.enqueue(`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`);
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return;
|
const is_file_of_interest = Boolean(filename.match(target_files_match)) ||
|
||||||
|
file_stat?.isDirectory();
|
||||||
|
if (!is_file_of_interest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!filename.match(/^src\/pages\/|\.css$/))
|
||||||
|
return reloadWatcher();
|
||||||
|
if (checkExcludedPatterns({ path: filename }))
|
||||||
|
return reloadWatcher();
|
||||||
|
if (filename.match(/ /))
|
||||||
|
return reloadWatcher();
|
||||||
|
if (global.RECOMPILING)
|
||||||
|
return;
|
||||||
|
owns_recompile = true;
|
||||||
|
const action = does_file_exist ? "created" : "deleted";
|
||||||
|
const type = filename.match(/\.css$/)
|
||||||
|
? "Sylesheet"
|
||||||
|
: file_stat?.isDirectory()
|
||||||
|
? "Directory"
|
||||||
|
: filename.match(/\/pages\/api\//)
|
||||||
|
? "API Route"
|
||||||
|
: "Page";
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
const is_file_of_interest = Boolean(filename.match(target_files_match)) ||
|
catch (error) {
|
||||||
file_stat?.isDirectory();
|
log.error(`Watcher rebuild failed: ${error}`);
|
||||||
if (!is_file_of_interest) {
|
}
|
||||||
return;
|
finally {
|
||||||
|
if (owns_recompile) {
|
||||||
|
global.RECOMPILING = false;
|
||||||
|
global.IS_SERVER_COMPONENT = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!filename.match(/^src\/pages\/|\.css$/))
|
|
||||||
return reloadWatcher();
|
|
||||||
if (checkExcludedPatterns({ path: filename }))
|
|
||||||
return reloadWatcher();
|
|
||||||
if (filename.match(/ /))
|
|
||||||
return reloadWatcher();
|
|
||||||
if (global.RECOMPILING)
|
|
||||||
return;
|
|
||||||
const action = does_file_exist ? "created" : "deleted";
|
|
||||||
const type = filename.match(/\.css$/)
|
|
||||||
? "Sylesheet"
|
|
||||||
: file_stat?.isDirectory()
|
|
||||||
? "Directory"
|
|
||||||
: filename.match(/\/pages\/api\//)
|
|
||||||
? "API Route"
|
|
||||||
: "Page";
|
|
||||||
await fullRebuild({
|
|
||||||
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
global.PAGES_SRC_WATCHER = pages_src_watcher;
|
global.PAGES_SRC_WATCHER = pages_src_watcher;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ const { ROOT_DIR } = grabDirNames();
|
|||||||
export default async function grabPageBundledReactComponent({ file_path, return_tsx_only, }) {
|
export default async function grabPageBundledReactComponent({ file_path, return_tsx_only, }) {
|
||||||
try {
|
try {
|
||||||
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
||||||
const mod = await import(path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[file_path].path));
|
const abs = path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[file_path].path);
|
||||||
|
Loader.registry.delete(abs);
|
||||||
|
const mod = await import(`${abs}?t=${Date.now()}`);
|
||||||
const Main = mod.default;
|
const Main = mod.default;
|
||||||
return { component: Main };
|
return { component: Main };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
|
|||||||
const final_root_server_path = root_server_ctx_map?.local_path
|
const final_root_server_path = root_server_ctx_map?.local_path
|
||||||
? path.join(ROOT_DIR, root_server_ctx_map.path)
|
? path.join(ROOT_DIR, root_server_ctx_map.path)
|
||||||
: root_server_file_path;
|
: root_server_file_path;
|
||||||
|
if (final_root_server_path) {
|
||||||
|
Loader.registry.delete(final_root_server_path);
|
||||||
|
}
|
||||||
const root_server_module = final_root_server_path
|
const root_server_module = final_root_server_path
|
||||||
? await import(`${final_root_server_path}?t=${now}`)
|
? await import(`${final_root_server_path}?t=${now}`)
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -34,6 +37,9 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
|
|||||||
const final_page_server_path = page_server_ctx?.local_path
|
const final_page_server_path = page_server_ctx?.local_path
|
||||||
? path.join(ROOT_DIR, page_server_ctx.path)
|
? path.join(ROOT_DIR, page_server_ctx.path)
|
||||||
: server_file_path;
|
: server_file_path;
|
||||||
|
if (final_page_server_path) {
|
||||||
|
Loader.registry.delete(final_page_server_path);
|
||||||
|
}
|
||||||
const server_module = final_page_server_path
|
const server_module = final_page_server_path
|
||||||
? await import(`${final_page_server_path}?t=${now}`)
|
? await import(`${final_page_server_path}?t=${now}`)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.96",
|
"version": "1.0.97",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -6,6 +6,14 @@ import { rmSync } from "fs";
|
|||||||
|
|
||||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||||
|
|
||||||
|
process.on("uncaughtException", (error) => {
|
||||||
|
log.error(`Uncaught exception: ${error}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on("unhandledRejection", (reason) => {
|
||||||
|
log.error(`Unhandled rejection: ${reason}`);
|
||||||
|
});
|
||||||
|
|
||||||
log.info("Running development server ...");
|
log.info("Running development server ...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -13,6 +21,9 @@ try {
|
|||||||
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
|
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
await bunextInit();
|
try {
|
||||||
|
await bunextInit();
|
||||||
await startServer();
|
await startServer();
|
||||||
|
} catch (error) {
|
||||||
|
log.error(`Failed to start development server: ${error}`);
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ export default async function buildOnstartErrorHandler(params?: Params) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Killing Bundler ...`);
|
// console.log(`Killing Bundler ...`);
|
||||||
console.log(`global.BUNDLER_CTX_DISPOSED`, global.BUNDLER_CTX_DISPOSED);
|
// console.log(`global.BUNDLER_CTX_DISPOSED`, global.BUNDLER_CTX_DISPOSED);
|
||||||
|
|
||||||
global.BUNDLER_CTX_DISPOSED = true;
|
global.BUNDLER_CTX_DISPOSED = true;
|
||||||
|
|
||||||
|
|||||||
@@ -75,43 +75,47 @@ export default async function pagesSSRBundler(params?: Params) {
|
|||||||
);
|
);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
await esbuild.build({
|
try {
|
||||||
entryPoints,
|
await esbuild.build({
|
||||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
entryPoints,
|
||||||
bundle: true,
|
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||||
minify: !dev,
|
bundle: true,
|
||||||
format: "esm",
|
minify: !dev,
|
||||||
target: "esnext",
|
format: "esm",
|
||||||
platform: "node",
|
target: "esnext",
|
||||||
define: {
|
platform: "node",
|
||||||
"process.env.NODE_ENV": JSON.stringify(
|
define: {
|
||||||
dev ? "development" : "production",
|
"process.env.NODE_ENV": JSON.stringify(
|
||||||
),
|
dev ? "development" : "production",
|
||||||
},
|
),
|
||||||
entryNames: "[dir]/[hash]",
|
},
|
||||||
metafile: true,
|
entryNames: "[dir]/[hash]",
|
||||||
plugins: [
|
metafile: true,
|
||||||
tailwindEsbuildPlugin,
|
plugins: [
|
||||||
ssrVirtualFilesPlugin({
|
tailwindEsbuildPlugin,
|
||||||
entryToPage,
|
ssrVirtualFilesPlugin({
|
||||||
}),
|
entryToPage,
|
||||||
ssrCTXArtifactTracker({
|
}),
|
||||||
entryToPage,
|
ssrCTXArtifactTracker({
|
||||||
post_build_fn: params?.post_build_fn,
|
entryToPage,
|
||||||
}),
|
post_build_fn: params?.post_build_fn,
|
||||||
],
|
}),
|
||||||
jsx: "automatic",
|
],
|
||||||
external: [
|
jsx: "automatic",
|
||||||
"react",
|
external: [
|
||||||
"react-dom",
|
"react",
|
||||||
"react/jsx-runtime",
|
"react-dom",
|
||||||
"react/jsx-dev-runtime",
|
"react/jsx-runtime",
|
||||||
"bun:*",
|
"react/jsx-dev-runtime",
|
||||||
"sqlite-vec",
|
"bun:*",
|
||||||
"better-sqlite3",
|
"sqlite-vec",
|
||||||
...(config.ssr_compiler_excludes || []),
|
"better-sqlite3",
|
||||||
],
|
...(config.ssr_compiler_excludes || []),
|
||||||
splitting: true,
|
],
|
||||||
// logLevel: "silent",
|
splitting: true,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||||
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,16 +97,11 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
post_build_fn?.({ artifacts });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||||
log.success(`[Built] in ${elapsed}ms`);
|
log.success(`[Built] in ${elapsed}ms`);
|
||||||
|
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
|
|
||||||
global.MAIN_CTX_BUILD_STARTS = 0;
|
global.MAIN_CTX_BUILD_STARTS = 0;
|
||||||
global.BUNDLER_CTX_DISPOSED = false;
|
global.BUNDLER_CTX_DISPOSED = false;
|
||||||
|
|
||||||
@@ -114,6 +109,7 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
BUNX_BUNDLER_ERROR_EXIT_FILE,
|
BUNX_BUNDLER_ERROR_EXIT_FILE,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// SSR must finish before HMR so server props are fresh
|
||||||
if (build_only) {
|
if (build_only) {
|
||||||
try {
|
try {
|
||||||
await pagesSSRBundler();
|
await pagesSSRBundler();
|
||||||
@@ -131,17 +127,22 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
await fullRebuild();
|
await fullRebuild();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
pagesSSRBundler();
|
await pagesSSRBundler();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`SSR Bundler Error: ${error}`);
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (artifacts?.[0] && artifacts.length > 0) {
|
||||||
|
try {
|
||||||
|
await post_build_fn?.({ artifacts });
|
||||||
|
} catch (error) {
|
||||||
|
log.error(`Post-build Error: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (global.SSR_BUNDLER_CTX) {
|
global.RECOMPILING = false;
|
||||||
// global.SSR_BUNDLER_CTX.rebuild();
|
global.IS_SERVER_COMPONENT = false;
|
||||||
// } else {
|
|
||||||
// pagesSSRContextBundler();
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,9 +41,16 @@ export default function ssrCTXArtifactTracker({
|
|||||||
build.onEnd(async (result) => {
|
build.onEnd(async (result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||||
await global.SSR_BUNDLER_CTX?.dispose();
|
try {
|
||||||
|
await global.SSR_BUNDLER_CTX?.dispose();
|
||||||
|
} catch {}
|
||||||
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
build_starts = 0;
|
build_starts = 0;
|
||||||
console.log("SSR Build errors:", result.errors);
|
for (const err of result.errors) {
|
||||||
|
console.error(
|
||||||
|
`SSR Build error: ${err.text}${err.location ? ` (${err.location.file}:${err.location.line}:${err.location.column})` : ""}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ export default async function bunextInit(params?: Params) {
|
|||||||
} else if (is_dev) {
|
} else if (is_dev) {
|
||||||
log.build(`Building Modules ...`);
|
log.build(`Building Modules ...`);
|
||||||
await allPagesESBuildContextBundler({
|
await allPagesESBuildContextBundler({
|
||||||
post_build_fn: () => {
|
post_build_fn: async () => {
|
||||||
serverPostBuildFn();
|
await serverPostBuildFn();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
watcherEsbuildCTX();
|
watcherEsbuildCTX();
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import chokidar from "chokidar";
|
import chokidar from "chokidar";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { existsSync, statSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import fullRebuild from "./full-rebuild";
|
import fullRebuild from "./full-rebuild";
|
||||||
import { AppData } from "../../data/app-data";
|
import { AppData } from "../../data/app-data";
|
||||||
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
||||||
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
||||||
|
import { log } from "../../utils/log";
|
||||||
|
|
||||||
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
|
|
||||||
export default async function chokadirWatcherEsbuildCTX() {
|
export default async function chokadirWatcherEsbuildCTX() {
|
||||||
// Define ignored patterns directly in Chokidar for better performance
|
|
||||||
const watcher = chokidar.watch(ROOT_DIR, {
|
const watcher = chokidar.watch(ROOT_DIR, {
|
||||||
ignored: [
|
ignored: [
|
||||||
/(^|[\/\\])\../, // ignore dotfiles
|
/(^|[\/\\])\../,
|
||||||
/node_modules/,
|
/node_modules/,
|
||||||
/public/,
|
/public/,
|
||||||
/\.bunext/,
|
/\.bunext/,
|
||||||
@@ -31,96 +31,117 @@ export default async function chokadirWatcherEsbuildCTX() {
|
|||||||
event: "add" | "change" | "unlink" | "addDir" | "unlinkDir",
|
event: "add" | "change" | "unlink" | "addDir" | "unlinkDir",
|
||||||
filePath: string,
|
filePath: string,
|
||||||
) => {
|
) => {
|
||||||
const filename = path.relative(ROOT_DIR, filePath);
|
let owns_recompile = false;
|
||||||
|
|
||||||
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
try {
|
||||||
await fullRebuild();
|
const filename = path.relative(ROOT_DIR, filePath);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (global.BUNDLER_CTX_DISPOSED) {
|
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
||||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
await fullRebuild();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
if (global.BUNDLER_CTX_DISPOSED) {
|
||||||
pagesSSRBundler();
|
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename.match(/\/styles$/) || filename === "styles") {
|
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||||
global.RECOMPILING = true;
|
await pagesSSRBundler().catch((error) => {
|
||||||
await Bun.sleep(1000);
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
await fullRebuild({
|
});
|
||||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
}
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filename.match(/bunext.config\.ts/)) {
|
if (filename.match(/\/styles$/) || filename === "styles") {
|
||||||
await fullRebuild({
|
owns_recompile = true;
|
||||||
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
|
||||||
|
|
||||||
if (event === "change") {
|
|
||||||
if (filename.match(target_files_match)) {
|
|
||||||
if (global.RECOMPILING) return;
|
|
||||||
global.RECOMPILING = true;
|
global.RECOMPILING = true;
|
||||||
|
await Bun.sleep(1000);
|
||||||
if (filename.match(/.*\.server\.tsx?/)) {
|
await fullRebuild({
|
||||||
global.IS_SERVER_COMPONENT = true;
|
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||||
}
|
});
|
||||||
|
return;
|
||||||
if (global.BUNDLER_CTX) {
|
|
||||||
await global.BUNDLER_CTX.rebuild();
|
|
||||||
}
|
|
||||||
|
|
||||||
// HMR for error pages
|
|
||||||
if (filename.match(/(404|500)\.tsx?/)) {
|
|
||||||
global.HMR_CONTROLLERS.forEach((controller) => {
|
|
||||||
controller?.controller?.enqueue(
|
|
||||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Structural Changes (Add/Delete)
|
|
||||||
if (["add", "unlink", "addDir", "unlinkDir"].includes(event)) {
|
|
||||||
const is_file_of_interest =
|
|
||||||
!!filename.match(target_files_match) || event.includes("Dir");
|
|
||||||
|
|
||||||
if (!is_file_of_interest) return;
|
|
||||||
|
|
||||||
// Validation logic
|
|
||||||
if (
|
|
||||||
!filename.match(/^src\/pages\/|\.css$/) ||
|
|
||||||
checkExcludedPatterns({ path: filename }) ||
|
|
||||||
filename.includes(" ")
|
|
||||||
) {
|
|
||||||
// With chokidar, you rarely need to "reload" the whole watcher.
|
|
||||||
// But we keep the logic for consistency.
|
|
||||||
return reloadWatcher();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.RECOMPILING) return;
|
if (filename.match(/bunext.config\.ts/)) {
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const action = event.startsWith("add") ? "created" : "deleted";
|
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
||||||
const type = filename.match(/\.css$/)
|
|
||||||
? "Stylesheet"
|
|
||||||
: event.includes("Dir")
|
|
||||||
? "Directory"
|
|
||||||
: filename.match(/\/pages\/api\//)
|
|
||||||
? "API Route"
|
|
||||||
: "Page";
|
|
||||||
|
|
||||||
await fullRebuild({
|
if (event === "change") {
|
||||||
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
if (filename.match(target_files_match)) {
|
||||||
});
|
if (global.RECOMPILING) return;
|
||||||
|
owns_recompile = true;
|
||||||
|
global.RECOMPILING = true;
|
||||||
|
|
||||||
|
if (filename.match(/.*\.server\.tsx?/)) {
|
||||||
|
global.IS_SERVER_COMPONENT = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.BUNDLER_CTX) {
|
||||||
|
await global.BUNDLER_CTX.rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.match(/(404|500)\.tsx?/)) {
|
||||||
|
for (
|
||||||
|
let i = global.HMR_CONTROLLERS.length - 1;
|
||||||
|
i >= 0;
|
||||||
|
i--
|
||||||
|
) {
|
||||||
|
const controller = global.HMR_CONTROLLERS[i];
|
||||||
|
try {
|
||||||
|
controller?.controller?.enqueue(
|
||||||
|
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (["add", "unlink", "addDir", "unlinkDir"].includes(event)) {
|
||||||
|
const is_file_of_interest =
|
||||||
|
!!filename.match(target_files_match) ||
|
||||||
|
event.includes("Dir");
|
||||||
|
|
||||||
|
if (!is_file_of_interest) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!filename.match(/^src\/pages\/|\.css$/) ||
|
||||||
|
checkExcludedPatterns({ path: filename }) ||
|
||||||
|
filename.includes(" ")
|
||||||
|
) {
|
||||||
|
return reloadWatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.RECOMPILING) return;
|
||||||
|
|
||||||
|
owns_recompile = true;
|
||||||
|
const action = event.startsWith("add") ? "created" : "deleted";
|
||||||
|
const type = filename.match(/\.css$/)
|
||||||
|
? "Stylesheet"
|
||||||
|
: event.includes("Dir")
|
||||||
|
? "Directory"
|
||||||
|
: filename.match(/\/pages\/api\//)
|
||||||
|
? "API Route"
|
||||||
|
: "Page";
|
||||||
|
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
log.error(`Watcher rebuild failed: ${error}`);
|
||||||
|
} finally {
|
||||||
|
if (owns_recompile) {
|
||||||
|
global.RECOMPILING = false;
|
||||||
|
global.IS_SERVER_COMPONENT = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,8 +151,6 @@ export default async function chokadirWatcherEsbuildCTX() {
|
|||||||
.on("unlink", (path) => handleEvent("unlink", path))
|
.on("unlink", (path) => handleEvent("unlink", path))
|
||||||
.on("addDir", (path) => handleEvent("addDir", path))
|
.on("addDir", (path) => handleEvent("addDir", path))
|
||||||
.on("unlinkDir", (path) => handleEvent("unlinkDir", path));
|
.on("unlinkDir", (path) => handleEvent("unlinkDir", path));
|
||||||
|
|
||||||
// global.PAGES_SRC_WATCHER = watcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadWatcher() {
|
function reloadWatcher() {
|
||||||
|
|||||||
@@ -23,17 +23,16 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
|||||||
global.SSR_BUNDLER_CTX = undefined;
|
global.SSR_BUNDLER_CTX = undefined;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
// await pagesSSRBundler();
|
|
||||||
|
|
||||||
await allPagesESBuildContextBundler({
|
await allPagesESBuildContextBundler({
|
||||||
post_build_fn: () => {
|
post_build_fn: async () => {
|
||||||
serverPostBuildFn();
|
await serverPostBuildFn();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
log.error(error);
|
||||||
|
} finally {
|
||||||
global.RECOMPILING = false;
|
global.RECOMPILING = false;
|
||||||
global.IS_SERVER_COMPONENT = false;
|
global.IS_SERVER_COMPONENT = false;
|
||||||
log.error(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.PAGES_SRC_WATCHER) {
|
if (global.PAGES_SRC_WATCHER) {
|
||||||
|
|||||||
@@ -33,15 +33,23 @@ export default async function serverPostBuildFn(params?: Params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params?.reload_all_controllers) {
|
if (params?.reload_all_controllers) {
|
||||||
controller.controller.enqueue(reload_enqueue);
|
try {
|
||||||
|
controller.controller.enqueue(reload_enqueue);
|
||||||
|
} catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const target_artifact =
|
const target_artifact =
|
||||||
global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
||||||
|
|
||||||
if (!target_artifact.local_path) {
|
if (!target_artifact?.local_path) {
|
||||||
controller.controller.enqueue(reload_enqueue);
|
try {
|
||||||
|
controller.controller.enqueue(reload_enqueue);
|
||||||
|
} catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,19 +57,18 @@ export default async function serverPostBuildFn(params?: Params) {
|
|||||||
? new Request(target_artifact.req_url)
|
? new Request(target_artifact.req_url)
|
||||||
: new Request(controller.page_url);
|
: new Request(controller.page_url);
|
||||||
|
|
||||||
const page_component = global.IS_SERVER_COMPONENT
|
// Always re-run server fns so fixed errors clear on the first HMR
|
||||||
? await grabPageComponent({
|
const page_component = await grabPageComponent({
|
||||||
req: mock_req,
|
req: mock_req,
|
||||||
return_server_res_only: true,
|
return_server_res_only: true,
|
||||||
is_hydration: true,
|
is_hydration: true,
|
||||||
})
|
});
|
||||||
: {};
|
|
||||||
|
|
||||||
if (page_component instanceof Response) {
|
if (page_component instanceof Response) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { serverRes } = page_component;
|
const { serverRes } = page_component || {};
|
||||||
|
|
||||||
const final_artifact: Omit<GlobalHMRControllerObject, "controller"> = {
|
const final_artifact: Omit<GlobalHMRControllerObject, "controller"> = {
|
||||||
..._.omit(controller, ["controller"]),
|
..._.omit(controller, ["controller"]),
|
||||||
@@ -72,9 +79,8 @@ export default async function serverPostBuildFn(params?: Params) {
|
|||||||
delete final_artifact.target_map;
|
delete final_artifact.target_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverRes) {
|
// Always replace so prior error props cannot linger
|
||||||
final_artifact.page_props = serverRes;
|
final_artifact.page_props = serverRes || {};
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let final_data: { [k: string]: any } = {};
|
let final_data: { [k: string]: any } = {};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import fullRebuild from "./full-rebuild";
|
|||||||
import { AppData } from "../../data/app-data";
|
import { AppData } from "../../data/app-data";
|
||||||
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
import checkExcludedPatterns from "../../utils/check-excluded-patterns";
|
||||||
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
import pagesSSRBundler from "../bundler/pages-ssr-bundler";
|
||||||
|
import { log } from "../../utils/log";
|
||||||
|
|
||||||
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
const { ROOT_DIR, BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
|
|
||||||
@@ -16,116 +17,136 @@ export default async function watcherEsbuildCTX() {
|
|||||||
persistent: true,
|
persistent: true,
|
||||||
},
|
},
|
||||||
async (event, filename) => {
|
async (event, filename) => {
|
||||||
if (!filename) return;
|
let owns_recompile = false;
|
||||||
|
|
||||||
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
try {
|
||||||
await fullRebuild();
|
if (!filename) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filename.match(/^\.\w+/)) {
|
if (existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE)) {
|
||||||
return;
|
await fullRebuild();
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (global.BUNDLER_CTX_DISPOSED) {
|
if (filename.match(/^\.\w+/)) {
|
||||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
if (global.BUNDLER_CTX_DISPOSED) {
|
||||||
pagesSSRBundler();
|
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (filename.endsWith(AppData["BunextTmpFileExt"])) {
|
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||||
return;
|
await pagesSSRBundler().catch((error) => {
|
||||||
}
|
log.error(`SSR Bundler Error: ${error}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const full_file_path = path.join(ROOT_DIR, filename);
|
if (filename.endsWith(AppData["BunextTmpFileExt"])) {
|
||||||
const does_file_exist = existsSync(full_file_path);
|
return;
|
||||||
const file_stat = does_file_exist
|
}
|
||||||
? statSync(full_file_path)
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
if (full_file_path.match(/\/styles$/)) {
|
const full_file_path = path.join(ROOT_DIR, filename);
|
||||||
global.RECOMPILING = true;
|
const does_file_exist = existsSync(full_file_path);
|
||||||
await Bun.sleep(1000);
|
const file_stat = does_file_exist
|
||||||
await fullRebuild({
|
? statSync(full_file_path)
|
||||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
: undefined;
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const excluded_match =
|
if (full_file_path.match(/\/styles$/)) {
|
||||||
/node_modules\/|^public\/|^\.bunext\/|^\.git\/|^\.?dist\/|bun\.lockb$/;
|
owns_recompile = true;
|
||||||
|
|
||||||
if (filename.match(excluded_match)) return;
|
|
||||||
|
|
||||||
if (filename.match(/bunext.config\.ts/)) {
|
|
||||||
await fullRebuild({
|
|
||||||
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
|
||||||
// const rebuild_skip_paths = /\/pages\/api\//;
|
|
||||||
|
|
||||||
if (event !== "rename") {
|
|
||||||
if (filename.match(target_files_match)) {
|
|
||||||
if (global.RECOMPILING) return;
|
|
||||||
global.RECOMPILING = true;
|
global.RECOMPILING = true;
|
||||||
|
await Bun.sleep(1000);
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (filename.match(/.*\.server\.tsx?/)) {
|
const excluded_match =
|
||||||
global.IS_SERVER_COMPONENT = true;
|
/node_modules\/|^public\/|^\.bunext\/|^\.git\/|^\.?dist\/|bun\.lockb$/;
|
||||||
}
|
|
||||||
|
|
||||||
if (global.BUNDLER_CTX) {
|
if (filename.match(excluded_match)) return;
|
||||||
await global.BUNDLER_CTX.rebuild();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filename.match(/(404|500)\.tsx?/)) {
|
if (filename.match(/bunext.config\.ts/)) {
|
||||||
for (
|
await fullRebuild({
|
||||||
let i = global.HMR_CONTROLLERS.length - 1;
|
msg: `bunext.config.ts file changed. Rebuilding server ...`,
|
||||||
i >= 0;
|
});
|
||||||
i--
|
return;
|
||||||
) {
|
}
|
||||||
const controller = global.HMR_CONTROLLERS[i];
|
|
||||||
controller?.controller?.enqueue(
|
const target_files_match = /\.(tsx?|jsx?|css)$/;
|
||||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
|
||||||
);
|
if (event !== "rename") {
|
||||||
|
if (filename.match(target_files_match)) {
|
||||||
|
if (global.RECOMPILING) return;
|
||||||
|
owns_recompile = true;
|
||||||
|
global.RECOMPILING = true;
|
||||||
|
|
||||||
|
if (filename.match(/.*\.server\.tsx?/)) {
|
||||||
|
global.IS_SERVER_COMPONENT = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (global.BUNDLER_CTX) {
|
||||||
|
await global.BUNDLER_CTX.rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.match(/(404|500)\.tsx?/)) {
|
||||||
|
for (
|
||||||
|
let i = global.HMR_CONTROLLERS.length - 1;
|
||||||
|
i >= 0;
|
||||||
|
i--
|
||||||
|
) {
|
||||||
|
const controller = global.HMR_CONTROLLERS[i];
|
||||||
|
try {
|
||||||
|
controller?.controller?.enqueue(
|
||||||
|
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
global.HMR_CONTROLLERS.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const is_file_of_interest =
|
||||||
|
Boolean(filename.match(target_files_match)) ||
|
||||||
|
file_stat?.isDirectory();
|
||||||
|
|
||||||
|
if (!is_file_of_interest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filename.match(/^src\/pages\/|\.css$/))
|
||||||
|
return reloadWatcher();
|
||||||
|
if (checkExcludedPatterns({ path: filename }))
|
||||||
|
return reloadWatcher();
|
||||||
|
if (filename.match(/ /)) return reloadWatcher();
|
||||||
|
|
||||||
|
if (global.RECOMPILING) return;
|
||||||
|
|
||||||
|
owns_recompile = true;
|
||||||
|
const action = does_file_exist ? "created" : "deleted";
|
||||||
|
const type = filename.match(/\.css$/)
|
||||||
|
? "Sylesheet"
|
||||||
|
: file_stat?.isDirectory()
|
||||||
|
? "Directory"
|
||||||
|
: filename.match(/\/pages\/api\//)
|
||||||
|
? "API Route"
|
||||||
|
: "Page";
|
||||||
|
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
log.error(`Watcher rebuild failed: ${error}`);
|
||||||
|
} finally {
|
||||||
|
if (owns_recompile) {
|
||||||
|
global.RECOMPILING = false;
|
||||||
|
global.IS_SERVER_COMPONENT = false;
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_file_of_interest =
|
|
||||||
Boolean(filename.match(target_files_match)) ||
|
|
||||||
file_stat?.isDirectory();
|
|
||||||
|
|
||||||
if (!is_file_of_interest) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!filename.match(/^src\/pages\/|\.css$/)) return reloadWatcher();
|
|
||||||
if (checkExcludedPatterns({ path: filename }))
|
|
||||||
return reloadWatcher();
|
|
||||||
if (filename.match(/ /)) return reloadWatcher();
|
|
||||||
|
|
||||||
if (global.RECOMPILING) return;
|
|
||||||
|
|
||||||
const action = does_file_exist ? "created" : "deleted";
|
|
||||||
const type = filename.match(/\.css$/)
|
|
||||||
? "Sylesheet"
|
|
||||||
: file_stat?.isDirectory()
|
|
||||||
? "Directory"
|
|
||||||
: filename.match(/\/pages\/api\//)
|
|
||||||
? "API Route"
|
|
||||||
: "Page";
|
|
||||||
|
|
||||||
await fullRebuild({
|
|
||||||
msg: `${type} ${action}: ${filename}. Rebuilding ...`,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,12 @@ export default async function grabPageBundledReactComponent({
|
|||||||
}: Params): Promise<GrabPageReactBundledComponentRes | undefined> {
|
}: Params): Promise<GrabPageReactBundledComponentRes | undefined> {
|
||||||
try {
|
try {
|
||||||
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
||||||
const mod = await import(
|
const abs = path.join(
|
||||||
path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[file_path].path)
|
ROOT_DIR,
|
||||||
|
global.SSR_BUNDLER_CTX_MAP[file_path].path,
|
||||||
);
|
);
|
||||||
|
Loader.registry.delete(abs);
|
||||||
|
const mod = await import(`${abs}?t=${Date.now()}`);
|
||||||
|
|
||||||
const Main = mod.default as FC;
|
const Main = mod.default as FC;
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ export default async function grabPageCombinedServerRes({
|
|||||||
? path.join(ROOT_DIR, root_server_ctx_map.path)
|
? path.join(ROOT_DIR, root_server_ctx_map.path)
|
||||||
: root_server_file_path;
|
: root_server_file_path;
|
||||||
|
|
||||||
|
if (final_root_server_path) {
|
||||||
|
Loader.registry.delete(final_root_server_path);
|
||||||
|
}
|
||||||
const root_server_module: BunextPageServerModule = final_root_server_path
|
const root_server_module: BunextPageServerModule = final_root_server_path
|
||||||
? await import(`${final_root_server_path}?t=${now}`)
|
? await import(`${final_root_server_path}?t=${now}`)
|
||||||
: undefined;
|
: undefined;
|
||||||
@@ -65,6 +68,9 @@ export default async function grabPageCombinedServerRes({
|
|||||||
? path.join(ROOT_DIR, page_server_ctx.path)
|
? path.join(ROOT_DIR, page_server_ctx.path)
|
||||||
: server_file_path;
|
: server_file_path;
|
||||||
|
|
||||||
|
if (final_page_server_path) {
|
||||||
|
Loader.registry.delete(final_page_server_path);
|
||||||
|
}
|
||||||
const server_module: BunextPageServerModule = final_page_server_path
|
const server_module: BunextPageServerModule = final_page_server_path
|
||||||
? await import(`${final_page_server_path}?t=${now}`)
|
? await import(`${final_page_server_path}?t=${now}`)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user