Rename global variables
This commit is contained in:
@@ -15,7 +15,7 @@ export default function () {
|
||||
rmSync(BUNX_CWD_PAGES_REWRITE_DIR, { recursive: true });
|
||||
} catch (error) {}
|
||||
|
||||
global.SKIPPED_BROWSER_MODULES = new Set<string>();
|
||||
global.BUNEXT_SKIPPED_BROWSER_MODULES = new Set<string>();
|
||||
|
||||
await bunextInit({ build_only: true });
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
||||
|
||||
const pages = grabAllPages({ exclude_api: true });
|
||||
|
||||
global.PAGE_FILES = pages;
|
||||
global.BUNEXT_PAGE_FILES = pages;
|
||||
|
||||
const dev = isDevelopment();
|
||||
|
||||
@@ -60,7 +60,7 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
||||
(e) => `hydration-virtual:${e}`,
|
||||
);
|
||||
|
||||
global.BUNDLER_CTX = await esbuild.context({
|
||||
global.BUNEXT_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints,
|
||||
outdir: HYDRATION_DST_DIR,
|
||||
bundle: true,
|
||||
@@ -96,14 +96,14 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
||||
"react-dom/client",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
...(global.CONFIG.page_compiler_excludes || []),
|
||||
...(global.BUNEXT_CONFIG.page_compiler_excludes || []),
|
||||
],
|
||||
logLevel: did_process_exit_because_of_bundler_error
|
||||
? "silent"
|
||||
: undefined,
|
||||
});
|
||||
|
||||
await global.BUNDLER_CTX.rebuild();
|
||||
await global.BUNEXT_BUNDLER_CTX.rebuild();
|
||||
} catch (error) {
|
||||
console.log(`ESBUILD Error =>`, error);
|
||||
}
|
||||
|
||||
@@ -4,23 +4,23 @@ export default async function buildOnstartErrorHandler(params?: Params) {
|
||||
// const error_msg = `Build Failed. Please check all your components and imports.`;
|
||||
// log.error(error_msg);
|
||||
|
||||
if (global.BUNDLER_CTX_DISPOSED) {
|
||||
if (global.BUNEXT_BUNDLER_CTX_DISPOSED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(`Killing Bundler ...`);
|
||||
// console.log(`global.BUNDLER_CTX_DISPOSED`, global.BUNDLER_CTX_DISPOSED);
|
||||
// console.log(`global.BUNEXT_BUNDLER_CTX_DISPOSED`, global.BUNEXT_BUNDLER_CTX_DISPOSED);
|
||||
|
||||
global.BUNDLER_CTX_DISPOSED = true;
|
||||
global.BUNEXT_BUNDLER_CTX_DISPOSED = true;
|
||||
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
|
||||
await Promise.all([
|
||||
global.SSR_BUNDLER_CTX?.dispose(),
|
||||
global.BUNDLER_CTX?.dispose(),
|
||||
global.BUNEXT_SSR_BUNDLER_CTX?.dispose(),
|
||||
global.BUNEXT_BUNDLER_CTX?.dispose(),
|
||||
]);
|
||||
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
global.BUNDLER_CTX = undefined;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
global.BUNEXT_BUNDLER_CTX = undefined;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export default async function bunReactModulesBundler() {
|
||||
|
||||
const PUBLIC_ROOT = BUNEXT_VENDOR_DIR.replace(BUNX_CWD_DIR, "/.bunext");
|
||||
|
||||
global.REACT_IMPORTS_MAP = {
|
||||
global.BUNEXT_REACT_IMPORTS_MAP = {
|
||||
imports: {
|
||||
react: `${PUBLIC_ROOT}/react.js`,
|
||||
"react-dom": `${PUBLIC_ROOT}/react-dom.js`,
|
||||
|
||||
@@ -23,7 +23,7 @@ export default async function pagesSSRBundler(params?: Params) {
|
||||
include_server: true,
|
||||
});
|
||||
const dev = isDevelopment();
|
||||
const config = global.CONFIG;
|
||||
const config = global.BUNEXT_CONFIG;
|
||||
|
||||
try {
|
||||
writeFileSync(
|
||||
@@ -116,7 +116,7 @@ export default async function pagesSSRBundler(params?: Params) {
|
||||
splitting: true,
|
||||
});
|
||||
} catch (error) {
|
||||
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
log.error(`SSR Bundler Error: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,9 @@ export default async function pagesSSRContextBundler(params?: Params) {
|
||||
const pages = grabAllPages();
|
||||
const dev = isDevelopment();
|
||||
|
||||
if (global.SSR_BUNDLER_CTX) {
|
||||
await global.SSR_BUNDLER_CTX.dispose();
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
if (global.BUNEXT_SSR_BUNDLER_CTX) {
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX.dispose();
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
}
|
||||
|
||||
const entryToPage = new Map<string, PageFiles & { tsx: string }>();
|
||||
@@ -46,7 +46,7 @@ export default async function pagesSSRContextBundler(params?: Params) {
|
||||
|
||||
const entryPoints = [...entryToPage.keys()].map((e) => `ssr-virtual:${e}`);
|
||||
|
||||
global.SSR_BUNDLER_CTX = await esbuild.context({
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints,
|
||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
bundle: true,
|
||||
@@ -82,5 +82,5 @@ export default async function pagesSSRContextBundler(params?: Params) {
|
||||
// logLevel: "silent",
|
||||
});
|
||||
|
||||
await global.SSR_BUNDLER_CTX.rebuild();
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ const BunSkipNonBrowserPlugin: Bun.BunPlugin = {
|
||||
// const skipped_modules = new Set<string>();
|
||||
|
||||
build.onResolve({ filter: skipFilter }, (args) => {
|
||||
global.SKIPPED_BROWSER_MODULES.add(args.path);
|
||||
global.BUNEXT_SKIPPED_BROWSER_MODULES.add(args.path);
|
||||
return {
|
||||
path: args.path,
|
||||
namespace: "skipped",
|
||||
@@ -18,8 +18,8 @@ const BunSkipNonBrowserPlugin: Bun.BunPlugin = {
|
||||
});
|
||||
|
||||
// build.onEnd(() => {
|
||||
// log.warn(`global.SKIPPED_BROWSER_MODULES`, [
|
||||
// ...global.SKIPPED_BROWSER_MODULES,
|
||||
// log.warn(`global.BUNEXT_SKIPPED_BROWSER_MODULES`, [
|
||||
// ...global.BUNEXT_SKIPPED_BROWSER_MODULES,
|
||||
// ]);
|
||||
// });
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ export default function esbuildCTXArtifactTracker({
|
||||
name: "artifact-tracker",
|
||||
setup(build) {
|
||||
build.onStart(async () => {
|
||||
global.MAIN_CTX_BUILD_STARTS++;
|
||||
global.BUNEXT_MAIN_CTX_BUILD_STARTS++;
|
||||
build_start = performance.now();
|
||||
|
||||
const does_error_file_exist = existsSync(
|
||||
@@ -44,7 +44,7 @@ export default function esbuildCTXArtifactTracker({
|
||||
);
|
||||
|
||||
if (
|
||||
global.MAIN_CTX_BUILD_STARTS >= MAX_BUILD_STARTS &&
|
||||
global.BUNEXT_MAIN_CTX_BUILD_STARTS >= MAX_BUILD_STARTS &&
|
||||
!does_error_file_exist
|
||||
) {
|
||||
await buildOnstartErrorHandler();
|
||||
@@ -53,8 +53,8 @@ export default function esbuildCTXArtifactTracker({
|
||||
|
||||
build.onEnd(async (result) => {
|
||||
if (result.errors.length > 0) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
|
||||
log.error(`Build errors:`);
|
||||
for (const err of result.errors) {
|
||||
@@ -64,17 +64,17 @@ export default function esbuildCTXArtifactTracker({
|
||||
}
|
||||
|
||||
for (
|
||||
let i = global.HMR_CONTROLLERS.length - 1;
|
||||
let i = global.BUNEXT_HMR_CONTROLLERS.length - 1;
|
||||
i >= 0;
|
||||
i--
|
||||
) {
|
||||
const controller = global.HMR_CONTROLLERS[i];
|
||||
const controller = global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
try {
|
||||
controller?.controller?.enqueue(
|
||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
||||
);
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,10 +89,15 @@ export default function esbuildCTXArtifactTracker({
|
||||
if (artifacts?.[0] && artifacts.length > 0) {
|
||||
for (let i = 0; i < artifacts.length; i++) {
|
||||
const artifact = artifacts[i];
|
||||
if (artifact?.local_path && global.BUNDLER_CTX_MAP) {
|
||||
global.BUNDLER_CTX_MAP[artifact.local_path] =
|
||||
if (
|
||||
artifact?.local_path &&
|
||||
global.BUNEXT_BUNDLER_CTX_MAP
|
||||
) {
|
||||
global.BUNEXT_BUNDLER_CTX_MAP[artifact.local_path] =
|
||||
_.merge(
|
||||
global.BUNDLER_CTX_MAP[artifact.local_path],
|
||||
global.BUNEXT_BUNDLER_CTX_MAP[
|
||||
artifact.local_path
|
||||
],
|
||||
artifact,
|
||||
);
|
||||
}
|
||||
@@ -102,8 +107,8 @@ export default function esbuildCTXArtifactTracker({
|
||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
log.success(`[Built] in ${elapsed}ms`);
|
||||
|
||||
global.MAIN_CTX_BUILD_STARTS = 0;
|
||||
global.BUNDLER_CTX_DISPOSED = false;
|
||||
global.BUNEXT_MAIN_CTX_BUILD_STARTS = 0;
|
||||
global.BUNEXT_BUNDLER_CTX_DISPOSED = false;
|
||||
|
||||
const does_error_file_exist = existsSync(
|
||||
BUNX_BUNDLER_ERROR_EXIT_FILE,
|
||||
@@ -141,8 +146,8 @@ export default function esbuildCTXArtifactTracker({
|
||||
}
|
||||
}
|
||||
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -32,19 +32,19 @@ export default function ssrCTXArtifactTracker({
|
||||
build_starts++;
|
||||
build_start = performance.now();
|
||||
if (build_starts == MAX_BUILD_STARTS) {
|
||||
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
await global.SSR_BUNDLER_CTX?.dispose();
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
}
|
||||
});
|
||||
|
||||
build.onEnd(async (result) => {
|
||||
if (result.errors.length > 0) {
|
||||
global.SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = true;
|
||||
try {
|
||||
await global.SSR_BUNDLER_CTX?.dispose();
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
|
||||
} catch {}
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
build_starts = 0;
|
||||
for (const err of result.errors) {
|
||||
console.error(
|
||||
@@ -65,10 +65,11 @@ export default function ssrCTXArtifactTracker({
|
||||
const artifact = artifacts[i];
|
||||
if (
|
||||
artifact?.local_path &&
|
||||
global.SSR_BUNDLER_CTX_MAP
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP
|
||||
) {
|
||||
global.SSR_BUNDLER_CTX_MAP[artifact.local_path] =
|
||||
artifact;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP[
|
||||
artifact.local_path
|
||||
] = artifact;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,11 +84,15 @@ export default function ssrCTXArtifactTracker({
|
||||
try {
|
||||
writeFileSync(
|
||||
path.join(BUNX_TMP_DIR, "ctx-map.json"),
|
||||
JSON.stringify(global.SSR_BUNDLER_CTX_MAP, null, 4),
|
||||
JSON.stringify(
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP,
|
||||
null,
|
||||
4,
|
||||
),
|
||||
);
|
||||
} catch (error) {}
|
||||
|
||||
global.SSR_BUNDLER_CTX_DISPOSED = false;
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = false;
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -77,7 +77,7 @@ export default async function reactModulesBundler() {
|
||||
|
||||
const PUBLIC_ROOT = BUNEXT_VENDOR_DIR.replace(BUNX_CWD_DIR, "/.bunext");
|
||||
|
||||
global.REACT_IMPORTS_MAP = {
|
||||
global.BUNEXT_REACT_IMPORTS_MAP = {
|
||||
imports: {
|
||||
react: `${PUBLIC_ROOT}/react.js`,
|
||||
"react-dom": `${PUBLIC_ROOT}/react-dom.js`,
|
||||
|
||||
@@ -21,8 +21,11 @@ export default async function recordArtifacts({
|
||||
}
|
||||
}
|
||||
|
||||
if (global.BUNDLER_CTX_MAP) {
|
||||
global.BUNDLER_CTX_MAP = _.merge(global.BUNDLER_CTX_MAP, artifacts_map);
|
||||
if (global.BUNEXT_BUNDLER_CTX_MAP) {
|
||||
global.BUNEXT_BUNDLER_CTX_MAP = _.merge(
|
||||
global.BUNEXT_BUNDLER_CTX_MAP,
|
||||
artifacts_map,
|
||||
);
|
||||
}
|
||||
|
||||
// await Bun.write(
|
||||
|
||||
@@ -22,37 +22,37 @@ import type { FSWatcher } from "fs";
|
||||
* # Declare Global Variables
|
||||
*/
|
||||
declare global {
|
||||
var CONFIG: BunextConfig;
|
||||
var SERVER: Server<any> | undefined;
|
||||
var RECOMPILING: boolean;
|
||||
var BUILDING_SSR: boolean;
|
||||
var IS_SERVER_COMPONENT: boolean;
|
||||
var WATCHER_TIMEOUT: any;
|
||||
var ROUTER: FileSystemRouter;
|
||||
var HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
||||
var LAST_BUILD_TIME: number;
|
||||
var BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
var SSR_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
// var API_ROUTES_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
var BUNDLER_REBUILDS: 0;
|
||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var CURRENT_VERSION: string | undefined;
|
||||
var PAGE_FILES: PageFiles[];
|
||||
var ROOT_FILE_UPDATED: boolean;
|
||||
var SKIPPED_BROWSER_MODULES: Set<string>;
|
||||
var BUNDLER_CTX: BuildContext | undefined;
|
||||
var SSR_BUNDLER_CTX: BuildContext | undefined;
|
||||
// var API_ROUTES_BUNDLER_CTX: BuildContext | undefined;
|
||||
var DIR_NAMES: DirNames;
|
||||
var REACT_IMPORTS_MAP: { imports: Record<string, string> };
|
||||
var REACT_DOM_SERVER: any;
|
||||
var REACT_DOM_MODULE_CACHE: Map<string, { main: any; css: string }>;
|
||||
var BUNDLER_CTX_DISPOSED: boolean | undefined;
|
||||
var SSR_BUNDLER_CTX_DISPOSED: boolean | undefined;
|
||||
var REBUILD_RETRIES: number;
|
||||
var IS_404_PAGE: boolean;
|
||||
var CONSTANTS: ReturnType<typeof grabConstants>;
|
||||
var MAIN_CTX_BUILD_STARTS: number;
|
||||
var BUNEXT_CONFIG: BunextConfig;
|
||||
var BUNEXT_SERVER: Server<any> | undefined;
|
||||
var BUNEXT_RECOMPILING: boolean;
|
||||
var BUNEXT_BUILDING_SSR: boolean;
|
||||
var BUNEXT_IS_SERVER_COMPONENT: boolean;
|
||||
var BUNEXT_WATCHER_TIMEOUT: any;
|
||||
var BUNEXT_ROUTER: FileSystemRouter;
|
||||
var BUNEXT_HMR_CONTROLLERS: GlobalHMRControllerObject[];
|
||||
var BUNEXT_LAST_BUILD_TIME: number;
|
||||
var BUNEXT_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
var BUNEXT_SSR_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
// var BUNEXT_API_ROUTES_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
var BUNEXT_BUNDLER_REBUILDS: 0;
|
||||
var BUNEXT_PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var BUNEXT_CURRENT_VERSION: string | undefined;
|
||||
var BUNEXT_PAGE_FILES: PageFiles[];
|
||||
var BUNEXT_ROOT_FILE_UPDATED: boolean;
|
||||
var BUNEXT_SKIPPED_BROWSER_MODULES: Set<string>;
|
||||
var BUNEXT_BUNDLER_CTX: BuildContext | undefined;
|
||||
var BUNEXT_SSR_BUNDLER_CTX: BuildContext | undefined;
|
||||
// var BUNEXT_API_ROUTES_BUNDLER_CTX: BuildContext | undefined;
|
||||
var BUNEXT_DIR_NAMES: DirNames;
|
||||
var BUNEXT_REACT_IMPORTS_MAP: { imports: Record<string, string> };
|
||||
var BUNEXT_REACT_DOM_SERVER: any;
|
||||
var BUNEXT_REACT_DOM_MODULE_CACHE: Map<string, { main: any; css: string }>;
|
||||
var BUNEXT_BUNDLER_CTX_DISPOSED: boolean | undefined;
|
||||
var BUNEXT_SSR_BUNDLER_CTX_DISPOSED: boolean | undefined;
|
||||
var BUNEXT_REBUILD_RETRIES: number;
|
||||
var BUNEXT_IS_404_PAGE: boolean;
|
||||
var BUNEXT_CONSTANTS: ReturnType<typeof grabConstants>;
|
||||
var BUNEXT_MAIN_CTX_BUILD_STARTS: number;
|
||||
}
|
||||
|
||||
const dirNames = grabDirNames();
|
||||
@@ -63,23 +63,23 @@ type Params = {
|
||||
};
|
||||
|
||||
export default async function bunextInit(params?: Params) {
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
global.BUNDLER_REBUILDS = 0;
|
||||
global.REBUILD_RETRIES = 0;
|
||||
global.PAGE_FILES = [];
|
||||
global.SKIPPED_BROWSER_MODULES = new Set<string>();
|
||||
global.DIR_NAMES = dirNames;
|
||||
global.REACT_IMPORTS_MAP = { imports: {} };
|
||||
global.REACT_DOM_MODULE_CACHE = new Map<string, any>();
|
||||
global.MAIN_CTX_BUILD_STARTS = 0;
|
||||
global.BUNEXT_HMR_CONTROLLERS = [];
|
||||
global.BUNEXT_BUNDLER_CTX_MAP = {};
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP = {};
|
||||
// global.BUNEXT_API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
global.BUNEXT_BUNDLER_REBUILDS = 0;
|
||||
global.BUNEXT_REBUILD_RETRIES = 0;
|
||||
global.BUNEXT_PAGE_FILES = [];
|
||||
global.BUNEXT_SKIPPED_BROWSER_MODULES = new Set<string>();
|
||||
global.BUNEXT_DIR_NAMES = dirNames;
|
||||
global.BUNEXT_REACT_IMPORTS_MAP = { imports: {} };
|
||||
global.BUNEXT_REACT_DOM_MODULE_CACHE = new Map<string, any>();
|
||||
global.BUNEXT_MAIN_CTX_BUILD_STARTS = 0;
|
||||
|
||||
await init();
|
||||
log.banner();
|
||||
|
||||
global.CONSTANTS = grabConstants();
|
||||
global.BUNEXT_CONSTANTS = grabConstants();
|
||||
|
||||
await reactModulesBundler();
|
||||
|
||||
@@ -88,7 +88,7 @@ export default async function bunextInit(params?: Params) {
|
||||
dir: PAGES_DIR,
|
||||
});
|
||||
|
||||
global.ROUTER = router;
|
||||
global.BUNEXT_ROUTER = router;
|
||||
|
||||
const is_dev = isDevelopment();
|
||||
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ export default async function trimCacheKey({
|
||||
key,
|
||||
});
|
||||
|
||||
const config = global.CONFIG;
|
||||
const config = global.BUNEXT_CONFIG;
|
||||
|
||||
const default_expiry_time_seconds =
|
||||
config.default_cache_expiry ||
|
||||
|
||||
@@ -35,7 +35,7 @@ export default async function () {
|
||||
|
||||
const current_version = package_json.version;
|
||||
|
||||
global.CURRENT_VERSION = current_version;
|
||||
global.BUNEXT_CURRENT_VERSION = current_version;
|
||||
} catch (error) {}
|
||||
|
||||
const keys = Object.keys(dirNames) as (keyof ReturnType<
|
||||
@@ -65,7 +65,7 @@ export default async function () {
|
||||
|
||||
const config: BunextConfig = (await grabConfig()) || {};
|
||||
|
||||
global.CONFIG = {
|
||||
global.BUNEXT_CONFIG = {
|
||||
...config,
|
||||
development: is_dev,
|
||||
};
|
||||
|
||||
@@ -33,11 +33,12 @@ export default async function bunextRequestHandler({
|
||||
|
||||
let response: Response | undefined = undefined;
|
||||
|
||||
if (global.CONSTANTS.config?.middleware) {
|
||||
const middleware_res = await global.CONSTANTS.config.middleware({
|
||||
req: initial_req,
|
||||
url,
|
||||
});
|
||||
if (global.BUNEXT_CONSTANTS.config?.middleware) {
|
||||
const middleware_res =
|
||||
await global.BUNEXT_CONSTANTS.config.middleware({
|
||||
req: initial_req,
|
||||
url,
|
||||
});
|
||||
|
||||
if (middleware_res instanceof Response) {
|
||||
return middleware_res;
|
||||
|
||||
@@ -41,11 +41,11 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.BUNDLER_CTX_DISPOSED) {
|
||||
if (global.BUNEXT_BUNDLER_CTX_DISPOSED) {
|
||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||
}
|
||||
|
||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||
if (global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED) {
|
||||
await pagesSSRBundler().catch((error) => {
|
||||
log.error(`SSR Bundler Error: ${error}`);
|
||||
});
|
||||
@@ -53,7 +53,7 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
|
||||
if (filename.match(/\/styles$/) || filename === "styles") {
|
||||
owns_recompile = true;
|
||||
global.RECOMPILING = true;
|
||||
global.BUNEXT_RECOMPILING = true;
|
||||
await Bun.sleep(1000);
|
||||
await fullRebuild({
|
||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||
@@ -72,31 +72,31 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
|
||||
if (event === "change") {
|
||||
if (filename.match(target_files_match)) {
|
||||
if (global.RECOMPILING) return;
|
||||
if (global.BUNEXT_RECOMPILING) return;
|
||||
owns_recompile = true;
|
||||
global.RECOMPILING = true;
|
||||
global.BUNEXT_RECOMPILING = true;
|
||||
|
||||
if (filename.match(/.*\.server\.tsx?/)) {
|
||||
global.IS_SERVER_COMPONENT = true;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = true;
|
||||
}
|
||||
|
||||
if (global.BUNDLER_CTX) {
|
||||
await global.BUNDLER_CTX.rebuild();
|
||||
if (global.BUNEXT_BUNDLER_CTX) {
|
||||
await global.BUNEXT_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
if (filename.match(/(404|500)\.tsx?/)) {
|
||||
for (
|
||||
let i = global.HMR_CONTROLLERS.length - 1;
|
||||
let i = global.BUNEXT_HMR_CONTROLLERS.length - 1;
|
||||
i >= 0;
|
||||
i--
|
||||
) {
|
||||
const controller = global.HMR_CONTROLLERS[i];
|
||||
const controller = global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
try {
|
||||
controller?.controller?.enqueue(
|
||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
||||
);
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,7 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
return reloadWatcher();
|
||||
}
|
||||
|
||||
if (global.RECOMPILING) return;
|
||||
if (global.BUNEXT_RECOMPILING) return;
|
||||
|
||||
owns_recompile = true;
|
||||
const action = event.startsWith("add") ? "created" : "deleted";
|
||||
@@ -139,8 +139,8 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
log.error(`Watcher rebuild failed: ${error}`);
|
||||
} finally {
|
||||
if (owns_recompile) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -154,8 +154,8 @@ export default async function chokadirWatcherEsbuildCTX() {
|
||||
}
|
||||
|
||||
function reloadWatcher() {
|
||||
if (global.PAGES_SRC_WATCHER) {
|
||||
global.PAGES_SRC_WATCHER.close();
|
||||
if (global.BUNEXT_PAGES_SRC_WATCHER) {
|
||||
global.BUNEXT_PAGES_SRC_WATCHER.close();
|
||||
chokadirWatcherEsbuildCTX();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,20 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
||||
try {
|
||||
const { msg } = params || {};
|
||||
|
||||
global.RECOMPILING = true;
|
||||
global.BUNEXT_RECOMPILING = true;
|
||||
|
||||
if (msg) {
|
||||
log.watch(msg);
|
||||
}
|
||||
|
||||
global.ROUTER.reload();
|
||||
global.BUNEXT_ROUTER.reload();
|
||||
|
||||
try {
|
||||
await global.BUNDLER_CTX?.dispose();
|
||||
global.BUNDLER_CTX = undefined;
|
||||
await global.BUNEXT_BUNDLER_CTX?.dispose();
|
||||
global.BUNEXT_BUNDLER_CTX = undefined;
|
||||
|
||||
await global.SSR_BUNDLER_CTX?.dispose();
|
||||
global.SSR_BUNDLER_CTX = undefined;
|
||||
await global.BUNEXT_SSR_BUNDLER_CTX?.dispose();
|
||||
global.BUNEXT_SSR_BUNDLER_CTX = undefined;
|
||||
} catch (error) {}
|
||||
|
||||
await allPagesESBuildContextBundler({
|
||||
@@ -31,12 +31,12 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
||||
} catch (error: any) {
|
||||
log.error(error);
|
||||
} finally {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
}
|
||||
|
||||
if (global.PAGES_SRC_WATCHER) {
|
||||
global.PAGES_SRC_WATCHER.close();
|
||||
if (global.BUNEXT_PAGES_SRC_WATCHER) {
|
||||
global.BUNEXT_PAGES_SRC_WATCHER.close();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ type Params = {
|
||||
};
|
||||
|
||||
function removeController(controller: ReadableStreamDefaultController<string>) {
|
||||
const idx = global.HMR_CONTROLLERS.findIndex(
|
||||
const idx = global.BUNEXT_HMR_CONTROLLERS.findIndex(
|
||||
(c) => c.controller == controller,
|
||||
);
|
||||
if (typeof idx == "number" && idx >= 0) {
|
||||
global.HMR_CONTROLLERS.splice(idx, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ export default async function ({ req }: Params): Promise<Response> {
|
||||
return new Response("Invalid Referer Header", { status: 400 });
|
||||
}
|
||||
|
||||
const match = global.ROUTER.match(referer_url.pathname);
|
||||
const match = global.BUNEXT_ROUTER.match(referer_url.pathname);
|
||||
|
||||
const target_map = match?.filePath
|
||||
? global.BUNDLER_CTX_MAP?.[match.filePath]
|
||||
? global.BUNEXT_BUNDLER_CTX_MAP?.[match.filePath]
|
||||
: undefined;
|
||||
|
||||
let controller: ReadableStreamDefaultController<string>;
|
||||
@@ -37,7 +37,7 @@ export default async function ({ req }: Params): Promise<Response> {
|
||||
const stream = new ReadableStream<string>({
|
||||
start(c) {
|
||||
controller = c;
|
||||
global.HMR_CONTROLLERS.push({
|
||||
global.BUNEXT_HMR_CONTROLLERS.push({
|
||||
controller: c,
|
||||
page_url: referer_url.href,
|
||||
target_map,
|
||||
|
||||
@@ -52,10 +52,10 @@ export default async function ({ req }: Params): Promise<Response> {
|
||||
let module: any;
|
||||
const now = Date.now();
|
||||
|
||||
if (is_dev && global.SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
|
||||
if (is_dev && global.BUNEXT_SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
|
||||
const target_import = path.join(
|
||||
ROOT_DIR,
|
||||
global.SSR_BUNDLER_CTX_MAP[match.filePath].path,
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP[match.filePath].path,
|
||||
);
|
||||
|
||||
module = await import(`${target_import}?t=${now}`);
|
||||
@@ -108,9 +108,7 @@ export default async function ({ req }: Params): Promise<Response> {
|
||||
);
|
||||
}
|
||||
|
||||
routeParams.body = JSON.parse(
|
||||
new TextDecoder().decode(body) || "{}",
|
||||
);
|
||||
routeParams.body = JSON.parse(new TextDecoder().decode(body) || "{}");
|
||||
}
|
||||
|
||||
const target_module = (module["default"] ||
|
||||
|
||||
@@ -7,15 +7,15 @@ type Params = {
|
||||
};
|
||||
|
||||
export default async function serverPostBuildFn(params?: Params) {
|
||||
if (!global.HMR_CONTROLLERS?.[0] || !global.BUNDLER_CTX_MAP) {
|
||||
if (!global.BUNEXT_HMR_CONTROLLERS?.[0] || !global.BUNEXT_BUNDLER_CTX_MAP) {
|
||||
return;
|
||||
}
|
||||
|
||||
const reload_payload = { reload: true };
|
||||
const reload_enqueue = `event: update\ndata: ${JSON.stringify(reload_payload)}\n\n`;
|
||||
|
||||
for (let i = global.HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||
const controller = global.HMR_CONTROLLERS[i];
|
||||
for (let i = global.BUNEXT_HMR_CONTROLLERS.length - 1; i >= 0; i--) {
|
||||
const controller = global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
|
||||
if (!controller) {
|
||||
continue;
|
||||
@@ -29,19 +29,19 @@ export default async function serverPostBuildFn(params?: Params) {
|
||||
try {
|
||||
controller.controller.enqueue(reload_enqueue);
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const target_artifact =
|
||||
global.BUNDLER_CTX_MAP[controller.target_map.local_path];
|
||||
global.BUNEXT_BUNDLER_CTX_MAP[controller.target_map.local_path];
|
||||
|
||||
if (!target_artifact?.local_path) {
|
||||
try {
|
||||
controller.controller.enqueue(reload_enqueue);
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ export default async function serverPostBuildFn(params?: Params) {
|
||||
try {
|
||||
let final_data: { [k: string]: any } = {};
|
||||
|
||||
if (global.ROOT_FILE_UPDATED) {
|
||||
if (global.BUNEXT_ROOT_FILE_UPDATED) {
|
||||
final_data = reload_payload;
|
||||
} else {
|
||||
final_data = final_artifact;
|
||||
@@ -91,9 +91,9 @@ export default async function serverPostBuildFn(params?: Params) {
|
||||
`event: update\ndata: ${JSON.stringify(final_data)}\n\n`,
|
||||
);
|
||||
|
||||
global.ROOT_FILE_UPDATED = false;
|
||||
global.BUNEXT_ROOT_FILE_UPDATED = false;
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export default async function startServer() {
|
||||
|
||||
const server = Bun.serve(serverParams);
|
||||
|
||||
global.SERVER = server;
|
||||
global.BUNEXT_SERVER = server;
|
||||
|
||||
log.server(`http://${server.hostname}:${server.port}`);
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ export default async function watcherEsbuildCTX() {
|
||||
if (!filename) return;
|
||||
const full_file_path = path.join(ROOT_DIR, filename);
|
||||
|
||||
if (global.CONFIG.exclude_watch_patterns) {
|
||||
if (global.BUNEXT_CONFIG.exclude_watch_patterns) {
|
||||
for (
|
||||
let i = 0;
|
||||
i < global.CONFIG.exclude_watch_patterns.length;
|
||||
i < global.BUNEXT_CONFIG.exclude_watch_patterns.length;
|
||||
i++
|
||||
) {
|
||||
const watch_pattern =
|
||||
global.CONFIG.exclude_watch_patterns[i];
|
||||
global.BUNEXT_CONFIG.exclude_watch_patterns[i];
|
||||
|
||||
if (watch_pattern instanceof RegExp) {
|
||||
const is_path_excluded =
|
||||
@@ -60,12 +60,12 @@ export default async function watcherEsbuildCTX() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.BUNDLER_CTX_DISPOSED) {
|
||||
if (global.BUNEXT_BUNDLER_CTX_DISPOSED) {
|
||||
await fullRebuild({ msg: `Restarting Bundler ...` });
|
||||
return;
|
||||
}
|
||||
|
||||
if (global.SSR_BUNDLER_CTX_DISPOSED) {
|
||||
if (global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED) {
|
||||
await pagesSSRBundler().catch((error) => {
|
||||
log.error(`SSR Bundler Error: ${error}`);
|
||||
});
|
||||
@@ -82,7 +82,7 @@ export default async function watcherEsbuildCTX() {
|
||||
|
||||
if (full_file_path.match(/\/styles$/)) {
|
||||
owns_recompile = true;
|
||||
global.RECOMPILING = true;
|
||||
global.BUNEXT_RECOMPILING = true;
|
||||
await Bun.sleep(1000);
|
||||
await fullRebuild({
|
||||
msg: `Detected new \`styles\` directory. Rebuilding ...`,
|
||||
@@ -106,31 +106,33 @@ export default async function watcherEsbuildCTX() {
|
||||
|
||||
if (event !== "rename") {
|
||||
if (filename.match(target_files_match)) {
|
||||
if (global.RECOMPILING) return;
|
||||
if (global.BUNEXT_RECOMPILING) return;
|
||||
owns_recompile = true;
|
||||
global.RECOMPILING = true;
|
||||
global.BUNEXT_RECOMPILING = true;
|
||||
|
||||
if (filename.match(/.*\.server\.tsx?/)) {
|
||||
global.IS_SERVER_COMPONENT = true;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = true;
|
||||
}
|
||||
|
||||
if (global.BUNDLER_CTX) {
|
||||
await global.BUNDLER_CTX.rebuild();
|
||||
if (global.BUNEXT_BUNDLER_CTX) {
|
||||
await global.BUNEXT_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
if (filename.match(/(404|500)\.tsx?/)) {
|
||||
for (
|
||||
let i = global.HMR_CONTROLLERS.length - 1;
|
||||
let i =
|
||||
global.BUNEXT_HMR_CONTROLLERS.length - 1;
|
||||
i >= 0;
|
||||
i--
|
||||
) {
|
||||
const controller = global.HMR_CONTROLLERS[i];
|
||||
const controller =
|
||||
global.BUNEXT_HMR_CONTROLLERS[i];
|
||||
try {
|
||||
controller?.controller?.enqueue(
|
||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
||||
);
|
||||
} catch {
|
||||
global.HMR_CONTROLLERS.splice(i, 1);
|
||||
global.BUNEXT_HMR_CONTROLLERS.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +154,7 @@ export default async function watcherEsbuildCTX() {
|
||||
return reloadWatcher();
|
||||
if (filename.match(/ /)) return reloadWatcher();
|
||||
|
||||
if (global.RECOMPILING) return;
|
||||
if (global.BUNEXT_RECOMPILING) return;
|
||||
|
||||
owns_recompile = true;
|
||||
const action = does_file_exist ? "created" : "deleted";
|
||||
@@ -171,19 +173,19 @@ export default async function watcherEsbuildCTX() {
|
||||
log.error(`Watcher rebuild failed: ${error}`);
|
||||
} finally {
|
||||
if (owns_recompile) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
global.BUNEXT_RECOMPILING = false;
|
||||
global.BUNEXT_IS_SERVER_COMPONENT = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
global.PAGES_SRC_WATCHER = pages_src_watcher;
|
||||
global.BUNEXT_PAGES_SRC_WATCHER = pages_src_watcher;
|
||||
}
|
||||
|
||||
function reloadWatcher() {
|
||||
if (global.PAGES_SRC_WATCHER) {
|
||||
global.PAGES_SRC_WATCHER.close();
|
||||
if (global.BUNEXT_PAGES_SRC_WATCHER) {
|
||||
global.BUNEXT_PAGES_SRC_WATCHER.close();
|
||||
watcherEsbuildCTX();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export default async function genWebHTML({
|
||||
env: {
|
||||
NODE_ENV: dev ? "development" : "production",
|
||||
...public_envs,
|
||||
...global.CONFIG.public_envs,
|
||||
...global.BUNEXT_CONFIG.public_envs,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ export default async function genWebHTML({
|
||||
type="importmap"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify(
|
||||
global.REACT_IMPORTS_MAP,
|
||||
global.BUNEXT_REACT_IMPORTS_MAP,
|
||||
),
|
||||
}}
|
||||
defer
|
||||
|
||||
@@ -19,10 +19,10 @@ export default async function grabPageBundledReactComponent({
|
||||
return_tsx_only,
|
||||
}: Params): Promise<GrabPageReactBundledComponentRes | undefined> {
|
||||
try {
|
||||
if (global.SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
||||
if (global.BUNEXT_SSR_BUNDLER_CTX_MAP?.[file_path]) {
|
||||
const abs = path.join(
|
||||
ROOT_DIR,
|
||||
global.SSR_BUNDLER_CTX_MAP[file_path].path,
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP[file_path].path,
|
||||
);
|
||||
// Loader.registry.delete(abs);
|
||||
const mod = await import(`${abs}?t=${Date.now()}`);
|
||||
|
||||
@@ -35,7 +35,7 @@ export default async function grabPageCombinedServerRes({
|
||||
? grabPageServerPath({ file_path: root_file_path })
|
||||
: {};
|
||||
const root_server_ctx_map =
|
||||
global.SSR_BUNDLER_CTX_MAP[root_server_file_path || ""];
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP[root_server_file_path || ""];
|
||||
const final_root_server_path = root_server_ctx_map?.local_path
|
||||
? path.join(ROOT_DIR, root_server_ctx_map.path)
|
||||
: root_server_file_path;
|
||||
@@ -63,7 +63,8 @@ export default async function grabPageCombinedServerRes({
|
||||
}
|
||||
|
||||
const { server_file_path } = grabPageServerPath({ file_path });
|
||||
const page_server_ctx = global.SSR_BUNDLER_CTX_MAP[server_file_path || ""];
|
||||
const page_server_ctx =
|
||||
global.BUNEXT_SSR_BUNDLER_CTX_MAP[server_file_path || ""];
|
||||
const final_page_server_path = page_server_ctx?.local_path
|
||||
? path.join(ROOT_DIR, page_server_ctx.path)
|
||||
: server_file_path;
|
||||
|
||||
@@ -45,7 +45,7 @@ export default async function grabPageComponent(
|
||||
} = params;
|
||||
|
||||
const url = req?.url ? new URL(req.url) : undefined;
|
||||
const router = global.ROUTER;
|
||||
const router = global.BUNEXT_ROUTER;
|
||||
const is_dev = isDevelopment();
|
||||
|
||||
const forwarded_proto = req?.headers.get("x-forwarded-proto");
|
||||
@@ -89,7 +89,7 @@ export default async function grabPageComponent(
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
|
||||
let bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||
let bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path];
|
||||
|
||||
if (!bundledMap?.path) {
|
||||
if (does_error_file_exist) {
|
||||
@@ -106,7 +106,7 @@ export default async function grabPageComponent(
|
||||
msg: `Retrying Bundle map for file \`${file_path}\``,
|
||||
});
|
||||
await Bun.sleep(1000);
|
||||
bundledMap = global.BUNDLER_CTX_MAP[file_path];
|
||||
bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[file_path];
|
||||
if (bundledMap?.path) break;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ export default async function grabPageComponent(
|
||||
}
|
||||
|
||||
if (req && !is_hydration) {
|
||||
global.BUNDLER_CTX_MAP[file_path].req_url = req.url;
|
||||
global.BUNEXT_BUNDLER_CTX_MAP[file_path].req_url = req.url;
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
@@ -168,8 +168,9 @@ export default async function grabPageComponent(
|
||||
error?.status === 404;
|
||||
|
||||
if (!params.retry && is_dev) {
|
||||
while (global.REBUILD_RETRIES < 2) {
|
||||
global.REBUILD_RETRIES = global.REBUILD_RETRIES + 1;
|
||||
while (global.BUNEXT_REBUILD_RETRIES < 2) {
|
||||
global.BUNEXT_REBUILD_RETRIES =
|
||||
global.BUNEXT_REBUILD_RETRIES + 1;
|
||||
|
||||
await fullRebuild();
|
||||
await Bun.sleep(200);
|
||||
@@ -182,17 +183,17 @@ export default async function grabPageComponent(
|
||||
component_retried instanceof Response ||
|
||||
component_retried.success
|
||||
) {
|
||||
global.REBUILD_RETRIES = 0;
|
||||
global.BUNEXT_REBUILD_RETRIES = 0;
|
||||
await serverPostBuildFn();
|
||||
return component_retried;
|
||||
}
|
||||
}
|
||||
|
||||
global.REBUILD_RETRIES = 0;
|
||||
global.BUNEXT_REBUILD_RETRIES = 0;
|
||||
}
|
||||
|
||||
if (is404) {
|
||||
global.IS_404_PAGE = true;
|
||||
global.BUNEXT_IS_404_PAGE = true;
|
||||
} else {
|
||||
log.error(`Error Grabbing Page Component: ${error.message}`);
|
||||
log.error(`Page: ${passed_file_path || url?.pathname}`);
|
||||
|
||||
@@ -21,7 +21,7 @@ export default async function grabPageErrorComponent({
|
||||
is404,
|
||||
url,
|
||||
}: Params): Promise<GrabPageComponentRes | Response> {
|
||||
const router = global.ROUTER;
|
||||
const router = global.BUNEXT_ROUTER;
|
||||
|
||||
const { BUNX_ROOT_500_PRESET_COMPONENT, BUNX_ROOT_404_PRESET_COMPONENT } =
|
||||
grabDirNames();
|
||||
@@ -59,7 +59,7 @@ export default async function grabPageErrorComponent({
|
||||
|
||||
const file_path = match.filePath;
|
||||
|
||||
const bundledMap = global.BUNDLER_CTX_MAP?.[file_path];
|
||||
const bundledMap = global.BUNEXT_BUNDLER_CTX_MAP?.[file_path];
|
||||
|
||||
const page_component = await grabPageModules({
|
||||
file_path: file_path,
|
||||
|
||||
@@ -148,13 +148,14 @@ async function loadEntry<T>(page_file_path: string): Promise<T> {
|
||||
const mod_file_path = toModPath(page_file_path);
|
||||
const mod_css_path = mod_file_path.replace(/\.js$/, ".css");
|
||||
|
||||
if (global.REACT_DOM_MODULE_CACHE.has(page_file_path)) {
|
||||
return global.REACT_DOM_MODULE_CACHE.get(page_file_path)?.main as T;
|
||||
if (global.BUNEXT_REACT_DOM_MODULE_CACHE.has(page_file_path)) {
|
||||
return global.BUNEXT_REACT_DOM_MODULE_CACHE.get(page_file_path)
|
||||
?.main as T;
|
||||
}
|
||||
|
||||
const mod = await import(`${mod_file_path}?t=${now}`);
|
||||
|
||||
global.REACT_DOM_MODULE_CACHE.set(page_file_path, {
|
||||
global.BUNEXT_REACT_DOM_MODULE_CACHE.set(page_file_path, {
|
||||
main: mod,
|
||||
css: mod_css_path,
|
||||
});
|
||||
|
||||
@@ -3,8 +3,12 @@ type Params = {
|
||||
};
|
||||
|
||||
export default function ({ path }: Params): boolean {
|
||||
for (let i = 0; i < global.CONSTANTS.RouteIgnorePatterns.length; i++) {
|
||||
const regex = global.CONSTANTS.RouteIgnorePatterns[i];
|
||||
for (
|
||||
let i = 0;
|
||||
i < global.BUNEXT_CONSTANTS.RouteIgnorePatterns.length;
|
||||
i++
|
||||
) {
|
||||
const regex = global.BUNEXT_CONSTANTS.RouteIgnorePatterns[i];
|
||||
if (path.match(regex)) return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ export default function grabAppPort() {
|
||||
return numberfy(process.env.PORT);
|
||||
}
|
||||
|
||||
if (global.CONFIG.port) {
|
||||
return global.CONFIG.port;
|
||||
if (global.BUNEXT_CONFIG.port) {
|
||||
return global.BUNEXT_CONFIG.port;
|
||||
}
|
||||
|
||||
return numberfy(defaultPort);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import AppNames from "./grab-app-names";
|
||||
|
||||
export default function grabAssetsPrefix() {
|
||||
if (global.CONFIG.assets_prefix) {
|
||||
return global.CONFIG.assets_prefix;
|
||||
if (global.BUNEXT_CONFIG.assets_prefix) {
|
||||
return global.BUNEXT_CONFIG.assets_prefix;
|
||||
}
|
||||
|
||||
const { defaultAssetPrefix } = AppNames;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default function grabConstants() {
|
||||
const config = global.CONFIG;
|
||||
const config = global.BUNEXT_CONFIG;
|
||||
const MB_IN_BYTES = 1024 * 1024;
|
||||
|
||||
const ClientWindowPagePropsName = "__PAGE_PROPS__";
|
||||
|
||||
@@ -31,7 +31,7 @@ export type DirNames = {
|
||||
};
|
||||
|
||||
export default function grabDirNames(): DirNames {
|
||||
if (global.DIR_NAMES) return global.DIR_NAMES;
|
||||
if (global.BUNEXT_DIR_NAMES) return global.BUNEXT_DIR_NAMES;
|
||||
|
||||
const ROOT_DIR = process.cwd();
|
||||
const SRC_DIR = path.join(ROOT_DIR, "src");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import grabAppPort from "./grab-app-port";
|
||||
|
||||
export default function grabOrigin() {
|
||||
if (global.CONFIG.origin) {
|
||||
return global.CONFIG.origin;
|
||||
if (global.BUNEXT_CONFIG.origin) {
|
||||
return global.BUNEXT_CONFIG.origin;
|
||||
}
|
||||
|
||||
const port = grabAppPort();
|
||||
|
||||
@@ -28,7 +28,7 @@ export default async function grabRouteParams({
|
||||
url,
|
||||
query: _.merge(query, passed_query),
|
||||
body,
|
||||
server: global.SERVER,
|
||||
server: global.BUNEXT_SERVER,
|
||||
};
|
||||
|
||||
return routeParams;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default function grabRouter() {
|
||||
// if (process.env.NODE_ENV !== "production") {
|
||||
// global.ROUTER.reload();
|
||||
// global.BUNEXT_ROUTER.reload();
|
||||
// }
|
||||
|
||||
return global.ROUTER;
|
||||
return global.BUNEXT_ROUTER;
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,6 +31,6 @@ export const log = {
|
||||
),
|
||||
banner: () =>
|
||||
console.log(
|
||||
`\n ${chalk.cyan.bold(AppNames.name)} ${chalk.gray(`v${global.CURRENT_VERSION || AppNames["version"]}`)}\n`,
|
||||
`\n ${chalk.cyan.bold(AppNames.name)} ${chalk.gray(`v${global.BUNEXT_CURRENT_VERSION || AppNames["version"]}`)}\n`,
|
||||
),
|
||||
};
|
||||
|
||||
@@ -8,5 +8,5 @@ export default function refreshRouter() {
|
||||
dir: PAGES_DIR,
|
||||
});
|
||||
|
||||
global.ROUTER = router;
|
||||
global.BUNEXT_ROUTER = router;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user