diff --git a/.vscode/launch.json b/.vscode/launch.json index 38242e143e..5c42d297ae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -98,7 +98,7 @@ // "args": ["--serve", "--origin=http://localhost:3000"], "args": ["dev", "--origin=http://localhost:3000"], "cwd": "${workspaceFolder}/examples/hello-next", - "console": "internalConsole" + "console": "internalConsole" }, { "type": "lldb", @@ -154,7 +154,7 @@ "request": "launch", "name": "Demo .bun", "program": "${workspaceFolder}/build/debug/macos-x86_64/bun", - "args": ["bun", "--use=./bun-framework-next"], + "args": ["bun", "--use=bun-framework-next"], "cwd": "${workspaceFolder}/examples/hello-next", "console": "internalConsole" }, diff --git a/examples/hello-next/bun-framework-next/.npmignore b/examples/hello-next/bun-framework-next/.npmignore deleted file mode 100644 index dc09544775..0000000000 --- a/examples/hello-next/bun-framework-next/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -*.bun -node_modules \ No newline at end of file diff --git a/examples/hello-next/bun-framework-next/client.development.tsx b/examples/hello-next/bun-framework-next/client.development.tsx index 0d019e1754..f8fd054c30 100644 --- a/examples/hello-next/bun-framework-next/client.development.tsx +++ b/examples/hello-next/bun-framework-next/client.development.tsx @@ -1,7 +1,8 @@ -import "./bun-error"; globalThis.global = globalThis; globalThis.Bun_disableCSSImports = true; +import "./bun-error"; + import * as React from "react"; var onlyChildPolyfill = React.Children.only; React.Children.only = function (children) { diff --git a/examples/hello-next/bun-framework-next/fallback.development.tsx b/examples/hello-next/bun-framework-next/fallback.development.tsx deleted file mode 100644 index 1cd5f847e1..0000000000 --- a/examples/hello-next/bun-framework-next/fallback.development.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import { insertStyleSheet } from "./page-loader"; -import type { - FallbackMessageContainer, - FallbackStep, -} from "../../../src/api/schema"; - -var once = false; -function insertGlobalStyleSheet(detail) { - if (!once) { - document.head.insertAdjacentHTML( - "beforeend", - `` - ); - once = true; - } - pageLoader.cssQueue.push(insertStyleSheet(detail).then(() => {})); -} - -[...globalThis["__BUN"].allImportedStyles].map((detail) => - insertGlobalStyleSheet(detail) -); - -document.addEventListener("onimportcss", insertGlobalStyleSheet, { - passive: true, -}); - -import { renderError, _boot, pageLoader } from "./client.development"; -import { renderFallbackError } from "bun-error"; - -function renderFallback({ - router, - reason, - problems, -}: FallbackMessageContainer) { - const route = router.routes[router.route]; - - if (!document.getElementById("__next")) { - const next = document.createElement("div"); - next.id = "__next"; - document.body.prepend(next); - } - - document.removeEventListener("onimportcss", insertGlobalStyleSheet); - document.addEventListener("onimportcss", pageLoader.onImportCSS, { - passive: true, - }); - - globalThis.__NEXT_DATA__.pages["/_app"] = [ - ...globalThis.__NEXT_DATA__.pages["/_app"], - ...globalThis["__BUN"].allImportedStyles, - ]; - - return import(route) - .then((Namespace) => { - return _boot(Namespace, true); - }) - .then(() => { - const cssQueue = pageLoader.cssQueue.slice(); - pageLoader.cssQueue = []; - return Promise.all([...cssQueue]); - }) - .finally(() => { - document.body.style.visibility = "visible"; - document.removeEventListener("onimportcss", pageLoader.onImportCSS); - }); -} - -export default function render(props: FallbackMessageContainer) { - renderFallback(props).then( - () => { - Promise.all(pageLoader.cssQueue).finally(() => { - renderFallbackError(props); - document.body.style.visibility = "visible"; - }); - }, - (err) => { - Promise.all(pageLoader.cssQueue).finally(() => { - renderFallbackError(props); - }); - } - ); -} diff --git a/examples/hello-next/bun-framework-next/index.js b/examples/hello-next/bun-framework-next/index.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/hello-next/bun-framework-next/next-server.tsx b/examples/hello-next/bun-framework-next/next-server.tsx deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/hello-next/bun-framework-next/package.json b/examples/hello-next/bun-framework-next/package.json deleted file mode 100644 index af62863437..0000000000 --- a/examples/hello-next/bun-framework-next/package.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "name": "bun-framework-next", - "version": "0.0.0-18", - "description": "", - "framework": { - "displayName": "Next.js", - "static": "public", - "assetPrefix": "_next/", - "router": { - "dir": [ - "pages", - "src/pages" - ], - "extensions": [ - ".js", - ".ts", - ".tsx", - ".jsx" - ] - }, - "css": "onimportcss", - "development": { - "client": "client.development.tsx", - "fallback": "fallback.development.tsx", - "server": "server.development.tsx", - "css": "onimportcss", - "define": { - "client": { - ".env": "NEXT_PUBLIC_", - "defaults": { - "process.env.__NEXT_TRAILING_SLASH": "false", - "process.env.NODE_ENV": "\"development\"", - "process.env.__NEXT_ROUTER_BASEPATH": "''", - "process.env.__NEXT_SCROLL_RESTORATION": "false", - "process.env.__NEXT_I18N_SUPPORT": "false", - "process.env.__NEXT_HAS_REWRITES": "false", - "process.env.__NEXT_ANALYTICS_ID": "null", - "process.env.__NEXT_OPTIMIZE_CSS": "false", - "process.env.__NEXT_CROSS_ORIGIN": "''", - "process.env.__NEXT_STRICT_MODE": "false", - "process.env.__NEXT_IMAGE_OPTS": "null" - } - }, - "server": { - ".env": "NEXT_", - "defaults": { - "process.env.__NEXT_TRAILING_SLASH": "false", - "process.env.__NEXT_OPTIMIZE_FONTS": "false", - "process.env.NODE_ENV": "\"development\"", - "process.env.__NEXT_OPTIMIZE_IMAGES": "false", - "process.env.__NEXT_OPTIMIZE_CSS": "false", - "process.env.__NEXT_ROUTER_BASEPATH": "''", - "process.env.__NEXT_SCROLL_RESTORATION": "false", - "process.env.__NEXT_I18N_SUPPORT": "false", - "process.env.__NEXT_HAS_REWRITES": "false", - "process.env.__NEXT_ANALYTICS_ID": "null", - "process.env.__NEXT_CROSS_ORIGIN": "''", - "process.env.__NEXT_STRICT_MODE": "false", - "process.env.__NEXT_IMAGE_OPTS": "null", - "global": "globalThis", - "window": "undefined" - } - } - } - }, - "production": { - "client": "client.production.tsx", - "server": "server.production.tsx", - "fallback": "fallback.production.tsx", - "css": "onimportcss" - } - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "dependencies": { - "react-is": "^17.0.2" - } -} diff --git a/examples/hello-next/bun-framework-next/page-loader.ts b/examples/hello-next/bun-framework-next/page-loader.ts deleted file mode 100644 index fc07578db8..0000000000 --- a/examples/hello-next/bun-framework-next/page-loader.ts +++ /dev/null @@ -1,147 +0,0 @@ -import NextPageLoader from "next/dist/client/page-loader"; -import getAssetPathFromRoute from "next/dist/shared/lib/router/utils/get-asset-path-from-route"; -// import createRouteLoader from "./route-loader"; - -export function insertStyleSheet(url: string) { - if (document.querySelector(`link[href="${url}"]`)) { - return Promise.resolve(); - } - - return new Promise((resolve, reject) => { - const link = document.createElement("link"); - link.rel = "stylesheet"; - - link.onload = () => resolve(); - link.onerror = () => reject(); - - link.href = url; - - // if (headCount) { - // document.head.insertBefore(headCount, link); - // } else { - document.head.appendChild(link); - // } - }); -} - -export default class PageLoader extends NextPageLoader { - public routeLoader: RouteLoader; - - constructor(_, __, pages) { - super(_, __); - - // TODO: assetPrefix? - // this.routeLoader = {}; //createRouteLoader(""); - - // Rewrite the pages object to omit the entry script - // At this point, the entry point has been loaded so we don't want to do that again. - for (let name in pages) { - for (let i = 0; i < pages[name].length; i += 1) { - const lastDot = pages[name][i].lastIndexOf("."); - if (lastDot == -1) continue; - if ( - pages[name][i].substring(lastDot - ".entry".length, lastDot) !== - ".entry" - ) - continue; - - pages[name][i] = - pages[name][i].substring(0, lastDot - ".entry".length) + - pages[name][i].substring(lastDot); - } - } - - this.pages = pages; - this.pageList = Object.keys(this.pages); - } - - pageList: string[]; - pages: Record; - - getPageList() { - return this.pageList; - } - - cssQueue = []; - - onImportCSS = (event) => { - this.cssQueue.push( - insertStyleSheet(event.detail).then( - () => {}, - () => {} - ) - ); - }; - - prefetch(route) { - return Promise.resolve({}); - } - - async loadPage(route: string): Promise { - const assets = - this.pages[route] || this.pages[getAssetPathFromRoute(route)]; - - var src; - console.log(getAssetPathFromRoute(route), assets); - for (let asset of assets) { - if (!asset.endsWith(".css")) { - src = asset; - break; - } - } - console.assert(src, "Invalid or unknown route passed to loadPage"); - - document.removeEventListener("onimportcss", this.onImportCSS); - this.cssQueue.length = 0; - document.addEventListener("onimportcss", this.onImportCSS, { - passive: true, - }); - - try { - const res = await import(src); - - if (this.cssQueue.length > 0) { - await Promise.all(this.cssQueue); - this.cssQueue.length = 0; - } - - document.removeEventListener("onimportcss", this.onImportCSS); - - if (this.cssQueue.length > 0) { - await Promise.all(this.cssQueue); - - this.cssQueue.length = 0; - } - - return { - page: res.default, - mod: res, - styleSheets: [], - __N_SSG: false, - __N_SSP: false, - }; - } catch (exception) { - console.error({ exception }); - } - - // return this.routeLoader.loadRoute(route).then((res) => { - // debugger; - // if ("component" in res) { - // return { - // page: res.component, - // mod: res.exports, - // styleSheets: res.styles.map((o) => ({ - // href: o.href, - // text: o.content, - // })), - // }; - // } - // throw res.error; - // }); - } - - // not used in development! - // prefetch(route: string): Promise { - // return this.routeLoader.prefetch(route); - // } -} diff --git a/examples/hello-next/bun-framework-next/render.tsx b/examples/hello-next/bun-framework-next/render.tsx deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/examples/hello-next/bun-framework-next/renderDocument.tsx b/examples/hello-next/bun-framework-next/renderDocument.tsx deleted file mode 100644 index 356ff788b5..0000000000 --- a/examples/hello-next/bun-framework-next/renderDocument.tsx +++ /dev/null @@ -1,722 +0,0 @@ -import * as App from "next/app"; -import { AmpStateContext } from "next/dist/shared/lib/amp-context"; -import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context"; -import Loadable from "next/dist/shared/lib/loadable"; -import { LoadableContext } from "next/dist/shared/lib/loadable-context"; -import { RouterContext } from "next/dist/shared/lib/router-context"; -import { NextRouter } from "next/dist/shared/lib/router/router"; -import { - AppType, - ComponentsEnhancer, - DocumentInitialProps, - DocumentProps, - DocumentType, - getDisplayName, - loadGetInitialProps, - NextComponentType, - RenderPage, - RenderPageResult, - HtmlContext, -} from "next/dist/shared/lib/utils"; -import * as NextDocument from "next/document"; -import * as ReactDOMServer from "react-dom/server.browser"; -import * as url from "url"; -import * as React from "react"; -import * as ReactIs from "react-is"; -import { BODY_RENDER_TARGET } from "next/constants"; - -const dev = process.env.NODE_ENV === "development"; - -type ParsedUrlQuery = Record; - -const isJSFile = (file: string) => - file.endsWith(".js") || - file.endsWith(".jsx") || - file.endsWith(".mjs") || - file.endsWith(".ts") || - file.endsWith(".tsx"); - -const notImplementedProxy = (base) => - new Proxy( - {}, - { - deleteProperty: function (target, prop) { - return undefined; - }, - enumerate: function (oTarget, sKey) { - return [].entries(); - }, - ownKeys: function (oTarget, sKey) { - return [].values(); - }, - has: function (oTarget, sKey) { - return false; - }, - defineProperty: function (oTarget, sKey, oDesc) { - return undefined; - }, - getOwnPropertyDescriptor: function (oTarget, sKey) { - return undefined; - }, - get(this, prop) { - throw new ReferenceError( - `${base} is not available for this environment.` - ); - }, - set(this, prop, value) { - throw new ReferenceError( - `${base} is not available for this environment.` - ); - }, - } - ); - -globalThis.fetch = (url, options) => { - return Promise.reject(new Error(`fetch is not implemented yet. sorry!!`)); -}; - -function getScripts(files: DocumentFiles) { - const { context, props } = this; - const { - assetPrefix, - buildManifest, - isDevelopment, - devOnlyCacheBusterQueryString, - disableOptimizedLoading, - } = context; - const normalScripts = files.allFiles.filter(isJSFile); - const lowPriorityScripts = buildManifest.lowPriorityFiles?.filter(isJSFile); - - return [...normalScripts, ...lowPriorityScripts].map((file) => { - return ( -