Major Bugfix. Fix server component client compatibility

This commit is contained in:
2026-03-22 10:34:30 +01:00
parent 9f619c8898
commit a9af20a8b2
39 changed files with 508 additions and 79 deletions
+2
View File
@@ -5,6 +5,7 @@ export default function grabDirNames(): {
API_DIR: string;
PUBLIC_DIR: string;
HYDRATION_DST_DIR: string;
BUNX_CWD_DIR: string;
BUNX_ROOT_DIR: string;
CONFIG_FILE: string;
BUNX_TMP_DIR: string;
@@ -18,4 +19,5 @@ export default function grabDirNames(): {
HYDRATION_DST_DIR_MAP_JSON_FILE: string;
BUNEXT_CACHE_DIR: string;
BUNX_CWD_MODULE_CACHE_DIR: string;
BUNX_CWD_PAGES_REWRITE_DIR: string;
};
+3
View File
@@ -12,6 +12,7 @@ export default function grabDirNames() {
const CONFIG_FILE = path.join(ROOT_DIR, "bunext.config.ts");
const BUNX_CWD_DIR = path.resolve(ROOT_DIR, ".bunext");
const BUNX_CWD_MODULE_CACHE_DIR = path.resolve(BUNX_CWD_DIR, "module-cache");
const BUNX_CWD_PAGES_REWRITE_DIR = path.resolve(BUNX_CWD_DIR, "pages");
const BUNX_TMP_DIR = path.resolve(BUNX_CWD_DIR, ".tmp");
const BUNX_HYDRATION_SRC_DIR = path.resolve(BUNX_CWD_DIR, "client", "hydration-src");
const BUNX_ROOT_DIR = path.resolve(__dirname, "../../");
@@ -28,6 +29,7 @@ export default function grabDirNames() {
API_DIR,
PUBLIC_DIR,
HYDRATION_DST_DIR,
BUNX_CWD_DIR,
BUNX_ROOT_DIR,
CONFIG_FILE,
BUNX_TMP_DIR,
@@ -41,5 +43,6 @@ export default function grabDirNames() {
HYDRATION_DST_DIR_MAP_JSON_FILE,
BUNEXT_CACHE_DIR,
BUNX_CWD_MODULE_CACHE_DIR,
BUNX_CWD_PAGES_REWRITE_DIR,
};
}
+1 -1
View File
@@ -1 +1 @@
export default function grabRouter(): import("bun").FileSystemRouter;
export default function grabRouter(): Bun.FileSystemRouter;
+9
View File
@@ -0,0 +1,9 @@
type Params = {
page_path: string;
};
/**
* # Transform a page path to the destination
* path in the .bunext directory
*/
export default function pagePathTransform({ page_path }: Params): string;
export {};
+14
View File
@@ -0,0 +1,14 @@
import path from "path";
import grabDirNames from "./grab-dir-names";
const { ROOT_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
/**
* # Transform a page path to the destination
* path in the .bunext directory
*/
export default function pagePathTransform({ page_path }) {
const page_path_relative_dir = page_path
.replace(ROOT_DIR, "")
.replace(/\/src\/pages/, "");
const target_path = path.join(BUNX_CWD_PAGES_REWRITE_DIR, page_path_relative_dir);
return target_path;
}
+5
View File
@@ -0,0 +1,5 @@
type Params = {
page_url?: string | string[];
};
export default function rewritePagesModule(params?: Params): Promise<void>;
export {};
+25
View File
@@ -0,0 +1,25 @@
import grabAllPages from "./grab-all-pages";
import pagePathTransform from "./page-path-transform";
import stripServerSideLogic from "../functions/bundler/strip-server-side-logic";
export default async function rewritePagesModule(params) {
const { page_url } = params || {};
let target_pages;
if (page_url) {
target_pages = Array.isArray(page_url) ? page_url : [page_url];
}
else {
const pages = grabAllPages({ exclude_api: true });
target_pages = pages.map((p) => p.local_path);
}
for (let i = 0; i < target_pages.length; i++) {
const page_path = target_pages[i];
const dst_path = pagePathTransform({ page_path });
const origin_page_content = await Bun.file(page_path).text();
const dst_page_content = stripServerSideLogic({
txt_code: origin_page_content,
});
await Bun.write(dst_path, dst_page_content, {
createPath: true,
});
}
}