@teyik0/furin 0.5.0-alpha.1 → 0.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/entry-template.ts +3 -1
- package/dist/build/index.js +360 -219
- package/dist/build/private-server-sourcemaps.d.ts +2 -0
- package/dist/build/types.d.ts +2 -0
- package/dist/cli/index.js +363 -221
- package/dist/client/document.d.ts +2 -0
- package/dist/client/link.js +11 -0
- package/dist/client.js +11 -0
- package/dist/config.d.ts +7 -2
- package/dist/config.js +24 -1
- package/dist/furin.js +217 -82
- package/dist/rsc-client.js +9 -1
- package/dist/rsc.js +19 -7
- package/dist/server/browser-events/shutdown.d.ts +3 -0
- package/dist/server/cache/redis/index.d.ts +2 -0
- package/dist/server/cache/redis/index.js +67 -12
- package/dist/server/cache/redis/scripts.d.ts +5 -5
- package/dist/server/dev/plugin.d.ts +1 -0
- package/dist/server/evlog.d.ts +1 -1
- package/dist/server/internal.js +3 -1
- package/dist/server/production-server.d.ts +13 -0
- package/dist/server/production-server.js +2906 -0
- package/dist/server/router/hmr.d.ts +6 -0
- package/dist/server/router/hmr.production.d.ts +5 -0
- package/dist/server/router/plugin.d.ts +5 -1
- package/dist/server/sync/index.js +5 -2
- package/dist/server/sync/stream.d.ts +4 -0
- package/dist/shared/production-build.d.ts +2 -0
- package/package.json +8 -3
- package/src/adapter/bun.ts +74 -15
- package/src/adapter/vercel.ts +15 -1
- package/src/build/elysia-aot.ts +1 -1
- package/src/build/entry-template.ts +3 -1
- package/src/build/hydrate.ts +5 -1
- package/src/build/index.ts +5 -0
- package/src/build/private-server-sourcemaps.ts +20 -0
- package/src/build/server-app-entry.ts +3 -2
- package/src/build/types.ts +2 -0
- package/src/cli/index.ts +1 -0
- package/src/client/document.tsx +19 -0
- package/src/config.ts +30 -2
- package/src/furin.ts +37 -12
- package/src/rsc/codec.ts +11 -6
- package/src/rsc/render-error.ts +3 -1
- package/src/server/browser-events/plugin.ts +7 -0
- package/src/server/browser-events/shutdown.ts +32 -0
- package/src/server/cache/redis/index.ts +19 -2
- package/src/server/cache/redis/scripts.ts +47 -7
- package/src/server/dev/plugin.ts +10 -1
- package/src/server/evlog.ts +11 -4
- package/src/server/production-server.ts +135 -0
- package/src/server/render/document.tsx +7 -1
- package/src/server/render/ssr.ts +2 -1
- package/src/server/render/template.ts +5 -1
- package/src/server/router/discovery.ts +3 -1
- package/src/server/router/hmr.production.ts +11 -0
- package/src/server/router/hmr.ts +84 -77
- package/src/server/router/plugin.ts +76 -17
- package/src/server/router/schema-merge.ts +9 -2
- package/src/server/sync/stream.ts +43 -2
- package/src/shared/production-build.ts +20 -0
|
@@ -4,6 +4,7 @@ import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
|
4
4
|
import { type CompileContext } from "../internal.ts";
|
|
5
5
|
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
6
6
|
type RouteModuleImport = (specifier: string) => Promise<Record<string, unknown>>;
|
|
7
|
+
export declare function reportDevRouteFailure(error: unknown, route: ResolvedRoute): void;
|
|
7
8
|
/**
|
|
8
9
|
* Reuses one virtual ESM module per source version. A timestamp generated on
|
|
9
10
|
* every request leaks module-registry entries because Bun cannot release old
|
|
@@ -39,6 +40,11 @@ export declare function refreshLayoutChain(chain: RuntimeRoute[], pagePath: stri
|
|
|
39
40
|
* `notFound`) are scan-time invariants in dev and are preserved as-is.
|
|
40
41
|
*/
|
|
41
42
|
export declare function rebuildDevRoute(base: ResolvedRoute, page: RuntimePage, chain: RuntimeRoute[]): ResolvedRoute;
|
|
43
|
+
/** Resolve the current source-version modules for both HTML and data requests. */
|
|
44
|
+
export declare function resolveCurrentDevRoute(route: ResolvedRoute, root: RootLayout): Promise<{
|
|
45
|
+
route: ResolvedRoute;
|
|
46
|
+
root: RootLayout;
|
|
47
|
+
}>;
|
|
42
48
|
/** @internal Handles a request in dev mode using the current source-version modules. */
|
|
43
49
|
export declare function handleDevRequest(route: ResolvedRoute, ctx: Context, root: RootLayout, searchRoutes?: SearchRouteMetadata[]): Promise<unknown>;
|
|
44
50
|
/**
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
export declare function handleDevRequest(): Promise<never>;
|
|
2
|
+
export declare function resolveCurrentDevRoute<Route, Root>(route: Route, root: Root): Promise<{
|
|
3
|
+
route: Route;
|
|
4
|
+
root: Root;
|
|
5
|
+
}>;
|
|
6
|
+
export declare function reportDevRouteFailure(): void;
|
|
2
7
|
export declare function invalidateStampedRouteModules(): void;
|
|
@@ -2,6 +2,10 @@ import { type AnyElysia, type Context } from "elysia";
|
|
|
2
2
|
import type { SearchRouteMetadata } from "../../shared/search-params.ts";
|
|
3
3
|
import type { ResolvedRoute, ResolvedRoutesSource, RootLayout } from "./types.ts";
|
|
4
4
|
type DataResolvedRoutesSource = ResolvedRoutesSource | ((request: Request) => Promise<ResolvedRoute[]>);
|
|
5
|
+
type RefreshDevRoute = (route: ResolvedRoute) => Promise<{
|
|
6
|
+
route: ResolvedRoute;
|
|
7
|
+
root: RootLayout;
|
|
8
|
+
}>;
|
|
5
9
|
export declare function createRoutePlugin(route: ResolvedRoute, root: RootLayout, buildId?: string, searchRoutes?: SearchRouteMetadata[]): AnyElysia;
|
|
6
10
|
export declare function renderResolvedRoute(route: ResolvedRoute, ctx: Context, root: RootLayout, buildId: string, searchRoutes: SearchRouteMetadata[] | undefined): unknown;
|
|
7
11
|
/**
|
|
@@ -17,5 +21,5 @@ export declare function renderResolvedRoute(route: ResolvedRoute, ctx: Context,
|
|
|
17
21
|
* - `__furinNotFound` — not-found payload
|
|
18
22
|
* - `__furinRedirect` — logical path after a server-side redirect
|
|
19
23
|
*/
|
|
20
|
-
export declare function createDataEndpoint(routesSource: DataResolvedRoutesSource, root?: RootLayout): AnyElysia;
|
|
24
|
+
export declare function createDataEndpoint(routesSource: DataResolvedRoutesSource, root?: RootLayout, refreshDevRoute?: RefreshDevRoute): AnyElysia;
|
|
21
25
|
export {};
|
|
@@ -2693,7 +2693,7 @@ var init_toolkit = __esm(() => {
|
|
|
2693
2693
|
|
|
2694
2694
|
// src/server/evlog.ts
|
|
2695
2695
|
import { Elysia } from "elysia";
|
|
2696
|
-
var loggerStorage, integration, getRequestLogger;
|
|
2696
|
+
var loggerStorage, integration, getRequestLogger, runtimeWaitUntil;
|
|
2697
2697
|
var init_evlog = __esm(() => {
|
|
2698
2698
|
init_toolkit();
|
|
2699
2699
|
loggerStorage = createLoggerStorage("Furin request context. Make sure the Furin plugin is registered before your routes.", "@teyik0/furin:evlog");
|
|
@@ -2714,6 +2714,7 @@ var init_evlog = __esm(() => {
|
|
|
2714
2714
|
storage: loggerStorage.storage
|
|
2715
2715
|
});
|
|
2716
2716
|
getRequestLogger = loggerStorage.useLogger;
|
|
2717
|
+
runtimeWaitUntil = new Set;
|
|
2717
2718
|
});
|
|
2718
2719
|
|
|
2719
2720
|
// src/server/context-logger.ts
|
|
@@ -2820,13 +2821,15 @@ function createSyncChangesPlugin(options) {
|
|
|
2820
2821
|
};
|
|
2821
2822
|
});
|
|
2822
2823
|
}
|
|
2823
|
-
var DEFAULT_CHANGE_LIMIT = 100, MAX_CHANGE_LIMIT = 500, MAX_CURSOR_LENGTH = 128, UNSIGNED_INTEGER_PATTERN, defaultSyncPath = "/_furin/sync", cursorStates, resolvedStates;
|
|
2824
|
+
var DEFAULT_CHANGE_LIMIT = 100, MAX_CHANGE_LIMIT = 500, MAX_CURSOR_LENGTH = 128, UNSIGNED_INTEGER_PATTERN, defaultSyncPath = "/_furin/sync", cursorStates, resolvedStates, pendingUnsubscriptions, unsubscriptions;
|
|
2824
2825
|
var init_stream = __esm(() => {
|
|
2825
2826
|
init_config();
|
|
2826
2827
|
init_runtime();
|
|
2827
2828
|
UNSIGNED_INTEGER_PATTERN = /^\d+$/;
|
|
2828
2829
|
cursorStates = new Map;
|
|
2829
2830
|
resolvedStates = new Set;
|
|
2831
|
+
pendingUnsubscriptions = new Set;
|
|
2832
|
+
unsubscriptions = new WeakMap;
|
|
2830
2833
|
});
|
|
2831
2834
|
|
|
2832
2835
|
// src/server/sync/index.ts
|
|
@@ -41,3 +41,7 @@ export declare function createSyncChangesPlugin(options: FurinSyncOptions): impo
|
|
|
41
41
|
}>>;
|
|
42
42
|
/** @internal — closes process-local stream state between tests. */
|
|
43
43
|
export declare function __resetSyncState(): void;
|
|
44
|
+
/** Release process-local Sync subscriptions after Bun has drained HTTP traffic. */
|
|
45
|
+
export declare function closeSyncCursorStates(): Promise<void>;
|
|
46
|
+
/** Wait for released connections without closing subscriptions owned by other servers. */
|
|
47
|
+
export declare function waitForSyncCursorUnsubscriptions(): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.2",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -113,6 +113,11 @@
|
|
|
113
113
|
"bun": "./src/server/internal.ts",
|
|
114
114
|
"import": "./dist/server/internal.js"
|
|
115
115
|
},
|
|
116
|
+
"./production-server": {
|
|
117
|
+
"types": "./dist/server/production-server.d.ts",
|
|
118
|
+
"bun": "./src/server/production-server.ts",
|
|
119
|
+
"import": "./dist/server/production-server.js"
|
|
120
|
+
},
|
|
116
121
|
"./server-only": {
|
|
117
122
|
"types": "./dist/server-only.d.ts",
|
|
118
123
|
"bun": "./src/server-only.ts",
|
|
@@ -157,7 +162,6 @@
|
|
|
157
162
|
"magic-string": "^1.2.3",
|
|
158
163
|
"react-server-dom-webpack": "19.2.8",
|
|
159
164
|
"seroval": "^1.6.7",
|
|
160
|
-
"typebox": "1.3.34",
|
|
161
165
|
"yuku-ast": "0.9.5",
|
|
162
166
|
"yuku-parser": "0.9.5"
|
|
163
167
|
},
|
|
@@ -170,7 +174,8 @@
|
|
|
170
174
|
"elysia": "2.0.0-beta.19",
|
|
171
175
|
"evlog": "^2.29.0",
|
|
172
176
|
"react": "19.2.8",
|
|
173
|
-
"react-dom": "19.2.8"
|
|
177
|
+
"react-dom": "19.2.8",
|
|
178
|
+
"typebox": "1.3.34"
|
|
174
179
|
},
|
|
175
180
|
"engines": {
|
|
176
181
|
"bun": ">=1.4.0"
|
package/src/adapter/bun.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
import { runBunBuild } from "../build/bun-build.ts";
|
|
4
4
|
import { prepareCompileEntryApps } from "../build/compile-entry.ts";
|
|
5
5
|
import { elysiaAot } from "../build/elysia-aot.ts";
|
|
6
6
|
import type { BuildEntryOptions } from "../build/entry-template.ts";
|
|
7
|
+
import { movePrivateServerSourceMaps } from "../build/private-server-sourcemaps.ts";
|
|
7
8
|
import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
|
|
8
9
|
import { materializeServerAppEntry, serverBootSource } from "../build/server-app-entry.ts";
|
|
9
10
|
import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
|
|
@@ -49,6 +50,63 @@ function compiledServerFilename(platform: NodeJS.Platform): string {
|
|
|
49
50
|
return platform === "win32" ? "server.exe" : "server";
|
|
50
51
|
}
|
|
51
52
|
|
|
53
|
+
function serverSourcemapMode(enabled: boolean | undefined): "external" | "none" {
|
|
54
|
+
return enabled ? "external" : "none";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function relocateServerMaps(
|
|
58
|
+
build: Bun.BuildOutput,
|
|
59
|
+
enabled: boolean | undefined,
|
|
60
|
+
targetDir: string,
|
|
61
|
+
buildRoot: string
|
|
62
|
+
): void {
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
movePrivateServerSourceMaps(
|
|
67
|
+
targetDir,
|
|
68
|
+
join(buildRoot, "private", "server-sourcemaps", "bun"),
|
|
69
|
+
build.outputs.filter((output) => output.kind === "sourcemap").map((output) => output.path)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function writeServerMetafile(
|
|
74
|
+
build: Bun.BuildOutput,
|
|
75
|
+
analyze: boolean | undefined,
|
|
76
|
+
buildRoot: string
|
|
77
|
+
): void {
|
|
78
|
+
if (!analyze) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (build.metafile === undefined) {
|
|
82
|
+
throw new Error("[furin] Bun server build did not produce the requested metafile.");
|
|
83
|
+
}
|
|
84
|
+
const analysisDir = join(buildRoot, "analysis");
|
|
85
|
+
ensureDir(analysisDir);
|
|
86
|
+
const metafilePath = join(analysisDir, "bun-server.json");
|
|
87
|
+
writeFileSync(metafilePath, `${JSON.stringify(build.metafile, null, 2)}\n`);
|
|
88
|
+
console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function finalizeEmbeddedAssets(
|
|
92
|
+
compile: BuildAppOptions["compile"],
|
|
93
|
+
apps: RuntimeTargetApp[],
|
|
94
|
+
targetDir: string,
|
|
95
|
+
manifest: TargetBuildManifest
|
|
96
|
+
): void {
|
|
97
|
+
if (compile !== "embed") {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const app of apps) {
|
|
101
|
+
rmSync(join(targetDir, clientDirNameForPrefix(app.prefix)), {
|
|
102
|
+
force: true,
|
|
103
|
+
recursive: true,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
manifest.clientDir = null;
|
|
107
|
+
manifest.templatePath = null;
|
|
108
|
+
}
|
|
109
|
+
|
|
52
110
|
async function createBunAppEntry(
|
|
53
111
|
apps: RuntimeTargetApp[],
|
|
54
112
|
entryApps: BuildEntryOptions["apps"],
|
|
@@ -109,6 +167,10 @@ export async function buildBunTarget(
|
|
|
109
167
|
const targetDir = resolve(rootDir, targetManifest.targetDir);
|
|
110
168
|
|
|
111
169
|
rmSync(targetDir, { force: true, recursive: true });
|
|
170
|
+
rmSync(join(buildRoot, "private", "server-sourcemaps", "bun"), {
|
|
171
|
+
force: true,
|
|
172
|
+
recursive: true,
|
|
173
|
+
});
|
|
112
174
|
ensureDir(targetDir);
|
|
113
175
|
|
|
114
176
|
const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
|
|
@@ -148,13 +210,14 @@ export async function buildBunTarget(
|
|
|
148
210
|
const entry = generateBootEntry(appEntry, targetDir, "_compile-entry.ts");
|
|
149
211
|
const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
|
|
150
212
|
|
|
151
|
-
await runBunBuild({
|
|
213
|
+
const serverBuild = await runBunBuild({
|
|
152
214
|
bytecode: true,
|
|
153
215
|
compile: { assets: embeddedAssets, outfile },
|
|
154
216
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
155
217
|
entrypoints: [entry.entrypoint],
|
|
156
218
|
files: entry.files,
|
|
157
219
|
format: "esm",
|
|
220
|
+
metafile: options.analyze,
|
|
158
221
|
minify: true,
|
|
159
222
|
plugins: [
|
|
160
223
|
entry.plugin,
|
|
@@ -166,33 +229,27 @@ export async function buildBunTarget(
|
|
|
166
229
|
environmentGuardPlugin("ssr"),
|
|
167
230
|
elysiaAot(appEntry),
|
|
168
231
|
],
|
|
169
|
-
sourcemap:
|
|
232
|
+
sourcemap: serverSourcemapMode(options.serverSourceMaps),
|
|
170
233
|
splitting: true,
|
|
171
234
|
target: "bun",
|
|
172
235
|
});
|
|
236
|
+
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
237
|
+
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
173
238
|
|
|
174
239
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
175
240
|
|
|
176
241
|
targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, serverFilename));
|
|
177
242
|
|
|
178
243
|
// Embed mode: assets are in the binary — clean up client dirs too.
|
|
179
|
-
|
|
180
|
-
for (const app of apps) {
|
|
181
|
-
rmSync(join(targetDir, clientDirNameForPrefix(app.prefix)), {
|
|
182
|
-
force: true,
|
|
183
|
-
recursive: true,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
targetManifest.clientDir = null;
|
|
187
|
-
targetManifest.templatePath = null;
|
|
188
|
-
}
|
|
244
|
+
finalizeEmbeddedAssets(options.compile, apps, targetDir, targetManifest);
|
|
189
245
|
} else if (serverEntry && appEntry) {
|
|
190
246
|
// Disk mode: generate server.ts then bundle it into self-contained server.js
|
|
191
247
|
const entry = generateBootEntry(appEntry, targetDir, "server.ts");
|
|
192
248
|
|
|
193
|
-
await runBunBuild({
|
|
249
|
+
const serverBuild = await runBunBuild({
|
|
194
250
|
entrypoints: [entry.entrypoint],
|
|
195
251
|
files: entry.files,
|
|
252
|
+
metafile: options.analyze,
|
|
196
253
|
minify: true,
|
|
197
254
|
naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
|
|
198
255
|
outdir: targetDir,
|
|
@@ -206,9 +263,11 @@ export async function buildBunTarget(
|
|
|
206
263
|
environmentGuardPlugin("ssr"),
|
|
207
264
|
elysiaAot(appEntry),
|
|
208
265
|
],
|
|
209
|
-
sourcemap:
|
|
266
|
+
sourcemap: serverSourcemapMode(options.serverSourceMaps),
|
|
210
267
|
target: "bun",
|
|
211
268
|
});
|
|
269
|
+
relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
|
|
270
|
+
writeServerMetafile(serverBuild, options.analyze, buildRoot);
|
|
212
271
|
console.log(
|
|
213
272
|
`[furin] Server bundle: ${toPosixPath(join(targetManifest.targetDir, "server.js"))}`
|
|
214
273
|
);
|
package/src/adapter/vercel.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { basename, dirname, extname, join, relative } from "node:path";
|
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { runBunBuild } from "../build/bun-build.ts";
|
|
5
5
|
import { elysiaAot } from "../build/elysia-aot.ts";
|
|
6
|
+
import { movePrivateServerSourceMaps } from "../build/private-server-sourcemaps.ts";
|
|
6
7
|
import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
|
|
7
8
|
import { materializeServerAppEntry } from "../build/server-app-entry.ts";
|
|
8
9
|
import { ensureDir, toPosixPath } from "../build/shared.ts";
|
|
@@ -695,6 +696,10 @@ export async function buildVercelTarget(
|
|
|
695
696
|
const functionsDir = join(outputDir, "functions");
|
|
696
697
|
const serverFunctionDir = join(functionsDir, "__server.func");
|
|
697
698
|
rmSync(targetDir, { force: true, recursive: true });
|
|
699
|
+
rmSync(join(buildRoot, "private", "server-sourcemaps", "vercel"), {
|
|
700
|
+
force: true,
|
|
701
|
+
recursive: true,
|
|
702
|
+
});
|
|
698
703
|
rmSync(outputDir, { force: true, recursive: true });
|
|
699
704
|
ensureDir(targetDir);
|
|
700
705
|
ensureDir(staticDir);
|
|
@@ -771,10 +776,19 @@ export async function buildVercelTarget(
|
|
|
771
776
|
environmentGuardPlugin("ssr"),
|
|
772
777
|
elysiaAot(appEntry),
|
|
773
778
|
],
|
|
774
|
-
sourcemap: "none",
|
|
779
|
+
sourcemap: options.serverSourceMaps ? "external" : "none",
|
|
775
780
|
splitting: true,
|
|
776
781
|
target: "bun",
|
|
777
782
|
});
|
|
783
|
+
if (options.serverSourceMaps) {
|
|
784
|
+
movePrivateServerSourceMaps(
|
|
785
|
+
serverFunctionDir,
|
|
786
|
+
join(buildRoot, "private", "server-sourcemaps", "vercel"),
|
|
787
|
+
serverBuild.outputs
|
|
788
|
+
.filter((output) => output.kind === "sourcemap")
|
|
789
|
+
.map((output) => output.path)
|
|
790
|
+
);
|
|
791
|
+
}
|
|
778
792
|
if (options.analyze) {
|
|
779
793
|
if (serverBuild.metafile === undefined) {
|
|
780
794
|
throw new Error("[furin] Vercel server build did not produce the requested metafile.");
|
package/src/build/elysia-aot.ts
CHANGED
|
@@ -42,7 +42,7 @@ export function handleWSResponse(){return e()}
|
|
|
42
42
|
/** Elysia AOT plugin with the no-WebSocket stub compatibility fix. */
|
|
43
43
|
export function elysiaAot(entry: string): Bun.BunPlugin {
|
|
44
44
|
const entryPath = resolve(entry);
|
|
45
|
-
const hooks = aotFactory({ entry, strip:
|
|
45
|
+
const hooks = aotFactory({ entry, strip: false, target: "bun" });
|
|
46
46
|
return {
|
|
47
47
|
name: "elysia-aot",
|
|
48
48
|
async setup(build) {
|
|
@@ -224,7 +224,7 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
224
224
|
"",
|
|
225
225
|
"// Force production mode — Bun may inline process.env.NODE_ENV at bundle time.",
|
|
226
226
|
"__setDevMode(false);",
|
|
227
|
-
'process.env.NODE_ENV = "production";',
|
|
227
|
+
...(mode === "boot" ? ['process.env.NODE_ENV = "production";'] : []),
|
|
228
228
|
]
|
|
229
229
|
: []),
|
|
230
230
|
...contextBlocks,
|
|
@@ -254,7 +254,9 @@ export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
|
254
254
|
`const __serverModule = await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
255
255
|
"export const app = __serverModule.default;",
|
|
256
256
|
"export const port = __serverModule.port;",
|
|
257
|
+
"export const idleTimeout = __serverModule.idleTimeout;",
|
|
257
258
|
"export const startServer = __serverModule.startServer;",
|
|
259
|
+
"export const onShutdown = __serverModule.onShutdown;",
|
|
258
260
|
"export default __serverModule.default;",
|
|
259
261
|
"",
|
|
260
262
|
]
|
package/src/build/hydrate.ts
CHANGED
|
@@ -206,6 +206,7 @@ const _match = routes.find((r) => r.regex.test(pathname));
|
|
|
206
206
|
// a matched loader threw notFound(). The latter still has a _match; the
|
|
207
207
|
// former does not — so the two cases fork on _match below.
|
|
208
208
|
const dataEl = document.getElementById("__FURIN_DATA__");
|
|
209
|
+
const frameTemplate = document.getElementById("__FURIN_ROUTE_FRAMES__") as HTMLTemplateElement | null;
|
|
209
210
|
let loaderData = dataEl ? JSON.parse(dataEl.textContent || "{}") : {};
|
|
210
211
|
const syncEl = document.getElementById("__FURIN_SYNC__");
|
|
211
212
|
const syncConfig = syncEl ? JSON.parse(syncEl.textContent || "{}") : {};
|
|
@@ -222,6 +223,7 @@ const documentState: DocumentState = {
|
|
|
222
223
|
assets: {
|
|
223
224
|
buildId,
|
|
224
225
|
entryModule: entryEl?.getAttribute("src") ?? undefined,
|
|
226
|
+
extensionErrorFilterScript: document.querySelector("[data-furin-extension-error-filter]")?.textContent ?? undefined,
|
|
225
227
|
faviconHref,
|
|
226
228
|
frameworkModules,
|
|
227
229
|
staticMode: document.querySelector('meta[name="furin-mode"][content="static"]') !== null,
|
|
@@ -231,6 +233,9 @@ const documentState: DocumentState = {
|
|
|
231
233
|
},
|
|
232
234
|
dataJson: dataEl?.textContent ?? undefined,
|
|
233
235
|
head,
|
|
236
|
+
routeFrames: frameTemplate?.hasAttribute("data-furin-document-state")
|
|
237
|
+
? (frameTemplate.content.textContent ?? "")
|
|
238
|
+
: undefined,
|
|
234
239
|
syncJson: syncEl?.textContent ?? undefined,
|
|
235
240
|
};
|
|
236
241
|
|
|
@@ -305,7 +310,6 @@ if (__deferred && __deferred._chunks) {
|
|
|
305
310
|
// Wrapped in an async IIFE to avoid top-level await, which causes Bun's HTML
|
|
306
311
|
// bundler to misidentify which chunk to reference as the entry in index.html.
|
|
307
312
|
(async () => {
|
|
308
|
-
const frameTemplate = document.getElementById("__FURIN_ROUTE_FRAMES__") as HTMLTemplateElement | null;
|
|
309
313
|
if (frameTemplate) {
|
|
310
314
|
const payload = frameTemplate.content.textContent || "";
|
|
311
315
|
const routeFrameStream = (window as unknown as { __FURIN_ROUTE_FRAME_STREAM__?: FurinRouteFrameStream })
|
package/src/build/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
|
|
|
11
11
|
import { normalizePrefix } from "../server/instance.ts";
|
|
12
12
|
import { scanPages } from "../server/router/discovery.ts";
|
|
13
13
|
import { assertNoPrefixSlugCollisions } from "../shared/prefix.ts";
|
|
14
|
+
import { withProductionBuild } from "../shared/production-build.ts";
|
|
14
15
|
import { scanFurinInstances } from "./scan-server";
|
|
15
16
|
import { ensureDir, toBuildRouteManifestEntry, toPosixPath } from "./shared";
|
|
16
17
|
import type { BuildAppOptions, BuildAppResult, BuildManifest } from "./types";
|
|
@@ -82,6 +83,10 @@ function resolveAppSpecs(
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
export async function buildApp(options: BuildAppOptions): Promise<BuildAppResult> {
|
|
86
|
+
return withProductionBuild(() => buildAppInternal(options));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function buildAppInternal(options: BuildAppOptions): Promise<BuildAppResult> {
|
|
85
90
|
const rootDir = resolve(options.rootDir ?? process.cwd());
|
|
86
91
|
const buildRoot = join(rootDir, BUILD_OUTPUT_DIR);
|
|
87
92
|
const serverEntry = (() => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { existsSync, renameSync } from "node:fs";
|
|
2
|
+
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
3
|
+
import { ensureDir } from "./shared.ts";
|
|
4
|
+
|
|
5
|
+
/** Keep server maps out of Bun assets and Vercel's deployment artifact. */
|
|
6
|
+
export function movePrivateServerSourceMaps(
|
|
7
|
+
outputDir: string,
|
|
8
|
+
privateDir: string,
|
|
9
|
+
filenames: readonly string[]
|
|
10
|
+
): void {
|
|
11
|
+
for (const filename of filenames) {
|
|
12
|
+
const source = isAbsolute(filename) ? filename : join(outputDir, filename);
|
|
13
|
+
if (!existsSync(source)) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const destination = join(privateDir, relative(outputDir, source));
|
|
17
|
+
ensureDir(dirname(destination));
|
|
18
|
+
renameSync(source, destination);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -45,7 +45,8 @@ export async function materializeServerAppEntry(
|
|
|
45
45
|
|
|
46
46
|
export function serverBootSource(appEntry: string): string {
|
|
47
47
|
return `// Auto-generated by furin build - do not edit
|
|
48
|
-
import
|
|
48
|
+
import { startProductionServer } from "@teyik0/furin/production-server";
|
|
49
|
+
import app, { idleTimeout, onShutdown, port, startServer } from ${JSON.stringify(toPosixPath(appEntry))};
|
|
49
50
|
|
|
50
51
|
if (typeof startServer === "function") {
|
|
51
52
|
await startServer();
|
|
@@ -53,7 +54,7 @@ if (typeof startServer === "function") {
|
|
|
53
54
|
const serverPort = process.env.PORT === undefined
|
|
54
55
|
? typeof port === "number" ? port : 3000
|
|
55
56
|
: Number(process.env.PORT);
|
|
56
|
-
app
|
|
57
|
+
startProductionServer({ app, idleTimeout, onShutdown, port: serverPort });
|
|
57
58
|
console.log(\`[furin] Server running at http://localhost:\${app.server?.port}\`);
|
|
58
59
|
}
|
|
59
60
|
`;
|
package/src/build/types.ts
CHANGED
|
@@ -116,6 +116,8 @@ export interface BuildAppOptions {
|
|
|
116
116
|
reactCompiler?: boolean;
|
|
117
117
|
rootDir?: string;
|
|
118
118
|
serverEntry?: string;
|
|
119
|
+
/** Emit server source maps outside deployable output directories. */
|
|
120
|
+
serverSourceMaps?: boolean;
|
|
119
121
|
/** Configuration for the `static` build target. */
|
|
120
122
|
staticConfig?: StaticExportConfig;
|
|
121
123
|
target: BuildTarget | "all";
|
package/src/cli/index.ts
CHANGED
|
@@ -184,6 +184,7 @@ if (command === "preview") {
|
|
|
184
184
|
reactCompiler: config.reactCompiler,
|
|
185
185
|
rootDir: config.rootDir,
|
|
186
186
|
serverEntry: resolvedServerEntry,
|
|
187
|
+
serverSourceMaps: config.serverSourceMaps,
|
|
187
188
|
staticConfig: config.static,
|
|
188
189
|
target: target as BuildTarget | "all",
|
|
189
190
|
vercelConfig: config.vercel,
|
package/src/client/document.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import type { HeadOptions, MetaDescriptor } from "../client.ts";
|
|
|
4
4
|
export interface DocumentAssets {
|
|
5
5
|
buildId: string | undefined;
|
|
6
6
|
entryModule: string | undefined;
|
|
7
|
+
extensionErrorFilterScript?: string;
|
|
7
8
|
faviconHref: string | undefined;
|
|
8
9
|
frameworkModules: readonly string[];
|
|
9
10
|
staticMode: boolean;
|
|
@@ -14,6 +15,7 @@ export interface DocumentState {
|
|
|
14
15
|
assets: DocumentAssets;
|
|
15
16
|
dataJson: string | undefined;
|
|
16
17
|
head: HeadOptions | undefined;
|
|
18
|
+
routeFrames?: string;
|
|
17
19
|
syncJson: string | undefined;
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -70,6 +72,13 @@ export function HeadContent(): ReactNode {
|
|
|
70
72
|
|
|
71
73
|
return (
|
|
72
74
|
<>
|
|
75
|
+
{state.assets.extensionErrorFilterScript === undefined ? null : (
|
|
76
|
+
<script
|
|
77
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: framework-owned development script.
|
|
78
|
+
dangerouslySetInnerHTML={{ __html: state.assets.extensionErrorFilterScript }}
|
|
79
|
+
data-furin-extension-error-filter=""
|
|
80
|
+
/>
|
|
81
|
+
)}
|
|
73
82
|
<meta charSet="utf-8" data-furin-head="" />
|
|
74
83
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
|
75
84
|
{state.assets.buildId ? <meta content={state.assets.buildId} name="furin-build-id" /> : null}
|
|
@@ -129,6 +138,16 @@ export function Scripts(): ReactNode {
|
|
|
129
138
|
type="application/json"
|
|
130
139
|
/>
|
|
131
140
|
)}
|
|
141
|
+
{state.routeFrames === undefined ? null : (
|
|
142
|
+
<template
|
|
143
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: route frames are escaped before insertion.
|
|
144
|
+
dangerouslySetInnerHTML={{
|
|
145
|
+
__html: state.routeFrames.replaceAll("&", "&").replaceAll("<", "<"),
|
|
146
|
+
}}
|
|
147
|
+
data-furin-document-state=""
|
|
148
|
+
id="__FURIN_ROUTE_FRAMES__"
|
|
149
|
+
/>
|
|
150
|
+
)}
|
|
132
151
|
<script
|
|
133
152
|
// biome-ignore lint/security/noDangerouslySetInnerHtml: value is escaped framework JSON.
|
|
134
153
|
dangerouslySetInnerHTML={{ __html: serializeJson(state.head ?? {}) }}
|
package/src/config.ts
CHANGED
|
@@ -6,6 +6,32 @@ export const BUILD_TARGETS = ["bun", "vercel", "static", "package"] as const;
|
|
|
6
6
|
|
|
7
7
|
export type BuildTarget = (typeof BUILD_TARGETS)[number];
|
|
8
8
|
|
|
9
|
+
// https://vercel.com/docs/regions#region-list
|
|
10
|
+
const VERCEL_REGIONS = [
|
|
11
|
+
"arn1",
|
|
12
|
+
"bom1",
|
|
13
|
+
"cdg1",
|
|
14
|
+
"cle1",
|
|
15
|
+
"cpt1",
|
|
16
|
+
"dub1",
|
|
17
|
+
"dxb1",
|
|
18
|
+
"fra1",
|
|
19
|
+
"gru1",
|
|
20
|
+
"hkg1",
|
|
21
|
+
"hnd1",
|
|
22
|
+
"iad1",
|
|
23
|
+
"icn1",
|
|
24
|
+
"kix1",
|
|
25
|
+
"lhr1",
|
|
26
|
+
"pdx1",
|
|
27
|
+
"sfo1",
|
|
28
|
+
"sin1",
|
|
29
|
+
"syd1",
|
|
30
|
+
"yul1",
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
export type VercelRegion = (typeof VERCEL_REGIONS)[number];
|
|
34
|
+
|
|
9
35
|
/**
|
|
10
36
|
* Configuration for the `static` build target.
|
|
11
37
|
* Produces a fully pre-rendered directory deployable to any static host
|
|
@@ -34,7 +60,7 @@ export interface StaticExportConfig {
|
|
|
34
60
|
|
|
35
61
|
export interface VercelDeploymentConfig {
|
|
36
62
|
/** Vercel compute regions, such as "cdg1" or "iad1". */
|
|
37
|
-
regions?:
|
|
63
|
+
regions?: VercelRegion[];
|
|
38
64
|
}
|
|
39
65
|
|
|
40
66
|
const buildTargetSchema = t.Union(BUILD_TARGETS.map((v) => t.Literal(v)));
|
|
@@ -79,6 +105,8 @@ export const configSchema = t.Object({
|
|
|
79
105
|
reactCompiler: t.Optional(t.Boolean()),
|
|
80
106
|
rootDir: t.Optional(t.String()),
|
|
81
107
|
serverEntry: t.Optional(t.String()),
|
|
108
|
+
/** Emit private server source maps for error-tool uploads. Off by default. */
|
|
109
|
+
serverSourceMaps: t.Optional(t.Boolean()),
|
|
82
110
|
static: t.Optional(
|
|
83
111
|
t.Object({
|
|
84
112
|
basePath: t.Optional(t.String()),
|
|
@@ -90,7 +118,7 @@ export const configSchema = t.Object({
|
|
|
90
118
|
vercel: t.Optional(
|
|
91
119
|
t.Object({
|
|
92
120
|
regions: t.Optional(
|
|
93
|
-
t.Array(t.
|
|
121
|
+
t.Array(t.Enum(VERCEL_REGIONS), {
|
|
94
122
|
minItems: 1,
|
|
95
123
|
uniqueItems: true,
|
|
96
124
|
})
|