Bugfix. Fix SSR pages filters. Remove dedicated API bundler, use SSR bundler for pages and api routes.
This commit is contained in:
parent
532d0d6b56
commit
84d490b189
@ -8,35 +8,37 @@ const { BUNX_CWD_MODULE_CACHE_DIR } = grabDirNames();
|
||||
export default async function apiRoutesContextBundler() {
|
||||
const pages = grabAllPages({ api_only: true });
|
||||
const dev = isDevelopment();
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
}
|
||||
global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints: pages.map((p) => p.local_path),
|
||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
bundle: true,
|
||||
minify: !dev,
|
||||
format: "esm",
|
||||
target: "esnext",
|
||||
platform: "node",
|
||||
define: {
|
||||
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
|
||||
},
|
||||
entryNames: "api/[dir]/[hash]",
|
||||
metafile: true,
|
||||
plugins: [
|
||||
tailwindEsbuildPlugin,
|
||||
apiRoutesCTXArtifactTracker({ pages }),
|
||||
],
|
||||
jsx: "automatic",
|
||||
external: [
|
||||
"react",
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
});
|
||||
await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
// if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
// await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
// global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
// }
|
||||
// global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
// entryPoints: pages.map((p) => p.local_path),
|
||||
// outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
// bundle: true,
|
||||
// minify: !dev,
|
||||
// format: "esm",
|
||||
// target: "esnext",
|
||||
// platform: "node",
|
||||
// define: {
|
||||
// "process.env.NODE_ENV": JSON.stringify(
|
||||
// dev ? "development" : "production",
|
||||
// ),
|
||||
// },
|
||||
// entryNames: "api/[dir]/[hash]",
|
||||
// metafile: true,
|
||||
// plugins: [
|
||||
// tailwindEsbuildPlugin,
|
||||
// apiRoutesCTXArtifactTracker({ pages }),
|
||||
// ],
|
||||
// jsx: "automatic",
|
||||
// external: [
|
||||
// "react",
|
||||
// "react-dom",
|
||||
// "react/jsx-runtime",
|
||||
// "react/jsx-dev-runtime",
|
||||
// "bun:*",
|
||||
// ],
|
||||
// });
|
||||
// await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ export default async function buildOnstartErrorHandler(params) {
|
||||
global.BUNDLER_CTX_DISPOSED = true;
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
await Promise.all([
|
||||
Promise.all([
|
||||
global.SSR_BUNDLER_CTX?.dispose(),
|
||||
global.BUNDLER_CTX?.dispose(),
|
||||
]);
|
||||
|
||||
@ -9,7 +9,7 @@ import ssrVirtualFilesPlugin from "./plugins/ssr-virtual-files-plugin";
|
||||
import ssrCTXArtifactTracker from "./plugins/ssr-ctx-artifact-tracker";
|
||||
const { BUNX_CWD_MODULE_CACHE_DIR } = grabDirNames();
|
||||
export default async function pagesSSRContextBundler(params) {
|
||||
const pages = grabAllPages({ exclude_api: true });
|
||||
const pages = grabAllPages();
|
||||
const dev = isDevelopment();
|
||||
if (global.SSR_BUNDLER_CTX) {
|
||||
await global.SSR_BUNDLER_CTX.dispose();
|
||||
@ -61,6 +61,7 @@ export default async function pagesSSRContextBundler(params) {
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
// logLevel: "silent",
|
||||
});
|
||||
|
||||
@ -44,17 +44,21 @@ export default function apiRoutesCTXArtifactTracker({ pages }) {
|
||||
url_path,
|
||||
};
|
||||
});
|
||||
if (artifacts?.[0] && artifacts.length > 0) {
|
||||
for (let i = 0; i < artifacts.length; i++) {
|
||||
const artifact = artifacts[i];
|
||||
if (artifact?.local_path &&
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP) {
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP[artifact.local_path] = artifact;
|
||||
}
|
||||
}
|
||||
}
|
||||
// const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
// log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
// if (artifacts?.[0] && artifacts.length > 0) {
|
||||
// for (let i = 0; i < artifacts.length; i++) {
|
||||
// const artifact = artifacts[i];
|
||||
// if (
|
||||
// artifact?.local_path &&
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP
|
||||
// ) {
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP[
|
||||
// artifact.local_path
|
||||
// ] = artifact;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -48,12 +48,6 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
||||
else {
|
||||
pagesSSRContextBundler();
|
||||
}
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
else {
|
||||
apiRoutesContextBundler();
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import {} from "esbuild";
|
||||
import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-result";
|
||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||
import { log } from "../../../utils/log";
|
||||
let build_start = 0;
|
||||
let build_starts = 0;
|
||||
const MAX_BUILD_STARTS = 2;
|
||||
@ -34,7 +35,11 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
|
||||
artifact;
|
||||
}
|
||||
}
|
||||
post_build_fn?.({ artifacts });
|
||||
// post_build_fn?.({ artifacts });
|
||||
// const elapsed = (performance.now() - build_start).toFixed(
|
||||
// 0,
|
||||
// );
|
||||
// log.success(`SSR [Built] in ${elapsed}ms`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
4
dist/functions/bunext-init.d.ts
vendored
4
dist/functions/bunext-init.d.ts
vendored
@ -23,9 +23,6 @@ declare global {
|
||||
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;
|
||||
@ -34,7 +31,6 @@ declare global {
|
||||
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: ReturnType<typeof grabDirNames>;
|
||||
var REACT_IMPORTS_MAP: {
|
||||
imports: Record<string, string>;
|
||||
|
||||
2
dist/functions/bunext-init.js
vendored
2
dist/functions/bunext-init.js
vendored
@ -15,7 +15,7 @@ export default async function bunextInit() {
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
global.BUNDLER_REBUILDS = 0;
|
||||
global.REBUILD_RETRIES = 0;
|
||||
global.PAGE_FILES = [];
|
||||
|
||||
4
dist/functions/server/handle-routes.js
vendored
4
dist/functions/server/handle-routes.js
vendored
@ -30,8 +30,8 @@ export default async function ({ req }) {
|
||||
});
|
||||
let module;
|
||||
const now = Date.now();
|
||||
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);
|
||||
if (is_dev && global.SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
|
||||
const target_import = path.join(ROOT_DIR, global.SSR_BUNDLER_CTX_MAP[match.filePath].path);
|
||||
module = await import(`${target_import}?t=${now}`);
|
||||
}
|
||||
else {
|
||||
|
||||
10
dist/utils/grab-all-pages.js
vendored
10
dist/utils/grab-all-pages.js
vendored
@ -2,7 +2,6 @@ import { existsSync, readdirSync, statSync } from "fs";
|
||||
import grabDirNames from "./grab-dir-names";
|
||||
import path from "path";
|
||||
import AppNames from "./grab-app-names";
|
||||
import pagePathTransform from "./page-path-transform";
|
||||
import checkExcludedPatterns from "./check-excluded-patterns";
|
||||
export default function grabAllPages(params) {
|
||||
const { PAGES_DIR } = grabDirNames();
|
||||
@ -32,18 +31,15 @@ function grabPageDirRecursively({ page_dir }) {
|
||||
if (page.match(new RegExp(`${AppNames["RootPagesComponentName"]}`))) {
|
||||
continue;
|
||||
}
|
||||
if (checkExcludedPatterns({ path: page })) {
|
||||
if (checkExcludedPatterns({ path: full_page_path })) {
|
||||
continue;
|
||||
}
|
||||
if (page.match(/\/api\//)) {
|
||||
continue;
|
||||
}
|
||||
if (page_name.split(".").length > 2) {
|
||||
if (page_name.match(/\.server\.tsx?/)) {
|
||||
continue;
|
||||
}
|
||||
const page_stat = statSync(full_page_path);
|
||||
if (page_stat.isDirectory()) {
|
||||
if (checkExcludedPatterns({ path: page }))
|
||||
if (checkExcludedPatterns({ path: full_page_path }))
|
||||
continue;
|
||||
const new_page_files = grabPageDirRecursively({
|
||||
page_dir: full_page_path,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@moduletrace/bunext",
|
||||
"version": "1.0.75",
|
||||
"version": "1.0.76",
|
||||
"main": "dist/index.js",
|
||||
"module": "index.ts",
|
||||
"dependencies": {
|
||||
|
||||
@ -11,39 +11,39 @@ export default async function apiRoutesContextBundler() {
|
||||
const pages = grabAllPages({ api_only: true });
|
||||
const dev = isDevelopment();
|
||||
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
}
|
||||
// if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
// await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
// global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
// }
|
||||
|
||||
global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints: pages.map((p) => p.local_path),
|
||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
bundle: true,
|
||||
minify: !dev,
|
||||
format: "esm",
|
||||
target: "esnext",
|
||||
platform: "node",
|
||||
define: {
|
||||
"process.env.NODE_ENV": JSON.stringify(
|
||||
dev ? "development" : "production",
|
||||
),
|
||||
},
|
||||
entryNames: "api/[dir]/[hash]",
|
||||
metafile: true,
|
||||
plugins: [
|
||||
tailwindEsbuildPlugin,
|
||||
apiRoutesCTXArtifactTracker({ pages }),
|
||||
],
|
||||
jsx: "automatic",
|
||||
external: [
|
||||
"react",
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
});
|
||||
// global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
// entryPoints: pages.map((p) => p.local_path),
|
||||
// outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
// bundle: true,
|
||||
// minify: !dev,
|
||||
// format: "esm",
|
||||
// target: "esnext",
|
||||
// platform: "node",
|
||||
// define: {
|
||||
// "process.env.NODE_ENV": JSON.stringify(
|
||||
// dev ? "development" : "production",
|
||||
// ),
|
||||
// },
|
||||
// entryNames: "api/[dir]/[hash]",
|
||||
// metafile: true,
|
||||
// plugins: [
|
||||
// tailwindEsbuildPlugin,
|
||||
// apiRoutesCTXArtifactTracker({ pages }),
|
||||
// ],
|
||||
// jsx: "automatic",
|
||||
// external: [
|
||||
// "react",
|
||||
// "react-dom",
|
||||
// "react/jsx-runtime",
|
||||
// "react/jsx-dev-runtime",
|
||||
// "bun:*",
|
||||
// ],
|
||||
// });
|
||||
|
||||
await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
// await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export default async function buildOnstartErrorHandler(params?: Params) {
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
|
||||
await Promise.all([
|
||||
Promise.all([
|
||||
global.SSR_BUNDLER_CTX?.dispose(),
|
||||
global.BUNDLER_CTX?.dispose(),
|
||||
]);
|
||||
|
||||
@ -16,7 +16,7 @@ type Params = {
|
||||
};
|
||||
|
||||
export default async function pagesSSRContextBundler(params?: Params) {
|
||||
const pages = grabAllPages({ exclude_api: true });
|
||||
const pages = grabAllPages();
|
||||
const dev = isDevelopment();
|
||||
|
||||
if (global.SSR_BUNDLER_CTX) {
|
||||
@ -77,6 +77,7 @@ export default async function pagesSSRContextBundler(params?: Params) {
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
// logLevel: "silent",
|
||||
});
|
||||
|
||||
@ -66,22 +66,22 @@ export default function apiRoutesCTXArtifactTracker({ pages }: Params) {
|
||||
};
|
||||
});
|
||||
|
||||
if (artifacts?.[0] && artifacts.length > 0) {
|
||||
for (let i = 0; i < artifacts.length; i++) {
|
||||
const artifact = artifacts[i];
|
||||
if (
|
||||
artifact?.local_path &&
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP
|
||||
) {
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP[
|
||||
artifact.local_path
|
||||
] = artifact;
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (artifacts?.[0] && artifacts.length > 0) {
|
||||
// for (let i = 0; i < artifacts.length; i++) {
|
||||
// const artifact = artifacts[i];
|
||||
// if (
|
||||
// artifact?.local_path &&
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP
|
||||
// ) {
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP[
|
||||
// artifact.local_path
|
||||
// ] = artifact;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
// log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -31,6 +31,7 @@ export default function esbuildCTXArtifactTracker({
|
||||
build.onStart(async () => {
|
||||
build_starts++;
|
||||
build_start = performance.now();
|
||||
|
||||
if (build_starts == MAX_BUILD_STARTS) {
|
||||
await buildOnstartErrorHandler();
|
||||
}
|
||||
@ -74,12 +75,6 @@ export default function esbuildCTXArtifactTracker({
|
||||
} else {
|
||||
pagesSSRContextBundler();
|
||||
}
|
||||
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
} else {
|
||||
apiRoutesContextBundler();
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -2,6 +2,7 @@ import { type Plugin } from "esbuild";
|
||||
import type { PageFiles } from "../../../types";
|
||||
import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-result";
|
||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||
import { log } from "../../../utils/log";
|
||||
|
||||
let build_start = 0;
|
||||
let build_starts = 0;
|
||||
@ -56,7 +57,12 @@ export default function ssrCTXArtifactTracker({
|
||||
}
|
||||
}
|
||||
|
||||
post_build_fn?.({ artifacts });
|
||||
// post_build_fn?.({ artifacts });
|
||||
|
||||
// const elapsed = (performance.now() - build_start).toFixed(
|
||||
// 0,
|
||||
// );
|
||||
// log.success(`SSR [Built] in ${elapsed}ms`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -33,7 +33,7 @@ declare global {
|
||||
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 API_ROUTES_BUNDLER_CTX_MAP: { [k: string]: BundlerCTXMap };
|
||||
var BUNDLER_REBUILDS: 0;
|
||||
var PAGES_SRC_WATCHER: FSWatcher | undefined;
|
||||
var CURRENT_VERSION: string | undefined;
|
||||
@ -42,7 +42,7 @@ declare global {
|
||||
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 API_ROUTES_BUNDLER_CTX: BuildContext | undefined;
|
||||
var DIR_NAMES: ReturnType<typeof grabDirNames>;
|
||||
var REACT_IMPORTS_MAP: { imports: Record<string, string> };
|
||||
var REACT_DOM_SERVER: any;
|
||||
@ -60,7 +60,7 @@ export default async function bunextInit() {
|
||||
global.HMR_CONTROLLERS = [];
|
||||
global.BUNDLER_CTX_MAP = {};
|
||||
global.SSR_BUNDLER_CTX_MAP = {};
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP = {};
|
||||
global.BUNDLER_REBUILDS = 0;
|
||||
global.REBUILD_RETRIES = 0;
|
||||
global.PAGE_FILES = [];
|
||||
|
||||
@ -52,10 +52,10 @@ export default async function ({ req }: Params): Promise<Response | undefined> {
|
||||
let module: any;
|
||||
const now = Date.now();
|
||||
|
||||
if (is_dev && global.API_ROUTES_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
|
||||
if (is_dev && global.SSR_BUNDLER_CTX_MAP?.[match.filePath]?.path) {
|
||||
const target_import = path.join(
|
||||
ROOT_DIR,
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP[match.filePath].path,
|
||||
global.SSR_BUNDLER_CTX_MAP[match.filePath].path,
|
||||
);
|
||||
|
||||
module = await import(`${target_import}?t=${now}`);
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import type { APIResponseObject } from "../types";
|
||||
|
||||
type Params = {
|
||||
path: string;
|
||||
};
|
||||
|
||||
@ -3,7 +3,6 @@ import grabDirNames from "./grab-dir-names";
|
||||
import path from "path";
|
||||
import type { PageFiles } from "../types";
|
||||
import AppNames from "./grab-app-names";
|
||||
import pagePathTransform from "./page-path-transform";
|
||||
import checkExcludedPatterns from "./check-excluded-patterns";
|
||||
|
||||
type Params = {
|
||||
@ -50,22 +49,18 @@ function grabPageDirRecursively({ page_dir }: { page_dir: string }) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checkExcludedPatterns({ path: page })) {
|
||||
if (checkExcludedPatterns({ path: full_page_path })) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (page.match(/\/api\//)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (page_name.split(".").length > 2) {
|
||||
if (page_name.match(/\.server\.tsx?/)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const page_stat = statSync(full_page_path);
|
||||
|
||||
if (page_stat.isDirectory()) {
|
||||
if (checkExcludedPatterns({ path: page })) continue;
|
||||
if (checkExcludedPatterns({ path: full_page_path })) continue;
|
||||
const new_page_files = grabPageDirRecursively({
|
||||
page_dir: full_page_path,
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user