Refactor artifacts to use relative directory for build step and retrieval

This commit is contained in:
2026-09-23 05:08:54 +01:00
parent 2803dfa0be
commit 2335c60cc3
26 changed files with 117 additions and 204 deletions
+8 -34
View File
@@ -10,6 +10,7 @@ import isDevelopment from "../../utils/is-development";
import _ from "lodash";
import path from "path";
import grabDirNames from "../../utils/grab-dir-names";
import grabRelativePath from "../../utils/grab-relative-path";
const { ROOT_DIR } = grabDirNames();
@@ -52,10 +53,15 @@ export default async function ({ req }: Params): Promise<Response> {
let module: any;
const now = Date.now();
if (is_dev && global.BUNEXT_SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
const relative_match_path = grabRelativePath(match.filePath);
if (
is_dev &&
global.BUNEXT_SSR_BUNDLER_CTX_MAP?.[relative_match_path]?.path
) {
const target_import = path.join(
ROOT_DIR,
global.BUNEXT_SSR_BUNDLER_CTX_MAP[match.filePath].path,
global.BUNEXT_SSR_BUNDLER_CTX_MAP[relative_match_path].path,
);
module = await import(`${target_import}?t=${now}`);
@@ -148,35 +154,3 @@ export default async function ({ req }: Params): Promise<Response> {
return Response.json({ err: `Route handler error` });
}
// const relative_path = match.filePath.replace(API_DIR, "");
// const relative_module_js_file = relative_path.replace(/\.tsx?$/, ".js");
// const bun_module_file = path.join(
// BUNX_CWD_MODULE_CACHE_DIR,
// "api",
// relative_module_js_file,
// );
// if (existsSync(bun_module_file)) {
// module = await import(`${bun_module_file}?t=${now}`);
// } else {
// const import_path = is_dev
// ? `${match.filePath}?t=${now}`
// : match.filePath;
// module = await import(import_path);
// }
// if (is_dev) {
// const tmp_path = `${match.filePath}.${now}${AppData["BunextTmpFileExt"]}`;
// cpSync(match.filePath, tmp_path);
// module = await import(`${tmp_path}?t=${now}`);
// try {
// unlinkSync(tmp_path);
// } catch (error) {}
// } else {
// // const import_path = is_dev ? `${match.filePath}?t=${now}` : match.filePath;
// module = await import(match.filePath);
// }
// const import_path = is_dev ? `${match.filePath}?t=${now}` : match.filePath;
// module = await import(import_path);