@teyik0/furin 0.1.0-alpha.9 → 0.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +33 -0
- package/package.json +61 -25
- package/src/adapter/bun.ts +90 -41
- package/src/adapter/static.ts +100 -40
- package/src/build/client.ts +13 -14
- package/src/build/compile-entry.ts +20 -14
- package/src/build/entry-template.ts +90 -8
- package/src/build/hydrate.ts +219 -36
- package/src/build/index.ts +10 -9
- package/src/build/route-types.ts +65 -9
- package/src/build/scan-server.ts +52 -67
- package/src/build/server-routes-entry.ts +7 -11
- package/src/build/shared.ts +2 -1
- package/src/build/ssg-cache.ts +32 -0
- package/src/build/types.ts +5 -1
- package/src/cli/index.ts +1 -0
- package/src/client/boundaries.tsx +259 -0
- package/src/client/default-screens.tsx +304 -0
- package/src/client/link.tsx +347 -0
- package/src/client/router/boundary-tree.tsx +116 -0
- package/src/client/router/context.ts +40 -0
- package/src/client/router/history.ts +41 -0
- package/src/client/router/index.ts +56 -0
- package/src/client/router/link-utils.ts +177 -0
- package/src/client/router/navigation.ts +61 -0
- package/src/client/router/provider.tsx +759 -0
- package/src/client/router/search/index.ts +99 -0
- package/src/client/router/search-store.ts +86 -0
- package/src/client/router/spa-response.ts +143 -0
- package/src/client/router/types.ts +271 -0
- package/src/client/server-error.ts +47 -0
- package/src/client.ts +80 -3
- package/src/config.ts +11 -3
- package/src/env.d.ts +1 -0
- package/src/furin.ts +114 -29
- package/src/plugin/index.ts +7 -8
- package/src/plugin/transform-client.ts +146 -120
- package/src/server/auto-invalidate/index.ts +10 -0
- package/src/server/auto-invalidate/plugin.ts +25 -0
- package/src/server/auto-invalidate/registry.ts +60 -0
- package/src/server/auto-invalidate/runtime.ts +133 -0
- package/src/server/auto-invalidate/types.ts +16 -0
- package/src/server/cache/dev-loader.ts +211 -0
- package/src/server/cache/index.ts +34 -0
- package/src/server/cache/invalidation.ts +111 -0
- package/src/server/cache/isr-ssg.ts +41 -0
- package/src/server/cache/isr.ts +17 -0
- package/src/server/cache/registry.ts +35 -0
- package/src/server/cache/route-cache.ts +124 -0
- package/src/server/cache/ssg.ts +15 -0
- package/src/{context-logger.ts → server/context-logger.ts} +5 -0
- package/src/server/dev-inspector.ts +60 -0
- package/src/{dev-page-plugin.ts → server/dev-page-plugin.ts} +15 -0
- package/src/{internal.ts → server/internal.ts} +17 -0
- package/src/server/lang-detect.ts +46 -0
- package/src/server/render/assemble.ts +133 -0
- package/src/server/render/element.tsx +113 -0
- package/src/server/render/index.ts +22 -0
- package/src/server/render/isr.ts +317 -0
- package/src/server/render/loaders.ts +328 -0
- package/src/server/render/not-found.ts +98 -0
- package/src/{render → server/render}/shell.ts +28 -13
- package/src/server/render/ssg.ts +148 -0
- package/src/server/render/ssr.ts +583 -0
- package/src/server/router/discovery.ts +474 -0
- package/src/server/router/hmr.ts +376 -0
- package/src/server/router/index.ts +28 -0
- package/src/server/router/patterns.ts +219 -0
- package/src/server/router/plugin.ts +384 -0
- package/src/server/router/schemas.ts +278 -0
- package/src/server/router/types.ts +59 -0
- package/src/shared/await.tsx +192 -0
- package/src/shared/deferred-ndjson.ts +244 -0
- package/src/shared/digest.ts +71 -0
- package/src/shared/error.ts +49 -0
- package/src/shared/not-found.ts +40 -0
- package/src/shared/search-params.ts +182 -0
- package/src/shared/utils/ast-walk.ts +51 -0
- package/src/{utils.ts → shared/utils/index.ts} +32 -1
- package/dist/adapter/bun.d.ts +0 -3
- package/dist/adapter/static.d.ts +0 -3
- package/dist/build/client.d.ts +0 -25
- package/dist/build/compile-entry.d.ts +0 -23
- package/dist/build/entry-template.d.ts +0 -14
- package/dist/build/hydrate.d.ts +0 -24
- package/dist/build/index.d.ts +0 -7
- package/dist/build/index.js +0 -3727
- package/dist/build/route-types.d.ts +0 -21
- package/dist/build/scan-server.d.ts +0 -8
- package/dist/build/server-routes-entry.d.ts +0 -23
- package/dist/build/shared.d.ts +0 -11
- package/dist/build/types.d.ts +0 -76
- package/dist/cli/config.d.ts +0 -9
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -3762
- package/dist/client.d.ts +0 -195
- package/dist/client.js +0 -20
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -28
- package/dist/context-logger.d.ts +0 -26
- package/dist/dev-page-plugin.d.ts +0 -109
- package/dist/furin.d.ts +0 -34
- package/dist/furin.js +0 -2744
- package/dist/internal.d.ts +0 -19
- package/dist/link.d.ts +0 -245
- package/dist/link.js +0 -1232
- package/dist/plugin/index.d.ts +0 -20
- package/dist/plugin/index.js +0 -1408
- package/dist/plugin/transform-client.d.ts +0 -9
- package/dist/render/assemble.d.ts +0 -15
- package/dist/render/cache.d.ts +0 -95
- package/dist/render/element.d.ts +0 -4
- package/dist/render/index.d.ts +0 -27
- package/dist/render/loaders.d.ts +0 -12
- package/dist/render/shell.d.ts +0 -29
- package/dist/render/template.d.ts +0 -6
- package/dist/router.d.ts +0 -45
- package/dist/router.js +0 -1671
- package/dist/runtime-env.d.ts +0 -3
- package/dist/utils.d.ts +0 -6
- package/src/link.tsx +0 -1120
- package/src/render/assemble.ts +0 -66
- package/src/render/cache.ts +0 -241
- package/src/render/element.tsx +0 -28
- package/src/render/index.ts +0 -483
- package/src/render/loaders.ts +0 -117
- package/src/router.ts +0 -439
- /package/src/{render → server/render}/template.ts +0 -0
- /package/src/{runtime-env.ts → server/runtime-env.ts} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 teyik0
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/teyik0/furin/main/apps/docs/public/furin-logo.webp" alt="Furin" width="120" />
|
|
3
|
+
<h1>Furin</h1>
|
|
4
|
+
<p>React meta-framework powered by Elysia and Bun — file-based routing, SSR, SSG, ISR, and full TypeScript inference.</p>
|
|
5
|
+
|
|
6
|
+
<a href="https://www.npmjs.com/package/@teyik0/furin"><img src="https://img.shields.io/npm/v/%40teyik0%2Ffurin?style=flat-square&logo=npm&color=orange" alt="npm version" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@teyik0/furin"><img src="https://img.shields.io/npm/dm/%40teyik0%2Ffurin?style=flat-square&color=orange" alt="npm downloads" /></a>
|
|
8
|
+
<a href="https://github.com/teyik0/furin/blob/main/LICENSE"><img src="https://img.shields.io/github/license/teyik0/furin?style=flat-square" alt="License" /></a>
|
|
9
|
+
<a href="https://bun.sh"><img src="https://img.shields.io/badge/bun-%3E%3D1.3.0-f5d147?style=flat-square&logo=bun&logoColor=black" alt="Bun" /></a>
|
|
10
|
+
<a href="https://www.typescriptlang.org"><img src="https://img.shields.io/badge/TypeScript-strict-3178c6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript" /></a>
|
|
11
|
+
<a href="https://react.review/repo/Teyik0/furin"><img src="https://react.review/api/badge/Teyik0/furin" alt="React Review" /></a>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
bun create furin@latest my-app
|
|
20
|
+
cd my-app
|
|
21
|
+
bun install
|
|
22
|
+
bun run dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For the shadcn/ui starter:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
bun create furin@latest my-app --template full
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
Full API reference, rendering modes, routing, and deployment guides at **[teyik0.github.io/furin](https://teyik0.github.io/furin/)**.
|
package/package.json
CHANGED
|
@@ -1,77 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-alpha.2",
|
|
4
|
+
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "teyik0",
|
|
7
|
+
"sideEffects": false,
|
|
4
8
|
"type": "module",
|
|
9
|
+
"engines": {
|
|
10
|
+
"bun": ">=1.3.0"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react",
|
|
14
|
+
"furin",
|
|
15
|
+
"framework",
|
|
16
|
+
"elysia",
|
|
17
|
+
"bun",
|
|
18
|
+
"ssr",
|
|
19
|
+
"ssg",
|
|
20
|
+
"routing",
|
|
21
|
+
"file-based-routing"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/teyik0/furin.git"
|
|
26
|
+
},
|
|
27
|
+
"bugs": {
|
|
28
|
+
"url": "https://github.com/teyik0/furin/issues"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/teyik0/furin#readme",
|
|
5
31
|
"files": [
|
|
6
32
|
"dist",
|
|
7
|
-
"src"
|
|
33
|
+
"src",
|
|
34
|
+
"LICENSE",
|
|
35
|
+
"README.md"
|
|
8
36
|
],
|
|
9
37
|
"main": "./dist/furin.js",
|
|
10
38
|
"module": "./dist/furin.js",
|
|
11
|
-
"types": "./
|
|
39
|
+
"types": "./dist/furin.d.ts",
|
|
12
40
|
"bin": {
|
|
13
41
|
"furin": "./src/cli/index.ts"
|
|
14
42
|
},
|
|
15
43
|
"exports": {
|
|
16
44
|
".": {
|
|
17
|
-
"types": "./
|
|
45
|
+
"types": "./dist/furin.d.ts",
|
|
18
46
|
"bun": "./src/furin.ts",
|
|
19
47
|
"import": "./dist/furin.js"
|
|
20
48
|
},
|
|
21
49
|
"./client": {
|
|
22
|
-
"types": "./
|
|
50
|
+
"types": "./dist/client.d.ts",
|
|
23
51
|
"bun": "./src/client.ts",
|
|
24
52
|
"import": "./dist/client.js"
|
|
25
53
|
},
|
|
26
54
|
"./build": {
|
|
27
|
-
"types": "./
|
|
55
|
+
"types": "./dist/build/index.d.ts",
|
|
28
56
|
"bun": "./src/build/index.ts",
|
|
29
57
|
"import": "./dist/build/index.js"
|
|
30
58
|
},
|
|
31
59
|
"./config": {
|
|
32
|
-
"types": "./
|
|
60
|
+
"types": "./dist/config.d.ts",
|
|
33
61
|
"bun": "./src/config.ts",
|
|
34
62
|
"import": "./dist/config.js"
|
|
35
63
|
},
|
|
36
64
|
"./router": {
|
|
37
|
-
"types": "./
|
|
38
|
-
"bun": "./src/router.ts",
|
|
39
|
-
"import": "./dist/router.js"
|
|
65
|
+
"types": "./dist/server/router/index.d.ts",
|
|
66
|
+
"bun": "./src/server/router/index.ts",
|
|
67
|
+
"import": "./dist/server/router/index.js"
|
|
40
68
|
},
|
|
41
69
|
"./strip-plugin": {
|
|
42
|
-
"types": "./
|
|
70
|
+
"types": "./dist/plugin/index.d.ts",
|
|
43
71
|
"bun": "./src/plugin/index.ts",
|
|
44
72
|
"import": "./dist/plugin/index.js"
|
|
45
73
|
},
|
|
46
74
|
"./link": {
|
|
47
|
-
"types": "./
|
|
48
|
-
"bun": "./src/link.tsx",
|
|
49
|
-
"import": "./dist/link.js"
|
|
75
|
+
"types": "./dist/client/link.d.ts",
|
|
76
|
+
"bun": "./src/client/link.tsx",
|
|
77
|
+
"import": "./dist/client/link.js"
|
|
78
|
+
},
|
|
79
|
+
"./search": {
|
|
80
|
+
"types": "./dist/client/router/search/index.d.ts",
|
|
81
|
+
"bun": "./src/client/router/search/index.ts",
|
|
82
|
+
"import": "./dist/client/router/search/index.js"
|
|
50
83
|
},
|
|
51
84
|
"./env": {
|
|
52
|
-
"types": "./
|
|
85
|
+
"types": "./dist/env.d.ts",
|
|
86
|
+
"bun": "./src/env.d.ts"
|
|
53
87
|
}
|
|
54
88
|
},
|
|
55
89
|
"scripts": {
|
|
56
|
-
"
|
|
57
|
-
"test
|
|
58
|
-
"
|
|
59
|
-
"
|
|
90
|
+
"fix": "ultracite fix",
|
|
91
|
+
"test": "bun test --parallel --isolate --bail --preload ../../tests/setup.ts",
|
|
92
|
+
"test:dev": "bun test --changed --parallel --isolate --bail --preload ../../tests/setup.ts",
|
|
93
|
+
"tscheck": "tsc --noEmit",
|
|
94
|
+
"build": "bun run build.ts"
|
|
60
95
|
},
|
|
61
96
|
"dependencies": {
|
|
62
|
-
"@elysiajs/static": "^1.4.
|
|
97
|
+
"@elysiajs/static": "^1.4.10",
|
|
63
98
|
"magic-string": "^0.30.21",
|
|
64
|
-
"
|
|
99
|
+
"seroval": "^1.5.4",
|
|
100
|
+
"yuku-parser": "^0.5.37"
|
|
65
101
|
},
|
|
66
102
|
"devDependencies": {
|
|
67
|
-
"@types/react": "^19.2.
|
|
103
|
+
"@types/react": "^19.2.17",
|
|
68
104
|
"@types/react-dom": "^19.2.3",
|
|
69
105
|
"expect-type": "^1.3.0"
|
|
70
106
|
},
|
|
71
107
|
"peerDependencies": {
|
|
72
108
|
"elysia": "^1.4.28",
|
|
73
|
-
"evlog": "^2.
|
|
74
|
-
"react": "^19.2.
|
|
75
|
-
"react-dom": "^19.2.
|
|
109
|
+
"evlog": "^2.19.1",
|
|
110
|
+
"react": "^19.2.7",
|
|
111
|
+
"react-dom": "^19.2.7"
|
|
76
112
|
}
|
|
77
113
|
}
|
package/src/adapter/bun.ts
CHANGED
|
@@ -5,34 +5,63 @@ import { buildClient } from "../build/client.ts";
|
|
|
5
5
|
import { generateCompileEntry } from "../build/compile-entry.ts";
|
|
6
6
|
import { generateServerRoutesEntry } from "../build/server-routes-entry.ts";
|
|
7
7
|
import { buildTargetManifest, copyDirRecursive, ensureDir, toPosixPath } from "../build/shared.ts";
|
|
8
|
+
import { buildSSGCacheSnapshot } from "../build/ssg-cache.ts";
|
|
8
9
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
9
10
|
import type { BuildTarget } from "../config.ts";
|
|
10
|
-
import { generateProdIndexHtml } from "../render/shell.ts";
|
|
11
|
-
import
|
|
11
|
+
import { generateProdIndexHtml } from "../server/render/shell.ts";
|
|
12
|
+
import { setProductionTemplateContent } from "../server/render/template.ts";
|
|
13
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/index.ts";
|
|
12
14
|
|
|
13
15
|
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
14
|
-
// through package exports, and is the Web-standard API.
|
|
15
|
-
|
|
16
|
+
// through package exports, and is the Web-standard API. The main entry is
|
|
17
|
+
// `src/furin.ts` (or `dist/furin.js`), so we strip two path segments to reach
|
|
18
|
+
// the package root.
|
|
19
|
+
const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
20
|
+
const _pkgSrcDir = existsSync(join(_pkgRoot, "src", "furin.ts"))
|
|
21
|
+
? join(_pkgRoot, "src")
|
|
22
|
+
: join(_pkgRoot, "dist");
|
|
23
|
+
// The published package always ships `src/` (see package.json "files"), and the
|
|
24
|
+
// "bun" export condition resolves to the TypeScript sources, so the fingerprint
|
|
25
|
+
// inputs are always the `.ts` files. Some of these inputs (e.g. entry-template)
|
|
26
|
+
// are never emitted to `dist/` as `.js`, so detecting the extension off the dist
|
|
27
|
+
// copy would point at files that don't exist and silently weaken the build ID.
|
|
28
|
+
const _ext = ".ts";
|
|
16
29
|
const BUILD_ID_INPUT_PATHS = [
|
|
17
|
-
`${_pkgSrcDir}/build/compile-entry
|
|
18
|
-
`${_pkgSrcDir}/build/entry-template
|
|
19
|
-
`${_pkgSrcDir}/build/server-routes-entry
|
|
20
|
-
`${_pkgSrcDir}/render/index
|
|
21
|
-
`${_pkgSrcDir}/render/shell
|
|
22
|
-
`${_pkgSrcDir}/router
|
|
30
|
+
`${_pkgSrcDir}/build/compile-entry${_ext}`,
|
|
31
|
+
`${_pkgSrcDir}/build/entry-template${_ext}`,
|
|
32
|
+
`${_pkgSrcDir}/build/server-routes-entry${_ext}`,
|
|
33
|
+
`${_pkgSrcDir}/server/render/index${_ext}`,
|
|
34
|
+
`${_pkgSrcDir}/server/render/shell${_ext}`,
|
|
35
|
+
`${_pkgSrcDir}/server/router/index${_ext}`,
|
|
23
36
|
];
|
|
24
37
|
|
|
25
38
|
async function createBuildFingerprint(
|
|
26
39
|
entryChunk: string,
|
|
27
40
|
cssChunks: string[],
|
|
28
41
|
routes: ResolvedRoute[],
|
|
29
|
-
|
|
42
|
+
root: RootLayout,
|
|
30
43
|
serverEntry: string | null
|
|
31
44
|
): Promise<string> {
|
|
32
|
-
const fingerprintPaths = new Set<string>([
|
|
45
|
+
const fingerprintPaths = new Set<string>([root.path, ...routes.map((route) => route.path)]);
|
|
33
46
|
if (serverEntry) {
|
|
34
47
|
fingerprintPaths.add(serverEntry);
|
|
35
48
|
}
|
|
49
|
+
if (root.errorPath) {
|
|
50
|
+
fingerprintPaths.add(root.errorPath);
|
|
51
|
+
}
|
|
52
|
+
if (root.notFoundPath) {
|
|
53
|
+
fingerprintPaths.add(root.notFoundPath);
|
|
54
|
+
}
|
|
55
|
+
for (const route of routes) {
|
|
56
|
+
for (const segment of route.segmentBoundaries) {
|
|
57
|
+
if (segment.errorPath) {
|
|
58
|
+
fingerprintPaths.add(segment.errorPath);
|
|
59
|
+
}
|
|
60
|
+
if (segment.notFoundPath) {
|
|
61
|
+
fingerprintPaths.add(segment.notFoundPath);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
36
65
|
for (const path of BUILD_ID_INPUT_PATHS) {
|
|
37
66
|
if (!existsSync(path)) {
|
|
38
67
|
// A missing framework source file would silently produce an empty-string
|
|
@@ -46,7 +75,7 @@ async function createBuildFingerprint(
|
|
|
46
75
|
}
|
|
47
76
|
|
|
48
77
|
const fileParts = await Promise.all(
|
|
49
|
-
[...fingerprintPaths].
|
|
78
|
+
[...fingerprintPaths].toSorted().map(async (path) => {
|
|
50
79
|
const content = existsSync(path) ? await Bun.file(path).text() : "";
|
|
51
80
|
return `${toPosixPath(path)}:${content}`;
|
|
52
81
|
})
|
|
@@ -58,14 +87,39 @@ async function createBuildFingerprint(
|
|
|
58
87
|
)
|
|
59
88
|
.sort();
|
|
60
89
|
|
|
61
|
-
return [entryChunk, ...[...cssChunks].
|
|
90
|
+
return [entryChunk, ...[...cssChunks].toSorted(), ...routeParts, ...fileParts].join("\n");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function buildCompileMetadata(root: RootLayout, routes: ResolvedRoute[]) {
|
|
94
|
+
const rootConventions =
|
|
95
|
+
root.errorPath || root.notFoundPath
|
|
96
|
+
? {
|
|
97
|
+
errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
|
|
98
|
+
notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined,
|
|
99
|
+
}
|
|
100
|
+
: undefined;
|
|
101
|
+
|
|
102
|
+
const routeMetadata: NonNullable<Parameters<typeof generateCompileEntry>[0]["routeMetadata"]> =
|
|
103
|
+
{};
|
|
104
|
+
for (const route of routes) {
|
|
105
|
+
routeMetadata[toPosixPath(route.path)] = {
|
|
106
|
+
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
107
|
+
depth: b.depth,
|
|
108
|
+
path: toPosixPath(b.path),
|
|
109
|
+
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
110
|
+
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { rootConventions, routeMetadata };
|
|
62
116
|
}
|
|
63
117
|
|
|
64
118
|
export async function buildBunTarget(
|
|
65
119
|
routes: ResolvedRoute[],
|
|
66
120
|
rootDir: string,
|
|
67
121
|
buildRoot: string,
|
|
68
|
-
|
|
122
|
+
root: RootLayout,
|
|
69
123
|
serverEntry: string | null,
|
|
70
124
|
options: BuildAppOptions
|
|
71
125
|
): Promise<TargetBuildManifest> {
|
|
@@ -85,17 +139,18 @@ export async function buildBunTarget(
|
|
|
85
139
|
|
|
86
140
|
const { entryChunk, cssChunks } = await buildClient(routes, {
|
|
87
141
|
outDir: targetDir,
|
|
88
|
-
rootLayout:
|
|
142
|
+
rootLayout: root.path,
|
|
89
143
|
plugins: options.plugins,
|
|
90
144
|
publicPath: "/_client/",
|
|
91
145
|
basePath: "",
|
|
146
|
+
clientLogging: options.clientLogging ?? false,
|
|
92
147
|
});
|
|
93
148
|
|
|
94
149
|
const buildFingerprint = await createBuildFingerprint(
|
|
95
150
|
entryChunk,
|
|
96
151
|
cssChunks,
|
|
97
152
|
routes,
|
|
98
|
-
|
|
153
|
+
root,
|
|
99
154
|
serverEntry
|
|
100
155
|
);
|
|
101
156
|
const buildId = Bun.hash(buildFingerprint).toString(16).slice(0, 12);
|
|
@@ -104,12 +159,14 @@ export async function buildBunTarget(
|
|
|
104
159
|
// Write index.html with the buildId meta tag injected so the client can
|
|
105
160
|
// detect stale deploys via X-Furin-Build-ID header comparison.
|
|
106
161
|
const clientDir = join(targetDir, "client");
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
162
|
+
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
163
|
+
writeFileSync(join(clientDir, "index.html"), indexHtml);
|
|
164
|
+
setProductionTemplateContent(indexHtml);
|
|
111
165
|
|
|
112
166
|
const routeManifest = routes.map((r) => ({ pattern: r.pattern, path: r.path, mode: r.mode }));
|
|
167
|
+
const ssgCache = serverEntry
|
|
168
|
+
? await buildSSGCacheSnapshot(routes, root, "http://localhost")
|
|
169
|
+
: undefined;
|
|
113
170
|
const publicDir = existsSync(join(rootDir, "public")) ? join(rootDir, "public") : undefined;
|
|
114
171
|
const targetPublicDir = publicDir ? join(targetDir, "public") : undefined;
|
|
115
172
|
|
|
@@ -117,45 +174,34 @@ export async function buildBunTarget(
|
|
|
117
174
|
copyDirRecursive(publicDir, targetPublicDir);
|
|
118
175
|
}
|
|
119
176
|
|
|
177
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
178
|
+
|
|
120
179
|
if (options.compile && serverEntry) {
|
|
121
180
|
const clientDir = join(targetDir, "client");
|
|
122
181
|
const outfile = join(targetDir, "server");
|
|
123
182
|
|
|
124
183
|
const entryPath = generateCompileEntry({
|
|
125
184
|
buildId,
|
|
126
|
-
rootPath,
|
|
185
|
+
rootPath: root.path,
|
|
127
186
|
routes: routeManifest,
|
|
128
187
|
serverEntry,
|
|
129
188
|
outDir: targetDir,
|
|
130
189
|
embed: options.compile === "embed" ? { clientDir } : undefined,
|
|
131
190
|
publicDir,
|
|
191
|
+
rootConventions,
|
|
192
|
+
routeMetadata,
|
|
193
|
+
ssgCache,
|
|
132
194
|
});
|
|
133
195
|
|
|
134
196
|
await Bun.build({
|
|
135
197
|
entrypoints: [entryPath],
|
|
136
198
|
compile: { outfile },
|
|
137
199
|
minify: true,
|
|
138
|
-
sourcemap: "
|
|
200
|
+
sourcemap: "none",
|
|
139
201
|
define: { "process.env.NODE_ENV": JSON.stringify("production") },
|
|
140
202
|
plugins: options.plugins,
|
|
141
203
|
});
|
|
142
204
|
|
|
143
|
-
// macOS: Gatekeeper kills Bun-compiled binaries because Bun appends JS code to its own
|
|
144
|
-
// signed runtime, corrupting the original Oven signature. We must remove the corrupt
|
|
145
|
-
// signature first, then re-sign ad-hoc (-s -) so macOS accepts the binary.
|
|
146
|
-
if (process.platform === "darwin") {
|
|
147
|
-
Bun.spawnSync(["codesign", "--remove-signature", outfile]);
|
|
148
|
-
const sign = Bun.spawnSync(["codesign", "-f", "-s", "-", outfile]);
|
|
149
|
-
if (sign.exitCode !== 0) {
|
|
150
|
-
console.warn(
|
|
151
|
-
`[furin] Warning: codesign failed (exit ${sign.exitCode}). ` +
|
|
152
|
-
"The binary may be killed by Gatekeeper on macOS. Run manually:\n" +
|
|
153
|
-
` codesign --remove-signature ${outfile}\n` +
|
|
154
|
-
` codesign -f -s - ${outfile}`
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
205
|
console.log(`[furin] Server binary: ${outfile}`);
|
|
160
206
|
|
|
161
207
|
targetManifest.serverPath = toPosixPath(join(targetManifest.targetDir, "server"));
|
|
@@ -170,10 +216,13 @@ export async function buildBunTarget(
|
|
|
170
216
|
// Disk mode: generate server.ts then bundle it into self-contained server.js
|
|
171
217
|
const entryPath = generateServerRoutesEntry({
|
|
172
218
|
buildId,
|
|
173
|
-
rootPath,
|
|
219
|
+
rootPath: root.path,
|
|
174
220
|
routes: routeManifest,
|
|
175
221
|
serverEntry,
|
|
176
222
|
outDir: targetDir,
|
|
223
|
+
rootConventions,
|
|
224
|
+
routeMetadata,
|
|
225
|
+
ssgCache,
|
|
177
226
|
});
|
|
178
227
|
|
|
179
228
|
await Bun.build({
|
|
@@ -181,7 +230,7 @@ export async function buildBunTarget(
|
|
|
181
230
|
outdir: targetDir,
|
|
182
231
|
target: "bun",
|
|
183
232
|
minify: true,
|
|
184
|
-
sourcemap: "
|
|
233
|
+
sourcemap: "none",
|
|
185
234
|
plugins: options.plugins,
|
|
186
235
|
});
|
|
187
236
|
console.log(
|
package/src/adapter/static.ts
CHANGED
|
@@ -4,11 +4,17 @@ import { buildClient } from "../build/client.ts";
|
|
|
4
4
|
import { ensureDir, toPosixPath } from "../build/shared.ts";
|
|
5
5
|
import type { BuildAppOptions, StaticTargetBuildManifest } from "../build/types.ts";
|
|
6
6
|
import type { StaticExportConfig } from "../config.ts";
|
|
7
|
-
import { resolvePath } from "../render/assemble.ts";
|
|
8
|
-
import { prerenderSSG } from "../render/index.ts";
|
|
9
|
-
import { generateProdIndexHtml } from "../render/shell.ts";
|
|
10
|
-
import { setProductionTemplateContent } from "../render/template.ts";
|
|
11
|
-
import
|
|
7
|
+
import { resolvePath } from "../server/render/assemble.ts";
|
|
8
|
+
import { prerenderSSG } from "../server/render/index.ts";
|
|
9
|
+
import { generateProdIndexHtml } from "../server/render/shell.ts";
|
|
10
|
+
import { setProductionTemplateContent } from "../server/render/template.ts";
|
|
11
|
+
import {
|
|
12
|
+
createSearchRouteMetadata,
|
|
13
|
+
type ResolvedRoute,
|
|
14
|
+
type RootLayout,
|
|
15
|
+
} from "../server/router/index.ts";
|
|
16
|
+
import type { SearchRouteMetadata } from "../shared/search-params.ts";
|
|
17
|
+
import { mapWithConcurrency } from "../shared/utils/index.ts";
|
|
12
18
|
|
|
13
19
|
/** Maximum concurrent pre-render calls (mirrors warmSSGCache). */
|
|
14
20
|
const STATIC_CONCURRENCY = 4;
|
|
@@ -22,20 +28,21 @@ const TRAILING_SLASHES_RE = /\/+$/;
|
|
|
22
28
|
// ── Path helpers ──────────────────────────────────────────────────────────────
|
|
23
29
|
|
|
24
30
|
/**
|
|
25
|
-
* Converts a URL path to a filesystem output path.
|
|
26
|
-
* "/" → "outDir/index.html"
|
|
27
|
-
* "/docs/routing" → "outDir/docs/routing/index.html"
|
|
31
|
+
* Converts a URL path to a filesystem output path for the given file name.
|
|
32
|
+
* "/" + "index.html" → "outDir/index.html"
|
|
33
|
+
* "/docs/routing" + "index.html" → "outDir/docs/routing/index.html"
|
|
34
|
+
* "/docs/routing" + "__furin_data.ndjson" → "outDir/docs/routing/__furin_data.ndjson"
|
|
28
35
|
*
|
|
29
36
|
* The resolved path is validated to stay within `outDir` so that `..`
|
|
30
37
|
* segments injected via dynamic `staticParams()` values cannot escape
|
|
31
38
|
* the output directory.
|
|
32
39
|
*/
|
|
33
|
-
function pathToOutputFile(urlPath: string, outDir: string): string {
|
|
40
|
+
function pathToOutputFile(urlPath: string, outDir: string, fileName: string): string {
|
|
34
41
|
const normalizedOutDir = resolve(outDir);
|
|
35
42
|
if (urlPath === "/" || urlPath === "") {
|
|
36
|
-
return join(normalizedOutDir,
|
|
43
|
+
return join(normalizedOutDir, fileName);
|
|
37
44
|
}
|
|
38
|
-
const resolved = resolve(normalizedOutDir, urlPath.slice(1),
|
|
45
|
+
const resolved = resolve(normalizedOutDir, urlPath.slice(1), fileName);
|
|
39
46
|
if (!resolved.startsWith(`${normalizedOutDir}${sep}`)) {
|
|
40
47
|
throw new Error(
|
|
41
48
|
`[furin] static: unsafe output path detected for URL "${urlPath}" — path traversal via ".." is not allowed.`
|
|
@@ -53,13 +60,22 @@ async function prerenderAndWrite(
|
|
|
53
60
|
outDir: string,
|
|
54
61
|
renderedRoutes: string[],
|
|
55
62
|
skippedRoutes: string[],
|
|
56
|
-
basePath: string
|
|
63
|
+
basePath: string,
|
|
64
|
+
searchRoutes: SearchRouteMetadata[]
|
|
57
65
|
): Promise<void> {
|
|
58
66
|
const urlPath = resolvePath(route.pattern, params);
|
|
59
|
-
const
|
|
67
|
+
const htmlOutputFile = pathToOutputFile(urlPath, outDir, "index.html");
|
|
68
|
+
const dataOutputFile = pathToOutputFile(urlPath, outDir, "__furin_data.ndjson");
|
|
60
69
|
|
|
61
70
|
try {
|
|
62
|
-
const entry = await prerenderSSG(
|
|
71
|
+
const entry = await prerenderSSG(
|
|
72
|
+
route,
|
|
73
|
+
params,
|
|
74
|
+
root,
|
|
75
|
+
"http://localhost",
|
|
76
|
+
basePath,
|
|
77
|
+
searchRoutes
|
|
78
|
+
);
|
|
63
79
|
|
|
64
80
|
if (entry instanceof Response) {
|
|
65
81
|
console.warn(
|
|
@@ -68,10 +84,14 @@ async function prerenderAndWrite(
|
|
|
68
84
|
return;
|
|
69
85
|
}
|
|
70
86
|
|
|
71
|
-
ensureDir(dirname(
|
|
72
|
-
writeFileSync(
|
|
87
|
+
ensureDir(dirname(htmlOutputFile));
|
|
88
|
+
writeFileSync(htmlOutputFile, entry.html);
|
|
89
|
+
// Persist the loader payload at a static-friendly URL: SPA navigation on
|
|
90
|
+
// file-server deployments (GitHub Pages, S3, …) fetches this file instead
|
|
91
|
+
// of the runtime `/_furin/data?path=…` endpoint, which doesn't exist there.
|
|
92
|
+
writeFileSync(dataOutputFile, entry.ndjson);
|
|
73
93
|
renderedRoutes.push(urlPath);
|
|
74
|
-
console.log(`[furin] static: ${urlPath} → ${toPosixPath(
|
|
94
|
+
console.log(`[furin] static: ${urlPath} → ${toPosixPath(htmlOutputFile)}`);
|
|
75
95
|
} catch (err) {
|
|
76
96
|
console.error(
|
|
77
97
|
`[furin] static: prerender failed for "${route.pattern}" (params: ${JSON.stringify(params)}):`,
|
|
@@ -131,36 +151,73 @@ async function buildTaskQueue(
|
|
|
131
151
|
outDir: string,
|
|
132
152
|
renderedRoutes: string[],
|
|
133
153
|
skippedRoutes: string[],
|
|
134
|
-
basePath: string
|
|
154
|
+
basePath: string,
|
|
155
|
+
searchRoutes: SearchRouteMetadata[]
|
|
135
156
|
): Promise<Array<() => Promise<void>>> {
|
|
136
157
|
const tasks: Array<() => Promise<void>> = [];
|
|
137
158
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
159
|
+
type StaticParamsResult =
|
|
160
|
+
| { paramSets: Record<string, string>[] | null; route: ResolvedRoute }
|
|
161
|
+
| { error: unknown; paramSets: null; route: ResolvedRoute };
|
|
162
|
+
|
|
163
|
+
const staticParamsResults: StaticParamsResult[] = await mapWithConcurrency(
|
|
164
|
+
ssgRoutes,
|
|
165
|
+
STATIC_CONCURRENCY,
|
|
166
|
+
async (route) => {
|
|
167
|
+
if (!DYNAMIC_SEGMENT_RE.test(route.pattern)) {
|
|
168
|
+
return { route, paramSets: [{}] };
|
|
169
|
+
}
|
|
170
|
+
if (!route.page.staticParams) {
|
|
171
|
+
console.warn(
|
|
172
|
+
`[furin] static: skipping dynamic route "${route.pattern}" — no staticParams() defined.`
|
|
173
|
+
);
|
|
174
|
+
skippedRoutes.push(route.pattern);
|
|
175
|
+
return { route, paramSets: null };
|
|
176
|
+
}
|
|
177
|
+
try {
|
|
178
|
+
const paramSets = (await route.page.staticParams()) ?? [];
|
|
179
|
+
return { route, paramSets };
|
|
180
|
+
} catch (err) {
|
|
181
|
+
return { error: err, paramSets: null, route };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
for (const result of staticParamsResults) {
|
|
187
|
+
if ("error" in result) {
|
|
188
|
+
console.error(
|
|
189
|
+
`[furin] static: staticParams() failed for "${result.route.pattern}":`,
|
|
190
|
+
result.error
|
|
142
191
|
);
|
|
192
|
+
skippedRoutes.push(result.route.pattern);
|
|
143
193
|
continue;
|
|
144
194
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
195
|
+
if (result.paramSets === null) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
// Defend against staticParams() returning a non-array (e.g. a bare object
|
|
199
|
+
// or `null`-after-coercion). Without this guard, a single malformed route
|
|
200
|
+
// would throw out of `for...of` and abort the entire build.
|
|
201
|
+
if (!Array.isArray(result.paramSets)) {
|
|
202
|
+
console.error(
|
|
203
|
+
`[furin] static: staticParams() for "${result.route.pattern}" returned a non-array value; skipping route.`
|
|
149
204
|
);
|
|
150
|
-
skippedRoutes.push(route.pattern);
|
|
205
|
+
skippedRoutes.push(result.route.pattern);
|
|
151
206
|
continue;
|
|
152
207
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
208
|
+
for (const params of result.paramSets) {
|
|
209
|
+
tasks.push(() =>
|
|
210
|
+
prerenderAndWrite(
|
|
211
|
+
result.route,
|
|
212
|
+
params,
|
|
213
|
+
root,
|
|
214
|
+
outDir,
|
|
215
|
+
renderedRoutes,
|
|
216
|
+
skippedRoutes,
|
|
217
|
+
basePath,
|
|
218
|
+
searchRoutes
|
|
219
|
+
)
|
|
220
|
+
);
|
|
164
221
|
}
|
|
165
222
|
}
|
|
166
223
|
|
|
@@ -252,6 +309,7 @@ export async function buildStaticTarget(
|
|
|
252
309
|
|
|
253
310
|
// ── 1. Validate SSR/ISR routes before doing any work ─────────────────────
|
|
254
311
|
const ssgRoutes = collectSsgRoutes(routes, onSSR, skippedRoutes);
|
|
312
|
+
const searchRoutes = createSearchRouteMetadata(ssgRoutes);
|
|
255
313
|
|
|
256
314
|
// ── 2. Clean & create output directories ─────────────────────────────────
|
|
257
315
|
rmSync(outDir, { force: true, recursive: true });
|
|
@@ -268,6 +326,7 @@ export async function buildStaticTarget(
|
|
|
268
326
|
plugins: options.plugins,
|
|
269
327
|
publicPath,
|
|
270
328
|
basePath,
|
|
329
|
+
clientLogging: Boolean(options.clientLogging),
|
|
271
330
|
});
|
|
272
331
|
|
|
273
332
|
// ── 4. Generate HTML shell template ──────────────────────────────────────
|
|
@@ -275,7 +334,7 @@ export async function buildStaticTarget(
|
|
|
275
334
|
// This ensures the browser finds it even when the site is served from a sub-path.
|
|
276
335
|
const publicFavicon = join(rootDir, "public", "favicon.ico");
|
|
277
336
|
const faviconHref = existsSync(publicFavicon) ? `${basePath}/favicon.ico` : undefined;
|
|
278
|
-
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref);
|
|
337
|
+
const shellHtml = generateProdIndexHtml(entryChunk, cssChunks, undefined, faviconHref, true);
|
|
279
338
|
|
|
280
339
|
// ── 5. Prime the renderer with the production shell ──────────────────────
|
|
281
340
|
// Must be called before any prerenderSSG invocation.
|
|
@@ -302,7 +361,8 @@ export async function buildStaticTarget(
|
|
|
302
361
|
outDir,
|
|
303
362
|
renderedRoutes,
|
|
304
363
|
skippedRoutes,
|
|
305
|
-
basePath
|
|
364
|
+
basePath,
|
|
365
|
+
searchRoutes
|
|
306
366
|
);
|
|
307
367
|
// Snapshot after queue-building: routes skipped due to missing staticParams() are
|
|
308
368
|
// already recorded; only routes added during task execution are prerender failures.
|