@teyik0/furin 0.2.0-alpha.5 → 0.3.0-alpha.1

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 (238) hide show
  1. package/README.md +2 -3
  2. package/dist/adapter/static.d.ts +1 -1
  3. package/dist/build/bun-build.d.ts +3 -0
  4. package/dist/build/entry-template.d.ts +2 -0
  5. package/dist/build/entry-template.ts +3 -0
  6. package/dist/build/hydrate.d.ts +1 -1
  7. package/dist/build/index.js +6944 -5067
  8. package/dist/build/production-instrumentation.d.ts +1 -0
  9. package/dist/build/route-types.d.ts +1 -1
  10. package/dist/build/types.d.ts +1 -0
  11. package/dist/cli/index.js +7874 -5971
  12. package/dist/client/boundaries.d.ts +4 -4
  13. package/dist/client/internal/runtime-types.d.ts +30 -0
  14. package/dist/client/link.d.ts +2 -1
  15. package/dist/client/link.js +712 -338
  16. package/dist/client/router/boundary-tree.d.ts +1 -1
  17. package/dist/client/router/index.d.ts +1 -1
  18. package/dist/client/router/link-utils.d.ts +5 -1
  19. package/dist/client/router/sync-catch-up.d.ts +4 -4
  20. package/dist/client/router/types.d.ts +2 -2
  21. package/dist/client-only.d.ts +1 -0
  22. package/dist/client-only.js +1 -0
  23. package/dist/client.d.ts +108 -111
  24. package/dist/client.js +16 -17
  25. package/dist/config.d.ts +1 -1
  26. package/dist/config.js +2 -2
  27. package/dist/devtools/devtools-element.d.ts +1 -0
  28. package/dist/devtools/protocol.d.ts +119 -0
  29. package/dist/furin.d.ts +7 -6
  30. package/dist/furin.js +6547 -3187
  31. package/dist/isomorphic.d.ts +18 -0
  32. package/dist/plugin/binding-scope.d.ts +2 -0
  33. package/dist/plugin/dead-code-elimination.d.ts +3 -0
  34. package/dist/plugin/index.js +933 -423
  35. package/dist/plugin/transform-client.d.ts +0 -2
  36. package/dist/plugin/transform-isomorphic.d.ts +9 -0
  37. package/dist/rsc/build/environment.d.ts +2 -0
  38. package/dist/rsc/build/index.d.ts +15 -0
  39. package/dist/rsc/client-codec.d.ts +1 -0
  40. package/dist/rsc/codec.d.ts +4 -0
  41. package/dist/rsc/flight-drain.d.ts +11 -0
  42. package/dist/rsc/render-error.d.ts +17 -0
  43. package/dist/rsc/server-codec.d.ts +2 -0
  44. package/dist/rsc/server-codec.js +24 -0
  45. package/dist/rsc/shared.d.ts +30 -0
  46. package/dist/rsc/symbols.d.ts +2 -0
  47. package/dist/rsc/transport-benchmark.d.ts +13 -0
  48. package/dist/rsc/version.d.ts +7 -0
  49. package/dist/rsc-client.d.ts +4 -0
  50. package/dist/rsc-client.js +166 -0
  51. package/dist/rsc-server.d.ts +11 -0
  52. package/dist/rsc.d.ts +11 -0
  53. package/dist/rsc.js +353 -0
  54. package/dist/server/cache/index.d.ts +2 -2
  55. package/dist/server/cache/invalidation.d.ts +2 -3
  56. package/dist/server/cache/isr-ssg.d.ts +5 -1
  57. package/dist/server/cache/isr.d.ts +9 -0
  58. package/dist/server/cache/route-cache.d.ts +10 -8
  59. package/dist/server/cache/store-view.d.ts +7 -7
  60. package/dist/server/dev-page-plugin.d.ts +4 -0
  61. package/dist/server/devtools/hub.d.ts +11 -0
  62. package/dist/server/devtools/instrumentation.d.ts +22 -0
  63. package/dist/server/devtools/instrumentation.production.d.ts +44 -0
  64. package/dist/server/devtools/plugin.d.ts +3 -0
  65. package/dist/server/devtools/request-context.d.ts +6 -0
  66. package/dist/server/internal.d.ts +2 -0
  67. package/dist/server/internal.js +3 -3
  68. package/dist/server/lang-detect.d.ts +1 -0
  69. package/dist/server/render/assemble.d.ts +4 -0
  70. package/dist/server/render/element.d.ts +1 -1
  71. package/dist/server/render/index.d.ts +2 -2
  72. package/dist/server/render/index.ts +6 -2
  73. package/dist/server/render/loaders.d.ts +8 -0
  74. package/dist/server/render/not-found.d.ts +1 -1
  75. package/dist/server/render/ppr-route.d.ts +8 -0
  76. package/dist/server/render/route-frame-transport.d.ts +2 -0
  77. package/dist/server/render/shell.ts +0 -1
  78. package/dist/server/render/ssr.d.ts +2 -3
  79. package/dist/server/router/discovery.d.ts +1 -1
  80. package/dist/server/router/hmr.d.ts +1 -1
  81. package/dist/server/router/index.d.ts +2 -1
  82. package/dist/server/router/index.js +23 -23
  83. package/dist/server/router/index.ts +1 -1
  84. package/dist/server/router/patterns.d.ts +1 -1
  85. package/dist/server/router/plugin.d.ts +4 -7
  86. package/dist/server/router/schema-merge.d.ts +3 -0
  87. package/dist/server/router/schemas.d.ts +12 -7
  88. package/dist/server/router/types.d.ts +1 -1
  89. package/dist/server/runtime-env.js +2 -2
  90. package/dist/server/sync/adapter.d.ts +45 -26
  91. package/dist/server/sync/config.d.ts +5 -9
  92. package/dist/server/sync/fingerprint.d.ts +2 -1
  93. package/dist/server/sync/index.d.ts +15 -4
  94. package/dist/server/sync/index.js +2868 -0
  95. package/dist/server/sync/notifier.d.ts +18 -0
  96. package/dist/server/sync/plugin.d.ts +53 -54
  97. package/dist/server/sync/postgres/index.d.ts +19 -0
  98. package/dist/server/sync/postgres/index.js +252 -0
  99. package/dist/server/sync/postgres/migrate.d.ts +2 -0
  100. package/dist/server/sync/postgres/migrate.js +16 -0
  101. package/dist/server/sync/postgres/migration.sql +66 -0
  102. package/dist/server/sync/redis/index.d.ts +30 -0
  103. package/dist/server/sync/redis/index.js +336 -0
  104. package/dist/server/sync/redis/scripts.d.ts +4 -0
  105. package/dist/server/sync/response.d.ts +10 -1
  106. package/dist/server/sync/runtime.d.ts +6 -0
  107. package/dist/server/sync/sqlite/index.d.ts +20 -0
  108. package/dist/server/sync/sqlite/index.js +250 -0
  109. package/dist/server/sync/stream.d.ts +12 -11
  110. package/dist/server-only.d.ts +1 -0
  111. package/dist/server-only.js +1 -0
  112. package/dist/shared/parser.d.ts +2 -0
  113. package/dist/shared/route-frame.d.ts +49 -0
  114. package/dist/shared/utils/index.d.ts +1 -1
  115. package/package.json +54 -12
  116. package/src/adapter/bun.ts +73 -16
  117. package/src/adapter/package.ts +3 -1
  118. package/src/adapter/static.ts +94 -48
  119. package/src/build/bun-build.ts +11 -0
  120. package/src/build/client.ts +22 -24
  121. package/src/build/entry-template.ts +3 -0
  122. package/src/build/hydrate.ts +33 -8
  123. package/src/build/index.ts +12 -0
  124. package/src/build/production-instrumentation.ts +14 -0
  125. package/src/build/route-types.ts +7 -8
  126. package/src/build/scan-server.ts +3 -2
  127. package/src/build/ssg-cache.ts +7 -2
  128. package/src/build/types.ts +1 -0
  129. package/src/cli/index.ts +53 -22
  130. package/src/client/boundaries.tsx +42 -18
  131. package/src/client/default-screens.tsx +4 -4
  132. package/src/client/internal/runtime-types.ts +31 -0
  133. package/src/client/link.tsx +35 -37
  134. package/src/client/router/boundary-tree.tsx +2 -2
  135. package/src/client/router/context.ts +13 -9
  136. package/src/client/router/index.ts +3 -0
  137. package/src/client/router/link-utils.ts +66 -3
  138. package/src/client/router/navigation.ts +9 -15
  139. package/src/client/router/provider.tsx +74 -52
  140. package/src/client/router/search/index.ts +5 -7
  141. package/src/client/router/search-store.ts +5 -1
  142. package/src/client/router/spa-response.ts +3 -4
  143. package/src/client/router/sync-catch-up.ts +9 -8
  144. package/src/client/router/types.ts +2 -2
  145. package/src/client/sync.ts +3 -2
  146. package/src/client-only.ts +1 -0
  147. package/src/client.ts +221 -174
  148. package/src/devtools/devtools-element.js +884 -0
  149. package/src/devtools/protocol.ts +139 -0
  150. package/src/furin.ts +185 -96
  151. package/src/isomorphic.ts +66 -0
  152. package/src/plugin/binding-scope.ts +158 -0
  153. package/src/plugin/dead-code-elimination.ts +202 -0
  154. package/src/plugin/index.ts +14 -18
  155. package/src/plugin/transform-client.ts +237 -273
  156. package/src/plugin/transform-isomorphic.ts +464 -0
  157. package/src/rsc/build/environment.ts +30 -0
  158. package/src/rsc/build/index.ts +94 -0
  159. package/src/rsc/client-codec.ts +11 -0
  160. package/src/rsc/codec.ts +85 -0
  161. package/src/rsc/flight-drain.ts +68 -0
  162. package/src/rsc/react-server-dom-webpack.d.ts +23 -0
  163. package/src/rsc/render-error.ts +120 -0
  164. package/src/rsc/server-codec.ts +25 -0
  165. package/src/rsc/shared.tsx +113 -0
  166. package/src/rsc/symbols.ts +2 -0
  167. package/src/rsc/transport-benchmark.ts +73 -0
  168. package/src/rsc/version.ts +57 -0
  169. package/src/rsc-client.ts +12 -0
  170. package/src/rsc-server.tsx +91 -0
  171. package/src/rsc.tsx +75 -0
  172. package/src/server/auto-invalidate/runtime.ts +32 -6
  173. package/src/server/cache/dev-loader.ts +70 -10
  174. package/src/server/cache/index.ts +7 -3
  175. package/src/server/cache/invalidation.ts +33 -15
  176. package/src/server/cache/isr-ssg.ts +12 -3
  177. package/src/server/cache/isr.ts +84 -9
  178. package/src/server/cache/route-cache.ts +49 -36
  179. package/src/server/cache/store-view.ts +7 -7
  180. package/src/server/context-logger.ts +7 -7
  181. package/src/server/dev-page-plugin.ts +8 -6
  182. package/src/server/devtools/hub.ts +64 -0
  183. package/src/server/devtools/instrumentation.production.ts +80 -0
  184. package/src/server/devtools/instrumentation.ts +72 -0
  185. package/src/server/devtools/plugin.ts +267 -0
  186. package/src/server/devtools/request-context.ts +76 -0
  187. package/src/server/instance.ts +1 -1
  188. package/src/server/internal.ts +2 -0
  189. package/src/server/lang-detect.ts +14 -10
  190. package/src/server/render/assemble.ts +73 -10
  191. package/src/server/render/element.tsx +11 -8
  192. package/src/server/render/index.ts +6 -2
  193. package/src/server/render/isr.ts +154 -110
  194. package/src/server/render/loaders.ts +259 -45
  195. package/src/server/render/not-found.ts +10 -15
  196. package/src/server/render/ppr-route.ts +146 -0
  197. package/src/server/render/route-frame-transport.ts +62 -0
  198. package/src/server/render/shell.ts +0 -1
  199. package/src/server/render/ssg.ts +6 -5
  200. package/src/server/render/ssr.ts +155 -67
  201. package/src/server/render/template.ts +2 -1
  202. package/src/server/router/discovery.ts +39 -22
  203. package/src/server/router/hmr.ts +15 -13
  204. package/src/server/router/index.ts +1 -1
  205. package/src/server/router/patterns.ts +16 -15
  206. package/src/server/router/plugin.ts +151 -158
  207. package/src/server/router/schema-merge.ts +52 -0
  208. package/src/server/router/schemas.ts +55 -73
  209. package/src/server/router/types.ts +1 -1
  210. package/src/server/sync/adapter.ts +44 -28
  211. package/src/server/sync/config.ts +9 -27
  212. package/src/server/sync/fingerprint.ts +8 -3
  213. package/src/server/sync/index.ts +37 -13
  214. package/src/server/sync/notifier.ts +109 -0
  215. package/src/server/sync/plugin.ts +184 -89
  216. package/src/server/sync/postgres/index.ts +301 -0
  217. package/src/server/sync/postgres/migrate.ts +15 -0
  218. package/src/server/sync/postgres/migration.sql +66 -0
  219. package/src/server/sync/redis/index.ts +342 -0
  220. package/src/server/sync/redis/scripts.ts +74 -0
  221. package/src/server/sync/response.ts +141 -16
  222. package/src/server/sync/runtime.ts +27 -0
  223. package/src/server/sync/sql.d.ts +4 -0
  224. package/src/server/sync/sqlite/index.ts +337 -0
  225. package/src/server/sync/sqlite/migration.sql +70 -0
  226. package/src/server/sync/stream.ts +137 -81
  227. package/src/server-only.ts +1 -0
  228. package/src/shared/await.tsx +4 -4
  229. package/src/shared/deferred-ndjson.ts +34 -6
  230. package/src/shared/digest.ts +2 -2
  231. package/src/shared/parser.ts +5 -0
  232. package/src/shared/route-frame.ts +429 -0
  233. package/src/shared/search-params.ts +7 -7
  234. package/src/shared/utils/index.ts +5 -3
  235. package/dist/server/dev-inspector.d.ts +0 -89
  236. package/dist/server/sync/memory-adapter.d.ts +0 -17
  237. package/src/server/dev-inspector.ts +0 -60
  238. package/src/server/sync/memory-adapter.ts +0 -196
@@ -0,0 +1,2 @@
1
+ import { type ParseResult, type SourceLang } from "yuku-parser";
2
+ export declare function parseSource(code: string, lang: SourceLang): ParseResult;
@@ -0,0 +1,49 @@
1
+ import type { SerovalNode } from "seroval";
2
+ import { type RscSourceKind } from "../rsc/shared.tsx";
3
+ export declare const MAX_ROUTE_FRAME_STREAM_BYTES: number;
4
+ export type RouteFrame = {
5
+ type: "data";
6
+ deferredKeys: readonly string[];
7
+ value: SerovalNode;
8
+ } | {
9
+ type: "defer-resolve";
10
+ key: string;
11
+ value: SerovalNode;
12
+ } | {
13
+ type: "defer-reject";
14
+ key: string;
15
+ value: SerovalNode;
16
+ } | {
17
+ type: "rsc-start";
18
+ id: string;
19
+ kind: RscSourceKind;
20
+ } | {
21
+ type: "rsc-chunk";
22
+ id: string;
23
+ value: string;
24
+ } | {
25
+ type: "rsc-end";
26
+ id: string;
27
+ } | {
28
+ type: "rsc-error";
29
+ id: string;
30
+ digest: string;
31
+ };
32
+ export declare function serializeRouteFrame(frame: RouteFrame): string;
33
+ export declare function serializeRouteFrameValue(value: unknown, idPrefix?: string): {
34
+ rscFrames: string;
35
+ value: SerovalNode;
36
+ };
37
+ export declare function containsRscSource(value: unknown): boolean;
38
+ export declare function serializeRouteFrames(data: object, deferredKeys: readonly string[] | undefined): string;
39
+ export declare function isRouteFrameLine(line: string): boolean;
40
+ export declare function parseRouteFrameLines(firstLine: string, readLine: () => Promise<string | undefined>): Promise<{
41
+ abort: (reason: unknown) => void;
42
+ completion: Promise<void>;
43
+ deferredPromises: {
44
+ [key: string]: Promise<unknown>;
45
+ };
46
+ syncData: {
47
+ [key: string]: unknown;
48
+ };
49
+ }>;
@@ -1,4 +1,4 @@
1
- import type { RuntimePage, RuntimeRoute } from "../../client";
1
+ import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
2
2
  export declare function isFurinPage(value: unknown): value is RuntimePage;
3
3
  export declare function isFurinRoute(value: unknown): value is RuntimeRoute;
4
4
  export declare function collectRouteChainFromRoute(route: RuntimeRoute): RuntimeRoute[];
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@teyik0/furin",
3
- "version": "0.2.0-alpha.5",
3
+ "version": "0.3.0-alpha.1",
4
4
  "description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
5
5
  "license": "MIT",
6
6
  "author": "teyik0",
7
7
  "sideEffects": false,
8
8
  "type": "module",
9
9
  "engines": {
10
- "bun": ">=1.3.0"
10
+ "bun": ">=1.4.0"
11
11
  },
12
12
  "keywords": [
13
13
  "react",
@@ -38,7 +38,8 @@
38
38
  "module": "./dist/furin.js",
39
39
  "types": "./dist/furin.d.ts",
40
40
  "bin": {
41
- "furin": "./src/cli/index.ts"
41
+ "furin": "./src/cli/index.ts",
42
+ "furin-sync-postgres-migrate": "./dist/server/sync/postgres/migrate.js"
42
43
  },
43
44
  "exports": {
44
45
  ".": {
@@ -51,6 +52,12 @@
51
52
  "bun": "./src/client.ts",
52
53
  "import": "./dist/client.js"
53
54
  },
55
+ "./rsc": {
56
+ "types": "./dist/rsc.d.ts",
57
+ "browser": "./src/rsc-client.ts",
58
+ "bun": "./src/rsc.tsx",
59
+ "import": "./dist/rsc.js"
60
+ },
54
61
  "./build": {
55
62
  "types": "./dist/build/index.d.ts",
56
63
  "bun": "./src/build/index.ts",
@@ -66,6 +73,28 @@
66
73
  "bun": "./src/server/router/index.ts",
67
74
  "import": "./dist/server/router/index.js"
68
75
  },
76
+ "./sync": {
77
+ "types": "./dist/server/sync/index.d.ts",
78
+ "bun": "./src/server/sync/index.ts",
79
+ "import": "./dist/server/sync/index.js"
80
+ },
81
+ "./sync/postgres": {
82
+ "types": "./dist/server/sync/postgres/index.d.ts",
83
+ "bun": "./src/server/sync/postgres/index.ts",
84
+ "import": "./dist/server/sync/postgres/index.js"
85
+ },
86
+ "./sync/postgres/migration.sql": "./src/server/sync/postgres/migration.sql",
87
+ "./sync/redis": {
88
+ "types": "./dist/server/sync/redis/index.d.ts",
89
+ "bun": "./src/server/sync/redis/index.ts",
90
+ "import": "./dist/server/sync/redis/index.js"
91
+ },
92
+ "./sync/sqlite": {
93
+ "types": "./dist/server/sync/sqlite/index.d.ts",
94
+ "bun": "./src/server/sync/sqlite/index.ts",
95
+ "import": "./dist/server/sync/sqlite/index.js"
96
+ },
97
+ "./sync/sqlite/migration.sql": "./src/server/sync/sqlite/migration.sql",
69
98
  "./strip-plugin": {
70
99
  "types": "./dist/plugin/index.d.ts",
71
100
  "bun": "./src/plugin/index.ts",
@@ -89,20 +118,33 @@
89
118
  "types": "./dist/server/internal.d.ts",
90
119
  "bun": "./src/server/internal.ts",
91
120
  "import": "./dist/server/internal.js"
121
+ },
122
+ "./server-only": {
123
+ "types": "./dist/server-only.d.ts",
124
+ "bun": "./src/server-only.ts",
125
+ "import": "./dist/server-only.js"
126
+ },
127
+ "./client-only": {
128
+ "types": "./dist/client-only.d.ts",
129
+ "bun": "./src/client-only.ts",
130
+ "import": "./dist/client-only.js"
92
131
  }
93
132
  },
94
133
  "scripts": {
95
134
  "fix": "ultracite fix",
96
- "test": "bun test --parallel --isolate --bail --preload ../../tests/setup.ts",
97
- "test:dev": "bun test --changed --parallel --isolate --bail --preload ../../tests/setup.ts",
135
+ "test": "bun test --parallel --isolate --bail",
136
+ "test:dev": "bun test --changed --parallel --isolate --bail",
98
137
  "tscheck": "tsc --noEmit",
99
- "build": "bun run build.ts"
138
+ "build": "bun run build.ts",
139
+ "benchmark:rsc": "bun scripts/benchmark-rsc-transport.ts"
100
140
  },
101
141
  "dependencies": {
102
142
  "@elysiajs/static": "^1.4.10",
103
- "magic-string": "^0.30.21",
104
- "seroval": "^1.5.4",
105
- "yuku-parser": "^0.5.43"
143
+ "@yuku-toolchain/types": "0.8.0",
144
+ "magic-string": "^1.1.0",
145
+ "react-server-dom-webpack": "19.2.8",
146
+ "seroval": "^1.5.6",
147
+ "yuku-parser": "0.8.0"
106
148
  },
107
149
  "devDependencies": {
108
150
  "@types/react": "^19.2.17",
@@ -111,8 +153,8 @@
111
153
  },
112
154
  "peerDependencies": {
113
155
  "elysia": "^1.4.29",
114
- "evlog": "^2.19.2",
115
- "react": "^19.2.7",
116
- "react-dom": "^19.2.7"
156
+ "evlog": "^2.22.3",
157
+ "react": "19.2.8",
158
+ "react-dom": "19.2.8"
117
159
  }
118
160
  }
@@ -1,14 +1,19 @@
1
1
  import { existsSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
+ import { runBunBuild } from "../build/bun-build.ts";
4
5
  import { buildClient } from "../build/client.ts";
5
6
  import { generateCompileEntry } from "../build/compile-entry.ts";
6
7
  import type { BuildEntryOptions, EntryAppContext } from "../build/entry-template.ts";
8
+ import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
7
9
  import { generateServerRoutesEntry } from "../build/server-routes-entry.ts";
8
10
  import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
9
11
  import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
10
12
  import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
11
13
  import type { BuildTarget } from "../config.ts";
14
+ import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
15
+ import { environmentGuardPlugin } from "../rsc/build/environment.ts";
16
+ import { buildRscGraph } from "../rsc/build/index.ts";
12
17
  import { ssgRouteCache } from "../server/cache/ssg.ts";
13
18
  import { generateProdIndexHtml } from "../server/render/shell.ts";
14
19
  import { setProductionTemplateContent } from "../server/render/template.ts";
@@ -38,6 +43,16 @@ const BUILD_ID_INPUT_PATHS = [
38
43
  `${_pkgSrcDir}/server/router/index${_ext}`,
39
44
  ];
40
45
 
46
+ function compareCodeUnits(a: string, b: string): number {
47
+ if (a < b) {
48
+ return -1;
49
+ }
50
+ if (a > b) {
51
+ return 1;
52
+ }
53
+ return 0;
54
+ }
55
+
41
56
  /**
42
57
  * Deterministic build-ID input covering everything that can change rendered
43
58
  * output: client chunks, route shape, route/root/error/not-found source
@@ -96,7 +111,7 @@ export async function createBuildFingerprint(
96
111
  .map((route) =>
97
112
  JSON.stringify({ mode: route.mode, path: toPosixPath(route.path), pattern: route.pattern })
98
113
  )
99
- .sort();
114
+ .sort(compareCodeUnits);
100
115
 
101
116
  return [entryChunk, ...[...cssChunks].toSorted(), ...routeParts, ...fileParts].join("\n");
102
117
  }
@@ -166,6 +181,9 @@ async function buildOneApp(
166
181
  serverEntry
167
182
  );
168
183
  const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
184
+ if (serverEntry) {
185
+ await buildRscGraph(routes, root, targetDir, buildId, options.plugins);
186
+ }
169
187
 
170
188
  // Write index.html with the buildId meta tag injected so the client can
171
189
  // detect stale deploys via X-Furin-Build-ID header comparison.
@@ -190,6 +208,7 @@ async function buildOneApp(
190
208
  buildId,
191
209
  entryApp: {
192
210
  buildId,
211
+ clientLogging: options.clientLogging ?? false,
193
212
  prefix,
194
213
  rootPath: root.path,
195
214
  routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
@@ -203,6 +222,34 @@ async function buildOneApp(
203
222
  };
204
223
  }
205
224
 
225
+ async function buildAppsSequentially(
226
+ apps: BunTargetApp[],
227
+ targetDir: string,
228
+ serverEntry: string | null,
229
+ options: BuildAppOptions
230
+ ): Promise<{
231
+ entryApps: BuildEntryOptions["apps"];
232
+ headlineBuildId: string;
233
+ hydrateIntermediates: string[];
234
+ }> {
235
+ const entryApps: BuildEntryOptions["apps"] = [];
236
+ const hydrateIntermediates: string[] = [];
237
+ let headlineBuildId = "";
238
+
239
+ for (const app of apps) {
240
+ // biome-ignore lint/performance/noAwaitInLoops: each app installs a build-time template before SSG snapshotting, so this must remain ordered.
241
+ const built = await buildOneApp(app, targetDir, serverEntry, options);
242
+ entryApps.push(built.entryApp);
243
+ hydrateIntermediates.push(built.hydrateIntermediate);
244
+ // The ROOT app's buildId is the manifest's headline id (back-compat).
245
+ if (app.prefix === "" || headlineBuildId === "") {
246
+ headlineBuildId = built.buildId;
247
+ }
248
+ }
249
+
250
+ return { entryApps, headlineBuildId, hydrateIntermediates };
251
+ }
252
+
206
253
  export async function buildBunTarget(
207
254
  apps: BunTargetApp[],
208
255
  rootDir: string,
@@ -228,17 +275,17 @@ export async function buildBunTarget(
228
275
  ensureDir(targetDir);
229
276
 
230
277
  const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
231
- const entryApps: BuildEntryOptions["apps"] = [];
232
- const hydrateIntermediates: string[] = [];
233
-
234
- for (const app of apps) {
235
- const built = await buildOneApp(app, targetDir, serverEntry, options);
236
- entryApps.push(built.entryApp);
237
- hydrateIntermediates.push(built.hydrateIntermediate);
238
- // The ROOT app's buildId is the manifest's headline id (back-compat).
239
- if (app.prefix === "" || targetManifest.buildId === "") {
240
- targetManifest.buildId = built.buildId;
241
- }
278
+ const { entryApps, headlineBuildId, hydrateIntermediates } = await buildAppsSequentially(
279
+ apps,
280
+ targetDir,
281
+ serverEntry,
282
+ options
283
+ );
284
+ targetManifest.buildId = headlineBuildId;
285
+ if (serverEntry) {
286
+ targetManifest.rscManifestPath = toPosixPath(
287
+ join(targetManifest.targetDir, "rsc", "manifest.json")
288
+ );
242
289
  }
243
290
 
244
291
  const targetPublicDir = publicDir ? join(targetDir, "public") : undefined;
@@ -256,13 +303,18 @@ export async function buildBunTarget(
256
303
  publicDir,
257
304
  });
258
305
 
259
- await Bun.build({
306
+ await runBunBuild({
260
307
  entrypoints: [entryPath],
261
308
  compile: { outfile },
262
309
  minify: true,
263
310
  sourcemap: "none",
264
311
  define: { "process.env.NODE_ENV": JSON.stringify("production") },
265
- plugins: options.plugins,
312
+ plugins: [
313
+ productionInstrumentationPlugin(),
314
+ ...(options.plugins ?? []),
315
+ isomorphicTransformPlugin("server"),
316
+ environmentGuardPlugin("ssr"),
317
+ ],
266
318
  });
267
319
 
268
320
  console.log(`[furin] Server binary: ${outfile}`);
@@ -288,13 +340,18 @@ export async function buildBunTarget(
288
340
  outDir: targetDir,
289
341
  });
290
342
 
291
- await Bun.build({
343
+ await runBunBuild({
292
344
  entrypoints: [entryPath],
293
345
  outdir: targetDir,
294
346
  target: "bun",
295
347
  minify: true,
296
348
  sourcemap: "none",
297
- plugins: options.plugins,
349
+ plugins: [
350
+ productionInstrumentationPlugin(),
351
+ ...(options.plugins ?? []),
352
+ isomorphicTransformPlugin("server"),
353
+ environmentGuardPlugin("ssr"),
354
+ ],
298
355
  });
299
356
  console.log(
300
357
  `[furin] Server bundle: ${toPosixPath(join(targetManifest.targetDir, "server.js"))}`
@@ -1,6 +1,7 @@
1
1
  import { existsSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join, relative, resolve } from "node:path";
3
3
  import { type BunTargetApp, createBuildFingerprint } from "../adapter/bun.ts";
4
+ import { runBunBuild } from "../build/bun-build.ts";
4
5
  import { buildClient } from "../build/client.ts";
5
6
  import { buildEntrySource } from "../build/entry-template.ts";
6
7
  import { copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
@@ -120,6 +121,7 @@ export async function buildPackageTarget(
120
121
  apps: [
121
122
  {
122
123
  buildId,
124
+ clientLogging: options.clientLogging ?? false,
123
125
  prefix,
124
126
  rootPath: root.path,
125
127
  routes: routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode })),
@@ -134,7 +136,7 @@ export async function buildPackageTarget(
134
136
  const registerEntry = join(targetDir, "register.ts");
135
137
  writeFileSync(registerEntry, registerSource);
136
138
 
137
- const result = await Bun.build({
139
+ const result = await runBunBuild({
138
140
  entrypoints: [registerEntry],
139
141
  outdir: targetDir,
140
142
  target: "bun",
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/performance/noAwaitInLoops: static build emits routes in sequence to keep output deterministic
1
2
  import { cpSync, existsSync, rmSync, writeFileSync } from "node:fs";
2
3
  import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
3
4
  import { buildClient } from "../build/client.ts";
@@ -5,14 +6,11 @@ import { ensureDir, toPosixPath } from "../build/shared.ts";
5
6
  import type { BuildAppOptions, StaticTargetBuildManifest } from "../build/types.ts";
6
7
  import type { StaticExportConfig } from "../config.ts";
7
8
  import { resolvePath } from "../server/render/assemble.ts";
8
- import { prerenderSSG } from "../server/render/index.ts";
9
9
  import { generateProdIndexHtml } from "../server/render/shell.ts";
10
+ import { prerenderSSG } from "../server/render/ssg.ts";
10
11
  import { setProductionTemplateContent } from "../server/render/template.ts";
11
- import {
12
- createSearchRouteMetadata,
13
- type ResolvedRoute,
14
- type RootLayout,
15
- } from "../server/router/index.ts";
12
+ import { createSearchRouteMetadata } from "../server/router/schemas.ts";
13
+ import type { ResolvedRoute, RootLayout } from "../server/router/types.ts";
16
14
  import type { SearchRouteMetadata } from "../shared/search-params.ts";
17
15
  import { mapWithConcurrency } from "../shared/utils/index.ts";
18
16
 
@@ -51,6 +49,38 @@ function pathToOutputFile(urlPath: string, outDir: string, fileName: string): st
51
49
  return resolved;
52
50
  }
53
51
 
52
+ function sortRouteList(routes: string[]): string[] {
53
+ return routes.toSorted((a, b) => (a < b ? -1 : Number(a > b)));
54
+ }
55
+
56
+ function assertNoStaticExportSkips(onSSR: "error" | "skip", skippedRoutes: string[]): void {
57
+ if (onSSR !== "error" || skippedRoutes.length === 0) {
58
+ return;
59
+ }
60
+ const failed = sortRouteList(skippedRoutes);
61
+ const list = failed.map((r) => ` • ${r}`).join("\n");
62
+ throw new Error(
63
+ `[furin] static: ${failed.length} route(s) cannot be statically exported:\n${list}\n` +
64
+ `Define \`staticParams()\` for dynamic SSG routes or set \`onSSR: "skip"\` in your static config.`
65
+ );
66
+ }
67
+
68
+ function assertNoPrerenderSkips(
69
+ onSSR: "error" | "skip",
70
+ skippedRoutes: string[],
71
+ afterQueueCount: number
72
+ ): void {
73
+ if (onSSR !== "error" || skippedRoutes.length <= afterQueueCount) {
74
+ return;
75
+ }
76
+ const failed = sortRouteList(skippedRoutes.slice(afterQueueCount));
77
+ const list = failed.map((r) => ` • ${r}`).join("\n");
78
+ throw new Error(
79
+ `[furin] static: ${failed.length} route(s) failed to pre-render:\n${list}\n` +
80
+ `Set \`onSSR: "skip"\` in your static config to suppress this error.`
81
+ );
82
+ }
83
+
54
84
  // ── Pre-render worker ─────────────────────────────────────────────────────────
55
85
 
56
86
  async function prerenderAndWrite(
@@ -165,18 +195,18 @@ async function buildTaskQueue(
165
195
  STATIC_CONCURRENCY,
166
196
  async (route) => {
167
197
  if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
168
- return { route, paramSets: [{}] };
198
+ return { paramSets: [{}], route };
169
199
  }
170
200
  if (!route.page.staticParams) {
171
201
  console.warn(
172
202
  `[furin] static: skipping dynamic route "${route.pattern}" — no staticParams() defined.`
173
203
  );
174
204
  skippedRoutes.push(route.pattern);
175
- return { route, paramSets: null };
205
+ return { paramSets: null, route };
176
206
  }
177
207
  try {
178
208
  const paramSets = (await route.page.staticParams()) ?? [];
179
- return { route, paramSets };
209
+ return { paramSets, route };
180
210
  } catch (err) {
181
211
  return { error: err, paramSets: null, route };
182
212
  }
@@ -184,12 +214,10 @@ async function buildTaskQueue(
184
214
  );
185
215
 
186
216
  for (const result of staticParamsResults) {
217
+ const { pattern } = result.route;
187
218
  if ("error" in result) {
188
- console.error(
189
- `[furin] static: staticParams() failed for "${result.route.pattern}":`,
190
- result.error
191
- );
192
- skippedRoutes.push(result.route.pattern);
219
+ console.error(`[furin] static: staticParams() failed for "${pattern}":`, result.error);
220
+ skippedRoutes.push(pattern);
193
221
  continue;
194
222
  }
195
223
  if (result.paramSets === null) {
@@ -206,6 +234,8 @@ async function buildTaskQueue(
206
234
  continue;
207
235
  }
208
236
  for (const params of result.paramSets) {
237
+ const urlPath = resolvePath(result.route.pattern, params);
238
+ pathToOutputFile(urlPath, outDir, "index.html");
209
239
  tasks.push(() =>
210
240
  prerenderAndWrite(
211
241
  result.route,
@@ -243,6 +273,24 @@ async function runWithConcurrency(
243
273
 
244
274
  // ── Main adapter ──────────────────────────────────────────────────────────────
245
275
 
276
+ function assertNoRequestLoaders(routes: ResolvedRoute[], root: RootLayout): void {
277
+ const offenders: string[] = [];
278
+ if (root.route.requestLoader !== undefined) {
279
+ offenders.push(" • <root layout>");
280
+ }
281
+ const requestScopedRoutes = routes.filter((route) =>
282
+ route.routeChain.some((entry) => entry.requestLoader !== undefined)
283
+ );
284
+ offenders.push(...requestScopedRoutes.map((route) => ` • ${route.pattern}`));
285
+ if (offenders.length === 0) {
286
+ return;
287
+ }
288
+ throw new Error(
289
+ "[furin] requestLoader requires a Bun server and is incompatible with a pure static export.\n" +
290
+ offenders.join("\n")
291
+ );
292
+ }
293
+
246
294
  export async function buildStaticTarget(
247
295
  routes: ResolvedRoute[],
248
296
  rootDir: string,
@@ -250,6 +298,8 @@ export async function buildStaticTarget(
250
298
  root: RootLayout,
251
299
  options: BuildAppOptions
252
300
  ): Promise<StaticTargetBuildManifest> {
301
+ assertNoRequestLoaders(routes, root);
302
+
253
303
  const staticConfig: StaticExportConfig = options.staticConfig ?? {};
254
304
 
255
305
  // Normalize basePath: treat "" and "/" identically as no prefix; strip any
@@ -311,7 +361,22 @@ export async function buildStaticTarget(
311
361
  const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
312
362
  const searchRoutes = createSearchRouteMetadata(ssgRoutes);
313
363
 
314
- // ── 2. Clean & create output directories ─────────────────────────────────
364
+ // ── 2. Resolve and validate every output path before writing artifacts ────
365
+ const tasks = await buildTaskQueue(
366
+ ssgRoutes,
367
+ root,
368
+ outDir,
369
+ renderedRoutes,
370
+ skippedRoutes,
371
+ basePath,
372
+ searchRoutes
373
+ );
374
+ assertNoStaticExportSkips(onSSR, skippedRoutes);
375
+ // Snapshot after queue-building: routes skipped due to missing staticParams() are
376
+ // already recorded; only routes added during task execution are prerender failures.
377
+ const afterQueueCount = skippedRoutes.length;
378
+
379
+ // ── 3. Clean & create output directories ─────────────────────────────────
315
380
  rmSync(outDir, { force: true, recursive: true });
316
381
  ensureDir(outDir);
317
382
 
@@ -319,71 +384,52 @@ export async function buildStaticTarget(
319
384
  rmSync(targetDir, { force: true, recursive: true });
320
385
  ensureDir(targetDir);
321
386
 
322
- // ── 3. Build client bundle ────────────────────────────────────────────────
387
+ // ── 4. Build client bundle ────────────────────────────────────────────────
323
388
  const { entryChunk, cssChunks } = await buildClient(ssgRoutes, {
389
+ basePath,
390
+ clientLogging: Boolean(options.clientLogging),
324
391
  outDir: targetDir,
325
- rootLayout: root.path,
326
392
  plugins: options.plugins,
327
393
  publicPath,
328
- basePath,
329
- clientLogging: Boolean(options.clientLogging),
394
+ rootLayout: root.path,
330
395
  });
331
396
 
332
- // ── 4. Generate HTML shell template ──────────────────────────────────────
397
+ // ── 5. Generate HTML shell template ──────────────────────────────────────
333
398
  // Emit a <link rel="icon"> only when a favicon.ico exists in the public dir.
334
399
  // This ensures the browser finds it even when the site is served from a sub-path.
335
400
  const publicFavicon = join(rootDir, "public", "favicon.ico");
336
401
  const faviconHref = existsSync(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
337
402
  const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
338
403
 
339
- // ── 5. Prime the renderer with the production shell ──────────────────────
404
+ // ── 6. Prime the renderer with the production shell ──────────────────────
340
405
  // Must be called before any prerenderSSG invocation.
341
406
  // prepareRender() checks getProductionTemplate() first (before IS_DEV), so
342
407
  // setting the content here is sufficient — no need to flip IS_DEV globally.
343
408
  setProductionTemplateContent(shellHtml);
344
409
 
345
- // ── 6. Copy public/ → outDir/ ─────────────────────────────────────────────
410
+ // ── 7. Copy public/ → outDir/ ─────────────────────────────────────────────
346
411
  const publicSrcDir = join(rootDir, "public");
347
412
  if (existsSync(publicSrcDir)) {
348
413
  cpSync(publicSrcDir, outDir, { recursive: true });
349
414
  }
350
415
 
351
- // ── 7. Copy _client/ chunks → outDir/_client/ ────────────────────────────
416
+ // ── 8. Copy _client/ chunks → outDir/_client/ ────────────────────────────
352
417
  const clientSrcDir = join(targetDir, "client");
353
418
  if (existsSync(clientSrcDir)) {
354
419
  cpSync(clientSrcDir, join(outDir, "_client"), { recursive: true });
355
420
  }
356
421
 
357
- // ── 8. Pre-render SSG routes ──────────────────────────────────────────────
358
- const tasks = await buildTaskQueue(
359
- ssgRoutes,
360
- root,
361
- outDir,
362
- renderedRoutes,
363
- skippedRoutes,
364
- basePath,
365
- searchRoutes
366
- );
367
- // Snapshot after queue-building: routes skipped due to missing staticParams() are
368
- // already recorded; only routes added during task execution are prerender failures.
369
- const afterQueueCount = skippedRoutes.length;
422
+ // ── 9. Pre-render SSG routes ──────────────────────────────────────────────
370
423
  await runWithConcurrency(tasks, STATIC_CONCURRENCY);
371
424
 
372
425
  // Fail the build when onSSR="error" and any prerender task was recorded as skipped.
373
- if (onSSR === "error" && skippedRoutes.length > afterQueueCount) {
374
- const failed = skippedRoutes.slice(afterQueueCount);
375
- const list = failed.map((r) => ` • ${r}`).join("\n");
376
- throw new Error(
377
- `[furin] static: ${failed.length} route(s) failed to pre-render:\n${list}\n` +
378
- `Set \`onSSR: "skip"\` in your static config to suppress this error.`
379
- );
380
- }
426
+ assertNoPrerenderSkips(onSSR, skippedRoutes, afterQueueCount);
381
427
 
382
- // ── 9. Write 404.html (SPA fallback for GitHub Pages) ───────────────────
428
+ // ── 10. Write 404.html (SPA fallback for GitHub Pages) ──────────────────
383
429
  writeFileSync(join(outDir, "404.html"), shellHtml);
384
430
  console.log("[furin] static: wrote 404.html (SPA shell fallback)");
385
431
 
386
- // ── 10. Clean up intermediate build artifacts ────────────────────────────
432
+ // ── 11. Clean up intermediate build artifacts ───────────────────────────
387
433
  rmSync(targetDir, { force: true, recursive: true });
388
434
 
389
435
  console.log(
@@ -395,7 +441,7 @@ export async function buildStaticTarget(
395
441
  basePath,
396
442
  generatedAt: new Date().toISOString(),
397
443
  outDir: toPosixPath(outDir),
398
- renderedRoutes,
399
- skippedRoutes,
444
+ renderedRoutes: sortRouteList(renderedRoutes),
445
+ skippedRoutes: sortRouteList(skippedRoutes),
400
446
  };
401
447
  }
@@ -0,0 +1,11 @@
1
+ type BunBuild = typeof Bun.build;
2
+
3
+ type BunBuildGlobal = typeof globalThis & {
4
+ __FURIN_BUN_BUILD_FOR_TESTS?: BunBuild;
5
+ };
6
+
7
+ export function runBunBuild(config: Bun.BuildConfig): ReturnType<BunBuild> {
8
+ return (((globalThis as BunBuildGlobal).__FURIN_BUN_BUILD_FOR_TESTS ?? Bun.build) as BunBuild)(
9
+ config
10
+ );
11
+ }