Updates
This commit is contained in:
parent
9a427412f3
commit
b2e92e5792
12
dist/commands/dev/index.js
vendored
12
dist/commands/dev/index.js
vendored
@ -2,6 +2,8 @@ import { Command } from "commander";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import writeErrorFile from "../../functions/write-error-file";
|
import writeErrorFile from "../../functions/write-error-file";
|
||||||
|
let retries = 0;
|
||||||
|
let timeout;
|
||||||
export default function () {
|
export default function () {
|
||||||
return new Command("dev")
|
return new Command("dev")
|
||||||
.description("Run development server")
|
.description("Run development server")
|
||||||
@ -10,11 +12,15 @@ export default function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function dev() {
|
async function dev() {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
if (retries == 1) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
||||||
const spawn_options = {
|
const spawn_options = {
|
||||||
cmd: ["bun", dev_spawn_file],
|
cmd: ["bun", dev_spawn_file],
|
||||||
stdio: ["inherit", "inherit", "inherit"],
|
stdio: ["inherit", "inherit", "inherit"],
|
||||||
onExit(subprocess, exitCode, signalCode, error) {
|
async onExit(subprocess, exitCode, signalCode, error) {
|
||||||
writeErrorFile({ exitCode, error });
|
writeErrorFile({ exitCode, error });
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
@ -23,6 +29,10 @@ async function dev() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
let dev_process = Bun.spawn(spawn_options);
|
let dev_process = Bun.spawn(spawn_options);
|
||||||
|
retries++;
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
retries = 0;
|
||||||
|
}, 5000);
|
||||||
const exited = await dev_process.exited;
|
const exited = await dev_process.exited;
|
||||||
if (exited) {
|
if (exited) {
|
||||||
return await dev();
|
return await dev();
|
||||||
|
|||||||
@ -20,8 +20,9 @@ export default async function allPagesESBuildContextBundler(params) {
|
|||||||
const tsx = await grabClientHydrationScript({
|
const tsx = await grabClientHydrationScript({
|
||||||
page_local_path: page.local_path,
|
page_local_path: page.local_path,
|
||||||
});
|
});
|
||||||
if (!tsx)
|
if (!tsx) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
const entryFile = path.join(BUNX_HYDRATION_SRC_DIR, `${page.url_path}.tsx`);
|
const entryFile = path.join(BUNX_HYDRATION_SRC_DIR, `${page.url_path}.tsx`);
|
||||||
// await Bun.write(entryFile, txt, { createPath: true });
|
// await Bun.write(entryFile, txt, { createPath: true });
|
||||||
entryToPage.set(entryFile, { ...page, tsx });
|
entryToPage.set(entryFile, { ...page, tsx });
|
||||||
|
|||||||
6
dist/functions/bundler/pages-ssr-bundler.js
vendored
6
dist/functions/bundler/pages-ssr-bundler.js
vendored
@ -16,7 +16,9 @@ export default async function pagesSSRBundler(params) {
|
|||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
if (page.local_path.match(/\/pages\/api\//)) {
|
if (page.local_path.match(/\/pages\/api\//)) {
|
||||||
const ts = await Bun.file(page.local_path).text();
|
const ts = await Bun.file(page.local_path).text();
|
||||||
entryToPage.set(page.local_path, { ...page, tsx: ts });
|
if (ts.match(/(export default)|(export \w+ handler)/)) {
|
||||||
|
entryToPage.set(page.local_path, { ...page, tsx: ts });
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const tsx = grabPageReactComponentString({
|
const tsx = grabPageReactComponentString({
|
||||||
@ -25,6 +27,8 @@ export default async function pagesSSRBundler(params) {
|
|||||||
});
|
});
|
||||||
if (!tsx)
|
if (!tsx)
|
||||||
continue;
|
continue;
|
||||||
|
if (!tsx.match(/export default/))
|
||||||
|
continue;
|
||||||
entryToPage.set(page.local_path, { ...page, tsx });
|
entryToPage.set(page.local_path, { ...page, tsx });
|
||||||
}
|
}
|
||||||
const entryPoints = [...entryToPage.keys()].map((e) => `ssr-virtual:${e}`);
|
const entryPoints = [...entryToPage.keys()].map((e) => `ssr-virtual:${e}`);
|
||||||
|
|||||||
@ -16,6 +16,9 @@ export default function ssrVirtualFilesPlugin({ entryToPage }) {
|
|||||||
if (!target?.tsx)
|
if (!target?.tsx)
|
||||||
return null;
|
return null;
|
||||||
const contents = target.tsx;
|
const contents = target.tsx;
|
||||||
|
if (!contents.match(/export/)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
contents: contents || "",
|
contents: contents || "",
|
||||||
loader: "tsx",
|
loader: "tsx",
|
||||||
|
|||||||
2
dist/functions/server/bunext-req-handler.js
vendored
2
dist/functions/server/bunext-req-handler.js
vendored
@ -34,7 +34,7 @@ export default async function bunextRequestHandler({ req: initial_req, server, }
|
|||||||
return new Response("Modules Rebuilt");
|
return new Response("Modules Rebuilt");
|
||||||
}
|
}
|
||||||
if (url.pathname === "/__hmr" && is_dev) {
|
if (url.pathname === "/__hmr" && is_dev) {
|
||||||
response = await handleHmr({ req });
|
return handleHmr({ req });
|
||||||
}
|
}
|
||||||
else if (url.pathname.startsWith("/.bunext")) {
|
else if (url.pathname.startsWith("/.bunext")) {
|
||||||
response = await handleBunextPublicAssets({ req });
|
response = await handleBunextPublicAssets({ req });
|
||||||
|
|||||||
2
dist/functions/server/handle-routes.d.ts
vendored
2
dist/functions/server/handle-routes.d.ts
vendored
@ -1,5 +1,5 @@
|
|||||||
type Params = {
|
type Params = {
|
||||||
req: Request;
|
req: Request;
|
||||||
};
|
};
|
||||||
export default function ({ req }: Params): Promise<Response | undefined>;
|
export default function ({ req }: Params): Promise<Response>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
2
dist/functions/server/handle-routes.js
vendored
2
dist/functions/server/handle-routes.js
vendored
@ -81,7 +81,7 @@ export default async function ({ req }) {
|
|||||||
}
|
}
|
||||||
return final_res;
|
return final_res;
|
||||||
}
|
}
|
||||||
return undefined;
|
return Response.json({ err: `Route handler error` });
|
||||||
}
|
}
|
||||||
// const relative_path = match.filePath.replace(API_DIR, "");
|
// const relative_path = match.filePath.replace(API_DIR, "");
|
||||||
// const relative_module_js_file = relative_path.replace(/\.tsx?$/, ".js");
|
// const relative_module_js_file = relative_path.replace(/\.tsx?$/, ".js");
|
||||||
|
|||||||
@ -32,6 +32,7 @@ export default async function grabPageCombinedServerRes({ file_path, debug, url,
|
|||||||
url,
|
url,
|
||||||
query,
|
query,
|
||||||
routeParams,
|
routeParams,
|
||||||
|
props: rootServerRes?.props || null,
|
||||||
});
|
});
|
||||||
const mergedServerRes = _.merge(rootServerRes || {}, serverRes || {});
|
const mergedServerRes = _.merge(rootServerRes || {}, serverRes || {});
|
||||||
return { serverRes: mergedServerRes };
|
return { serverRes: mergedServerRes };
|
||||||
|
|||||||
@ -7,6 +7,9 @@ import grabPageCombinedServerRes from "./grab-page-combined-server-res";
|
|||||||
import fullRebuild from "../full-rebuild";
|
import fullRebuild from "../full-rebuild";
|
||||||
import serverPostBuildFn from "../server-post-build-fn";
|
import serverPostBuildFn from "../server-post-build-fn";
|
||||||
import isDevelopment from "../../../utils/is-development";
|
import isDevelopment from "../../../utils/is-development";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
import grabDirNames from "../../../utils/grab-dir-names";
|
||||||
|
const { BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
class NotFoundError extends Error {
|
class NotFoundError extends Error {
|
||||||
status = 404;
|
status = 404;
|
||||||
constructor(message) {
|
constructor(message) {
|
||||||
@ -24,6 +27,7 @@ export default async function grabPageComponent(params) {
|
|||||||
url.protocol = forwarded_proto;
|
url.protocol = forwarded_proto;
|
||||||
}
|
}
|
||||||
let routeParams = undefined;
|
let routeParams = undefined;
|
||||||
|
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||||
try {
|
try {
|
||||||
routeParams = req ? await grabRouteParams({ req }) : undefined;
|
routeParams = req ? await grabRouteParams({ req }) : undefined;
|
||||||
let url_path = url ? url.pathname : undefined;
|
let url_path = url ? url.pathname : undefined;
|
||||||
@ -46,11 +50,26 @@ export default async function grabPageComponent(params) {
|
|||||||
// log.error(errMsg);
|
// log.error(errMsg);
|
||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
}
|
}
|
||||||
const bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
let bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||||
if (!bundledMap?.path) {
|
if (!bundledMap?.path) {
|
||||||
const errMsg = `No Bundled File Path for this request path!`;
|
if (does_error_file_exist) {
|
||||||
log.error(errMsg);
|
throw new Error(`Application Error. Please Check your components. ${match?.filePath} likely exists but has no exported module.`);
|
||||||
throw new Error(errMsg);
|
}
|
||||||
|
let retries = 0;
|
||||||
|
const MAX_RETRIES = 2;
|
||||||
|
while (retries < MAX_RETRIES) {
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `Retrying Bundle map for file \`${file_path}\``,
|
||||||
|
});
|
||||||
|
bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||||
|
if (bundledMap?.path)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!bundledMap?.path) {
|
||||||
|
const errMsg = `No Bundled File Path for this request path!`;
|
||||||
|
log.error(errMsg);
|
||||||
|
throw new Error(errMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (req && !is_hydration) {
|
if (req && !is_hydration) {
|
||||||
global.BUNDLER_CTX_MAP[file_path].req = req;
|
global.BUNDLER_CTX_MAP[file_path].req = req;
|
||||||
|
|||||||
@ -4,6 +4,7 @@ type Params = {
|
|||||||
server_function?: BunextPageServerFn;
|
server_function?: BunextPageServerFn;
|
||||||
query?: Record<string, string>;
|
query?: Record<string, string>;
|
||||||
routeParams?: BunxRouteParams;
|
routeParams?: BunxRouteParams;
|
||||||
|
props?: Record<string, any> | null;
|
||||||
};
|
};
|
||||||
export default function grabPageServerRes({ url, query, routeParams, server_function, }: Params): Promise<BunextPageModuleServerReturn>;
|
export default function grabPageServerRes({ url, query, routeParams, server_function, props, }: Params): Promise<BunextPageModuleServerReturn>;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { log } from "../../../utils/log";
|
import { log } from "../../../utils/log";
|
||||||
export default async function grabPageServerRes({ url, query, routeParams, server_function, }) {
|
export default async function grabPageServerRes({ url, query, routeParams, server_function, props, }) {
|
||||||
const default_props = {
|
const default_props = {
|
||||||
url: url
|
url: url
|
||||||
? {
|
? {
|
||||||
@ -22,26 +22,22 @@ export default async function grabPageServerRes({ url, query, routeParams, serve
|
|||||||
: null,
|
: null,
|
||||||
query,
|
query,
|
||||||
};
|
};
|
||||||
|
const init_props = props || null;
|
||||||
try {
|
try {
|
||||||
if (routeParams && server_function) {
|
if (routeParams && server_function) {
|
||||||
const serverData = await server_function({
|
const serverData = await server_function({
|
||||||
...routeParams,
|
...routeParams,
|
||||||
query: { ...routeParams.query, ...query },
|
query: { ...routeParams.query, ...query },
|
||||||
|
props: init_props,
|
||||||
});
|
});
|
||||||
return {
|
return _.merge(default_props, serverData);
|
||||||
...serverData,
|
|
||||||
...default_props,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return {
|
return _.merge(default_props);
|
||||||
...default_props,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
log.error(`Page ${url?.pathname} Server Error => ${error.message}\n`, error);
|
log.error(`Page ${url?.pathname} Server Error => ${error.message}\n`, error);
|
||||||
return {
|
return _.merge(default_props, {
|
||||||
...default_props,
|
|
||||||
error: error.message,
|
error: error.message,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
dist/types/index.d.ts
vendored
4
dist/types/index.d.ts
vendored
@ -190,7 +190,9 @@ export type BunextPageServerFn<T extends {
|
|||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
} = {
|
} = {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
}> = (ctx: Omit<BunxRouteParams, "body">) => Promise<BunextPageModuleServerReturn<T>>;
|
}> = (ctx: Omit<BunxRouteParams, "body"> & {
|
||||||
|
props?: any;
|
||||||
|
}) => Promise<BunextPageModuleServerReturn<T>>;
|
||||||
export type BunextRouteConfig = {
|
export type BunextRouteConfig = {
|
||||||
/**
|
/**
|
||||||
* Whether to cache the current page
|
* Whether to cache the current page
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.82",
|
"version": "1.0.83",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -4,6 +4,9 @@ import type { BunSpawnOptions } from "../../types";
|
|||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import writeErrorFile from "../../functions/write-error-file";
|
import writeErrorFile from "../../functions/write-error-file";
|
||||||
|
|
||||||
|
let retries = 0;
|
||||||
|
let timeout: any;
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
return new Command("dev")
|
return new Command("dev")
|
||||||
.description("Run development server")
|
.description("Run development server")
|
||||||
@ -13,12 +16,18 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function dev() {
|
async function dev() {
|
||||||
|
clearTimeout(timeout);
|
||||||
|
|
||||||
|
if (retries == 1) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
||||||
|
|
||||||
const spawn_options: BunSpawnOptions = {
|
const spawn_options: BunSpawnOptions = {
|
||||||
cmd: ["bun", dev_spawn_file],
|
cmd: ["bun", dev_spawn_file],
|
||||||
stdio: ["inherit", "inherit", "inherit"],
|
stdio: ["inherit", "inherit", "inherit"],
|
||||||
onExit(subprocess, exitCode, signalCode, error) {
|
async onExit(subprocess, exitCode, signalCode, error) {
|
||||||
writeErrorFile({ exitCode, error });
|
writeErrorFile({ exitCode, error });
|
||||||
},
|
},
|
||||||
env: {
|
env: {
|
||||||
@ -29,6 +38,12 @@ async function dev() {
|
|||||||
|
|
||||||
let dev_process = Bun.spawn(spawn_options);
|
let dev_process = Bun.spawn(spawn_options);
|
||||||
|
|
||||||
|
retries++;
|
||||||
|
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
retries = 0;
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
const exited = await dev_process.exited;
|
const exited = await dev_process.exited;
|
||||||
if (exited) {
|
if (exited) {
|
||||||
return await dev();
|
return await dev();
|
||||||
|
|||||||
@ -41,7 +41,9 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
|||||||
page_local_path: page.local_path,
|
page_local_path: page.local_path,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!tsx) continue;
|
if (!tsx) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const entryFile = path.join(
|
const entryFile = path.join(
|
||||||
BUNX_HYDRATION_SRC_DIR,
|
BUNX_HYDRATION_SRC_DIR,
|
||||||
|
|||||||
@ -25,7 +25,9 @@ export default async function pagesSSRBundler(params?: Params) {
|
|||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
if (page.local_path.match(/\/pages\/api\//)) {
|
if (page.local_path.match(/\/pages\/api\//)) {
|
||||||
const ts = await Bun.file(page.local_path).text();
|
const ts = await Bun.file(page.local_path).text();
|
||||||
entryToPage.set(page.local_path, { ...page, tsx: ts });
|
if (ts.match(/(export default)|(export \w+ handler)/)) {
|
||||||
|
entryToPage.set(page.local_path, { ...page, tsx: ts });
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ export default async function pagesSSRBundler(params?: Params) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!tsx) continue;
|
if (!tsx) continue;
|
||||||
|
if (!tsx.match(/export default/)) continue;
|
||||||
|
|
||||||
entryToPage.set(page.local_path, { ...page, tsx });
|
entryToPage.set(page.local_path, { ...page, tsx });
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,10 @@ export default function ssrVirtualFilesPlugin({ entryToPage }: Params) {
|
|||||||
|
|
||||||
const contents = target.tsx;
|
const contents = target.tsx;
|
||||||
|
|
||||||
|
if (!contents.match(/export/)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contents: contents || "",
|
contents: contents || "",
|
||||||
loader: "tsx",
|
loader: "tsx",
|
||||||
|
|||||||
@ -50,7 +50,7 @@ export default async function bunextRequestHandler({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (url.pathname === "/__hmr" && is_dev) {
|
if (url.pathname === "/__hmr" && is_dev) {
|
||||||
response = await handleHmr({ req });
|
return handleHmr({ req });
|
||||||
} else if (url.pathname.startsWith("/.bunext")) {
|
} else if (url.pathname.startsWith("/.bunext")) {
|
||||||
response = await handleBunextPublicAssets({ req });
|
response = await handleBunextPublicAssets({ req });
|
||||||
} else if (url.pathname.startsWith("/api/")) {
|
} else if (url.pathname.startsWith("/api/")) {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ type Params = {
|
|||||||
req: Request;
|
req: Request;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function ({ req }: Params): Promise<Response | undefined> {
|
export default async function ({ req }: Params): Promise<Response> {
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
const is_dev = isDevelopment();
|
const is_dev = isDevelopment();
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ export default async function ({ req }: Params): Promise<Response | undefined> {
|
|||||||
return final_res;
|
return final_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return Response.json({ err: `Route handler error` });
|
||||||
}
|
}
|
||||||
|
|
||||||
// const relative_path = match.filePath.replace(API_DIR, "");
|
// const relative_path = match.filePath.replace(API_DIR, "");
|
||||||
|
|||||||
@ -62,6 +62,7 @@ export default async function grabPageCombinedServerRes({
|
|||||||
url,
|
url,
|
||||||
query,
|
query,
|
||||||
routeParams,
|
routeParams,
|
||||||
|
props: rootServerRes?.props || null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mergedServerRes = _.merge(rootServerRes || {}, serverRes || {});
|
const mergedServerRes = _.merge(rootServerRes || {}, serverRes || {});
|
||||||
|
|||||||
@ -8,6 +8,10 @@ import grabPageCombinedServerRes from "./grab-page-combined-server-res";
|
|||||||
import fullRebuild from "../full-rebuild";
|
import fullRebuild from "../full-rebuild";
|
||||||
import serverPostBuildFn from "../server-post-build-fn";
|
import serverPostBuildFn from "../server-post-build-fn";
|
||||||
import isDevelopment from "../../../utils/is-development";
|
import isDevelopment from "../../../utils/is-development";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
import grabDirNames from "../../../utils/grab-dir-names";
|
||||||
|
|
||||||
|
const { BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||||
|
|
||||||
class NotFoundError extends Error {
|
class NotFoundError extends Error {
|
||||||
status = 404;
|
status = 404;
|
||||||
@ -52,6 +56,8 @@ export default async function grabPageComponent(
|
|||||||
|
|
||||||
let routeParams: BunxRouteParams | undefined = undefined;
|
let routeParams: BunxRouteParams | undefined = undefined;
|
||||||
|
|
||||||
|
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
routeParams = req ? await grabRouteParams({ req }) : undefined;
|
routeParams = req ? await grabRouteParams({ req }) : undefined;
|
||||||
|
|
||||||
@ -83,12 +89,31 @@ export default async function grabPageComponent(
|
|||||||
throw new Error(errMsg);
|
throw new Error(errMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
let bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||||
|
|
||||||
if (!bundledMap?.path) {
|
if (!bundledMap?.path) {
|
||||||
const errMsg = `No Bundled File Path for this request path!`;
|
if (does_error_file_exist) {
|
||||||
log.error(errMsg);
|
throw new Error(
|
||||||
throw new Error(errMsg);
|
`Application Error. Please Check your components. ${match?.filePath} likely exists but has no exported module.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let retries = 0;
|
||||||
|
const MAX_RETRIES = 2;
|
||||||
|
|
||||||
|
while (retries < MAX_RETRIES) {
|
||||||
|
await fullRebuild({
|
||||||
|
msg: `Retrying Bundle map for file \`${file_path}\``,
|
||||||
|
});
|
||||||
|
bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||||
|
if (bundledMap?.path) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bundledMap?.path) {
|
||||||
|
const errMsg = `No Bundled File Path for this request path!`;
|
||||||
|
log.error(errMsg);
|
||||||
|
throw new Error(errMsg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req && !is_hydration) {
|
if (req && !is_hydration) {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ type Params = {
|
|||||||
server_function?: BunextPageServerFn;
|
server_function?: BunextPageServerFn;
|
||||||
query?: Record<string, string>;
|
query?: Record<string, string>;
|
||||||
routeParams?: BunxRouteParams;
|
routeParams?: BunxRouteParams;
|
||||||
|
props?: Record<string, any> | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function grabPageServerRes({
|
export default async function grabPageServerRes({
|
||||||
@ -20,6 +21,7 @@ export default async function grabPageServerRes({
|
|||||||
query,
|
query,
|
||||||
routeParams,
|
routeParams,
|
||||||
server_function,
|
server_function,
|
||||||
|
props,
|
||||||
}: Params): Promise<BunextPageModuleServerReturn> {
|
}: Params): Promise<BunextPageModuleServerReturn> {
|
||||||
const default_props: BunextPageModuleServerReturn = {
|
const default_props: BunextPageModuleServerReturn = {
|
||||||
url: url
|
url: url
|
||||||
@ -43,31 +45,28 @@ export default async function grabPageServerRes({
|
|||||||
query,
|
query,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const init_props = props || null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (routeParams && server_function) {
|
if (routeParams && server_function) {
|
||||||
const serverData = await server_function({
|
const serverData = await server_function({
|
||||||
...routeParams,
|
...routeParams,
|
||||||
query: { ...routeParams.query, ...query },
|
query: { ...routeParams.query, ...query },
|
||||||
|
props: init_props,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return _.merge(default_props, serverData);
|
||||||
...serverData,
|
|
||||||
...default_props,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return _.merge(default_props);
|
||||||
...default_props,
|
|
||||||
};
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
log.error(
|
log.error(
|
||||||
`Page ${url?.pathname} Server Error => ${error.message}\n`,
|
`Page ${url?.pathname} Server Error => ${error.message}\n`,
|
||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return _.merge(default_props, {
|
||||||
...default_props,
|
|
||||||
error: error.message,
|
error: error.message,
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -223,7 +223,9 @@ export type BunextPageModuleMetaTwitter = {
|
|||||||
export type BunextPageServerFn<
|
export type BunextPageServerFn<
|
||||||
T extends { [k: string]: any } = { [k: string]: any },
|
T extends { [k: string]: any } = { [k: string]: any },
|
||||||
> = (
|
> = (
|
||||||
ctx: Omit<BunxRouteParams, "body">,
|
ctx: Omit<BunxRouteParams, "body"> & {
|
||||||
|
props?: any;
|
||||||
|
},
|
||||||
) => Promise<BunextPageModuleServerReturn<T>>;
|
) => Promise<BunextPageModuleServerReturn<T>>;
|
||||||
|
|
||||||
export type BunextRouteConfig = {
|
export type BunextRouteConfig = {
|
||||||
|
|||||||
@ -64,6 +64,7 @@ function grabPageDirRecursively({ page_dir }: { page_dir: string }) {
|
|||||||
const new_page_files = grabPageDirRecursively({
|
const new_page_files = grabPageDirRecursively({
|
||||||
page_dir: full_page_path,
|
page_dir: full_page_path,
|
||||||
});
|
});
|
||||||
|
|
||||||
pages_files.push(...new_page_files);
|
pages_files.push(...new_page_files);
|
||||||
} else if (page.match(/\.(ts|js)x?$/)) {
|
} else if (page.match(/\.(ts|js)x?$/)) {
|
||||||
const pages_file = grabPageFileObject({
|
const pages_file = grabPageFileObject({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user