Compare commits
No commits in common. "cb5126c94740b2edf27699a844bc866270db4d68" and "95fcee36b2ed74fd8288507b68c71bd7691bee5b" have entirely different histories.
cb5126c947
...
95fcee36b2
6
dist/commands/dev/index.js
vendored
6
dist/commands/dev/index.js
vendored
@ -4,7 +4,6 @@ import grabDirNames from "../../utils/grab-dir-names";
|
|||||||
import writeErrorFile from "../../functions/write-error-file";
|
import writeErrorFile from "../../functions/write-error-file";
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
let timeout;
|
let timeout;
|
||||||
const MAX_RETRIES = 5;
|
|
||||||
export default function () {
|
export default function () {
|
||||||
return new Command("dev")
|
return new Command("dev")
|
||||||
.description("Run development server")
|
.description("Run development server")
|
||||||
@ -14,8 +13,7 @@ export default function () {
|
|||||||
}
|
}
|
||||||
async function dev() {
|
async function dev() {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
if (retries >= MAX_RETRIES) {
|
if (retries == 1) {
|
||||||
console.error(`Dev server crashed ${MAX_RETRIES} times. Exiting.`);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
const dev_spawn_file = path.resolve(__dirname, "dev-spawn.ts");
|
||||||
@ -34,7 +32,7 @@ async function dev() {
|
|||||||
retries++;
|
retries++;
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
retries = 0;
|
retries = 0;
|
||||||
}, 10000);
|
}, 5000);
|
||||||
const exited = await dev_process.exited;
|
const exited = await dev_process.exited;
|
||||||
if (exited) {
|
if (exited) {
|
||||||
return await dev();
|
return await dev();
|
||||||
|
|||||||
@ -21,29 +21,14 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
|||||||
build_starts++;
|
build_starts++;
|
||||||
build_start = performance.now();
|
build_start = performance.now();
|
||||||
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
const does_error_file_exist = existsSync(BUNX_BUNDLER_ERROR_EXIT_FILE);
|
||||||
if (build_starts >= MAX_BUILD_STARTS &&
|
if (build_starts == MAX_BUILD_STARTS &&
|
||||||
!does_error_file_exist) {
|
!does_error_file_exist) {
|
||||||
await buildOnstartErrorHandler();
|
await buildOnstartErrorHandler();
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
build.onEnd((result) => {
|
build.onEnd((result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
build_starts = 0;
|
|
||||||
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];
|
|
||||||
try {
|
|
||||||
controller?.controller?.enqueue(`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`);
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
global.HMR_CONTROLLERS.splice(i, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const artifacts = grabArtifactsFromBundledResults({
|
const artifacts = grabArtifactsFromBundledResults({
|
||||||
@ -74,13 +59,8 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
|||||||
fullRebuild();
|
fullRebuild();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
|
||||||
pagesSSRBundler();
|
pagesSSRBundler();
|
||||||
}
|
}
|
||||||
catch (error) {
|
|
||||||
log.error(`SSR Bundler Error: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if (global.SSR_BUNDLER_CTX) {
|
// if (global.SSR_BUNDLER_CTX) {
|
||||||
// global.SSR_BUNDLER_CTX.rebuild();
|
// global.SSR_BUNDLER_CTX.rebuild();
|
||||||
// } else {
|
// } else {
|
||||||
|
|||||||
@ -22,9 +22,7 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
|
|||||||
});
|
});
|
||||||
build.onEnd((result) => {
|
build.onEnd((result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.SSR_BUNDLER_CTX_DISPOSED = false;
|
console.log("result.errors", result.errors);
|
||||||
build_starts = 0;
|
|
||||||
console.log("SSR Build errors:", result.errors);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const artifacts = grabArtifactsFromBundledResults({
|
const artifacts = grabArtifactsFromBundledResults({
|
||||||
|
|||||||
2
dist/functions/server/full-rebuild.js
vendored
2
dist/functions/server/full-rebuild.js
vendored
@ -23,8 +23,6 @@ export default async function fullRebuild(params) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
log.error(error);
|
log.error(error);
|
||||||
}
|
}
|
||||||
if (global.PAGES_SRC_WATCHER) {
|
if (global.PAGES_SRC_WATCHER) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/bunext",
|
"name": "@moduletrace/bunext",
|
||||||
"version": "1.0.86",
|
"version": "1.0.85",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "index.ts",
|
"module": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -12,7 +12,6 @@ import {
|
|||||||
import { FileSystemRouter } from "bun";
|
import { FileSystemRouter } from "bun";
|
||||||
import { BuildContext } from "esbuild";
|
import { BuildContext } from "esbuild";
|
||||||
import grabDirNames from "../../utils/grab-dir-names";
|
import grabDirNames from "../../utils/grab-dir-names";
|
||||||
import grabConstants from "../../utils/grab-constants";
|
|
||||||
|
|
||||||
// Fixture lives under test/ so the framework's directory guard allows it
|
// Fixture lives under test/ so the framework's directory guard allows it
|
||||||
const fixtureDir = path.resolve(__dirname, "../../../test/e2e-fixture");
|
const fixtureDir = path.resolve(__dirname, "../../../test/e2e-fixture");
|
||||||
@ -59,11 +58,6 @@ describe("E2E Integration", () => {
|
|||||||
global.HMR_CONTROLLERS = [];
|
global.HMR_CONTROLLERS = [];
|
||||||
global.BUNDLER_REBUILDS = 0;
|
global.BUNDLER_REBUILDS = 0;
|
||||||
global.PAGE_FILES = [];
|
global.PAGE_FILES = [];
|
||||||
global.CONSTANTS = grabConstants();
|
|
||||||
global.SSR_BUNDLER_CTX_MAP = {};
|
|
||||||
global.BUNDLER_CTX_MAP = {};
|
|
||||||
global.REACT_DOM_MODULE_CACHE = new Map<string, any>();
|
|
||||||
global.REBUILD_RETRIES = 0;
|
|
||||||
|
|
||||||
// Set up router pointing at the fixture's pages directory
|
// Set up router pointing at the fixture's pages directory
|
||||||
global.ROUTER = new Bun.FileSystemRouter({
|
global.ROUTER = new Bun.FileSystemRouter({
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, test, mock, afterAll, beforeEach } from "bun:test";
|
import { describe, expect, test, mock, afterAll } from "bun:test";
|
||||||
import bunextRequestHandler from "../../../../src/functions/server/bunext-req-handler";
|
import bunextRequestHandler from "../../../../src/functions/server/bunext-req-handler";
|
||||||
|
|
||||||
mock.module("../../../../src/utils/is-development", () => ({
|
mock.module("../../../../src/utils/is-development", () => ({
|
||||||
@ -34,21 +34,11 @@ mock.module("../../../../src/functions/server/web-pages/handle-web-pages", () =>
|
|||||||
default: async () => new Response("web-pages")
|
default: async () => new Response("web-pages")
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for the `bunext-req-handler` module.
|
||||||
|
* Ensures that requests are correctly routed to the proper subsystem.
|
||||||
|
*/
|
||||||
describe("bunext-req-handler", () => {
|
describe("bunext-req-handler", () => {
|
||||||
beforeEach(() => {
|
|
||||||
global.CONSTANTS = {
|
|
||||||
config: {
|
|
||||||
middleware: async ({ url }: any) => {
|
|
||||||
if (url.pathname === "/blocked") {
|
|
||||||
return new Response("Blocked by middleware", { status: 403 });
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
RouteIgnorePatterns: [],
|
|
||||||
} as any;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
mock.restore();
|
mock.restore();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,26 +1,24 @@
|
|||||||
import { afterAll, afterEach, describe, expect, test, mock } from "bun:test";
|
import { afterAll, afterEach, describe, expect, test } from "bun:test";
|
||||||
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { renderToString } from "react-dom/server";
|
import { renderToString } from "react-dom/server";
|
||||||
import React, { createContext, useContext } from "react";
|
|
||||||
import grabPageBundledReactComponent from "../../../../src/functions/server/web-pages/grab-page-bundled-react-component";
|
import grabPageBundledReactComponent from "../../../../src/functions/server/web-pages/grab-page-bundled-react-component";
|
||||||
import grabDirNames from "../../../../src/utils/grab-dir-names";
|
import grabDirNames from "../../../../src/utils/grab-dir-names";
|
||||||
|
|
||||||
const { BUNX_TMP_DIR } = grabDirNames();
|
const { BUNX_CWD_MODULE_CACHE_DIR, BUNX_TMP_DIR } = grabDirNames();
|
||||||
|
|
||||||
describe("grabPageBundledReactComponent", () => {
|
describe("grabPageBundledReactComponent", () => {
|
||||||
const originalConfig = global.CONFIG;
|
|
||||||
const fixtureDirs: string[] = [];
|
const fixtureDirs: string[] = [];
|
||||||
|
const originalConfig = global.CONFIG;
|
||||||
|
|
||||||
global.CONFIG = { development: true } as any;
|
global.CONFIG = { development: true } as any;
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
for (const fixtureDir of fixtureDirs.splice(0)) {
|
for (const fixtureDir of fixtureDirs.splice(0)) {
|
||||||
const fs = require("fs");
|
|
||||||
fs.rmSync(fixtureDir, { recursive: true, force: true });
|
fs.rmSync(fixtureDir, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
global.CONFIG = { development: true } as any;
|
global.CONFIG = { development: true } as any;
|
||||||
mock.restore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
@ -28,36 +26,50 @@ describe("grabPageBundledReactComponent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("keeps __root context connected during SSR", async () => {
|
test("keeps __root context connected during SSR", async () => {
|
||||||
|
fs.mkdirSync(BUNX_CWD_MODULE_CACHE_DIR, { recursive: true });
|
||||||
|
fs.mkdirSync(BUNX_TMP_DIR, { recursive: true });
|
||||||
|
|
||||||
const fixtureDir = path.join(BUNX_TMP_DIR, `ssr-context-${Date.now()}`);
|
const fixtureDir = path.join(BUNX_TMP_DIR, `ssr-context-${Date.now()}`);
|
||||||
fixtureDirs.push(fixtureDir);
|
fixtureDirs.push(fixtureDir);
|
||||||
|
fs.mkdirSync(fixtureDir, { recursive: true });
|
||||||
|
|
||||||
const rootFilePath = path.join(fixtureDir, "__root.tsx");
|
const rootFilePath = path.join(fixtureDir, "__root.tsx");
|
||||||
const pageFilePath = path.join(fixtureDir, "page.tsx");
|
const pageFilePath = path.join(fixtureDir, "page.tsx");
|
||||||
|
|
||||||
mock.module("../../../../src/functions/server/web-pages/grab-root-file-path", () => ({
|
fs.writeFileSync(
|
||||||
default: () => ({ root_file_path: rootFilePath })
|
rootFilePath,
|
||||||
}));
|
`import { createContext } from "react";
|
||||||
|
export const AppContext = createContext("missing-context");
|
||||||
|
|
||||||
mock.module("../../../../src/functions/server/web-pages/grab-tsx-string-module", () => ({
|
export default function Root({ children }: { children: React.ReactNode }) {
|
||||||
default: async () => {
|
return (
|
||||||
const AppContext = createContext("missing-context");
|
<AppContext.Provider value="server-context">
|
||||||
const Root = ({ children }: { children: React.ReactNode }) =>
|
{children}
|
||||||
React.createElement(AppContext.Provider, { value: "server-context" }, children);
|
</AppContext.Provider>
|
||||||
const Page = () => {
|
);
|
||||||
const value = useContext(AppContext);
|
|
||||||
return React.createElement("div", null, value);
|
|
||||||
};
|
|
||||||
const Main = (props: any) =>
|
|
||||||
React.createElement(Root, props, React.createElement(Page, props));
|
|
||||||
return { default: Main };
|
|
||||||
}
|
}
|
||||||
}));
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
pageFilePath,
|
||||||
|
`import { useContext } from "react";
|
||||||
|
import { AppContext } from "./__root";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
const value = useContext(AppContext);
|
||||||
|
|
||||||
|
return <div>{value}</div>;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
const result = await grabPageBundledReactComponent({
|
const result = await grabPageBundledReactComponent({
|
||||||
file_path: pageFilePath,
|
file_path: pageFilePath,
|
||||||
|
root_file_path: rootFilePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result?.component).toBeDefined();
|
expect(result?.component).toBeDefined();
|
||||||
const html = renderToString(React.createElement(result!.component));
|
expect(renderToString(result!.component)).toContain("server-context");
|
||||||
expect(html).toContain("server-context");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,18 +8,6 @@ mock.module("../../../../src/utils/log", () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
mock.module("../../../../src/utils/is-development", () => ({
|
|
||||||
default: () => false
|
|
||||||
}));
|
|
||||||
|
|
||||||
mock.module("../../../../src/functions/server/full-rebuild", () => ({
|
|
||||||
default: async () => {}
|
|
||||||
}));
|
|
||||||
|
|
||||||
mock.module("../../../../src/functions/server/server-post-build-fn", () => ({
|
|
||||||
default: async () => {}
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { log } from "../../../../src/utils/log";
|
import { log } from "../../../../src/utils/log";
|
||||||
import grabPageComponent from "../../../../src/functions/server/web-pages/grab-page-component";
|
import grabPageComponent from "../../../../src/functions/server/web-pages/grab-page-component";
|
||||||
|
|
||||||
@ -41,7 +29,7 @@ describe("grabPageComponent", () => {
|
|||||||
req: new Request("http://localhost:3000/unknown-foo-bar123"),
|
req: new Request("http://localhost:3000/unknown-foo-bar123"),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.serverRes?.response_options?.status).toBe(404);
|
expect(res.serverRes?.responseOptions?.status).toBe(404);
|
||||||
expect(log.error).not.toHaveBeenCalled();
|
expect(log.error).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -29,7 +29,7 @@ mock.module("/test-path", () => ({
|
|||||||
|
|
||||||
mock.module("/large-path", () => ({
|
mock.module("/large-path", () => ({
|
||||||
default: async () => new Response("Large OK", { status: 200 }),
|
default: async () => new Response("Large OK", { status: 200 }),
|
||||||
config: { max_request_body_mb: 1 }
|
config: { maxRequestBodyMB: 1 }
|
||||||
}));
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import writeErrorFile from "../../functions/write-error-file";
|
|||||||
|
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
let timeout: any;
|
let timeout: any;
|
||||||
const MAX_RETRIES = 5;
|
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
return new Command("dev")
|
return new Command("dev")
|
||||||
@ -19,8 +18,7 @@ export default function () {
|
|||||||
async function dev() {
|
async function dev() {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|
||||||
if (retries >= MAX_RETRIES) {
|
if (retries == 1) {
|
||||||
console.error(`Dev server crashed ${MAX_RETRIES} times. Exiting.`);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +42,7 @@ async function dev() {
|
|||||||
|
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
retries = 0;
|
retries = 0;
|
||||||
}, 10000);
|
}, 5000);
|
||||||
|
|
||||||
const exited = await dev_process.exited;
|
const exited = await dev_process.exited;
|
||||||
if (exited) {
|
if (exited) {
|
||||||
|
|||||||
@ -43,35 +43,16 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
build_starts >= MAX_BUILD_STARTS &&
|
build_starts == MAX_BUILD_STARTS &&
|
||||||
!does_error_file_exist
|
!does_error_file_exist
|
||||||
) {
|
) {
|
||||||
await buildOnstartErrorHandler();
|
await buildOnstartErrorHandler();
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
build.onEnd((result) => {
|
build.onEnd((result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
build_starts = 0;
|
|
||||||
|
|
||||||
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];
|
|
||||||
try {
|
|
||||||
controller?.controller?.enqueue(
|
|
||||||
`event: update\ndata: ${JSON.stringify({ reload: true })}\n\n`,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
global.HMR_CONTROLLERS.splice(i, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,11 +98,7 @@ export default function esbuildCTXArtifactTracker({
|
|||||||
cleanupLogsDirs();
|
cleanupLogsDirs();
|
||||||
fullRebuild();
|
fullRebuild();
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
pagesSSRBundler();
|
pagesSSRBundler();
|
||||||
} catch (error) {
|
|
||||||
log.error(`SSR Bundler Error: ${error}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (global.SSR_BUNDLER_CTX) {
|
// if (global.SSR_BUNDLER_CTX) {
|
||||||
|
|||||||
@ -40,9 +40,7 @@ export default function ssrCTXArtifactTracker({
|
|||||||
|
|
||||||
build.onEnd((result) => {
|
build.onEnd((result) => {
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
global.SSR_BUNDLER_CTX_DISPOSED = false;
|
console.log("result.errors", result.errors);
|
||||||
build_starts = 0;
|
|
||||||
console.log("SSR Build errors:", result.errors);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,8 +30,6 @@ export default async function fullRebuild(params?: { msg?: string }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
global.RECOMPILING = false;
|
|
||||||
global.IS_SERVER_COMPONENT = false;
|
|
||||||
log.error(error);
|
log.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user