Remove esm.sh externals
This commit is contained in:
parent
68d88bce4a
commit
7dbd1f7e12
3
dist/commands/build/index.js
vendored
3
dist/commands/build/index.js
vendored
@ -1,11 +1,8 @@
|
|||||||
import { Command } from "commander";
|
import { Command } from "commander";
|
||||||
import { log } from "../../utils/log";
|
import { log } from "../../utils/log";
|
||||||
import init from "../../functions/init";
|
import init from "../../functions/init";
|
||||||
// import rewritePagesModule from "../../utils/rewrite-pages-module";
|
|
||||||
import allPagesBunBundler from "../../functions/bundler/all-pages-bun-bundler";
|
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import { rmSync } from "fs";
|
import { rmSync } from "fs";
|
||||||
import allPagesBundler from "../../functions/bundler/all-pages-bundler";
|
|
||||||
import allPagesESBuildContextBundler from "../../functions/bundler/all-pages-esbuild-context-bundler";
|
import allPagesESBuildContextBundler from "../../functions/bundler/all-pages-esbuild-context-bundler";
|
||||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||||
export default function () {
|
export default function () {
|
||||||
|
|||||||
2
dist/commands/index.js
vendored
2
dist/commands/index.js
vendored
@ -11,7 +11,7 @@ import rewritePages from "./rewrite-pages";
|
|||||||
program
|
program
|
||||||
.name(`bunext`)
|
.name(`bunext`)
|
||||||
.description(`A React Next JS replacement built with bun JS`)
|
.description(`A React Next JS replacement built with bun JS`)
|
||||||
.version(`1.0.0`);
|
.version(`1.0.43`);
|
||||||
/**
|
/**
|
||||||
* # Declare Commands
|
* # Declare Commands
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -53,13 +53,14 @@ export default async function allPagesESBuildContextBundler(params) {
|
|||||||
logLevel: "silent",
|
logLevel: "silent",
|
||||||
// logLevel: "silent",
|
// logLevel: "silent",
|
||||||
// logLevel: dev ? "error" : "silent",
|
// logLevel: dev ? "error" : "silent",
|
||||||
external: [
|
// external: [
|
||||||
"react",
|
// "react",
|
||||||
"react-dom",
|
// "react-dom",
|
||||||
"react-dom/client",
|
// "react-dom/client",
|
||||||
"react/jsx-runtime",
|
// "react/jsx-runtime",
|
||||||
"react/jsx-dev-runtime",
|
// "react/jsx-dev-runtime",
|
||||||
],
|
// ],
|
||||||
|
// jsxDev: dev,
|
||||||
});
|
});
|
||||||
await global.BUNDLER_CTX.rebuild();
|
await global.BUNDLER_CTX.rebuild();
|
||||||
}
|
}
|
||||||
|
|||||||
2
dist/functions/bunext-init.d.ts
vendored
2
dist/functions/bunext-init.d.ts
vendored
@ -1,5 +1,6 @@
|
|||||||
import type { BundlerCTXMap, BunextConfig, GlobalHMRControllerObject, PageFiles } from "../types";
|
import type { BundlerCTXMap, BunextConfig, GlobalHMRControllerObject, PageFiles } from "../types";
|
||||||
import type { FileSystemRouter, Server } from "bun";
|
import type { FileSystemRouter, Server } from "bun";
|
||||||
|
import grabDirNames from "../utils/grab-dir-names";
|
||||||
import { type FSWatcher } from "fs";
|
import { type FSWatcher } from "fs";
|
||||||
import type { BuildContext } from "esbuild";
|
import type { BuildContext } from "esbuild";
|
||||||
/**
|
/**
|
||||||
@ -23,5 +24,6 @@ declare global {
|
|||||||
var ROOT_FILE_UPDATED: boolean;
|
var ROOT_FILE_UPDATED: boolean;
|
||||||
var SKIPPED_BROWSER_MODULES: Set<string>;
|
var SKIPPED_BROWSER_MODULES: Set<string>;
|
||||||
var BUNDLER_CTX: BuildContext | undefined;
|
var BUNDLER_CTX: BuildContext | undefined;
|
||||||
|
var DIR_NAMES: ReturnType<typeof grabDirNames>;
|
||||||
}
|
}
|
||||||
export default function bunextInit(): Promise<void>;
|
export default function bunextInit(): Promise<void>;
|
||||||
|
|||||||
4
dist/functions/bunext-init.js
vendored
4
dist/functions/bunext-init.js
vendored
@ -5,13 +5,15 @@ import isDevelopment from "../utils/is-development";
|
|||||||
import { log } from "../utils/log";
|
import { log } from "../utils/log";
|
||||||
import cron from "./server/cron";
|
import cron from "./server/cron";
|
||||||
import watcherEsbuildCTX from "./server/watcher-esbuild-ctx";
|
import watcherEsbuildCTX from "./server/watcher-esbuild-ctx";
|
||||||
const { PAGES_DIR } = grabDirNames();
|
const dirNames = grabDirNames();
|
||||||
|
const { PAGES_DIR } = dirNames;
|
||||||
export default async function bunextInit() {
|
export default async function bunextInit() {
|
||||||
global.HMR_CONTROLLERS = [];
|
global.HMR_CONTROLLERS = [];
|
||||||
global.BUNDLER_CTX_MAP = {};
|
global.BUNDLER_CTX_MAP = {};
|
||||||
global.BUNDLER_REBUILDS = 0;
|
global.BUNDLER_REBUILDS = 0;
|
||||||
global.PAGE_FILES = [];
|
global.PAGE_FILES = [];
|
||||||
global.SKIPPED_BROWSER_MODULES = new Set();
|
global.SKIPPED_BROWSER_MODULES = new Set();
|
||||||
|
global.DIR_NAMES = dirNames;
|
||||||
await init();
|
await init();
|
||||||
log.banner();
|
log.banner();
|
||||||
const router = new Bun.FileSystemRouter({
|
const router = new Bun.FileSystemRouter({
|
||||||
|
|||||||
2
dist/functions/server/bunext-req-handler.js
vendored
2
dist/functions/server/bunext-req-handler.js
vendored
@ -32,7 +32,7 @@ export default async function bunextRequestHandler({ req: initial_req, server, }
|
|||||||
if (url.pathname === "/__hmr" && is_dev) {
|
if (url.pathname === "/__hmr" && is_dev) {
|
||||||
response = await handleHmr({ req });
|
response = await handleHmr({ req });
|
||||||
}
|
}
|
||||||
else if (url.pathname.startsWith("/.bunext/public/pages")) {
|
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/")) {
|
||||||
|
|||||||
@ -2,22 +2,53 @@ import grabDirNames from "../../utils/grab-dir-names";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import isDevelopment from "../../utils/is-development";
|
import isDevelopment from "../../utils/is-development";
|
||||||
import { existsSync } from "fs";
|
import { existsSync } from "fs";
|
||||||
|
import { readFileResponse } from "./handle-public";
|
||||||
const { HYDRATION_DST_DIR } = grabDirNames();
|
const { HYDRATION_DST_DIR } = grabDirNames();
|
||||||
export default async function ({ req }) {
|
export default async function ({ req }) {
|
||||||
try {
|
try {
|
||||||
const is_dev = isDevelopment();
|
const is_dev = isDevelopment();
|
||||||
const url = new URL(req.url);
|
const url = new URL(req.url);
|
||||||
|
// switch (url.pathname) {
|
||||||
|
// case "/.bunext/react":
|
||||||
|
// return readFileResponse({
|
||||||
|
// file_path: is_dev
|
||||||
|
// ? global.DIR_NAMES.REACT_DEVELOPMENT_MODULE
|
||||||
|
// : global.DIR_NAMES.REACT_PRODUCTION_MODULE,
|
||||||
|
// });
|
||||||
|
// case "/.bunext/react-dom":
|
||||||
|
// return readFileResponse({
|
||||||
|
// file_path: is_dev
|
||||||
|
// ? global.DIR_NAMES.REACT_DOM_DEVELOPMENT_MODULE
|
||||||
|
// : global.DIR_NAMES.REACT_DOM_PRODUCTION_MODULE,
|
||||||
|
// });
|
||||||
|
// case "/.bunext/react-dom-client":
|
||||||
|
// return readFileResponse({
|
||||||
|
// file_path: is_dev
|
||||||
|
// ? global.DIR_NAMES.REACT_DOM_CLIENT_DEVELOPMENT_MODULE
|
||||||
|
// : global.DIR_NAMES.REACT_DOM_CLIENT_PRODUCTION_MODULE,
|
||||||
|
// });
|
||||||
|
// case "/.bunext/react-jsx-runtime":
|
||||||
|
// return readFileResponse({
|
||||||
|
// file_path: is_dev
|
||||||
|
// ? global.DIR_NAMES.REACT_JSX_RUNTIME_DEVELOPMENT_MODULE
|
||||||
|
// : global.DIR_NAMES.REACT_JSX_RUNTIME_PRODUCTION_MODULE,
|
||||||
|
// });
|
||||||
|
// case "/.bunext/react-jsx-dev-runtime":
|
||||||
|
// return readFileResponse({
|
||||||
|
// file_path: is_dev
|
||||||
|
// ? global.DIR_NAMES
|
||||||
|
// .REACT_JSX_DEVELOPMENT_RUNTIME_DEVELOPMENT_MODULE
|
||||||
|
// : global.DIR_NAMES
|
||||||
|
// .REACT_JSX_DEVELOPMENT_RUNTIME_PRODUCTION_MODULE,
|
||||||
|
// });
|
||||||
|
// default:
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
const file_path = path.join(HYDRATION_DST_DIR, url.pathname.replace(/\/\.bunext\/public\/pages\//, ""));
|
const file_path = path.join(HYDRATION_DST_DIR, url.pathname.replace(/\/\.bunext\/public\/pages\//, ""));
|
||||||
if (!file_path.startsWith(HYDRATION_DST_DIR + path.sep)) {
|
if (!file_path.startsWith(HYDRATION_DST_DIR + path.sep)) {
|
||||||
return new Response("Forbidden", { status: 403 });
|
return new Response("Forbidden", { status: 403 });
|
||||||
}
|
}
|
||||||
if (!existsSync(file_path)) {
|
return readFileResponse({ file_path });
|
||||||
return new Response(`File Doesn't Exist`, {
|
|
||||||
status: 404,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const file = Bun.file(file_path);
|
|
||||||
return new Response(file);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
return new Response(`File Not Found`, {
|
return new Response(`File Not Found`, {
|
||||||
|
|||||||
3
dist/functions/server/handle-public.d.ts
vendored
3
dist/functions/server/handle-public.d.ts
vendored
@ -2,4 +2,7 @@ type Params = {
|
|||||||
req: Request;
|
req: Request;
|
||||||
};
|
};
|
||||||
export default function ({ req }: Params): Promise<Response>;
|
export default function ({ req }: Params): Promise<Response>;
|
||||||
|
export declare function readFileResponse({ file_path }: {
|
||||||
|
file_path: string;
|
||||||
|
}): Response;
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
19
dist/functions/server/handle-public.js
vendored
19
dist/functions/server/handle-public.js
vendored
@ -11,14 +11,7 @@ export default async function ({ req }) {
|
|||||||
if (!file_path.startsWith(PUBLIC_DIR + path.sep)) {
|
if (!file_path.startsWith(PUBLIC_DIR + path.sep)) {
|
||||||
return new Response("Forbidden", { status: 403 });
|
return new Response("Forbidden", { status: 403 });
|
||||||
}
|
}
|
||||||
if (!existsSync(file_path)) {
|
return readFileResponse({ file_path });
|
||||||
return new Response(`Public File Doesn't Exist`, {
|
|
||||||
status: 404,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const file = Bun.file(file_path);
|
|
||||||
let res_opts = {};
|
|
||||||
return new Response(file, res_opts);
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
return new Response(`Public File Not Found`, {
|
return new Response(`Public File Not Found`, {
|
||||||
@ -26,3 +19,13 @@ export default async function ({ req }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export function readFileResponse({ file_path }) {
|
||||||
|
if (!existsSync(file_path)) {
|
||||||
|
return new Response(`Public File Doesn't Exist`, {
|
||||||
|
status: 404,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const file = Bun.file(file_path);
|
||||||
|
// let res_opts: ResponseInit = {};
|
||||||
|
return new Response(file);
|
||||||
|
}
|
||||||
|
|||||||
1
dist/functions/server/watcher-esbuild-ctx.js
vendored
1
dist/functions/server/watcher-esbuild-ctx.js
vendored
@ -1,7 +1,6 @@
|
|||||||
import { watch, existsSync } from "fs";
|
import { watch, existsSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import rebuildBundler from "./rebuild-bundler";
|
|
||||||
import { log } from "../../utils/log";
|
import { log } from "../../utils/log";
|
||||||
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
|
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
|
||||||
import serverPostBuildFn from "./server-post-build-fn";
|
import serverPostBuildFn from "./server-post-build-fn";
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
||||||
import { renderToString } from "react-dom/server";
|
import { renderToReadableStream, renderToString } from "react-dom/server";
|
||||||
import grabContants from "../../../utils/grab-constants";
|
import grabContants from "../../../utils/grab-constants";
|
||||||
import EJSON from "../../../utils/ejson";
|
import EJSON from "../../../utils/ejson";
|
||||||
import isDevelopment from "../../../utils/is-development";
|
import isDevelopment from "../../../utils/is-development";
|
||||||
@ -10,6 +10,8 @@ import { AppData } from "../../../data/app-data";
|
|||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import grabDirNames from "../../../utils/grab-dir-names";
|
||||||
|
const {} = grabDirNames();
|
||||||
let _reactVersion = "19";
|
let _reactVersion = "19";
|
||||||
try {
|
try {
|
||||||
_reactVersion = JSON.parse(readFileSync(path.join(process.cwd(), "node_modules/react/package.json"), "utf-8")).version;
|
_reactVersion = JSON.parse(readFileSync(path.join(process.cwd(), "node_modules/react/package.json"), "utf-8")).version;
|
||||||
@ -45,40 +47,46 @@ export default async function genWebHTML({ component, pageProps, bundledMap, mod
|
|||||||
const RootHead = root_module?.Head;
|
const RootHead = root_module?.Head;
|
||||||
const dev = isDevelopment();
|
const dev = isDevelopment();
|
||||||
const devSuffix = dev ? "?dev" : "";
|
const devSuffix = dev ? "?dev" : "";
|
||||||
const browser_imports = {
|
// const browser_imports: Record<string, string> = {
|
||||||
react: `https://esm.sh/react@${_reactVersion}`,
|
// react: `/.bunext/react`,
|
||||||
"react-dom": `https://esm.sh/react-dom@${_reactVersion}`,
|
// "react-dom": `/.bunext/react-dom`,
|
||||||
"react-dom/client": `https://esm.sh/react-dom@${_reactVersion}/client`,
|
// "react-dom/client": `/.bunext/react-dom-client`,
|
||||||
"react/jsx-runtime": `https://esm.sh/react@${_reactVersion}/jsx-runtime`,
|
// "react/jsx-runtime": `/.bunext/react-jsx-runtime`,
|
||||||
"react/jsx-dev-runtime": `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`,
|
// "react/jsx-dev-runtime": `/.bunext/react-jsx-dev-runtime`,
|
||||||
};
|
// };
|
||||||
|
// const browser_imports: Record<string, string> = {
|
||||||
|
// react: `https://esm.sh/react@${_reactVersion}`,
|
||||||
|
// "react-dom": `https://esm.sh/react-dom@${_reactVersion}`,
|
||||||
|
// "react-dom/client": `https://esm.sh/react-dom@${_reactVersion}/client`,
|
||||||
|
// "react/jsx-runtime": `https://esm.sh/react@${_reactVersion}/jsx-runtime`,
|
||||||
|
// "react/jsx-dev-runtime": `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`,
|
||||||
|
// };
|
||||||
// if (dev) {
|
// if (dev) {
|
||||||
// browser_imports["react/jsx-dev-runtime"] =
|
// browser_imports["react/jsx-dev-runtime"] =
|
||||||
// `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`;
|
// `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`;
|
||||||
// }
|
// }
|
||||||
const importMap = JSON.stringify({
|
// const importMap = JSON.stringify({
|
||||||
imports: browser_imports,
|
// imports: browser_imports,
|
||||||
});
|
|
||||||
const final_meta = _.merge(root_meta, page_meta);
|
|
||||||
let final_component = (_jsxs("html", { ...html_props, children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }), final_meta ? grabWebMetaHTML({ meta: final_meta }) : null, bundledMap?.css_path ? (_jsx("link", { rel: "stylesheet", href: `/${bundledMap.css_path}` })) : null, _jsx("script", { dangerouslySetInnerHTML: {
|
|
||||||
__html: `window.${ClientWindowPagePropsName} = ${serializedProps}`,
|
|
||||||
} }), bundledMap?.path ? (_jsxs(_Fragment, { children: [_jsx("script", { type: "importmap", dangerouslySetInnerHTML: {
|
|
||||||
__html: importMap,
|
|
||||||
}, defer: true }), _jsx("script", { src: `/${bundledMap.path}`, type: "module", id: AppData["BunextClientHydrationScriptID"], defer: true })] })) : null, is_dev ? (_jsx("script", { defer: true, dangerouslySetInnerHTML: {
|
|
||||||
__html: page_hydration_script,
|
|
||||||
} })) : null, RootHead ? (_jsx(RootHead, { serverRes: pageProps, ctx: routeParams })) : null, Head ? _jsx(Head, { serverRes: pageProps, ctx: routeParams }) : null] }), _jsx("body", { children: _jsx("div", { id: ClientRootElementIDName, suppressHydrationWarning: !dev, children: component }) })] }));
|
|
||||||
let html = `<!DOCTYPE html>\n`;
|
|
||||||
// const stream = await renderToReadableStream(final_component, {
|
|
||||||
// onError(error: any) {
|
|
||||||
// // This is where you "omit" or handle the errors
|
|
||||||
// // You can log it silently or ignore it
|
|
||||||
// if (error.message.includes('unique "key" prop')) return;
|
|
||||||
// console.error(error);
|
|
||||||
// },
|
|
||||||
// });
|
// });
|
||||||
// // 2. Convert the Web Stream to a String (Bun-optimized)
|
const final_meta = _.merge(root_meta, page_meta);
|
||||||
// const htmlBody = await new Response(stream).text();
|
let final_component = (_jsxs("html", { ...html_props, children: [_jsxs("head", { children: [_jsx("meta", { charSet: "utf-8", "data-bunext-head": true }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0", "data-bunext-head": true }), final_meta ? grabWebMetaHTML({ meta: final_meta }) : null, bundledMap?.css_path ? (_jsx("link", { rel: "stylesheet", href: `/${bundledMap.css_path}`, "data-bunext-head": true })) : null, _jsx("script", { dangerouslySetInnerHTML: {
|
||||||
// html += htmlBody;
|
__html: `window.${ClientWindowPagePropsName} = ${serializedProps}`,
|
||||||
html += renderToString(final_component);
|
}, "data-bunext-head": true }), RootHead ? (_jsx(RootHead, { serverRes: pageProps, ctx: routeParams })) : null, Head ? _jsx(Head, { serverRes: pageProps, ctx: routeParams }) : null, bundledMap?.path ? (_jsx(_Fragment, { children: _jsx("script", { src: `/${bundledMap.path}`, type: "module", id: AppData["BunextClientHydrationScriptID"], defer: true, "data-bunext-head": true }) })) : null, is_dev ? (_jsx("script", { defer: true, dangerouslySetInnerHTML: {
|
||||||
|
__html: page_hydration_script,
|
||||||
|
}, "data-bunext-head": true })) : null] }), _jsx("body", { children: _jsx("div", { id: ClientRootElementIDName, suppressHydrationWarning: !dev, children: component }) })] }));
|
||||||
|
let html = `<!DOCTYPE html>\n`;
|
||||||
|
const stream = await renderToReadableStream(final_component, {
|
||||||
|
onError(error) {
|
||||||
|
// This is where you "omit" or handle the errors
|
||||||
|
// You can log it silently or ignore it
|
||||||
|
if (error.message.includes('unique "key" prop'))
|
||||||
|
return;
|
||||||
|
console.error(error);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
// 2. Convert the Web Stream to a String (Bun-optimized)
|
||||||
|
const htmlBody = await new Response(stream).text();
|
||||||
|
html += htmlBody;
|
||||||
|
// html += renderToString(final_component);
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|||||||
36
dist/types/index.d.ts
vendored
36
dist/types/index.d.ts
vendored
@ -164,23 +164,25 @@ export type BunextPageModuleMeta = {
|
|||||||
robots?: string;
|
robots?: string;
|
||||||
canonical?: string;
|
canonical?: string;
|
||||||
themeColor?: string;
|
themeColor?: string;
|
||||||
og?: {
|
og?: BunextPageModuleMetaOG;
|
||||||
title?: string;
|
twitter?: BunextPageModuleMetaTwitter;
|
||||||
description?: string;
|
};
|
||||||
image?: string;
|
export type BunextPageModuleMetaOG = {
|
||||||
url?: string;
|
title?: string;
|
||||||
type?: string;
|
description?: string;
|
||||||
siteName?: string;
|
image?: string;
|
||||||
locale?: string;
|
url?: string;
|
||||||
};
|
type?: string;
|
||||||
twitter?: {
|
siteName?: string;
|
||||||
card?: "summary" | "summary_large_image" | "app" | "player";
|
locale?: string;
|
||||||
title?: string;
|
};
|
||||||
description?: string;
|
export type BunextPageModuleMetaTwitter = {
|
||||||
image?: string;
|
card?: "summary" | "summary_large_image" | "app" | "player";
|
||||||
site?: string;
|
title?: string;
|
||||||
creator?: string;
|
description?: string;
|
||||||
};
|
image?: string;
|
||||||
|
site?: string;
|
||||||
|
creator?: string;
|
||||||
};
|
};
|
||||||
export type BunextPageServerFn<T extends {
|
export type BunextPageServerFn<T extends {
|
||||||
[k: string]: any;
|
[k: string]: any;
|
||||||
|
|||||||
71
dist/utils/grab-dir-names.js
vendored
71
dist/utils/grab-dir-names.js
vendored
@ -23,6 +23,64 @@ export default function grabDirNames() {
|
|||||||
const BUNX_ROOT_500_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_500_FILE_NAME}.tsx`);
|
const BUNX_ROOT_500_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_500_FILE_NAME}.tsx`);
|
||||||
const BUNX_ROOT_404_FILE_NAME = `not-found`;
|
const BUNX_ROOT_404_FILE_NAME = `not-found`;
|
||||||
const BUNX_ROOT_404_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_404_FILE_NAME}.tsx`);
|
const BUNX_ROOT_404_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_404_FILE_NAME}.tsx`);
|
||||||
|
// const NODE_MODULES_DIR = path.resolve(
|
||||||
|
// existsSync(path.join(BUNX_ROOT_DIR, "source.md"))
|
||||||
|
// ? BUNX_ROOT_DIR
|
||||||
|
// : ROOT_DIR,
|
||||||
|
// "node_modules",
|
||||||
|
// );
|
||||||
|
// const REACT_MODULE_DIR = path.join(NODE_MODULES_DIR, "react");
|
||||||
|
// const REACT_DOM_MODULE_DIR = path.join(NODE_MODULES_DIR, "react-dom");
|
||||||
|
// const REACT_PRODUCTION_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react.production.js",
|
||||||
|
// );
|
||||||
|
// const REACT_DEVELOPMENT_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react.development.js",
|
||||||
|
// );
|
||||||
|
// const REACT_JSX_RUNTIME_PRODUCTION_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-jsx-runtime.production.js",
|
||||||
|
// );
|
||||||
|
// const REACT_JSX_RUNTIME_DEVELOPMENT_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-jsx-runtime.development.js",
|
||||||
|
// );
|
||||||
|
// const REACT_JSX_DEVELOPMENT_RUNTIME_PRODUCTION_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-jsx-dev-runtime.production.js",
|
||||||
|
// );
|
||||||
|
// const REACT_JSX_DEVELOPMENT_RUNTIME_DEVELOPMENT_MODULE = path.join(
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-jsx-dev-runtime.development.js",
|
||||||
|
// );
|
||||||
|
// const REACT_DOM_PRODUCTION_MODULE = path.join(
|
||||||
|
// REACT_DOM_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-dom.production.js",
|
||||||
|
// );
|
||||||
|
// const REACT_DOM_DEVELOPMENT_MODULE = path.join(
|
||||||
|
// REACT_DOM_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-dom.development.js",
|
||||||
|
// );
|
||||||
|
// const REACT_DOM_CLIENT_PRODUCTION_MODULE = path.join(
|
||||||
|
// REACT_DOM_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-dom-client.production.js",
|
||||||
|
// );
|
||||||
|
// const REACT_DOM_CLIENT_DEVELOPMENT_MODULE = path.join(
|
||||||
|
// REACT_DOM_MODULE_DIR,
|
||||||
|
// "cjs",
|
||||||
|
// "react-dom-client.development.js",
|
||||||
|
// );
|
||||||
return {
|
return {
|
||||||
ROOT_DIR,
|
ROOT_DIR,
|
||||||
SRC_DIR,
|
SRC_DIR,
|
||||||
@ -46,5 +104,18 @@ export default function grabDirNames() {
|
|||||||
BUNX_CWD_MODULE_CACHE_DIR,
|
BUNX_CWD_MODULE_CACHE_DIR,
|
||||||
BUNX_CWD_PAGES_REWRITE_DIR,
|
BUNX_CWD_PAGES_REWRITE_DIR,
|
||||||
HYDRATION_DST_DIR_MAP_JSON_FILE_NAME,
|
HYDRATION_DST_DIR_MAP_JSON_FILE_NAME,
|
||||||
|
// NODE_MODULES_DIR,
|
||||||
|
// REACT_MODULE_DIR,
|
||||||
|
// REACT_DOM_MODULE_DIR,
|
||||||
|
// REACT_PRODUCTION_MODULE,
|
||||||
|
// REACT_DEVELOPMENT_MODULE,
|
||||||
|
// REACT_JSX_RUNTIME_PRODUCTION_MODULE,
|
||||||
|
// REACT_JSX_RUNTIME_DEVELOPMENT_MODULE,
|
||||||
|
// REACT_JSX_DEVELOPMENT_RUNTIME_PRODUCTION_MODULE,
|
||||||
|
// REACT_JSX_DEVELOPMENT_RUNTIME_DEVELOPMENT_MODULE,
|
||||||
|
// REACT_DOM_PRODUCTION_MODULE,
|
||||||
|
// REACT_DOM_DEVELOPMENT_MODULE,
|
||||||
|
// REACT_DOM_CLIENT_PRODUCTION_MODULE,
|
||||||
|
// REACT_DOM_CLIENT_DEVELOPMENT_MODULE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "1.0.43",
|
"version": "1.0.44",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ import rewritePages from "./rewrite-pages";
|
|||||||
program
|
program
|
||||||
.name(`bunext`)
|
.name(`bunext`)
|
||||||
.description(`A React Next JS replacement built with bun JS`)
|
.description(`A React Next JS replacement built with bun JS`)
|
||||||
.version(`1.0.0`);
|
.version(`1.0.43`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* # Declare Commands
|
* # Declare Commands
|
||||||
|
|||||||
@ -76,13 +76,14 @@ export default async function allPagesESBuildContextBundler(params?: Params) {
|
|||||||
logLevel: "silent",
|
logLevel: "silent",
|
||||||
// logLevel: "silent",
|
// logLevel: "silent",
|
||||||
// logLevel: dev ? "error" : "silent",
|
// logLevel: dev ? "error" : "silent",
|
||||||
external: [
|
// external: [
|
||||||
"react",
|
// "react",
|
||||||
"react-dom",
|
// "react-dom",
|
||||||
"react-dom/client",
|
// "react-dom/client",
|
||||||
"react/jsx-runtime",
|
// "react/jsx-runtime",
|
||||||
"react/jsx-dev-runtime",
|
// "react/jsx-dev-runtime",
|
||||||
],
|
// ],
|
||||||
|
// jsxDev: dev,
|
||||||
});
|
});
|
||||||
|
|
||||||
await global.BUNDLER_CTX.rebuild();
|
await global.BUNDLER_CTX.rebuild();
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { watch, existsSync } from "fs";
|
import { watch, existsSync } from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import rebuildBundler from "./rebuild-bundler";
|
|
||||||
import { log } from "../../utils/log";
|
import { log } from "../../utils/log";
|
||||||
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
|
import allPagesESBuildContextBundler from "../bundler/all-pages-esbuild-context-bundler";
|
||||||
import serverPostBuildFn from "./server-post-build-fn";
|
import serverPostBuildFn from "./server-post-build-fn";
|
||||||
|
|||||||
@ -82,44 +82,52 @@ export default async function genWebHTML({
|
|||||||
// "react/jsx-dev-runtime": `/.bunext/react-jsx-dev-runtime`,
|
// "react/jsx-dev-runtime": `/.bunext/react-jsx-dev-runtime`,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const browser_imports: Record<string, string> = {
|
// const browser_imports: Record<string, string> = {
|
||||||
react: `https://esm.sh/react@${_reactVersion}`,
|
// react: `https://esm.sh/react@${_reactVersion}`,
|
||||||
"react-dom": `https://esm.sh/react-dom@${_reactVersion}`,
|
// "react-dom": `https://esm.sh/react-dom@${_reactVersion}`,
|
||||||
"react-dom/client": `https://esm.sh/react-dom@${_reactVersion}/client`,
|
// "react-dom/client": `https://esm.sh/react-dom@${_reactVersion}/client`,
|
||||||
"react/jsx-runtime": `https://esm.sh/react@${_reactVersion}/jsx-runtime`,
|
// "react/jsx-runtime": `https://esm.sh/react@${_reactVersion}/jsx-runtime`,
|
||||||
"react/jsx-dev-runtime": `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`,
|
// "react/jsx-dev-runtime": `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`,
|
||||||
};
|
// };
|
||||||
|
|
||||||
// if (dev) {
|
// if (dev) {
|
||||||
// browser_imports["react/jsx-dev-runtime"] =
|
// browser_imports["react/jsx-dev-runtime"] =
|
||||||
// `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`;
|
// `https://esm.sh/react@${_reactVersion}/jsx-dev-runtime`;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const importMap = JSON.stringify({
|
// const importMap = JSON.stringify({
|
||||||
imports: browser_imports,
|
// imports: browser_imports,
|
||||||
});
|
// });
|
||||||
|
|
||||||
const final_meta = _.merge(root_meta, page_meta);
|
const final_meta = _.merge(root_meta, page_meta);
|
||||||
|
|
||||||
let final_component = (
|
let final_component = (
|
||||||
<html {...html_props}>
|
<html {...html_props}>
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
<meta charSet="utf-8" data-bunext-head />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0"
|
content="width=device-width, initial-scale=1.0"
|
||||||
|
data-bunext-head
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{final_meta ? grabWebMetaHTML({ meta: final_meta }) : null}
|
{final_meta ? grabWebMetaHTML({ meta: final_meta }) : null}
|
||||||
|
|
||||||
|
{/* <link rel="preconnect" href="https://esm.sh" /> */}
|
||||||
|
|
||||||
{bundledMap?.css_path ? (
|
{bundledMap?.css_path ? (
|
||||||
<link rel="stylesheet" href={`/${bundledMap.css_path}`} />
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href={`/${bundledMap.css_path}`}
|
||||||
|
data-bunext-head
|
||||||
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
<script
|
<script
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: `window.${ClientWindowPagePropsName} = ${serializedProps}`,
|
__html: `window.${ClientWindowPagePropsName} = ${serializedProps}`,
|
||||||
}}
|
}}
|
||||||
|
data-bunext-head
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{RootHead ? (
|
{RootHead ? (
|
||||||
@ -129,18 +137,20 @@ export default async function genWebHTML({
|
|||||||
|
|
||||||
{bundledMap?.path ? (
|
{bundledMap?.path ? (
|
||||||
<>
|
<>
|
||||||
<script
|
{/* <script
|
||||||
type="importmap"
|
type="importmap"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: importMap,
|
__html: importMap,
|
||||||
}}
|
}}
|
||||||
defer
|
defer
|
||||||
/>
|
data-bunext-head
|
||||||
|
/> */}
|
||||||
<script
|
<script
|
||||||
src={`/${bundledMap.path}`}
|
src={`/${bundledMap.path}`}
|
||||||
type="module"
|
type="module"
|
||||||
id={AppData["BunextClientHydrationScriptID"]}
|
id={AppData["BunextClientHydrationScriptID"]}
|
||||||
defer
|
defer
|
||||||
|
data-bunext-head
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
@ -151,6 +161,7 @@ export default async function genWebHTML({
|
|||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: page_hydration_script,
|
__html: page_hydration_script,
|
||||||
}}
|
}}
|
||||||
|
data-bunext-head
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user