@teyik0/furin 0.4.0-alpha.1 → 0.5.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.
- package/dist/adapter/bun.d.ts +2 -18
- package/dist/adapter/package.d.ts +2 -2
- package/dist/adapter/runtime-build.d.ts +33 -0
- package/dist/adapter/vercel.d.ts +3 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +6 -4
- package/dist/build/compile-entry.ts +36 -77
- package/dist/build/elysia-aot.d.ts +9 -0
- package/dist/build/entry-template.d.ts +9 -3
- package/dist/build/entry-template.ts +55 -13
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +8912 -6391
- package/dist/build/server-app-entry.d.ts +12 -0
- package/dist/build/ssg-cache.d.ts +13 -0
- package/dist/build/types.d.ts +25 -2
- package/dist/build/virtual-entry.d.ts +8 -0
- package/dist/cache.d.ts +6 -0
- package/dist/cache.js +282 -0
- package/dist/cli/index.js +8936 -6308
- package/dist/cli/preview.d.ts +7 -0
- package/dist/client/boundaries.d.ts +1 -0
- package/dist/client/browser-events-runtime.d.ts +2 -0
- package/dist/client/browser-events.d.ts +2 -0
- package/dist/client/define-route.d.ts +9 -8
- package/dist/client/dev-error-overlay.d.ts +1 -0
- package/dist/client/dev-error-overlay.ts +201 -0
- package/dist/client/document.d.ts +1 -0
- package/dist/client/hmr.d.ts +4 -2
- package/dist/client/internal/runtime-types.d.ts +8 -1
- package/dist/client/link.js +465 -86
- package/dist/client/router/provider.d.ts +1 -1
- package/dist/client/router/sync-catch-up.d.ts +1 -1
- package/dist/client/router/types.d.ts +8 -10
- package/dist/client/sync.d.ts +1 -0
- package/dist/client.js +37 -23
- package/dist/config.d.ts +35 -17
- package/dist/config.js +10 -2
- package/dist/define-route.d.ts +282 -1015
- package/dist/devtools/protocol.d.ts +2 -2
- package/dist/furin.d.ts +21 -6
- package/dist/furin.js +12823 -8484
- package/dist/plugin/index.js +476 -7
- package/dist/plugin/routes.d.ts +10 -3
- package/dist/rsc/build/index.d.ts +5 -1
- package/dist/server/assets/production.d.ts +3 -0
- package/dist/server/auto-invalidate/plugin.d.ts +8 -24
- package/dist/server/auto-invalidate/runtime.d.ts +2 -2
- package/dist/server/browser-events/plugin.d.ts +11 -0
- package/dist/server/browser-events/types.d.ts +9 -0
- package/dist/server/cache/invalidation.d.ts +2 -3
- package/dist/server/cache/isr.d.ts +1 -0
- package/dist/server/cache/page-cache-state.d.ts +5 -0
- package/dist/server/cache/page-cache.d.ts +53 -0
- package/dist/server/cache/purger.d.ts +7 -0
- package/dist/server/cache/redis/index.d.ts +39 -0
- package/dist/server/cache/redis/index.js +396 -0
- package/dist/server/cache/redis/scripts.d.ts +6 -0
- package/dist/server/cache/runtime-cache.d.ts +21 -0
- package/dist/server/context-logger.d.ts +2 -2
- package/dist/server/dev/browser-events.d.ts +4 -0
- package/dist/server/dev/diagnostics.d.ts +39 -0
- package/dist/server/dev/error.d.ts +17 -0
- package/dist/server/dev/graph.d.ts +86 -0
- package/dist/server/dev/plugin.d.ts +9 -0
- package/dist/server/dev/request-security.d.ts +1 -0
- package/dist/server/dev/rewrite-module-specifiers.d.ts +7 -0
- package/dist/server/dev/runtime.production.d.ts +6 -0
- package/dist/server/dev/symbolicate.d.ts +11 -0
- package/dist/server/dev/transform-failure.d.ts +4 -0
- package/dist/server/dev-page-plugin.d.ts +7 -0
- package/dist/server/dev-page-plugin.production.d.ts +1 -0
- package/dist/server/devtools/hub.d.ts +3 -2
- package/dist/server/devtools/instrumentation.d.ts +1 -1
- package/dist/server/devtools/instrumentation.production.d.ts +1 -1
- package/dist/server/devtools/plugin.d.ts +1 -1
- package/dist/server/evlog.d.ts +14 -0
- package/dist/server/external-prerender.d.ts +2 -0
- package/dist/server/instance.d.ts +2 -2
- package/dist/server/internal.d.ts +20 -2
- package/dist/server/internal.js +2973 -1
- package/dist/server/render/element.d.ts +1 -0
- package/dist/server/render/index.d.ts +1 -1
- package/dist/server/render/index.ts +1 -1
- package/dist/server/render/not-found.d.ts +1 -1
- package/dist/server/render/ppr-document.d.ts +21 -0
- package/dist/server/render/ppr-request.d.ts +26 -0
- package/dist/server/render/ppr-route.d.ts +3 -1
- package/dist/server/render/shell.ts +0 -12
- package/dist/server/render/ssg.d.ts +7 -0
- package/dist/server/render/ssr.d.ts +17 -6
- package/dist/server/render/static-params.d.ts +4 -0
- package/dist/server/router/defined-route.d.ts +1 -1
- package/dist/server/router/hmr.production.d.ts +2 -0
- package/dist/server/router/patterns.d.ts +1 -0
- package/dist/server/router/plugin.d.ts +3 -1
- package/dist/server/router/schemas.d.ts +1 -0
- package/dist/server/sync/adapter.d.ts +13 -0
- package/dist/server/sync/config.d.ts +5 -5
- package/dist/server/sync/index.d.ts +6 -6
- package/dist/server/sync/index.js +1252 -599
- package/dist/server/sync/notifier.d.ts +1 -0
- package/dist/server/sync/plugin.d.ts +31 -158
- package/dist/server/sync/postgres/index.d.ts +12 -1
- package/dist/server/sync/postgres/index.js +101 -6
- package/dist/server/sync/stream.d.ts +37 -61
- package/dist/shared/await.d.ts +3 -3
- package/dist/shared/browser-events.d.ts +22 -0
- package/dist/shared/compact-json.d.ts +8 -0
- package/dist/shared/deferred-ndjson.d.ts +6 -5
- package/dist/shared/dev-diagnostics.d.ts +36 -0
- package/dist/shared/elysia-contract.d.ts +8 -14
- package/dist/shared/prefix.d.ts +2 -0
- package/package.json +26 -11
- package/src/adapter/README.md +53 -1
- package/src/adapter/bun.ts +106 -283
- package/src/adapter/package.ts +21 -11
- package/src/adapter/runtime-build.ts +382 -0
- package/src/adapter/static.ts +87 -8
- package/src/adapter/vercel.ts +876 -0
- package/src/build/client.ts +55 -13
- package/src/build/compile-entry.ts +36 -77
- package/src/build/elysia-aot.ts +102 -0
- package/src/build/entry-template.ts +55 -13
- package/src/build/hydrate.ts +60 -20
- package/src/build/index.ts +17 -8
- package/src/build/production-instrumentation.ts +56 -4
- package/src/build/server-app-entry.ts +60 -0
- package/src/build/shared.ts +5 -2
- package/src/build/ssg-cache.ts +93 -12
- package/src/build/types.ts +31 -2
- package/src/build/virtual-entry.ts +28 -0
- package/src/cache.ts +26 -0
- package/src/cli/config.ts +3 -3
- package/src/cli/index.ts +58 -3
- package/src/cli/preview.ts +90 -0
- package/src/client/boundaries.tsx +10 -1
- package/src/client/browser-events-runtime.ts +204 -0
- package/src/client/browser-events.ts +22 -0
- package/src/client/define-route.ts +7 -17
- package/src/client/dev-error-overlay.ts +201 -0
- package/src/client/document.tsx +4 -7
- package/src/client/hmr.ts +26 -3
- package/src/client/internal/runtime-types.ts +10 -1
- package/src/client/router/boundary-tree.tsx +4 -4
- package/src/client/router/provider.tsx +165 -63
- package/src/client/router/sync-catch-up.ts +3 -4
- package/src/client/router/types.ts +6 -6
- package/src/client/sync.ts +1 -0
- package/src/config.ts +28 -2
- package/src/define-route.ts +285 -134
- package/src/devtools/devtools-element.js +56 -77
- package/src/devtools/protocol.ts +2 -2
- package/src/furin.ts +272 -203
- package/src/plugin/route-config-autofix.ts +11 -2
- package/src/plugin/routes.ts +291 -65
- package/src/plugin/transform-client.ts +685 -3
- package/src/react-dom-edge.d.ts +6 -0
- package/src/rsc/build/index.ts +15 -3
- package/src/server/assets/production.ts +99 -0
- package/src/server/auto-invalidate/plugin.ts +4 -4
- package/src/server/auto-invalidate/runtime.ts +76 -41
- package/src/server/browser-events/plugin.ts +173 -0
- package/src/server/browser-events/types.ts +11 -0
- package/src/server/cache/dev-loader.ts +30 -29
- package/src/server/cache/invalidation.ts +67 -35
- package/src/server/cache/isr.ts +9 -0
- package/src/server/cache/page-cache-state.ts +22 -0
- package/src/server/cache/page-cache.ts +300 -0
- package/src/server/cache/purger.ts +41 -0
- package/src/server/cache/redis/index.ts +350 -0
- package/src/server/cache/redis/scripts.ts +160 -0
- package/src/server/cache/runtime-cache.ts +137 -0
- package/src/server/context-logger.ts +5 -5
- package/src/server/dev/browser-events.ts +54 -0
- package/src/server/dev/diagnostics.ts +297 -0
- package/src/server/dev/error.ts +148 -0
- package/src/server/dev/graph.ts +438 -0
- package/src/server/dev/plugin.ts +130 -0
- package/src/server/dev/request-security.ts +38 -0
- package/src/server/dev/rewrite-module-specifiers.ts +81 -0
- package/src/server/dev/runtime.production.ts +28 -0
- package/src/server/dev/symbolicate.ts +135 -0
- package/src/server/dev/transform-failure.ts +8 -0
- package/src/server/dev-page-plugin.production.ts +3 -0
- package/src/server/dev-page-plugin.ts +136 -53
- package/src/server/devtools/hub.ts +6 -5
- package/src/server/devtools/instrumentation.production.ts +1 -1
- package/src/server/devtools/instrumentation.ts +12 -6
- package/src/server/devtools/plugin.ts +7 -150
- package/src/server/evlog.ts +99 -0
- package/src/server/external-prerender.ts +10 -0
- package/src/server/instance.ts +3 -3
- package/src/server/internal.ts +46 -2
- package/src/server/render/assemble.ts +4 -4
- package/src/server/render/document.tsx +13 -4
- package/src/server/render/element.tsx +18 -14
- package/src/server/render/index.ts +1 -1
- package/src/server/render/isr.ts +509 -136
- package/src/server/render/loaders.ts +31 -15
- package/src/server/render/not-found.ts +32 -8
- package/src/server/render/ppr-document.ts +239 -0
- package/src/server/render/ppr-request.ts +104 -0
- package/src/server/render/ppr-route.ts +335 -28
- package/src/server/render/shell.ts +0 -12
- package/src/server/render/ssg.ts +186 -24
- package/src/server/render/ssr.ts +215 -89
- package/src/server/render/static-params.ts +174 -0
- package/src/server/render/template.ts +47 -11
- package/src/server/router/defined-route.ts +9 -40
- package/src/server/router/hmr.production.ts +7 -0
- package/src/server/router/hmr.ts +108 -67
- package/src/server/router/patterns.ts +5 -1
- package/src/server/router/plugin.ts +164 -66
- package/src/server/router/schema-merge.ts +1 -1
- package/src/server/router/schemas.ts +174 -61
- package/src/server/router/source-version.ts +3 -10
- package/src/server/sync/adapter.ts +13 -0
- package/src/server/sync/config.ts +12 -12
- package/src/server/sync/index.ts +8 -8
- package/src/server/sync/notifier.ts +1 -0
- package/src/server/sync/plugin.ts +18 -11
- package/src/server/sync/postgres/index.ts +111 -5
- package/src/server/sync/response.ts +3 -3
- package/src/server/sync/runtime.ts +12 -0
- package/src/server/sync/stream.ts +78 -113
- package/src/shared/await.tsx +3 -3
- package/src/shared/browser-events.ts +28 -0
- package/src/shared/compact-json.ts +77 -0
- package/src/shared/deferred-ndjson.ts +20 -6
- package/src/shared/dev-diagnostics.ts +44 -0
- package/src/shared/elysia-contract.ts +23 -25
- package/src/shared/prefix.ts +8 -0
- package/src/shared/route-map.ts +10 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-alpha.1",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -36,6 +36,16 @@
|
|
|
36
36
|
"bun": "./src/client.ts",
|
|
37
37
|
"import": "./dist/client.js"
|
|
38
38
|
},
|
|
39
|
+
"./cache": {
|
|
40
|
+
"types": "./dist/cache.d.ts",
|
|
41
|
+
"bun": "./src/cache.ts",
|
|
42
|
+
"import": "./dist/cache.js"
|
|
43
|
+
},
|
|
44
|
+
"./cache/redis": {
|
|
45
|
+
"types": "./dist/server/cache/redis/index.d.ts",
|
|
46
|
+
"bun": "./src/server/cache/redis/index.ts",
|
|
47
|
+
"import": "./dist/server/cache/redis/index.js"
|
|
48
|
+
},
|
|
39
49
|
"./routes": {
|
|
40
50
|
"types": "./dist/routes.d.ts",
|
|
41
51
|
"bun": "./src/routes.ts",
|
|
@@ -132,19 +142,24 @@
|
|
|
132
142
|
"benchmark:rsc": "bun scripts/benchmark-rsc-transport.ts",
|
|
133
143
|
"build": "bun run build.ts",
|
|
134
144
|
"fix": "ultracite fix",
|
|
135
|
-
"test": "bun test --parallel --isolate --bail",
|
|
136
|
-
"test:dev": "bun test --changed --parallel --isolate --bail",
|
|
145
|
+
"test": "bun test --parallel=2 --isolate --max-concurrency 4 --bail --timeout 15000",
|
|
146
|
+
"test:dev": "bun test --changed --parallel --isolate --max-concurrency 4 --bail --timeout 15000",
|
|
147
|
+
"test:hmr:soak": "FURIN_WEBVIEW_TESTS=1 FURIN_HMR_SOAK_TESTS=1 bun test tests/browser/hmr-conformance.webview.test.ts -t 'tracks memory' --timeout 3600000",
|
|
148
|
+
"test:webview": "FURIN_WEBVIEW_TESTS=1 bun test tests/browser/hmr-conformance.webview.test.ts --timeout 60000",
|
|
137
149
|
"tscheck": "tsc --noEmit"
|
|
138
150
|
},
|
|
139
151
|
"dependencies": {
|
|
140
|
-
"@
|
|
141
|
-
"@
|
|
142
|
-
"@
|
|
152
|
+
"@elysia/static": "2.0.0-beta.2",
|
|
153
|
+
"@jridgewell/trace-mapping": "^0.3.31",
|
|
154
|
+
"@vercel/functions": "^3.9.7",
|
|
155
|
+
"@yuku-toolchain/types": "0.9.5",
|
|
156
|
+
"exact-mirror": "1.2.6",
|
|
143
157
|
"magic-string": "^1.2.3",
|
|
144
158
|
"react-server-dom-webpack": "19.2.8",
|
|
145
|
-
"seroval": "^1.6.
|
|
146
|
-
"
|
|
147
|
-
"yuku-
|
|
159
|
+
"seroval": "^1.6.7",
|
|
160
|
+
"typebox": "1.3.34",
|
|
161
|
+
"yuku-ast": "0.9.5",
|
|
162
|
+
"yuku-parser": "0.9.5"
|
|
148
163
|
},
|
|
149
164
|
"devDependencies": {
|
|
150
165
|
"@types/react": "^19.2.18",
|
|
@@ -152,8 +167,8 @@
|
|
|
152
167
|
"expect-type": "^1.4.0"
|
|
153
168
|
},
|
|
154
169
|
"peerDependencies": {
|
|
155
|
-
"elysia": "
|
|
156
|
-
"evlog": "^2.
|
|
170
|
+
"elysia": "2.0.0-beta.19",
|
|
171
|
+
"evlog": "^2.29.0",
|
|
157
172
|
"react": "19.2.8",
|
|
158
173
|
"react-dom": "19.2.8"
|
|
159
174
|
},
|
package/src/adapter/README.md
CHANGED
|
@@ -8,6 +8,58 @@ Goal is having 3 modes:
|
|
|
8
8
|
|
|
9
9
|
All should be portable.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Server bundles and executables run Elysia 2's build-time AOT plugin against a
|
|
12
|
+
real generated application entry. The listener lives in a separate boot entry,
|
|
13
|
+
so AOT capture never opens a port. `strip` remains disabled while the Kiana beta
|
|
14
|
+
WebSocket capability imports helpers omitted by its automatic WS stub.
|
|
12
15
|
|
|
13
16
|
## Vercel adapter
|
|
17
|
+
|
|
18
|
+
The Vercel target emits Build Output API v3 directly to `.vercel/output`:
|
|
19
|
+
|
|
20
|
+
- content-hashed browser assets and `public/` files under `static/`;
|
|
21
|
+
- one bundled `bun1.4.x` Web Handler under `functions/__server.func`;
|
|
22
|
+
- SSG Prerender Functions with no timed expiration and build-time fallbacks
|
|
23
|
+
for known URLs whose route tree has no query-dependent input;
|
|
24
|
+
- ISR Prerender Functions using each route's `revalidate` duration and
|
|
25
|
+
build-time fallbacks for fixed URLs or `staticParams()` values when the route
|
|
26
|
+
tree has no query-dependent input;
|
|
27
|
+
- a filesystem-first route table with a server fallback for SSR, APIs, and
|
|
28
|
+
`/_furin/data`.
|
|
29
|
+
|
|
30
|
+
The generated handler connects Furin cache invalidation to Vercel cache tags
|
|
31
|
+
and keeps background ISR work alive with `waitUntil`.
|
|
32
|
+
|
|
33
|
+
The Function bundle uses the same Elysia AOT capture path with the Bun target.
|
|
34
|
+
No custom Elysia runtime adapter is needed: Vercel invokes the application's
|
|
35
|
+
Web-standard `handle(Request)` API inside its Bun runtime.
|
|
36
|
+
|
|
37
|
+
Vercel Prerender Function invocations bypass Furin's process-local SSG/ISR
|
|
38
|
+
cache. The CDN owns freshness and each regeneration returns newly rendered
|
|
39
|
+
HTML; the in-memory cache remains exclusive to development and Bun targets.
|
|
40
|
+
|
|
41
|
+
The generated handler also installs Vercel Runtime Cache as the provider behind
|
|
42
|
+
`@teyik0/furin/cache`. Application code keeps one portable cache API while
|
|
43
|
+
development and Bun targets fall back to the in-memory provider.
|
|
44
|
+
|
|
45
|
+
Application `@elysia/static` mounts are rejected during Vercel builds: their
|
|
46
|
+
runtime filesystem mappings are not deployable CDN mappings. Place static files
|
|
47
|
+
under `public/` instead. PPR pages produce a cached public HTML shell, postponed
|
|
48
|
+
React state and public loader snapshot atomically. Vercel's native `chain`
|
|
49
|
+
continuation runs private request loaders and resumes React without caching the
|
|
50
|
+
personalized output. Build-time shells are generated by the production bundle
|
|
51
|
+
itself, ensuring the minified component tree remains compatible with its state.
|
|
52
|
+
|
|
53
|
+
Successful `/_furin/data` responses for SSG/ISR routes share the document's
|
|
54
|
+
cache tag and revalidation window. SSR, request-loader, deferred, and failed
|
|
55
|
+
navigation responses remain `private, no-store`.
|
|
56
|
+
|
|
57
|
+
JSON-only navigation data uses a compact JSON envelope. CrossJSON and Route
|
|
58
|
+
Frames remain the lossless transports for rich values, shared references,
|
|
59
|
+
deferred data, and RSC payloads.
|
|
60
|
+
|
|
61
|
+
The Vercel Function starts through a lightweight `index.js` bootstrap. Its
|
|
62
|
+
first request logs a `vercel_cold_start` event and every dynamic response
|
|
63
|
+
exposes `furin_module_init`, `furin_server_init`, `furin_handler_wait`, and
|
|
64
|
+
`furin_handler` through `Server-Timing`. `--analyze` writes both Vercel client
|
|
65
|
+
and server metafiles under `.furin/build/analysis`.
|
package/src/adapter/bun.ts
CHANGED
|
@@ -1,275 +1,94 @@
|
|
|
1
|
-
import { existsSync,
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
4
3
|
import { runBunBuild } from "../build/bun-build.ts";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
type BuildEntryOptions,
|
|
9
|
-
buildEntrySource,
|
|
10
|
-
type EntryAppContext,
|
|
11
|
-
} 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";
|
|
12
7
|
import { productionInstrumentationPlugin } from "../build/production-instrumentation.ts";
|
|
8
|
+
import { materializeServerAppEntry, serverBootSource } from "../build/server-app-entry.ts";
|
|
13
9
|
import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
|
|
14
|
-
import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
|
|
15
10
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
11
|
+
import { createVirtualBuildEntry, type VirtualBuildEntry } from "../build/virtual-entry.ts";
|
|
16
12
|
import type { BuildTarget } from "../config.ts";
|
|
17
|
-
import { createRoutesPlugin
|
|
13
|
+
import { createRoutesPlugin } from "../plugin/routes.ts";
|
|
18
14
|
import { isomorphicTransformPlugin } from "../plugin/transform-isomorphic.ts";
|
|
19
15
|
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
16
|
import { clientDirNameForPrefix } from "../shared/prefix.ts";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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 {
|
|
60
|
-
ensureDir(options.outDir);
|
|
61
|
-
const source = buildEntrySource({
|
|
62
|
-
apps: options.apps.map(({ embed: _embed, ...context }) => context),
|
|
63
|
-
headerComment: "// Auto-generated by furin build - do not edit",
|
|
64
|
-
serverEntry: options.serverEntry,
|
|
65
|
-
});
|
|
66
|
-
const entryPath = join(options.outDir, "server.ts");
|
|
67
|
-
writeFileSync(entryPath, source);
|
|
68
|
-
return entryPath;
|
|
17
|
+
import {
|
|
18
|
+
buildRuntimeAppsSequentially,
|
|
19
|
+
pprRuntimePlugin,
|
|
20
|
+
type RuntimeTargetApp,
|
|
21
|
+
} from "./runtime-build.ts";
|
|
22
|
+
|
|
23
|
+
function generateBootEntry(
|
|
24
|
+
appEntry: string,
|
|
25
|
+
outDir: string,
|
|
26
|
+
filename: "_compile-entry.ts" | "server.ts"
|
|
27
|
+
): VirtualBuildEntry {
|
|
28
|
+
ensureDir(outDir);
|
|
29
|
+
const entryPath = join(outDir, filename);
|
|
30
|
+
return createVirtualBuildEntry(entryPath, serverBootSource(appEntry), "ts");
|
|
69
31
|
}
|
|
70
32
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
}
|
|
33
|
+
function collectEmbeddedAssets(
|
|
34
|
+
entryApps: BuildEntryOptions["apps"],
|
|
35
|
+
publicDir: string | undefined,
|
|
36
|
+
compile: BuildAppOptions["compile"]
|
|
37
|
+
): string[] | undefined {
|
|
38
|
+
if (compile !== "embed") {
|
|
39
|
+
return;
|
|
105
40
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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);
|
|
116
|
-
}
|
|
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
|
-
};
|
|
41
|
+
const assets = entryApps.flatMap((app) => (app.embed ? [app.embed.clientDir] : []));
|
|
42
|
+
if (publicDir !== undefined) {
|
|
43
|
+
assets.push(publicDir);
|
|
153
44
|
}
|
|
154
|
-
|
|
155
|
-
return { rootConventions, routeMetadata };
|
|
45
|
+
return assets;
|
|
156
46
|
}
|
|
157
47
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
pagesDir: string;
|
|
161
|
-
prefix: string;
|
|
162
|
-
root: RootLayout;
|
|
163
|
-
routes: ResolvedRoute[];
|
|
48
|
+
function compiledServerFilename(platform: NodeJS.Platform): string {
|
|
49
|
+
return platform === "win32" ? "server.exe" : "server";
|
|
164
50
|
}
|
|
165
51
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
52
|
+
async function createBunAppEntry(
|
|
53
|
+
apps: RuntimeTargetApp[],
|
|
54
|
+
entryApps: BuildEntryOptions["apps"],
|
|
55
|
+
options: BuildAppOptions,
|
|
56
|
+
publicDir: string | undefined,
|
|
170
57
|
serverEntry: string | null,
|
|
171
|
-
|
|
172
|
-
): Promise<{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
58
|
+
targetDir: string
|
|
59
|
+
): Promise<string | undefined> {
|
|
60
|
+
if (!serverEntry) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const contexts = options.compile
|
|
64
|
+
? prepareCompileEntryApps({
|
|
65
|
+
apps: entryApps,
|
|
66
|
+
outDir: targetDir,
|
|
67
|
+
publicDir,
|
|
68
|
+
serverEntry,
|
|
69
|
+
})
|
|
70
|
+
: entryApps.map(({ embed: _embed, ...context }) => ({
|
|
71
|
+
...context,
|
|
72
|
+
extraContext: [
|
|
73
|
+
...(context.extraContext ?? []),
|
|
74
|
+
` clientDir: import.meta.dir + ${JSON.stringify(`/${clientDirNameForPrefix(context.prefix ?? "")}`)},`,
|
|
75
|
+
],
|
|
76
|
+
templateHtml: readFileSync(
|
|
77
|
+
join(targetDir, clientDirNameForPrefix(context.prefix ?? ""), "index.html"),
|
|
78
|
+
"utf8"
|
|
79
|
+
),
|
|
80
|
+
}));
|
|
81
|
+
return await materializeServerAppEntry({
|
|
82
|
+
apps: contexts,
|
|
83
|
+
headerComment: "// Auto-generated by furin build - do not edit",
|
|
84
|
+
instances: apps,
|
|
185
85
|
outDir: targetDir,
|
|
186
|
-
|
|
187
|
-
plugins: options.plugins,
|
|
188
|
-
publicPath: `${prefix}/_client/`,
|
|
189
|
-
rootLayout: root.path,
|
|
86
|
+
serverEntry,
|
|
190
87
|
});
|
|
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 };
|
|
269
88
|
}
|
|
270
89
|
|
|
271
90
|
export async function buildBunTarget(
|
|
272
|
-
apps:
|
|
91
|
+
apps: RuntimeTargetApp[],
|
|
273
92
|
rootDir: string,
|
|
274
93
|
buildRoot: string,
|
|
275
94
|
serverEntry: string | null,
|
|
@@ -293,11 +112,13 @@ export async function buildBunTarget(
|
|
|
293
112
|
ensureDir(targetDir);
|
|
294
113
|
|
|
295
114
|
const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
|
|
296
|
-
const { entryApps, headlineBuildId
|
|
115
|
+
const { entryApps, headlineBuildId } = await buildRuntimeAppsSequentially(
|
|
297
116
|
apps,
|
|
117
|
+
rootDir,
|
|
298
118
|
targetDir,
|
|
299
119
|
serverEntry,
|
|
300
|
-
options
|
|
120
|
+
options,
|
|
121
|
+
"bun"
|
|
301
122
|
);
|
|
302
123
|
targetManifest.buildId = headlineBuildId;
|
|
303
124
|
if (serverEntry) {
|
|
@@ -311,34 +132,48 @@ export async function buildBunTarget(
|
|
|
311
132
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
312
133
|
}
|
|
313
134
|
|
|
314
|
-
|
|
315
|
-
|
|
135
|
+
const appEntry = await createBunAppEntry(
|
|
136
|
+
apps,
|
|
137
|
+
entryApps,
|
|
138
|
+
options,
|
|
139
|
+
publicDir,
|
|
140
|
+
serverEntry,
|
|
141
|
+
targetDir
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (options.compile && serverEntry && appEntry) {
|
|
145
|
+
const serverFilename = compiledServerFilename(process.platform);
|
|
146
|
+
const outfile = join(targetDir, serverFilename);
|
|
316
147
|
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
outDir: targetDir,
|
|
320
|
-
publicDir,
|
|
321
|
-
serverEntry,
|
|
322
|
-
});
|
|
148
|
+
const entry = generateBootEntry(appEntry, targetDir, "_compile-entry.ts");
|
|
149
|
+
const embeddedAssets = collectEmbeddedAssets(entryApps, publicDir, options.compile);
|
|
323
150
|
|
|
324
151
|
await runBunBuild({
|
|
325
|
-
|
|
152
|
+
bytecode: true,
|
|
153
|
+
compile: { assets: embeddedAssets, outfile },
|
|
326
154
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
327
|
-
entrypoints: [
|
|
155
|
+
entrypoints: [entry.entrypoint],
|
|
156
|
+
files: entry.files,
|
|
157
|
+
format: "esm",
|
|
328
158
|
minify: true,
|
|
329
159
|
plugins: [
|
|
160
|
+
entry.plugin,
|
|
330
161
|
productionInstrumentationPlugin(),
|
|
162
|
+
pprRuntimePlugin(apps),
|
|
331
163
|
...(options.plugins ?? []),
|
|
332
164
|
createRoutesPlugin({ instances: apps, target: "server" }),
|
|
333
165
|
isomorphicTransformPlugin("server"),
|
|
334
166
|
environmentGuardPlugin("ssr"),
|
|
167
|
+
elysiaAot(appEntry),
|
|
335
168
|
],
|
|
336
169
|
sourcemap: "none",
|
|
170
|
+
splitting: true,
|
|
171
|
+
target: "bun",
|
|
337
172
|
});
|
|
338
173
|
|
|
339
174
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
340
175
|
|
|
341
|
-
targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir,
|
|
176
|
+
targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, serverFilename));
|
|
342
177
|
|
|
343
178
|
// Embed mode: assets are in the binary — clean up client dirs too.
|
|
344
179
|
if (options.compile === "embed") {
|
|
@@ -351,24 +186,25 @@ export async function buildBunTarget(
|
|
|
351
186
|
targetManifest.clientDir = null;
|
|
352
187
|
targetManifest.templatePath = null;
|
|
353
188
|
}
|
|
354
|
-
} else if (serverEntry) {
|
|
189
|
+
} else if (serverEntry && appEntry) {
|
|
355
190
|
// Disk mode: generate server.ts then bundle it into self-contained server.js
|
|
356
|
-
const
|
|
357
|
-
apps: entryApps,
|
|
358
|
-
outDir: targetDir,
|
|
359
|
-
serverEntry,
|
|
360
|
-
});
|
|
191
|
+
const entry = generateBootEntry(appEntry, targetDir, "server.ts");
|
|
361
192
|
|
|
362
193
|
await runBunBuild({
|
|
363
|
-
entrypoints: [
|
|
194
|
+
entrypoints: [entry.entrypoint],
|
|
195
|
+
files: entry.files,
|
|
364
196
|
minify: true,
|
|
197
|
+
naming: { chunk: "[name]-[hash].[ext]", entry: "[name].[ext]" },
|
|
365
198
|
outdir: targetDir,
|
|
366
199
|
plugins: [
|
|
200
|
+
entry.plugin,
|
|
367
201
|
productionInstrumentationPlugin(),
|
|
202
|
+
pprRuntimePlugin(apps),
|
|
368
203
|
...(options.plugins ?? []),
|
|
369
204
|
createRoutesPlugin({ instances: apps, target: "server" }),
|
|
370
205
|
isomorphicTransformPlugin("server"),
|
|
371
206
|
environmentGuardPlugin("ssr"),
|
|
207
|
+
elysiaAot(appEntry),
|
|
372
208
|
],
|
|
373
209
|
sourcemap: "none",
|
|
374
210
|
target: "bun",
|
|
@@ -380,18 +216,5 @@ export async function buildBunTarget(
|
|
|
380
216
|
targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, "server.js"));
|
|
381
217
|
}
|
|
382
218
|
|
|
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
219
|
return targetManifest;
|
|
397
220
|
}
|