@teyik0/furin 0.4.0-alpha.2 → 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.
Files changed (129) hide show
  1. package/dist/build/compile-entry.d.ts +2 -1
  2. package/dist/build/compile-entry.ts +17 -13
  3. package/dist/build/elysia-aot.d.ts +9 -0
  4. package/dist/build/entry-template.d.ts +5 -1
  5. package/dist/build/entry-template.ts +27 -6
  6. package/dist/build/index.js +969 -528
  7. package/dist/build/private-server-sourcemaps.d.ts +2 -0
  8. package/dist/build/server-app-entry.d.ts +12 -0
  9. package/dist/build/types.d.ts +2 -0
  10. package/dist/cache.d.ts +1 -0
  11. package/dist/cache.js +185 -0
  12. package/dist/cli/index.js +983 -541
  13. package/dist/client/document.d.ts +2 -0
  14. package/dist/client/internal/runtime-types.d.ts +8 -1
  15. package/dist/client/link.js +232 -11
  16. package/dist/client/sync.d.ts +1 -0
  17. package/dist/client.js +11 -0
  18. package/dist/config.d.ts +28 -22
  19. package/dist/config.js +25 -2
  20. package/dist/define-route.d.ts +273 -1009
  21. package/dist/furin.d.ts +20 -5
  22. package/dist/furin.js +6431 -5457
  23. package/dist/plugin/routes.d.ts +6 -0
  24. package/dist/rsc-client.js +9 -1
  25. package/dist/rsc.js +19 -7
  26. package/dist/server/assets/production.d.ts +3 -0
  27. package/dist/server/auto-invalidate/plugin.d.ts +8 -24
  28. package/dist/server/auto-invalidate/runtime.d.ts +2 -2
  29. package/dist/server/browser-events/shutdown.d.ts +3 -0
  30. package/dist/server/cache/invalidation.d.ts +1 -1
  31. package/dist/server/cache/page-cache-state.d.ts +5 -0
  32. package/dist/server/cache/page-cache.d.ts +53 -0
  33. package/dist/server/cache/redis/index.d.ts +41 -0
  34. package/dist/server/cache/redis/index.js +451 -0
  35. package/dist/server/cache/redis/scripts.d.ts +6 -0
  36. package/dist/server/context-logger.d.ts +2 -2
  37. package/dist/server/dev/plugin.d.ts +1 -0
  38. package/dist/server/dev/runtime.production.d.ts +1 -0
  39. package/dist/server/dev-page-plugin.d.ts +7 -0
  40. package/dist/server/evlog.d.ts +14 -0
  41. package/dist/server/internal.d.ts +6 -0
  42. package/dist/server/internal.js +2539 -0
  43. package/dist/server/production-server.d.ts +13 -0
  44. package/dist/server/production-server.js +2906 -0
  45. package/dist/server/render/not-found.d.ts +1 -1
  46. package/dist/server/render/ssg.d.ts +5 -0
  47. package/dist/server/render/static-params.d.ts +4 -0
  48. package/dist/server/router/defined-route.d.ts +1 -1
  49. package/dist/server/router/hmr.d.ts +6 -0
  50. package/dist/server/router/hmr.production.d.ts +5 -0
  51. package/dist/server/router/plugin.d.ts +5 -1
  52. package/dist/server/router/schemas.d.ts +1 -0
  53. package/dist/server/sync/index.js +798 -117
  54. package/dist/server/sync/plugin.d.ts +31 -158
  55. package/dist/server/sync/stream.d.ts +38 -49
  56. package/dist/shared/elysia-contract.d.ts +8 -14
  57. package/dist/shared/production-build.d.ts +2 -0
  58. package/package.json +19 -8
  59. package/src/adapter/README.md +9 -2
  60. package/src/adapter/bun.ts +146 -41
  61. package/src/adapter/package.ts +6 -2
  62. package/src/adapter/runtime-build.ts +11 -4
  63. package/src/adapter/static.ts +8 -6
  64. package/src/adapter/vercel.ts +64 -31
  65. package/src/build/client.ts +18 -1
  66. package/src/build/compile-entry.ts +17 -13
  67. package/src/build/elysia-aot.ts +102 -0
  68. package/src/build/entry-template.ts +27 -6
  69. package/src/build/hydrate.ts +5 -1
  70. package/src/build/index.ts +5 -5
  71. package/src/build/private-server-sourcemaps.ts +20 -0
  72. package/src/build/production-instrumentation.ts +2 -2
  73. package/src/build/server-app-entry.ts +61 -0
  74. package/src/build/shared.ts +3 -1
  75. package/src/build/ssg-cache.ts +5 -10
  76. package/src/build/types.ts +2 -0
  77. package/src/build/virtual-entry.ts +5 -4
  78. package/src/cache.ts +12 -0
  79. package/src/cli/config.ts +3 -3
  80. package/src/cli/index.ts +6 -2
  81. package/src/client/document.tsx +19 -0
  82. package/src/client/internal/runtime-types.ts +10 -1
  83. package/src/client/sync.ts +1 -0
  84. package/src/config.ts +33 -4
  85. package/src/define-route.ts +266 -128
  86. package/src/furin.ts +168 -154
  87. package/src/plugin/route-config-autofix.ts +11 -2
  88. package/src/plugin/routes.ts +85 -29
  89. package/src/rsc/codec.ts +11 -6
  90. package/src/rsc/render-error.ts +3 -1
  91. package/src/server/assets/production.ts +99 -0
  92. package/src/server/auto-invalidate/plugin.ts +4 -4
  93. package/src/server/auto-invalidate/runtime.ts +74 -42
  94. package/src/server/browser-events/plugin.ts +13 -1
  95. package/src/server/browser-events/shutdown.ts +32 -0
  96. package/src/server/cache/invalidation.ts +61 -20
  97. package/src/server/cache/page-cache-state.ts +22 -0
  98. package/src/server/cache/page-cache.ts +300 -0
  99. package/src/server/cache/redis/index.ts +367 -0
  100. package/src/server/cache/redis/scripts.ts +200 -0
  101. package/src/server/context-logger.ts +5 -5
  102. package/src/server/dev/plugin.ts +10 -1
  103. package/src/server/dev/runtime.production.ts +4 -0
  104. package/src/server/dev-page-plugin.ts +54 -10
  105. package/src/server/evlog.ts +106 -0
  106. package/src/server/internal.ts +7 -0
  107. package/src/server/production-server.ts +135 -0
  108. package/src/server/render/document.tsx +7 -1
  109. package/src/server/render/isr.ts +480 -132
  110. package/src/server/render/loaders.ts +18 -12
  111. package/src/server/render/not-found.ts +4 -4
  112. package/src/server/render/ppr-document.ts +2 -2
  113. package/src/server/render/ppr-route.ts +193 -7
  114. package/src/server/render/ssg.ts +148 -4
  115. package/src/server/render/ssr.ts +6 -7
  116. package/src/server/render/static-params.ts +174 -0
  117. package/src/server/render/template.ts +5 -1
  118. package/src/server/router/defined-route.ts +2 -1
  119. package/src/server/router/discovery.ts +3 -1
  120. package/src/server/router/hmr.production.ts +11 -0
  121. package/src/server/router/hmr.ts +85 -76
  122. package/src/server/router/plugin.ts +118 -50
  123. package/src/server/router/schema-merge.ts +10 -3
  124. package/src/server/router/schemas.ts +174 -61
  125. package/src/server/sync/plugin.ts +14 -10
  126. package/src/server/sync/response.ts +3 -3
  127. package/src/server/sync/stream.ts +43 -2
  128. package/src/shared/elysia-contract.ts +23 -25
  129. package/src/shared/production-build.ts +20 -0
@@ -1,9 +1,12 @@
1
- import { existsSync, 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
- import { generateCompileEntry } from "../build/compile-entry.ts";
5
- import { type BuildEntryOptions, buildEntrySource } from "../build/entry-template.ts";
4
+ import { prepareCompileEntryApps } from "../build/compile-entry.ts";
5
+ import { elysiaAot } from "../build/elysia-aot.ts";
6
+ import type { BuildEntryOptions } from "../build/entry-template.ts";
7
+ import { movePrivateServerSourceMaps } from "../build/private-server-sourcemaps.ts";
6
8
  import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
9
+ import { materializeServerAppEntry, serverBootSource } from "../build/server-app-entry.ts";
7
10
  import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
8
11
  import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
9
12
  import { createVirtualBuildEntry, type VirtualBuildEntry } from "../build/virtual-entry.ts";
@@ -18,15 +21,14 @@ import {
18
21
  type RuntimeTargetApp,
19
22
  } from "./runtime-build.ts";
20
23
 
21
- function generateDiskEntry(options: BuildEntryOptions): VirtualBuildEntry {
22
- ensureDir(options.outDir);
23
- const source = buildEntrySource({
24
- apps: options.apps.map(({ embed: _embed, ...context }) => context),
25
- headerComment: "// Auto-generated by furin build - do not edit",
26
- serverEntry: options.serverEntry,
27
- });
28
- const entryPath = join(options.outDir, "server.ts");
29
- return createVirtualBuildEntry(entryPath, source, "ts");
24
+ function generateBootEntry(
25
+ appEntry: string,
26
+ outDir: string,
27
+ filename: "_compile-entry.ts" | "server.ts"
28
+ ): VirtualBuildEntry {
29
+ ensureDir(outDir);
30
+ const entryPath = join(outDir, filename);
31
+ return createVirtualBuildEntry(entryPath, serverBootSource(appEntry), "ts");
30
32
  }
31
33
 
32
34
  function collectEmbeddedAssets(
@@ -44,6 +46,105 @@ function collectEmbeddedAssets(
44
46
  return assets;
45
47
  }
46
48
 
49
+ function compiledServerFilename(platform: NodeJS.Platform): string {
50
+ return platform === "win32" ? "server.exe" : "server";
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
+
110
+ async function createBunAppEntry(
111
+ apps: RuntimeTargetApp[],
112
+ entryApps: BuildEntryOptions["apps"],
113
+ options: BuildAppOptions,
114
+ publicDir: string | undefined,
115
+ serverEntry: string | null,
116
+ targetDir: string
117
+ ): Promise<string | undefined> {
118
+ if (!serverEntry) {
119
+ return;
120
+ }
121
+ const contexts = options.compile
122
+ ? prepareCompileEntryApps({
123
+ apps: entryApps,
124
+ outDir: targetDir,
125
+ publicDir,
126
+ serverEntry,
127
+ })
128
+ : entryApps.map(({ embed: _embed, ...context }) => ({
129
+ ...context,
130
+ extraContext: [
131
+ ...(context.extraContext ?? []),
132
+ ` clientDir: import.meta.dir + ${JSON.stringify(`/${clientDirNameForPrefix(context.prefix ?? "")}`)},`,
133
+ ],
134
+ templateHtml: readFileSync(
135
+ join(targetDir, clientDirNameForPrefix(context.prefix ?? ""), "index.html"),
136
+ "utf8"
137
+ ),
138
+ }));
139
+ return await materializeServerAppEntry({
140
+ apps: contexts,
141
+ headerComment: "// Auto-generated by furin build - do not edit",
142
+ instances: apps,
143
+ outDir: targetDir,
144
+ serverEntry,
145
+ });
146
+ }
147
+
47
148
  export async function buildBunTarget(
48
149
  apps: RuntimeTargetApp[],
49
150
  rootDir: string,
@@ -66,6 +167,10 @@ export async function buildBunTarget(
66
167
  const targetDir = resolve(rootDir, targetManifest.targetDir);
67
168
 
68
169
  rmSync(targetDir, { force: true, recursive: true });
170
+ rmSync(join(buildRoot, "private", "server-sourcemaps", "bun"), {
171
+ force: true,
172
+ recursive: true,
173
+ });
69
174
  ensureDir(targetDir);
70
175
 
71
176
  const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
@@ -89,24 +194,30 @@ export async function buildBunTarget(
89
194
  copyDirRecursive(publicDir, targetPublicDir);
90
195
  }
91
196
 
92
- if (options.compile && serverEntry) {
93
- const outfile = join(targetDir, "server");
197
+ const appEntry = await createBunAppEntry(
198
+ apps,
199
+ entryApps,
200
+ options,
201
+ publicDir,
202
+ serverEntry,
203
+ targetDir
204
+ );
94
205
 
95
- const entry = generateCompileEntry({
96
- apps: entryApps,
97
- outDir: targetDir,
98
- publicDir,
99
- serverEntry,
100
- });
206
+ if (options.compile && serverEntry && appEntry) {
207
+ const serverFilename = compiledServerFilename(process.platform);
208
+ const outfile = join(targetDir, serverFilename);
209
+
210
+ const entry = generateBootEntry(appEntry, targetDir, "_compile-entry.ts");
101
211
  const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
102
212
 
103
- await runBunBuild({
213
+ const serverBuild = await runBunBuild({
104
214
  bytecode: true,
105
215
  compile: { assets: embeddedAssets, outfile },
106
216
  define: { "process.env.NODE_ENV": JSON.stringify("production") },
107
217
  entrypoints: [entry.entrypoint],
108
218
  files: entry.files,
109
219
  format: "esm",
220
+ metafile: options.analyze,
110
221
  minify: true,
111
222
  plugins: [
112
223
  entry.plugin,
@@ -116,38 +227,29 @@ export async function buildBunTarget(
116
227
  createRoutesPlugin({ instances: apps, target: "server" }),
117
228
  isomorphicTransformPlugin("server"),
118
229
  environmentGuardPlugin("ssr"),
230
+ elysiaAot(appEntry),
119
231
  ],
120
- sourcemap: "none",
232
+ sourcemap: serverSourcemapMode(options.serverSourceMaps),
121
233
  splitting: true,
122
234
  target: "bun",
123
235
  });
236
+ relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
237
+ writeServerMetafile(serverBuild, options.analyze, buildRoot);
124
238
 
125
239
  console.log(`[furin] Server binary: ${outfile}`);
126
240
 
127
- targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, "server"));
241
+ targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, serverFilename));
128
242
 
129
243
  // Embed mode: assets are in the binary — clean up client dirs too.
130
- if (options.compile === "embed") {
131
- for (const app of apps) {
132
- rmSync(join(targetDir, clientDirNameForPrefix(app.prefix)), {
133
- force: true,
134
- recursive: true,
135
- });
136
- }
137
- targetManifest.clientDir = null;
138
- targetManifest.templatePath = null;
139
- }
140
- } else if (serverEntry) {
244
+ finalizeEmbeddedAssets(options.compile, apps, targetDir, targetManifest);
245
+ } else if (serverEntry && appEntry) {
141
246
  // Disk mode: generate server.ts then bundle it into self-contained server.js
142
- const entry = generateDiskEntry({
143
- apps: entryApps,
144
- outDir: targetDir,
145
- serverEntry,
146
- });
247
+ const entry = generateBootEntry(appEntry, targetDir, "server.ts");
147
248
 
148
- await runBunBuild({
249
+ const serverBuild = await runBunBuild({
149
250
  entrypoints: [entry.entrypoint],
150
251
  files: entry.files,
252
+ metafile: options.analyze,
151
253
  minify: true,
152
254
  naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
153
255
  outdir: targetDir,
@@ -159,10 +261,13 @@ export async function buildBunTarget(
159
261
  createRoutesPlugin({ instances: apps, target: "server" }),
160
262
  isomorphicTransformPlugin("server"),
161
263
  environmentGuardPlugin("ssr"),
264
+ elysiaAot(appEntry),
162
265
  ],
163
- sourcemap: "none",
266
+ sourcemap: serverSourcemapMode(options.serverSourceMaps),
164
267
  target: "bun",
165
268
  });
269
+ relocateServerMaps(serverBuild, options.serverSourceMaps, targetDir, buildRoot);
270
+ writeServerMetafile(serverBuild, options.analyze, buildRoot);
166
271
  console.log(
167
272
  `[furin] Server bundle: ${toPosixPath(join(targetManifest.targetDir, "server.js"))}`
168
273
  );
@@ -8,7 +8,11 @@ import { copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
8
8
  import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
9
9
  import type { BuildAppOptions, PackageTargetBuildManifest } from "../build/types.ts";
10
10
  import { createVirtualBuildEntry } from "../build/virtual-entry.ts";
11
- import { createRoutesPlugin, routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
11
+ import {
12
+ composableRouteModuleSpecifier,
13
+ createRoutesPlugin,
14
+ routeSourcePaths,
15
+ } from "../plugin/routes.ts";
12
16
  import { ssgRouteCache } from "../server/cache/ssg.ts";
13
17
  import { generateProdIndexHtml } from "../server/render/shell.ts";
14
18
  import { setProductionTemplateContent } from "../server/render/template.ts";
@@ -132,7 +136,7 @@ export async function buildPackageTarget(
132
136
  buildId,
133
137
  clientLogging: options.clientLogging ?? false,
134
138
  modulePaths,
135
- nativeRoutes: routeModuleSpecifier(app),
139
+ nativeRoutes: composableRouteModuleSpecifier(app),
136
140
  prefix,
137
141
  rootConventions,
138
142
  rootPath: root.path,
@@ -1,5 +1,5 @@
1
1
  import { existsSync, writeFileSync } from "node:fs";
2
- import { basename, dirname, join, relative, resolve } from "node:path";
2
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { buildClient } from "../build/client.ts";
5
5
  import type { BuildEntryOptions, EntryAppContext } from "../build/entry-template.ts";
@@ -11,7 +11,7 @@ import {
11
11
  type SSGCacheSnapshot,
12
12
  } from "../build/ssg-cache.ts";
13
13
  import type { BuildAppOptions } from "../build/types.ts";
14
- import { routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
14
+ import { composableRouteModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
15
15
  import { buildRscGraph } from "../rsc/build/index.ts";
16
16
  import { ssgRouteCache } from "../server/cache/ssg.ts";
17
17
  import { hasRequestLoader } from "../server/render/loaders.ts";
@@ -138,11 +138,17 @@ export async function createBuildFingerprint(
138
138
 
139
139
  function stableFingerprintPath(path: string, projectRoot: string): string {
140
140
  const projectPath = relative(projectRoot, path);
141
- if (projectPath !== ".." && !projectPath.startsWith("../") && !projectPath.startsWith("..\\")) {
141
+ if (
142
+ !isAbsolute(projectPath) &&
143
+ projectPath !== ".." &&
144
+ !projectPath.startsWith("../") &&
145
+ !projectPath.startsWith("..\\")
146
+ ) {
142
147
  return `app/${toPosixPath(projectPath)}`;
143
148
  }
144
149
  const frameworkPath = relative(_pkgRoot, path);
145
150
  if (
151
+ !isAbsolute(frameworkPath) &&
146
152
  frameworkPath !== ".." &&
147
153
  !frameworkPath.startsWith("../") &&
148
154
  !frameworkPath.startsWith("..\\")
@@ -316,9 +322,10 @@ export async function buildRuntimeApp(
316
322
  entryApp: {
317
323
  buildId,
318
324
  clientLogging: options.clientLogging ?? false,
325
+ deploymentTarget: targetName === "vercel" ? "vercel" : undefined,
319
326
  embed: options.compile === "embed" ? { clientDir } : undefined,
320
327
  modulePaths,
321
- nativeRoutes: routeModuleSpecifier(app),
328
+ nativeRoutes: composableRouteModuleSpecifier(app),
322
329
  prefix,
323
330
  rootConventions,
324
331
  rootPath: root.path,
@@ -1,6 +1,6 @@
1
1
  // biome-ignore-all lint/performance/noAwaitInLoops: static build emits routes in sequence to keep output deterministic
2
2
  import { cpSync, existsSync, rmSync, writeFileSync } from "node:fs";
3
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
+ import { dirname, isAbsolute, join, parse, relative, resolve, sep, win32 } from "node:path";
4
4
  import { toCrossJSONAsync } from "seroval";
5
5
  import { buildClient } from "../build/client.ts";
6
6
  import { ensureDir, toPosixPath } from "../build/shared.ts";
@@ -10,6 +10,7 @@ import type { StaticExportConfig } from "../config.ts";
10
10
  import { resolvePath } from "../server/render/assemble.ts";
11
11
  import { generateProdIndexHtml } from "../server/render/shell.ts";
12
12
  import { prerenderSSG } from "../server/render/ssg.ts";
13
+ import { hasStaticParams, resolveStaticParams } from "../server/render/static-params.ts";
13
14
  import { setProductionTemplateContent } from "../server/render/template.ts";
14
15
  import { createSearchRouteMetadata } from "../server/router/schemas.ts";
15
16
  import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
@@ -271,7 +272,7 @@ async function buildTaskQueue(
271
272
  if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
272
273
  return { paramSets: [{}], route };
273
274
  }
274
- if (!route.page.staticParams) {
275
+ if (!hasStaticParams(route)) {
275
276
  console.warn(
276
277
  `[furin] static: skipping dynamic route "${route.pattern}" — no staticParams() defined.`
277
278
  );
@@ -279,7 +280,7 @@ async function buildTaskQueue(
279
280
  return { paramSets: null, route };
280
281
  }
281
282
  try {
282
- const paramSets = (await route.page.staticParams()) ?? [];
283
+ const paramSets = (await resolveStaticParams(route, STATIC_RENDER_ORIGIN)) ?? [];
283
284
  return { paramSets, route };
284
285
  } catch (err) {
285
286
  return { error: err, paramSets: null, route };
@@ -394,7 +395,8 @@ export async function buildStaticTarget(
394
395
  );
395
396
  }
396
397
 
397
- const outDir = resolve(rootDir, staticConfig.outDir ?? "dist");
398
+ const rawOutDir = staticConfig.outDir ?? "dist";
399
+ const outDir = resolve(rootDir, rawOutDir);
398
400
 
399
401
  // Guard against destructive rmSync on obviously wrong output directories.
400
402
  const normalizedRoot = resolve(rootDir);
@@ -402,8 +404,8 @@ export async function buildStaticTarget(
402
404
  if (
403
405
  outDir === normalizedRoot ||
404
406
  outDir === normalizedBuildRoot ||
405
- outDir === "/" ||
406
- outDir === "."
407
+ outDir === parse(outDir).root ||
408
+ rawOutDir === win32.parse(rawOutDir).root
407
409
  ) {
408
410
  throw new Error(
409
411
  `[furin] static: outDir resolves to "${outDir}" which is unsafe to delete. ` +
@@ -1,17 +1,11 @@
1
- import {
2
- cpSync,
3
- existsSync,
4
- readFileSync,
5
- rmSync,
6
- statSync,
7
- symlinkSync,
8
- writeFileSync,
9
- } from "node:fs";
1
+ import { cpSync, existsSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
10
2
  import { basename, dirname, extname, join, relative } from "node:path";
11
3
  import { fileURLToPath, pathToFileURL } from "node:url";
12
4
  import { runBunBuild } from "../build/bun-build.ts";
13
- import { buildEntrySource } from "../build/entry-template.ts";
5
+ import { elysiaAot } from "../build/elysia-aot.ts";
6
+ import { movePrivateServerSourceMaps } from "../build/private-server-sourcemaps.ts";
14
7
  import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
8
+ import { materializeServerAppEntry } from "../build/server-app-entry.ts";
15
9
  import { ensureDir, toPosixPath } from "../build/shared.ts";
16
10
  import type { RoutePrerender } from "../build/ssg-cache.ts";
17
11
  import type { BuildAppOptions, VercelTargetBuildManifest } from "../build/types.ts";
@@ -32,7 +26,7 @@ import {
32
26
 
33
27
  const ISR_PATH_PARAM = "__furin_path";
34
28
  const DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
35
- const ELYSIA_STATIC_IMPORT_RE = /^@elysiajs\/static$/;
29
+ const ELYSIA_STATIC_IMPORT_RE = /^@elysia\/static$/;
36
30
  const MATCH_ALL_RE = /.*/;
37
31
  const REGEX_META_RE = /[.*+?^${}()|[\]\\]/;
38
32
  const UNSAFE_FUNCTION_PATH_RE = /[^a-zA-Z0-9_.[\]/-]/g;
@@ -95,12 +89,12 @@ function vercelRuntimePlugin(): Bun.BunPlugin {
95
89
  build.onResolve({ filter: ELYSIA_STATIC_IMPORT_RE }, ({ importer }) => {
96
90
  if (!isFurinRuntimeImporter(importer)) {
97
91
  throw new Error(
98
- "[furin] Application @elysiajs/static mounts are not supported by the Vercel target. Put CDN assets under public/ instead."
92
+ "[furin] Application @elysia/static mounts are not supported by the Vercel target. Put CDN assets under public/ instead."
99
93
  );
100
94
  }
101
95
  return {
102
96
  namespace: VERCEL_RUNTIME_STUB_NAMESPACE,
103
- path: "@elysiajs/static",
97
+ path: "@elysia/static",
104
98
  };
105
99
  });
106
100
  build.onLoad({ filter: MATCH_ALL_RE, namespace: VERCEL_RUNTIME_STUB_NAMESPACE }, () => ({
@@ -137,13 +131,23 @@ function serverEntryLoader(serverEntry: string): "js" | "jsx" | "ts" | "tsx" {
137
131
 
138
132
  function assertDefaultServerExport(serverEntry: string): void {
139
133
  const transpiler = new Bun.Transpiler({ loader: serverEntryLoader(serverEntry) });
140
- const { exports } = transpiler.scan(readFileSync(serverEntry, "utf8"));
134
+ const { exports, imports } = transpiler.scan(readFileSync(serverEntry, "utf8"));
141
135
  if (!exports.includes("default")) {
142
136
  throw new Error(
143
137
  `[furin] Vercel server entry "${toPosixPath(serverEntry)}" must export the Elysia app as default. ` +
144
138
  "Guard app.listen() with `if (import.meta.main)` so the same entry also runs locally."
145
139
  );
146
140
  }
141
+ if (imports.some(({ path }) => ELYSIA_STATIC_IMPORT_RE.test(path))) {
142
+ throw new AggregateError(
143
+ [
144
+ new Error(
145
+ "[furin] Application @elysia/static mounts are not supported by the Vercel target. Put CDN assets under public/ instead."
146
+ ),
147
+ ],
148
+ "[furin] Vercel build rejected application static mounts."
149
+ );
150
+ }
147
151
  }
148
152
 
149
153
  function escapeRegex(value: string): string {
@@ -367,7 +371,7 @@ function vercelEntrySource(
367
371
  apps: RuntimeTargetApp[],
368
372
  builds: RuntimeAppBuild[],
369
373
  prerenderSpecs: PrerenderSpec[],
370
- serverEntry: string,
374
+ appEntry: string,
371
375
  pprResumeKey: string
372
376
  ): string {
373
377
  const routeCount = builds.reduce((count, build) => count + build.entryApp.routes.length, 0);
@@ -395,15 +399,6 @@ function vercelEntrySource(
395
399
  )
396
400
  .sort((left, right) => compareRouteSpecificity(right.pattern, left.pattern))
397
401
  .map(({ source, tags }) => [source, tags]);
398
- const contextSource = buildEntrySource({
399
- apps: builds.map(({ entryApp, indexHtml }) => ({
400
- ...entryApp,
401
- embed: undefined,
402
- serveAssets: false,
403
- templateHtml: indexHtml,
404
- })),
405
- headerComment: "// Auto-generated by `furin build --target vercel` — do not edit",
406
- });
407
402
  return `import {
408
403
  addCacheTag,
409
404
  getCache as getVercelCache,
@@ -416,12 +411,11 @@ import {
416
411
  markExternalPrerenderRequest,
417
412
  restorePprResumeRequest,
418
413
  setCacheTagPurger,
414
+ setRuntimeEvlogWaitUntil,
419
415
  setRuntimeCacheProvider,
420
416
  waitForPendingISRRevalidations,
421
417
  } from "@teyik0/furin/internal";
422
418
 
423
- ${contextSource}
424
-
425
419
  const prerenderAliases = new Map(
426
420
  ${JSON.stringify(prerenderAliases)}.map(([alias, source]) => [alias, new RegExp(source)])
427
421
  );
@@ -445,6 +439,7 @@ function encodeCacheTag(value) {
445
439
  setRuntimeCacheProvider({
446
440
  getCache: (options) => getVercelCache(options),
447
441
  });
442
+ setRuntimeEvlogWaitUntil(waitUntil);
448
443
 
449
444
  async function purgeCacheTags(paths) {
450
445
  const purge = Promise.all([
@@ -458,7 +453,7 @@ setCachePurger(purgeCacheTags);
458
453
  setCacheTagPurger(purgeCacheTags);
459
454
 
460
455
  const serverInitStartedAt = performance.now();
461
- const serverModule = await import(${JSON.stringify(toPosixPath(serverEntry))});
456
+ const serverModule = await import(${JSON.stringify(toPosixPath(appEntry))});
462
457
  const app = serverModule.default;
463
458
  if (!app || typeof app.handle !== "function") {
464
459
  throw new TypeError("[furin] Vercel server entry must export the Elysia app as default.");
@@ -677,6 +672,7 @@ async function handle(request) {
677
672
  \`furin_server_init;dur=\${initialization.server_init_ms}\`,
678
673
  \`furin_handler_wait;dur=\${requestWaitMs}\`,
679
674
  \`furin_handler;dur=\${handlerMs}\`,
675
+ ...(isFirstRequest ? ["furin_instance_first_request"] : []),
680
676
  ].join(", ");
681
677
  return appendServerTiming(response, serverTiming);
682
678
  }
@@ -700,6 +696,10 @@ export async function buildVercelTarget(
700
696
  const functionsDir = join(outputDir, "functions");
701
697
  const serverFunctionDir = join(functionsDir, "__server.func");
702
698
  rmSync(targetDir, { force: true, recursive: true });
699
+ rmSync(join(buildRoot, "private", "server-sourcemaps", "vercel"), {
700
+ force: true,
701
+ recursive: true,
702
+ });
703
703
  rmSync(outputDir, { force: true, recursive: true });
704
704
  ensureDir(targetDir);
705
705
  ensureDir(staticDir);
@@ -719,6 +719,15 @@ export async function buildVercelTarget(
719
719
  const publicDir = join(rootDir, "public");
720
720
  if (existsSync(publicDir)) {
721
721
  cpSync(publicDir, staticDir, { recursive: true });
722
+ for (const app of apps) {
723
+ const appStaticDir = join(staticDir, app.prefix.slice(1));
724
+ const appPublicDir = join(appStaticDir, "public");
725
+ cpSync(publicDir, appPublicDir, { recursive: true });
726
+ const favicon = join(publicDir, "favicon.ico");
727
+ if (app.prefix !== "" && existsSync(favicon)) {
728
+ cpSync(favicon, join(appStaticDir, "favicon.ico"));
729
+ }
730
+ }
722
731
  }
723
732
  for (let appIndex = 0; appIndex < apps.length; appIndex += 1) {
724
733
  const app = apps[appIndex] as RuntimeTargetApp;
@@ -729,10 +738,22 @@ export async function buildVercelTarget(
729
738
 
730
739
  const pprResumeKey = crypto.randomUUID();
731
740
  const prerenderSpecs = await createPrerenderSpecs(apps, builds, functionsDir, pprResumeKey);
741
+ const appEntry = await materializeServerAppEntry({
742
+ apps: builds.map(({ entryApp, indexHtml }) => ({
743
+ ...entryApp,
744
+ embed: undefined,
745
+ serveAssets: false,
746
+ templateHtml: indexHtml,
747
+ })),
748
+ headerComment: "// Auto-generated by `furin build --target vercel` — do not edit",
749
+ instances: apps,
750
+ outDir: serverFunctionDir,
751
+ serverEntry,
752
+ });
732
753
  const entryPath = join(serverFunctionDir, "_vercel-handler.ts");
733
754
  const entry = createVirtualBuildEntry(
734
755
  entryPath,
735
- vercelEntrySource(apps, builds, prerenderSpecs, serverEntry, pprResumeKey),
756
+ vercelEntrySource(apps, builds, prerenderSpecs, appEntry, pprResumeKey),
736
757
  "ts"
737
758
  );
738
759
  const serverBuild = await runBunBuild({
@@ -753,10 +774,21 @@ export async function buildVercelTarget(
753
774
  createRoutesPlugin({ instances: apps, target: "server" }),
754
775
  isomorphicTransformPlugin("server"),
755
776
  environmentGuardPlugin("ssr"),
777
+ elysiaAot(appEntry),
756
778
  ],
757
- sourcemap: "none",
779
+ sourcemap: options.serverSourceMaps ? "external" : "none",
780
+ splitting: true,
758
781
  target: "bun",
759
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
+ }
760
792
  if (options.analyze) {
761
793
  if (serverBuild.metafile === undefined) {
762
794
  throw new Error("[furin] Vercel server build did not produce the requested metafile.");
@@ -766,8 +798,9 @@ export async function buildVercelTarget(
766
798
  writeFileSync(metafilePath, `${JSON.stringify(serverBuild.metafile, null, 2)}\n`);
767
799
  console.log(`[furin] Server metafile: ${toPosixPath(metafilePath)}`);
768
800
  }
769
- const handlerPath = join(serverFunctionDir, "handler.js");
770
- const serverBundleBytes = existsSync(handlerPath) ? statSync(handlerPath).size : 0;
801
+ const serverBundleBytes = serverBuild.outputs
802
+ .filter((output) => output.path.endsWith(".js"))
803
+ .reduce((total, output) => total + output.size, 0);
771
804
  writeFileSync(join(serverFunctionDir, "index.js"), vercelBootstrapSource(serverBundleBytes));
772
805
  await buildPprFallbacks(apps, builds, prerenderSpecs, functionsDir, rootDir, targetDir);
773
806
 
@@ -1,5 +1,5 @@
1
1
  import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
- import { basename, dirname, join } from "node:path";
2
+ import { basename, dirname, join, resolve } from "node:path";
3
3
  import { transformForClient } from "../plugin/transform-client";
4
4
  import { createRoutesPlugin } from "../plugin/routes.ts";
5
5
  import { environmentGuardPlugin } from "../rsc/build/environment.ts";
@@ -12,6 +12,7 @@ import type { BuildClientOptions, BunBuildAliasConfig } from "./types";
12
12
  import { createVirtualBuildEntry } from "./virtual-entry.ts";
13
13
 
14
14
  const SCRIPT_FILE_FILTER = /\.(tsx?|jsx?)$/;
15
+ const ROUTER_PROVIDER_PATH = resolve(import.meta.dir, "../client/router/provider.tsx");
15
16
 
16
17
  function resolveClientModuleSpecifiers(code: string): string {
17
18
  return code
@@ -109,6 +110,21 @@ export async function buildClient(
109
110
  },
110
111
  };
111
112
 
113
+ const routerLoggerPlugin: Bun.BunPlugin = {
114
+ name: "furin-client-router-logger",
115
+ setup(build) {
116
+ build.onResolve({ filter: /^evlog$/ }, ({ importer }) => {
117
+ if (importer === ROUTER_PROVIDER_PATH) {
118
+ return { namespace: "furin-client-router-logger", path: "router-logger" };
119
+ }
120
+ });
121
+ build.onLoad({ filter: /.*/, namespace: "furin-client-router-logger" }, () => ({
122
+ contents: "export const log = { warn: console.warn, error: console.error };",
123
+ loader: "js",
124
+ }));
125
+ },
126
+ };
127
+
112
128
  const clientBuildConfig: BunBuildAliasConfig = {
113
129
  // Use the JS file as entrypoint — NOT an HTML file. Bun's HTML bundler
114
130
  // with code-splitting incorrectly references a leaf chunk in the output
@@ -141,6 +157,7 @@ export async function buildClient(
141
157
  plugins: [
142
158
  hydrateEntry.plugin,
143
159
  ...(plugins ?? []),
160
+ ...(!clientLogging ? [routerLoggerPlugin] : []),
144
161
  ...(pagesDir
145
162
  ? [createRoutesPlugin({ instances: [{ pagesDir, prefix: basePath }], target: "client" })]
146
163
  : []),