From d4cc4012097097d2e538f39e46f8eb78f0fa1696 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Tue, 22 Sep 2026 16:43:14 +0100 Subject: [PATCH] Updates --- dist/commands/build/index.js | 15 ++++++++-- .../server/web-pages/grab-page-component.js | 2 ++ package.json | 2 +- src/commands/build/index.ts | 28 +++++++++++++++++-- .../server/web-pages/grab-page-component.tsx | 3 ++ 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/dist/commands/build/index.js b/dist/commands/build/index.js index bdf1d15..83a2254 100644 --- a/dist/commands/build/index.js +++ b/dist/commands/build/index.js @@ -4,7 +4,7 @@ import grabDirNames from "../../utils/grab-dir-names"; import { rmSync, writeFileSync } from "fs"; import bunextInit from "../../functions/bunext-init"; import pagesSSRBundler from "../../functions/bundler/pages-ssr-bundler"; -const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, } = grabDirNames(); +const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR, BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, ROOT_DIR, } = grabDirNames(); export default function () { return new Command("build") .description("Build Project") @@ -22,10 +22,19 @@ export default function () { await bunextInit({ build_only: true }); // await pagesSSRBundler(); if (global.BUNEXT_BUNDLER_CTX_MAP) { - writeFileSync(BUNDLER_CTX_MAP_JSON, JSON.stringify(global.BUNEXT_BUNDLER_CTX_MAP), "utf-8"); + let bundler_ctx_json_str = JSON.stringify(global.BUNEXT_BUNDLER_CTX_MAP); + if (process.env.BUNEXT_BUILD_ROOT_DIR) { + bundler_ctx_json_str = bundler_ctx_json_str.replaceAll(ROOT_DIR, process.env.BUNEXT_BUILD_ROOT_DIR); + } + writeFileSync(BUNDLER_CTX_MAP_JSON, bundler_ctx_json_str, "utf-8"); } if (global.BUNEXT_SSR_BUNDLER_CTX_MAP) { - writeFileSync(SSR_BUNDLER_CTX_MAP_JSON, JSON.stringify(global.BUNEXT_SSR_BUNDLER_CTX_MAP), "utf-8"); + let ssr_bundler_ctx_json_str = JSON.stringify(global.BUNEXT_SSR_BUNDLER_CTX_MAP); + if (process.env.BUNEXT_BUILD_ROOT_DIR) { + ssr_bundler_ctx_json_str = + ssr_bundler_ctx_json_str.replaceAll(ROOT_DIR, process.env.BUNEXT_BUILD_ROOT_DIR); + } + writeFileSync(SSR_BUNDLER_CTX_MAP_JSON, ssr_bundler_ctx_json_str, "utf-8"); } log.success("Modules Built Successfully!"); process.exit(); diff --git a/dist/functions/server/web-pages/grab-page-component.js b/dist/functions/server/web-pages/grab-page-component.js index 20b0845..375fb52 100644 --- a/dist/functions/server/web-pages/grab-page-component.js +++ b/dist/functions/server/web-pages/grab-page-component.js @@ -52,6 +52,8 @@ export default async function grabPageComponent(params) { throw new Error(errMsg); } let bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path]; + console.log("bundledMap", bundledMap); + console.log("file_path", file_path); if (!bundledMap?.path) { if (does_error_file_exist) { throw new Error(`Application Error. Please Check your components. ${match?.filePath} likely exists but has no exported module.`); diff --git a/package.json b/package.json index 14c8af0..d6f27b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/bunext", - "version": "1.1.9", + "version": "1.1.10", "main": "dist/index.js", "module": "index.ts", "dependencies": { diff --git a/src/commands/build/index.ts b/src/commands/build/index.ts index 6483af7..3a28ab9 100644 --- a/src/commands/build/index.ts +++ b/src/commands/build/index.ts @@ -11,6 +11,7 @@ const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_CWD_MODULE_CACHE_DIR, + ROOT_DIR, } = grabDirNames(); export default function () { @@ -32,17 +33,40 @@ export default function () { // await pagesSSRBundler(); if (global.BUNEXT_BUNDLER_CTX_MAP) { + let bundler_ctx_json_str = JSON.stringify( + global.BUNEXT_BUNDLER_CTX_MAP, + ); + + if (process.env.BUNEXT_BUILD_ROOT_DIR) { + bundler_ctx_json_str = bundler_ctx_json_str.replaceAll( + ROOT_DIR, + process.env.BUNEXT_BUILD_ROOT_DIR, + ); + } + writeFileSync( BUNDLER_CTX_MAP_JSON, - JSON.stringify(global.BUNEXT_BUNDLER_CTX_MAP), + bundler_ctx_json_str, "utf-8", ); } if (global.BUNEXT_SSR_BUNDLER_CTX_MAP) { + let ssr_bundler_ctx_json_str = JSON.stringify( + global.BUNEXT_SSR_BUNDLER_CTX_MAP, + ); + + if (process.env.BUNEXT_BUILD_ROOT_DIR) { + ssr_bundler_ctx_json_str = + ssr_bundler_ctx_json_str.replaceAll( + ROOT_DIR, + process.env.BUNEXT_BUILD_ROOT_DIR, + ); + } + writeFileSync( SSR_BUNDLER_CTX_MAP_JSON, - JSON.stringify(global.BUNEXT_SSR_BUNDLER_CTX_MAP), + ssr_bundler_ctx_json_str, "utf-8", ); } diff --git a/src/functions/server/web-pages/grab-page-component.tsx b/src/functions/server/web-pages/grab-page-component.tsx index f08f9c2..281b644 100644 --- a/src/functions/server/web-pages/grab-page-component.tsx +++ b/src/functions/server/web-pages/grab-page-component.tsx @@ -92,6 +92,9 @@ export default async function grabPageComponent( let bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path]; + console.log("bundledMap", bundledMap); + console.log("file_path", file_path); + if (!bundledMap?.path) { if (does_error_file_exist) { throw new Error(