Rename global variables

This commit is contained in:
2026-08-03 12:01:40 +01:00
parent 87948340b0
commit 78e86b3999
78 changed files with 431 additions and 408 deletions
@@ -13,7 +13,7 @@ export default async function allPagesESBuildContextBundler(params) {
try {
const did_process_exit_because_of_bundler_error = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
const pages = grabAllPages({ exclude_api: true });
global.PAGE_FILES = pages;
global.BUNEXT_PAGE_FILES = pages;
const dev = isDevelopment();
const entryToPage = new Map();
for (const page of pages) {
@@ -28,7 +28,7 @@ export default async function allPagesESBuildContextBundler(params) {
entryToPage.set(entryFile, { ...page, tsx });
}
const entryPoints = [...entryToPage.keys()].map((e) => `hydration-virtual:${e}`);
global.BUNDLER_CTX = await esbuild.context({
global.BUNEXT_BUNDLER_CTX = await esbuild.context({
entryPoints,
outdir: HYDRATION_DST_DIR,
bundle: true,
@@ -62,13 +62,13 @@ export default async function allPagesESBuildContextBundler(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);
+9 -9
View File
@@ -1,18 +1,18 @@
export default async function buildOnstartErrorHandler(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);
global.BUNDLER_CTX_DISPOSED = true;
global.RECOMPILING = false;
global.IS_SERVER_COMPONENT = false;
// console.log(`global.BUNEXT_BUNDLER_CTX_DISPOSED`, global.BUNEXT_BUNDLER_CTX_DISPOSED);
global.BUNEXT_BUNDLER_CTX_DISPOSED = true;
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;
}
+1 -1
View File
@@ -62,7 +62,7 @@ export default async function bunReactModulesBundler() {
});
rmSync(tmpDir, { force: true, recursive: true });
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`,
+2 -2
View File
@@ -16,7 +16,7 @@ export default async function pagesSSRBundler(params) {
include_server: true,
});
const dev = isDevelopment();
const config = global.CONFIG;
const config = global.BUNEXT_CONFIG;
try {
writeFileSync(path.join(BUNX_TMP_DIR, "ssr-pages.json"), JSON.stringify(pages, null, 4));
}
@@ -88,7 +88,7 @@ export default async function pagesSSRBundler(params) {
});
}
catch (error) {
global.SSR_BUNDLER_CTX_DISPOSED = true;
global.BUNEXT_SSR_BUNDLER_CTX_DISPOSED = true;
log.error(`SSR Bundler Error: ${error}`);
}
}
+5 -5
View File
@@ -11,9 +11,9 @@ const { BUNX_CWD_MODULE_CACHE_DIR } = grabDirNames();
export default async function pagesSSRContextBundler(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();
const { root_file_path } = grabRootFilePath();
@@ -32,7 +32,7 @@ export default async function pagesSSRContextBundler(params) {
entryToPage.set(page.local_path, { ...page, tsx });
}
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,
@@ -65,5 +65,5 @@ export default async function pagesSSRContextBundler(params) {
],
// logLevel: "silent",
});
await global.SSR_BUNDLER_CTX.rebuild();
await global.BUNEXT_SSR_BUNDLER_CTX.rebuild();
}
+3 -3
View File
@@ -5,7 +5,7 @@ const BunSkipNonBrowserPlugin = {
const skipFilter = /^(bun:|node:|fs$|path$|os$|crypto$|net$|events$|util$|tls$|url$|process$)/;
// 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",
@@ -13,8 +13,8 @@ const BunSkipNonBrowserPlugin = {
};
});
// build.onEnd(() => {
// log.warn(`global.SKIPPED_BROWSER_MODULES`, [
// ...global.SKIPPED_BROWSER_MODULES,
// log.warn(`global.BUNEXT_SKIPPED_BROWSER_MODULES`, [
// ...global.BUNEXT_SKIPPED_BROWSER_MODULES,
// ]);
// });
// build.onResolve({ filter: /^[^./]/ }, (args) => {
@@ -17,29 +17,29 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
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(BUNX_BUNDLER_ERROR_EXIT_FILE);
if (global.MAIN_CTX_BUILD_STARTS >= MAX_BUILD_STARTS &&
if (global.BUNEXT_MAIN_CTX_BUILD_STARTS >= MAX_BUILD_STARTS &&
!does_error_file_exist) {
await buildOnstartErrorHandler();
}
});
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) {
log.error(` ${err.text}${err.location ? ` (${err.location.file}:${err.location.line}:${err.location.column})` : ""}`);
}
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];
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);
}
}
return;
@@ -51,16 +51,17 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
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] =
_.merge(global.BUNDLER_CTX_MAP[artifact.local_path], artifact);
if (artifact?.local_path &&
global.BUNEXT_BUNDLER_CTX_MAP) {
global.BUNEXT_BUNDLER_CTX_MAP[artifact.local_path] =
_.merge(global.BUNEXT_BUNDLER_CTX_MAP[artifact.local_path], artifact);
}
}
}
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);
// SSR must finish before HMR so server props are fresh
if (build_only) {
@@ -94,8 +95,8 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
}
}
}
global.RECOMPILING = false;
global.IS_SERVER_COMPONENT = false;
global.BUNEXT_RECOMPILING = false;
global.BUNEXT_IS_SERVER_COMPONENT = false;
});
},
};
+10 -11
View File
@@ -15,19 +15,19 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
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(`SSR Build error: ${err.text}${err.location ? ` (${err.location.file}:${err.location.line}:${err.location.column})` : ""}`);
@@ -43,9 +43,8 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
for (let i = 0; i < artifacts.length; i++) {
const artifact = artifacts[i];
if (artifact?.local_path &&
global.SSR_BUNDLER_CTX_MAP) {
global.SSR_BUNDLER_CTX_MAP[artifact.local_path] =
artifact;
global.BUNEXT_SSR_BUNDLER_CTX_MAP) {
global.BUNEXT_SSR_BUNDLER_CTX_MAP[artifact.local_path] = artifact;
}
}
// post_build_fn?.({ artifacts });
@@ -55,10 +54,10 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
// log.success(`SSR [Built] in ${elapsed}ms`);
}
try {
writeFileSync(path.join(BUNX_TMP_DIR, "ctx-map.json"), JSON.stringify(global.SSR_BUNDLER_CTX_MAP, null, 4));
writeFileSync(path.join(BUNX_TMP_DIR, "ctx-map.json"), 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;
});
},
};
+1 -1
View File
@@ -65,7 +65,7 @@ export default async function reactModulesBundler() {
});
rmSync(tmpDir, { force: true, recursive: true });
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`,
+2 -2
View File
@@ -8,8 +8,8 @@ export default async function recordArtifacts({ artifacts, page_file_paths, }) {
artifacts_map[artifact.local_path] = artifact;
}
}
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(
// HYDRATION_DST_DIR_MAP_JSON_FILE,