@teyik0/furin 0.4.0-alpha.1 → 0.4.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 (193) hide show
  1. package/dist/adapter/bun.d.ts +2 -18
  2. package/dist/adapter/package.d.ts +2 -2
  3. package/dist/adapter/runtime-build.d.ts +33 -0
  4. package/dist/adapter/vercel.d.ts +3 -0
  5. package/dist/build/client.d.ts +1 -1
  6. package/dist/build/compile-entry.d.ts +4 -3
  7. package/dist/build/compile-entry.ts +24 -69
  8. package/dist/build/entry-template.d.ts +4 -2
  9. package/dist/build/entry-template.ts +31 -8
  10. package/dist/build/index.d.ts +1 -1
  11. package/dist/build/index.js +8596 -6375
  12. package/dist/build/ssg-cache.d.ts +13 -0
  13. package/dist/build/types.d.ts +25 -2
  14. package/dist/build/virtual-entry.d.ts +8 -0
  15. package/dist/cache.d.ts +5 -0
  16. package/dist/cache.js +97 -0
  17. package/dist/cli/index.js +9099 -6771
  18. package/dist/cli/preview.d.ts +7 -0
  19. package/dist/client/boundaries.d.ts +1 -0
  20. package/dist/client/browser-events-runtime.d.ts +2 -0
  21. package/dist/client/browser-events.d.ts +2 -0
  22. package/dist/client/define-route.d.ts +9 -8
  23. package/dist/client/dev-error-overlay.d.ts +1 -0
  24. package/dist/client/dev-error-overlay.ts +201 -0
  25. package/dist/client/document.d.ts +1 -0
  26. package/dist/client/hmr.d.ts +4 -2
  27. package/dist/client/link.js +251 -82
  28. package/dist/client/router/provider.d.ts +1 -1
  29. package/dist/client/router/sync-catch-up.d.ts +1 -1
  30. package/dist/client/router/types.d.ts +8 -10
  31. package/dist/client.js +37 -23
  32. package/dist/config.d.ts +17 -0
  33. package/dist/config.js +9 -1
  34. package/dist/define-route.d.ts +11 -8
  35. package/dist/devtools/protocol.d.ts +2 -2
  36. package/dist/furin.d.ts +1 -1
  37. package/dist/furin.js +12991 -9491
  38. package/dist/plugin/index.js +476 -7
  39. package/dist/plugin/routes.d.ts +4 -3
  40. package/dist/rsc/build/index.d.ts +5 -1
  41. package/dist/server/browser-events/plugin.d.ts +11 -0
  42. package/dist/server/browser-events/types.d.ts +9 -0
  43. package/dist/server/cache/invalidation.d.ts +1 -2
  44. package/dist/server/cache/isr.d.ts +1 -0
  45. package/dist/server/cache/purger.d.ts +7 -0
  46. package/dist/server/cache/runtime-cache.d.ts +21 -0
  47. package/dist/server/dev/browser-events.d.ts +4 -0
  48. package/dist/server/dev/diagnostics.d.ts +39 -0
  49. package/dist/server/dev/error.d.ts +17 -0
  50. package/dist/server/dev/graph.d.ts +86 -0
  51. package/dist/server/dev/plugin.d.ts +9 -0
  52. package/dist/server/dev/request-security.d.ts +1 -0
  53. package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
  54. package/dist/server/dev/runtime.production.d.ts +5 -0
  55. package/dist/server/dev/symbolicate.d.ts +11 -0
  56. package/dist/server/dev/transform-failure.d.ts +4 -0
  57. package/dist/server/dev-page-plugin.production.d.ts +1 -0
  58. package/dist/server/devtools/hub.d.ts +3 -2
  59. package/dist/server/devtools/instrumentation.d.ts +1 -1
  60. package/dist/server/devtools/instrumentation.production.d.ts +1 -1
  61. package/dist/server/devtools/plugin.d.ts +1 -1
  62. package/dist/server/external-prerender.d.ts +2 -0
  63. package/dist/server/instance.d.ts +2 -2
  64. package/dist/server/internal.d.ts +14 -2
  65. package/dist/server/internal.js +436 -1
  66. package/dist/server/render/element.d.ts +1 -0
  67. package/dist/server/render/index.d.ts +1 -1
  68. package/dist/server/render/index.ts +1 -1
  69. package/dist/server/render/ppr-document.d.ts +21 -0
  70. package/dist/server/render/ppr-request.d.ts +26 -0
  71. package/dist/server/render/ppr-route.d.ts +3 -1
  72. package/dist/server/render/shell.ts +0 -12
  73. package/dist/server/render/ssg.d.ts +2 -0
  74. package/dist/server/render/ssr.d.ts +17 -6
  75. package/dist/server/router/hmr.production.d.ts +2 -0
  76. package/dist/server/router/patterns.d.ts +1 -0
  77. package/dist/server/router/plugin.d.ts +3 -1
  78. package/dist/server/sync/adapter.d.ts +13 -0
  79. package/dist/server/sync/config.d.ts +5 -5
  80. package/dist/server/sync/index.d.ts +6 -6
  81. package/dist/server/sync/index.js +491 -516
  82. package/dist/server/sync/notifier.d.ts +1 -0
  83. package/dist/server/sync/postgres/index.d.ts +12 -1
  84. package/dist/server/sync/postgres/index.js +101 -6
  85. package/dist/server/sync/stream.d.ts +4 -13
  86. package/dist/shared/await.d.ts +3 -3
  87. package/dist/shared/browser-events.d.ts +22 -0
  88. package/dist/shared/compact-json.d.ts +8 -0
  89. package/dist/shared/deferred-ndjson.d.ts +6 -5
  90. package/dist/shared/dev-diagnostics.d.ts +36 -0
  91. package/dist/shared/prefix.d.ts +2 -0
  92. package/package.json +16 -7
  93. package/src/adapter/README.md +45 -0
  94. package/src/adapter/bun.ts +45 -268
  95. package/src/adapter/package.ts +15 -9
  96. package/src/adapter/runtime-build.ts +375 -0
  97. package/src/adapter/static.ts +79 -2
  98. package/src/adapter/vercel.ts +857 -0
  99. package/src/build/client.ts +38 -13
  100. package/src/build/compile-entry.ts +24 -69
  101. package/src/build/entry-template.ts +31 -8
  102. package/src/build/hydrate.ts +60 -20
  103. package/src/build/index.ts +19 -5
  104. package/src/build/production-instrumentation.ts +56 -4
  105. package/src/build/shared.ts +2 -1
  106. package/src/build/ssg-cache.ts +97 -11
  107. package/src/build/types.ts +31 -2
  108. package/src/build/virtual-entry.ts +27 -0
  109. package/src/cache.ts +14 -0
  110. package/src/cli/index.ts +55 -3
  111. package/src/cli/preview.ts +90 -0
  112. package/src/client/boundaries.tsx +10 -1
  113. package/src/client/browser-events-runtime.ts +204 -0
  114. package/src/client/browser-events.ts +22 -0
  115. package/src/client/define-route.ts +7 -17
  116. package/src/client/dev-error-overlay.ts +201 -0
  117. package/src/client/document.tsx +4 -7
  118. package/src/client/hmr.ts +26 -3
  119. package/src/client/router/boundary-tree.tsx +4 -4
  120. package/src/client/router/provider.tsx +165 -63
  121. package/src/client/router/sync-catch-up.ts +3 -4
  122. package/src/client/router/types.ts +6 -6
  123. package/src/config.ts +25 -0
  124. package/src/define-route.ts +20 -7
  125. package/src/devtools/devtools-element.js +56 -77
  126. package/src/devtools/protocol.ts +2 -2
  127. package/src/furin.ts +157 -77
  128. package/src/plugin/routes.ts +206 -36
  129. package/src/plugin/transform-client.ts +685 -3
  130. package/src/react-dom-edge.d.ts +6 -0
  131. package/src/rsc/build/index.ts +15 -3
  132. package/src/server/auto-invalidate/runtime.ts +5 -2
  133. package/src/server/browser-events/plugin.ts +168 -0
  134. package/src/server/browser-events/types.ts +11 -0
  135. package/src/server/cache/dev-loader.ts +30 -29
  136. package/src/server/cache/invalidation.ts +13 -22
  137. package/src/server/cache/isr.ts +9 -0
  138. package/src/server/cache/purger.ts +41 -0
  139. package/src/server/cache/runtime-cache.ts +137 -0
  140. package/src/server/dev/browser-events.ts +54 -0
  141. package/src/server/dev/diagnostics.ts +297 -0
  142. package/src/server/dev/error.ts +148 -0
  143. package/src/server/dev/graph.ts +438 -0
  144. package/src/server/dev/plugin.ts +130 -0
  145. package/src/server/dev/request-security.ts +38 -0
  146. package/src/server/dev/rewrite-module-specifiers.ts +81 -0
  147. package/src/server/dev/runtime.production.ts +24 -0
  148. package/src/server/dev/symbolicate.ts +135 -0
  149. package/src/server/dev/transform-failure.ts +8 -0
  150. package/src/server/dev-page-plugin.production.ts +3 -0
  151. package/src/server/dev-page-plugin.ts +92 -53
  152. package/src/server/devtools/hub.ts +6 -5
  153. package/src/server/devtools/instrumentation.production.ts +1 -1
  154. package/src/server/devtools/instrumentation.ts +12 -6
  155. package/src/server/devtools/plugin.ts +7 -150
  156. package/src/server/external-prerender.ts +10 -0
  157. package/src/server/instance.ts +3 -3
  158. package/src/server/internal.ts +39 -2
  159. package/src/server/render/assemble.ts +4 -4
  160. package/src/server/render/document.tsx +13 -4
  161. package/src/server/render/element.tsx +18 -14
  162. package/src/server/render/index.ts +1 -1
  163. package/src/server/render/isr.ts +44 -19
  164. package/src/server/render/loaders.ts +13 -3
  165. package/src/server/render/not-found.ts +28 -4
  166. package/src/server/render/ppr-document.ts +239 -0
  167. package/src/server/render/ppr-request.ts +104 -0
  168. package/src/server/render/ppr-route.ts +152 -31
  169. package/src/server/render/shell.ts +0 -12
  170. package/src/server/render/ssg.ts +38 -20
  171. package/src/server/render/ssr.ts +211 -83
  172. package/src/server/render/template.ts +47 -11
  173. package/src/server/router/defined-route.ts +7 -39
  174. package/src/server/router/hmr.production.ts +7 -0
  175. package/src/server/router/hmr.ts +106 -67
  176. package/src/server/router/patterns.ts +5 -1
  177. package/src/server/router/plugin.ts +124 -35
  178. package/src/server/router/source-version.ts +3 -10
  179. package/src/server/sync/adapter.ts +13 -0
  180. package/src/server/sync/config.ts +12 -12
  181. package/src/server/sync/index.ts +8 -8
  182. package/src/server/sync/notifier.ts +1 -0
  183. package/src/server/sync/plugin.ts +4 -1
  184. package/src/server/sync/postgres/index.ts +111 -5
  185. package/src/server/sync/runtime.ts +12 -0
  186. package/src/server/sync/stream.ts +78 -113
  187. package/src/shared/await.tsx +3 -3
  188. package/src/shared/browser-events.ts +28 -0
  189. package/src/shared/compact-json.ts +77 -0
  190. package/src/shared/deferred-ndjson.ts +20 -6
  191. package/src/shared/dev-diagnostics.ts +44 -0
  192. package/src/shared/prefix.ts +8 -0
  193. package/src/shared/route-map.ts +10 -1
@@ -1,62 +1,24 @@
1
- import { existsSync, rmSync, writeFileSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
3
- import { fileURLToPath } from "node:url";
1
+ import { existsSync, rmSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
4
3
  import { runBunBuild } from "../build/bun-build.ts";
5
- import { buildClient } from "../build/client.ts";
6
4
  import { generateCompileEntry } from "../build/compile-entry.ts";
7
- import {
8
- type BuildEntryOptions,
9
- buildEntrySource,
10
- type EntryAppContext,
11
- } from "../build/entry-template.ts";
5
+ import { type BuildEntryOptions, buildEntrySource } from "../build/entry-template.ts";
12
6
  import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
13
7
  import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
14
- import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
15
8
  import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
9
+ import { createVirtualBuildEntry, type VirtualBuildEntry } from "../build/virtual-entry.ts";
16
10
  import type { BuildTarget } from "../config.ts";
17
- import { createRoutesPlugin, routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
11
+ import { createRoutesPlugin } from "../plugin/routes.ts";
18
12
  import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
19
13
  import { environmentGuardPlugin } from "../rsc/build/environment.ts";
20
- import { buildRscGraph } from "../rsc/build/index.ts";
21
- import { ssgRouteCache } from "../server/cache/ssg.ts";
22
- import { generateProdIndexHtml } from "../server/render/shell.ts";
23
- import { setProductionTemplateContent } from "../server/render/template.ts";
24
- import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
25
14
  import { clientDirNameForPrefix } from "../shared/prefix.ts";
15
+ import {
16
+ buildRuntimeAppsSequentially,
17
+ pprRuntimePlugin,
18
+ type RuntimeTargetApp,
19
+ } from "./runtime-build.ts";
26
20
 
27
- // import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
28
- // through package exports, and is the Web-standard API. The main entry is
29
- // `src/furin.ts` (or `dist/furin.js`), so we strip two path segments to reach
30
- // the package root.
31
- const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
32
- const _pkgSrcDir = existsSync(join(_pkgRoot, "src", "furin.ts"))
33
- ? join(_pkgRoot, "src")
34
- : join(_pkgRoot, "dist");
35
- // The published package always ships `src/` (see package.json "files"), and the
36
- // "bun" export condition resolves to the TypeScript sources, so the fingerprint
37
- // inputs are always the `.ts` files. Some of these inputs (e.g. entry-template)
38
- // are never emitted to `dist/` as `.js`, so detecting the extension off the dist
39
- // copy would point at files that don't exist and silently weaken the build ID.
40
- const _ext = ".ts";
41
- const BUILD_ID_INPUT_PATHS = [
42
- `${_pkgSrcDir}/build/compile-entry${_ext}`,
43
- `${_pkgSrcDir}/build/entry-template${_ext}`,
44
- `${_pkgSrcDir}/plugin/routes${_ext}`,
45
- `${_pkgSrcDir}/server/render/index${_ext}`,
46
- `${_pkgSrcDir}/server/render/shell${_ext}`,
47
- ];
48
-
49
- function compareCodeUnits(a: string, b: string): number {
50
- if (a < b) {
51
- return -1;
52
- }
53
- if (a > b) {
54
- return 1;
55
- }
56
- return 0;
57
- }
58
-
59
- function generateDiskEntry(options: BuildEntryOptions): string {
21
+ function generateDiskEntry(options: BuildEntryOptions): VirtualBuildEntry {
60
22
  ensureDir(options.outDir);
61
23
  const source = buildEntrySource({
62
24
  apps: options.apps.map(({ embed: _embed, ...context }) => context),
@@ -64,212 +26,26 @@ function generateDiskEntry(options: BuildEntryOptions): string {
64
26
  serverEntry: options.serverEntry,
65
27
  });
66
28
  const entryPath = join(options.outDir, "server.ts");
67
- writeFileSync(entryPath, source);
68
- return entryPath;
29
+ return createVirtualBuildEntry(entryPath, source, "ts");
69
30
  }
70
31
 
71
- /**
72
- * Deterministic build-ID input covering everything that can change rendered
73
- * output: client chunks, route shape, route/root/error/not-found source
74
- * contents and the framework's own render pipeline sources. Shared with the
75
- * package target so packaged apps get the same stale-deploy detection —
76
- * SSR-only changes (loader/page code that never reaches the client bundle)
77
- * must still produce a new build ID.
78
- */
79
- export async function createBuildFingerprint(
80
- entryChunk: string,
81
- cssChunks: string[],
82
- routes: ResolvedRoute[],
83
- root: RootLayout,
84
- serverEntry: string | null
85
- ): Promise<string> {
86
- const fingerprintPaths = new Set<string>([root.path, ...routes.map((route) => route.path)]);
87
- if (serverEntry) {
88
- fingerprintPaths.add(serverEntry);
89
- }
90
- if (root.errorPath) {
91
- fingerprintPaths.add(root.errorPath);
92
- }
93
- if (root.notFoundPath) {
94
- fingerprintPaths.add(root.notFoundPath);
95
- }
96
- for (const route of routes) {
97
- for (const segment of route.segmentBoundaries) {
98
- if (segment.errorPath) {
99
- fingerprintPaths.add(segment.errorPath);
100
- }
101
- if (segment.notFoundPath) {
102
- fingerprintPaths.add(segment.notFoundPath);
103
- }
104
- }
32
+ function collectEmbeddedAssets(
33
+ entryApps: BuildEntryOptions["apps"],
34
+ publicDir: string | undefined,
35
+ compile: BuildAppOptions["compile"]
36
+ ): string[] | undefined {
37
+ if (compile !== "embed") {
38
+ return;
105
39
  }
106
- for (const path of BUILD_ID_INPUT_PATHS) {
107
- if (!existsSync(path)) {
108
- // A missing framework source file would silently produce an empty-string
109
- // contribution to the fingerprint, making the build ID unreliable.
110
- console.warn(
111
- `[furin] Warning: build fingerprint input "${toPosixPath(path)}" is missing — ` +
112
- "the generated build ID may not reflect all framework changes."
113
- );
114
- }
115
- fingerprintPaths.add(path);
40
+ const assets = entryApps.flatMap((app) => (app.embed ? [app.embed.clientDir] : []));
41
+ if (publicDir !== undefined) {
42
+ assets.push(publicDir);
116
43
  }
117
-
118
- const fileParts = await Promise.all(
119
- [...fingerprintPaths].toSorted().map(async (path) => {
120
- const content = existsSync(path) ? await Bun.file(path).text() : "";
121
- return `${toPosixPath(path)}:${content}`;
122
- })
123
- );
124
-
125
- const routeParts = routes
126
- .map((route) =>
127
- JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })
128
- )
129
- .sort(compareCodeUnits);
130
-
131
- return [entryChunk, ...[...cssChunks].toSorted(), ...routeParts, ...fileParts].join("\n");
132
- }
133
-
134
- function buildCompileMetadata(root: RootLayout, routes: ResolvedRoute[]) {
135
- const rootConventions =
136
- root.errorPath || root.notFoundPath
137
- ? {
138
- errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
139
- notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined,
140
- }
141
- : undefined;
142
-
143
- const routeMetadata: NonNullable<EntryAppContext["routeMetadata"]> = {};
144
- for (const route of routes) {
145
- routeMetadata[toPosixPath(route.path)] = {
146
- segmentBoundaries: route.segmentBoundaries.map((b) => ({
147
- depth: b.depth,
148
- errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
149
- notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
150
- path: toPosixPath(b.path),
151
- })),
152
- };
153
- }
154
-
155
- return { rootConventions, routeMetadata };
156
- }
157
-
158
- /** One mounted app's build input (root + routes scanned from its pagesDir). */
159
- export interface BunTargetApp {
160
- pagesDir: string;
161
- prefix: string;
162
- root: RootLayout;
163
- routes: ResolvedRoute[];
164
- }
165
-
166
- /** Builds one app's client bundle + compile context payload for the entry. */
167
- async function buildOneApp(
168
- app: BunTargetApp,
169
- targetDir: string,
170
- serverEntry: string | null,
171
- options: BuildAppOptions
172
- ): Promise<{
173
- buildId: string;
174
- entryApp: BuildEntryOptions["apps"][number];
175
- hydrateIntermediate: string;
176
- }> {
177
- const { prefix, root, routes } = app;
178
- const clientDirName = clientDirNameForPrefix(prefix);
179
- const label = prefix === "" ? "root app" : `app "${prefix}"`;
180
-
181
- const { entryChunk, cssChunks } = await buildClient(routes, {
182
- basePath: prefix,
183
- clientDirName,
184
- clientLogging: options.clientLogging ?? false,
185
- outDir: targetDir,
186
- pagesDir: app.pagesDir,
187
- plugins: options.plugins,
188
- publicPath: `${prefix}/_client/`,
189
- rootLayout: root.path,
190
- });
191
-
192
- const buildFingerprint = await createBuildFingerprint(
193
- `${prefix}\n${entryChunk}`,
194
- cssChunks,
195
- routes,
196
- root,
197
- serverEntry
198
- );
199
- const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
200
- if (serverEntry) {
201
- await buildRscGraph(routes, root, targetDir, buildId, options.plugins);
202
- }
203
-
204
- // Write index.html with the buildId meta tag injected so the client can
205
- // detect stale deploys via X-Furin-Build-ID header comparison.
206
- const clientDir = join(targetDir, clientDirName);
207
- const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
208
- writeFileSync(join(clientDir, "index.html"), indexHtml);
209
-
210
- // The SSG snapshot renders through the (build-time) default state bucket:
211
- // install this app's template, then clear the bucket's html caches so the
212
- // previous app's prerenders can never leak into this snapshot. The mount
213
- // prefix is passed explicitly — no instance scope exists at build time.
214
- setProductionTemplateContent(indexHtml);
215
- ssgRouteCache().clear();
216
- const ssgCache = serverEntry
217
- ? await buildSSGCacheSnapshot(routes, root, "http://localhost", prefix)
218
- : undefined;
219
-
220
- const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
221
- console.log(`[furin] Built ${label} (buildId ${buildId})`);
222
-
223
- return {
224
- buildId,
225
- entryApp: {
226
- buildId,
227
- clientLogging: options.clientLogging ?? false,
228
- embed: options.compile === "embed" ? { clientDir } : undefined,
229
- modulePaths: routeSourcePaths({ pagesDir: app.pagesDir, prefix }),
230
- nativeRoutes: routeModuleSpecifier(app),
231
- prefix,
232
- rootConventions,
233
- rootPath: root.path,
234
- routeMetadata,
235
- routes: routes.map((r) => ({ mode: r.mode, path: r.path, pattern: r.pattern })),
236
- ssgCache,
237
- },
238
- hydrateIntermediate:
239
- clientDirName === "client" ? "_hydrate.tsx" : `_hydrate-${clientDirName}.tsx`,
240
- };
241
- }
242
-
243
- async function buildAppsSequentially(
244
- apps: BunTargetApp[],
245
- targetDir: string,
246
- serverEntry: string | null,
247
- options: BuildAppOptions
248
- ): Promise<{
249
- entryApps: BuildEntryOptions["apps"];
250
- headlineBuildId: string;
251
- hydrateIntermediates: string[];
252
- }> {
253
- const entryApps: BuildEntryOptions["apps"] = [];
254
- const hydrateIntermediates: string[] = [];
255
- let headlineBuildId = "";
256
-
257
- for (const app of apps) {
258
- // biome-ignore lint/performance/noAwaitInLoops: each app installs a build-time template before SSG snapshotting, so this must remain ordered.
259
- const built = await buildOneApp(app, targetDir, serverEntry, options);
260
- entryApps.push(built.entryApp);
261
- hydrateIntermediates.push(built.hydrateIntermediate);
262
- // The ROOT app's buildId is the manifest's headline id (back-compat).
263
- if (app.prefix === "" || headlineBuildId === "") {
264
- headlineBuildId = built.buildId;
265
- }
266
- }
267
-
268
- return { entryApps, headlineBuildId, hydrateIntermediates };
44
+ return assets;
269
45
  }
270
46
 
271
47
  export async function buildBunTarget(
272
- apps: BunTargetApp[],
48
+ apps: RuntimeTargetApp[],
273
49
  rootDir: string,
274
50
  buildRoot: string,
275
51
  serverEntry: string | null,
@@ -293,11 +69,13 @@ export async function buildBunTarget(
293
69
  ensureDir(targetDir);
294
70
 
295
71
  const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
296
- const { entryApps, headlineBuildId, hydrateIntermediates } = await buildAppsSequentially(
72
+ const { entryApps, headlineBuildId } = await buildRuntimeAppsSequentially(
297
73
  apps,
74
+ rootDir,
298
75
  targetDir,
299
76
  serverEntry,
300
- options
77
+ options,
78
+ "bun"
301
79
  );
302
80
  targetManifest.buildId = headlineBuildId;
303
81
  if (serverEntry) {
@@ -314,26 +92,34 @@ export async function buildBunTarget(
314
92
  if (options.compile && serverEntry) {
315
93
  const outfile = join(targetDir, "server");
316
94
 
317
- const entryPath = generateCompileEntry({
95
+ const entry = generateCompileEntry({
318
96
  apps: entryApps,
319
97
  outDir: targetDir,
320
98
  publicDir,
321
99
  serverEntry,
322
100
  });
101
+ const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
323
102
 
324
103
  await runBunBuild({
325
- compile: { outfile },
104
+ bytecode: true,
105
+ compile: { assets: embeddedAssets, outfile },
326
106
  define: { "process.env.NODE_ENV": JSON.stringify("production") },
327
- entrypoints: [entryPath],
107
+ entrypoints: [entry.entrypoint],
108
+ files: entry.files,
109
+ format: "esm",
328
110
  minify: true,
329
111
  plugins: [
112
+ entry.plugin,
330
113
  productionInstrumentationPlugin(),
114
+ pprRuntimePlugin(apps),
331
115
  ...(options.plugins ?? []),
332
116
  createRoutesPlugin({ instances: apps, target: "server" }),
333
117
  isomorphicTransformPlugin("server"),
334
118
  environmentGuardPlugin("ssr"),
335
119
  ],
336
120
  sourcemap: "none",
121
+ splitting: true,
122
+ target: "bun",
337
123
  });
338
124
 
339
125
  console.log(`[furin] Server binary: ${outfile}`);
@@ -353,18 +139,22 @@ export async function buildBunTarget(
353
139
  }
354
140
  } else if (serverEntry) {
355
141
  // Disk mode: generate server.ts then bundle it into self-contained server.js
356
- const entryPath = generateDiskEntry({
142
+ const entry = generateDiskEntry({
357
143
  apps: entryApps,
358
144
  outDir: targetDir,
359
145
  serverEntry,
360
146
  });
361
147
 
362
148
  await runBunBuild({
363
- entrypoints: [entryPath],
149
+ entrypoints: [entry.entrypoint],
150
+ files: entry.files,
364
151
  minify: true,
152
+ naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
365
153
  outdir: targetDir,
366
154
  plugins: [
155
+ entry.plugin,
367
156
  productionInstrumentationPlugin(),
157
+ pprRuntimePlugin(apps),
368
158
  ...(options.plugins ?? []),
369
159
  createRoutesPlugin({ instances: apps, target: "server" }),
370
160
  isomorphicTransformPlugin("server"),
@@ -380,18 +170,5 @@ export async function buildBunTarget(
380
170
  targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, "server.js"));
381
171
  }
382
172
 
383
- // Clean up build intermediates — no longer needed once the bundle/binary is built.
384
- // NOTE: "index.html" is intentionally absent — generateProdIndexHtml writes
385
- // the final artifact to client/index.html (inside targetDir/client/), not to
386
- // targetDir directly, so there is nothing to remove here.
387
- for (const file of [
388
- "_compile-entry.ts",
389
- "_compile-entry.js.map",
390
- "server.ts", // disk mode intermediate
391
- ...hydrateIntermediates,
392
- ]) {
393
- rmSync(join(targetDir, file), { force: true });
394
- }
395
-
396
173
  return targetManifest;
397
174
  }
@@ -1,12 +1,13 @@
1
1
  import { existsSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join, relative, resolve } from "node:path";
3
- import { type BunTargetApp, createBuildFingerprint } from "../adapter/bun.ts";
3
+ import { createBuildFingerprint, type RuntimeTargetApp } from "../adapter/runtime-build.ts";
4
4
  import { runBunBuild } from "../build/bun-build.ts";
5
5
  import { buildClient } from "../build/client.ts";
6
6
  import { buildEntrySource } from "../build/entry-template.ts";
7
7
  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
+ import { createVirtualBuildEntry } from "../build/virtual-entry.ts";
10
11
  import { createRoutesPlugin, routeModuleSpecifier, routeSourcePaths } from "../plugin/routes.ts";
11
12
  import { ssgRouteCache } from "../server/cache/ssg.ts";
12
13
  import { generateProdIndexHtml } from "../server/render/shell.ts";
@@ -36,12 +37,13 @@ import { setProductionTemplateContent } from "../server/render/template.ts";
36
37
  * package without sources is production-only; its context is found by prefix.
37
38
  */
38
39
  export async function buildPackageTarget(
39
- app: BunTargetApp,
40
+ app: RuntimeTargetApp,
40
41
  rootDir: string,
41
42
  buildRoot: string,
42
43
  options: BuildAppOptions
43
44
  ): Promise<PackageTargetBuildManifest> {
44
45
  const { prefix, root, routes, pagesDir } = app;
46
+ const modulePaths = routeSourcePaths(app);
45
47
  const targetDir = join(buildRoot, "package");
46
48
 
47
49
  rmSync(targetDir, { force: true, recursive: true });
@@ -50,10 +52,13 @@ export async function buildPackageTarget(
50
52
  const { entryChunk, cssChunks } = await buildClient(routes, {
51
53
  basePath: prefix,
52
54
  clientLogging: options.clientLogging ?? false,
55
+ metafilePath: options.analyze ? join(buildRoot, "analysis", "package-client.json") : undefined,
56
+ optimizeImports: options.optimizeImports,
53
57
  outDir: targetDir,
54
58
  pagesDir,
55
59
  plugins: options.plugins,
56
60
  publicPath: `${prefix}/_client/`,
61
+ reactCompiler: options.reactCompiler,
57
62
  rootLayout: root.path,
58
63
  });
59
64
 
@@ -66,7 +71,9 @@ export async function buildPackageTarget(
66
71
  cssChunks,
67
72
  routes,
68
73
  root,
69
- null
74
+ null,
75
+ modulePaths,
76
+ rootDir
70
77
  );
71
78
  const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
72
79
 
@@ -124,7 +131,7 @@ export async function buildPackageTarget(
124
131
  {
125
132
  buildId,
126
133
  clientLogging: options.clientLogging ?? false,
127
- modulePaths: routeSourcePaths({ pagesDir, prefix }),
134
+ modulePaths,
128
135
  nativeRoutes: routeModuleSpecifier(app),
129
136
  prefix,
130
137
  rootConventions,
@@ -138,10 +145,11 @@ export async function buildPackageTarget(
138
145
  mode: "register",
139
146
  });
140
147
  const registerEntry = join(targetDir, "register.ts");
141
- writeFileSync(registerEntry, registerSource);
148
+ const register = createVirtualBuildEntry(registerEntry, registerSource, "ts");
142
149
 
143
150
  const result = await runBunBuild({
144
- entrypoints: [registerEntry],
151
+ entrypoints: [register.entrypoint],
152
+ files: register.files,
145
153
  minify: false,
146
154
  naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
147
155
  outdir: targetDir,
@@ -150,6 +158,7 @@ export async function buildPackageTarget(
150
158
  // the package's own page sources get bundled in.
151
159
  packages: "external",
152
160
  plugins: [
161
+ register.plugin,
153
162
  ...(options.plugins ?? []),
154
163
  createRoutesPlugin({ instances: [app], target: "server" }),
155
164
  ],
@@ -159,9 +168,6 @@ export async function buildPackageTarget(
159
168
  if (!result.success) {
160
169
  throw new AggregateError(result.logs, "[furin] package register build failed");
161
170
  }
162
- rmSync(registerEntry, { force: true });
163
- rmSync(join(targetDir, "_hydrate.tsx"), { force: true });
164
-
165
171
  // 2. index.js — the factory the host mounts. The baked relative pagesDir
166
172
  // keeps monorepo dev working; in a published package the compile context is
167
173
  // resolved by prefix instead.