Fix API bundler. Use new esbuild context builder for it.

This commit is contained in:
2026-04-11 12:06:53 +01:00
parent c4f7cf9164
commit 814a289460
30 changed files with 465 additions and 15 deletions
+34 -3
View File
@@ -24,11 +24,14 @@ export default async function ({ req }) {
},
});
}
const routeParams = await grabRouteParams({ req });
const routeParams = await grabRouteParams({
req,
query: match.query,
});
let module;
const now = Date.now();
if (global.SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
const target_import = path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[match.filePath].path);
if (is_dev && global.API_ROUTES_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
const target_import = path.join(ROOT_DIR, global.API_ROUTES_BUNDLER_CTX_MAP[match.filePath].path);
module = await import(`${target_import}?t=${now}`);
}
else {
@@ -80,3 +83,31 @@ export default async function ({ req }) {
}
return undefined;
}
// 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);
+4
View File
@@ -5,6 +5,7 @@ import { log } from "../../utils/log";
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
import serverPostBuildFn from "./server-post-build-fn";
import fullRebuild from "./full-rebuild";
import { AppData } from "../../data/app-data";
const { ROOT_DIR } = grabDirNames();
export default async function watcherEsbuildCTX() {
const pages_src_watcher = watch(ROOT_DIR, {
@@ -16,6 +17,9 @@ export default async function watcherEsbuildCTX() {
if (filename.match(/^\.\w+/)) {
return;
}
if (filename.endsWith(AppData["BunextTmpFileExt"])) {
return;
}
const full_file_path = path.join(ROOT_DIR, filename);
const does_file_exist = existsSync(full_file_path);
const file_stat = does_file_exist