@teyik0/furin 0.1.0-alpha.8 → 0.2.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/LICENSE +21 -0
- package/README.md +33 -0
- package/dist/adapter/bun.d.ts +2 -2
- package/dist/adapter/static.d.ts +1 -1
- package/dist/build/client.d.ts +2 -2
- package/dist/build/compile-entry.d.ts +2 -16
- package/dist/build/compile-entry.ts +109 -0
- package/dist/build/entry-template.d.ts +24 -0
- package/dist/build/entry-template.ts +156 -0
- package/dist/build/hydrate.d.ts +3 -3
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.js +4734 -548
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/server-routes-entry.d.ts +2 -12
- package/dist/build/server-routes-entry.ts +36 -0
- package/dist/build/shared.d.ts +1 -1
- package/dist/build/ssg-cache.d.ts +4 -0
- package/dist/build/types.d.ts +5 -1
- package/dist/cli/index.js +4713 -549
- package/dist/client/boundaries.d.ts +117 -0
- package/dist/client/default-screens.d.ts +17 -0
- package/dist/client/link.d.ts +22 -0
- package/dist/client/link.js +3450 -0
- package/dist/client/router/boundary-tree.d.ts +26 -0
- package/dist/client/router/context.d.ts +8 -0
- package/dist/client/router/history.d.ts +9 -0
- package/dist/client/router/index.d.ts +7 -0
- package/dist/client/router/link-utils.d.ts +51 -0
- package/dist/client/router/provider.d.ts +4 -0
- package/dist/client/router/spa-response.d.ts +58 -0
- package/dist/{link.d.ts → client/router/types.d.ts} +114 -80
- package/dist/client/server-error.d.ts +12 -0
- package/dist/client.d.ts +54 -4
- package/dist/client.js +77 -1
- package/dist/config.d.ts +12 -2
- package/dist/config.js +1 -0
- package/dist/env.d.ts +50 -0
- package/dist/furin.d.ts +37 -2
- package/dist/furin.js +5288 -601
- package/dist/plugin/index.js +140 -48
- package/dist/plugin/transform-client.d.ts +2 -1
- package/dist/server/auto-invalidate/index.d.ts +4 -0
- package/dist/server/auto-invalidate/plugin.d.ts +38 -0
- package/dist/server/auto-invalidate/registry.d.ts +9 -0
- package/dist/server/auto-invalidate/runtime.d.ts +9 -0
- package/dist/server/auto-invalidate/types.d.ts +12 -0
- package/dist/server/cache/dev-loader.d.ts +28 -0
- package/dist/server/cache/index.d.ts +10 -0
- package/dist/server/cache/invalidation.d.ts +12 -0
- package/dist/server/cache/isr-ssg.d.ts +26 -0
- package/dist/server/cache/isr.d.ts +6 -0
- package/dist/server/cache/registry.d.ts +5 -0
- package/dist/server/cache/route-cache.d.ts +26 -0
- package/dist/server/cache/ssg.d.ts +5 -0
- package/dist/server/context-logger.d.ts +28 -0
- package/dist/server/dev-inspector.d.ts +89 -0
- package/dist/{internal.d.ts → server/internal.d.ts} +16 -0
- package/dist/server/internal.js +17 -0
- package/dist/server/lang-detect.d.ts +5 -0
- package/dist/server/render/assemble.d.ts +47 -0
- package/dist/server/render/element.d.ts +24 -0
- package/dist/server/render/index.d.ts +7 -0
- package/dist/server/render/index.ts +22 -0
- package/dist/server/render/isr.d.ts +3 -0
- package/dist/server/render/loaders.d.ts +64 -0
- package/dist/server/render/not-found.d.ts +6 -0
- package/dist/{render → server/render}/shell.d.ts +17 -4
- package/{src → dist/server}/render/shell.ts +31 -9
- package/dist/server/render/ssg.d.ts +8 -0
- package/dist/server/render/ssr.d.ts +107 -0
- package/dist/server/router/discovery.d.ts +16 -0
- package/dist/server/router/hmr.d.ts +64 -0
- package/dist/server/router/index.d.ts +6 -0
- package/dist/server/router/index.js +28 -0
- package/dist/server/router/index.ts +29 -0
- package/dist/server/router/patterns.d.ts +40 -0
- package/dist/server/router/plugin.d.ts +20 -0
- package/dist/server/router/schemas.d.ts +51 -0
- package/dist/server/router/types.d.ts +60 -0
- package/dist/server/runtime-env.js +10 -0
- package/dist/shared/await.d.ts +67 -0
- package/dist/shared/deferred-ndjson.d.ts +32 -0
- package/dist/shared/digest.d.ts +16 -0
- package/dist/shared/error.d.ts +37 -0
- package/dist/shared/not-found.d.ts +19 -0
- package/dist/shared/utils/ast-walk.d.ts +18 -0
- package/dist/shared/utils/index.d.ts +13 -0
- package/package.json +56 -25
- package/src/adapter/bun.ts +90 -41
- package/src/adapter/static.ts +83 -36
- package/src/build/client.ts +8 -12
- package/src/build/compile-entry.ts +20 -14
- package/src/build/entry-template.ts +90 -8
- package/src/build/hydrate.ts +213 -36
- package/src/build/index.ts +10 -9
- package/src/build/route-types.ts +30 -4
- package/src/build/scan-server.ts +52 -67
- package/src/build/server-routes-entry.ts +7 -11
- package/src/build/shared.ts +1 -1
- package/src/build/ssg-cache.ts +31 -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 +338 -0
- package/src/client/router/boundary-tree.tsx +116 -0
- package/src/client/router/context.ts +38 -0
- package/src/client/router/history.ts +41 -0
- package/src/client/router/index.ts +47 -0
- package/src/client/router/link-utils.ts +180 -0
- package/src/client/router/provider.tsx +723 -0
- package/src/client/router/spa-response.ts +143 -0
- package/src/client/router/types.ts +263 -0
- package/src/client/server-error.ts +47 -0
- package/src/client.ts +83 -3
- package/src/config.ts +11 -3
- package/src/env.d.ts +1 -0
- package/src/furin.ts +104 -26
- 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/server/context-logger.ts +76 -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 +295 -0
- package/src/server/render/loaders.ts +328 -0
- package/src/server/render/not-found.ts +96 -0
- package/src/server/render/shell.ts +202 -0
- package/src/server/render/ssg.ts +137 -0
- package/src/server/render/ssr.ts +545 -0
- package/src/server/router/discovery.ts +474 -0
- package/src/server/router/hmr.ts +372 -0
- package/src/server/router/index.ts +29 -0
- package/src/server/router/patterns.ts +214 -0
- package/src/server/router/plugin.ts +401 -0
- package/src/server/router/schemas.ts +163 -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/utils/ast-walk.ts +51 -0
- package/src/{utils.ts → shared/utils/index.ts} +32 -1
- package/dist/link.js +0 -1173
- package/dist/render/assemble.d.ts +0 -13
- 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/router.d.ts +0 -34
- package/dist/router.js +0 -830
- package/dist/utils.d.ts +0 -6
- package/src/link.tsx +0 -1035
- package/src/render/assemble.ts +0 -64
- package/src/render/cache.ts +0 -241
- package/src/render/element.tsx +0 -28
- package/src/render/index.ts +0 -479
- package/src/render/loaders.ts +0 -113
- package/src/router.ts +0 -400
- /package/dist/{dev-page-plugin.d.ts → server/dev-page-plugin.d.ts} +0 -0
- /package/dist/{render → server/render}/template.d.ts +0 -0
- /package/dist/{runtime-env.d.ts → server/runtime-env.d.ts} +0 -0
- /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/dist/adapter/bun.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
2
|
-
import type { ResolvedRoute } from "../router.ts";
|
|
3
|
-
export declare function buildBunTarget(routes: ResolvedRoute[], rootDir: string, buildRoot: string,
|
|
2
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/index.ts";
|
|
3
|
+
export declare function buildBunTarget(routes: ResolvedRoute[], rootDir: string, buildRoot: string, root: RootLayout, serverEntry: string | null, options: BuildAppOptions): Promise<TargetBuildManifest>;
|
package/dist/adapter/static.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { BuildAppOptions, StaticTargetBuildManifest } from "../build/types.ts";
|
|
2
|
-
import type { ResolvedRoute, RootLayout } from "../router.ts";
|
|
2
|
+
import type { ResolvedRoute, RootLayout } from "../server/router/index.ts";
|
|
3
3
|
export declare function buildStaticTarget(routes: ResolvedRoute[], rootDir: string, buildRoot: string, root: RootLayout, options: BuildAppOptions): Promise<StaticTargetBuildManifest>;
|
package/dist/build/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedRoute } from "../router";
|
|
1
|
+
import type { ResolvedRoute } from "../server/router/index.ts";
|
|
2
2
|
import type { BuildClientOptions } from "./types";
|
|
3
3
|
export interface BuildClientResult {
|
|
4
4
|
/** Public paths of all CSS chunks, e.g. `["/_client/chunk-abc.css"]` */
|
|
@@ -22,4 +22,4 @@ export interface BuildClientResult {
|
|
|
22
22
|
* it as an SSR template, injects the pre-rendered React HTML into
|
|
23
23
|
* <!--ssr-outlet-->, and sends the complete page.
|
|
24
24
|
*/
|
|
25
|
-
export declare function buildClient(routes: ResolvedRoute[], { outDir, rootLayout, plugins, publicPath, basePath }: BuildClientOptions): Promise<BuildClientResult>;
|
|
25
|
+
export declare function buildClient(routes: ResolvedRoute[], { outDir, rootLayout, plugins, publicPath, basePath, clientLogging }: BuildClientOptions): Promise<BuildClientResult>;
|
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
buildId?: string;
|
|
3
|
-
embed?: {
|
|
4
|
-
clientDir: string;
|
|
5
|
-
};
|
|
6
|
-
outDir: string;
|
|
7
|
-
publicDir?: string;
|
|
8
|
-
rootPath: string;
|
|
9
|
-
routes: Array<{
|
|
10
|
-
mode: "ssr" | "ssg" | "isr";
|
|
11
|
-
path: string;
|
|
12
|
-
pattern: string;
|
|
13
|
-
}>;
|
|
14
|
-
serverEntry: string;
|
|
15
|
-
}
|
|
1
|
+
import { type BuildEntryOptions } from "./entry-template";
|
|
16
2
|
/**
|
|
17
3
|
* Generates a single `_compile-entry.ts` that:
|
|
18
4
|
* 1. Statically imports every page module so Bun bundles them into the binary
|
|
@@ -20,4 +6,4 @@ export interface CompileEntryOptions {
|
|
|
20
6
|
* 3. Sets production mode and registers everything in a single CompileContext
|
|
21
7
|
* 4. Dynamically imports server.ts to boot the app
|
|
22
8
|
*/
|
|
23
|
-
export declare function generateCompileEntry(options:
|
|
9
|
+
export declare function generateCompileEntry(options: BuildEntryOptions): string;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { buildEntrySource, type BuildEntryOptions } from "./entry-template";
|
|
4
|
+
import { collectFilesRecursive, ensureDir, toPosixPath } from "./shared";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generates a single `_compile-entry.ts` that:
|
|
8
|
+
* 1. Statically imports every page module so Bun bundles them into the binary
|
|
9
|
+
* 2. Optionally embeds client assets via `with { type: "file" }` (embed mode)
|
|
10
|
+
* 3. Sets production mode and registers everything in a single CompileContext
|
|
11
|
+
* 4. Dynamically imports server.ts to boot the app
|
|
12
|
+
*/
|
|
13
|
+
export function generateCompileEntry(options: BuildEntryOptions): string {
|
|
14
|
+
const {
|
|
15
|
+
buildId,
|
|
16
|
+
outDir,
|
|
17
|
+
rootPath,
|
|
18
|
+
routes,
|
|
19
|
+
serverEntry,
|
|
20
|
+
embed,
|
|
21
|
+
publicDir,
|
|
22
|
+
rootConventions,
|
|
23
|
+
routeMetadata,
|
|
24
|
+
ssgCache,
|
|
25
|
+
} = options;
|
|
26
|
+
ensureDir(outDir);
|
|
27
|
+
|
|
28
|
+
// Build embedded asset imports if embed mode
|
|
29
|
+
const assetImports: string[] = [];
|
|
30
|
+
let embeddedBlock: string[] = [];
|
|
31
|
+
if (embed) {
|
|
32
|
+
if (!existsSync(embed.clientDir)) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`[furin] Client directory not found: ${embed.clientDir}. Run the client build first.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
const clientFiles = collectFilesRecursive(embed.clientDir).filter(
|
|
38
|
+
(file) => !file.endsWith(".map")
|
|
39
|
+
);
|
|
40
|
+
const assetEntries: string[] = [];
|
|
41
|
+
let templateVarName: string | null = null;
|
|
42
|
+
|
|
43
|
+
let assetIndex = 0;
|
|
44
|
+
for (const file of clientFiles) {
|
|
45
|
+
const varName = `_asset${assetIndex++}`;
|
|
46
|
+
const relPath = toPosixPath(relative(outDir, file));
|
|
47
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
48
|
+
|
|
49
|
+
assetImports.push(
|
|
50
|
+
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const clientRelativePath = toPosixPath(relative(embed.clientDir, file));
|
|
54
|
+
if (clientRelativePath === "index.html") {
|
|
55
|
+
templateVarName = varName;
|
|
56
|
+
} else {
|
|
57
|
+
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (templateVarName === null) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`[furin] Embed mode requires a client index.html at ${join(embed.clientDir, "index.html")}. Run the client build first.`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (publicDir && existsSync(publicDir)) {
|
|
68
|
+
const publicFiles = collectFilesRecursive(publicDir);
|
|
69
|
+
for (const file of publicFiles) {
|
|
70
|
+
const varName = `_asset${assetIndex++}`;
|
|
71
|
+
const relPath = toPosixPath(relative(outDir, file));
|
|
72
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
73
|
+
|
|
74
|
+
assetImports.push(
|
|
75
|
+
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const publicRelativePath = toPosixPath(relative(publicDir, file));
|
|
79
|
+
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
embeddedBlock = [
|
|
84
|
+
" embedded: {",
|
|
85
|
+
` template: ${templateVarName},`,
|
|
86
|
+
" assets: {",
|
|
87
|
+
...assetEntries,
|
|
88
|
+
" },",
|
|
89
|
+
" },",
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const source = buildEntrySource({
|
|
94
|
+
buildId,
|
|
95
|
+
headerComment: "// Auto-generated by furin compile — do not edit",
|
|
96
|
+
rootPath,
|
|
97
|
+
routes,
|
|
98
|
+
serverEntry,
|
|
99
|
+
extraImports: assetImports,
|
|
100
|
+
extraContext: embeddedBlock,
|
|
101
|
+
rootConventions,
|
|
102
|
+
routeMetadata,
|
|
103
|
+
ssgCache,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const entryPath = join(outDir, "_compile-entry.ts");
|
|
107
|
+
writeFileSync(entryPath, source);
|
|
108
|
+
return entryPath;
|
|
109
|
+
}
|
|
@@ -1,14 +1,38 @@
|
|
|
1
|
+
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
1
2
|
export interface EntryTemplateOptions {
|
|
2
3
|
buildId?: string;
|
|
3
4
|
extraContext?: string[];
|
|
4
5
|
extraImports?: string[];
|
|
5
6
|
headerComment: string;
|
|
7
|
+
rootConventions?: {
|
|
8
|
+
errorPath?: string;
|
|
9
|
+
notFoundPath?: string;
|
|
10
|
+
};
|
|
6
11
|
rootPath: string;
|
|
12
|
+
routeMetadata?: Record<string, {
|
|
13
|
+
segmentBoundaries: Array<{
|
|
14
|
+
depth: number;
|
|
15
|
+
path: string;
|
|
16
|
+
errorPath?: string;
|
|
17
|
+
notFoundPath?: string;
|
|
18
|
+
}>;
|
|
19
|
+
}>;
|
|
7
20
|
routes: Array<{
|
|
8
21
|
mode: "ssr" | "ssg" | "isr";
|
|
9
22
|
path: string;
|
|
10
23
|
pattern: string;
|
|
11
24
|
}>;
|
|
12
25
|
serverEntry: string;
|
|
26
|
+
ssgCache?: Record<string, SsgCacheEntry>;
|
|
27
|
+
}
|
|
28
|
+
/** Unified options for generating a build entry (compile or disk-based). */
|
|
29
|
+
export interface BuildEntryOptions extends Omit<EntryTemplateOptions, "headerComment"> {
|
|
30
|
+
outDir: string;
|
|
31
|
+
headerComment?: string;
|
|
32
|
+
/** Embed mode: bundles client assets into the binary via `with { type: "file" }`. */
|
|
33
|
+
embed?: {
|
|
34
|
+
clientDir: string;
|
|
35
|
+
};
|
|
36
|
+
publicDir?: string;
|
|
13
37
|
}
|
|
14
38
|
export declare function buildEntrySource(options: EntryTemplateOptions): string;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
5
|
+
|
|
6
|
+
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
7
|
+
// through package exports, and is the Web-standard API. The main entry is
|
|
8
|
+
// `src/furin.ts` (or `dist/furin.js`), so we strip two path segments to reach
|
|
9
|
+
// the package root.
|
|
10
|
+
const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
11
|
+
const _pkgSrcDirRaw = existsSync(join(_pkgRoot, "src", "furin.ts"))
|
|
12
|
+
? join(_pkgRoot, "src")
|
|
13
|
+
: join(_pkgRoot, "dist");
|
|
14
|
+
// Normalize to forward slashes so endsWith checks and template paths work on Windows.
|
|
15
|
+
const _pkgSrcDir = _pkgSrcDirRaw.replace(/\\/g, "/");
|
|
16
|
+
const _ext = _pkgSrcDir.endsWith("/src") ? ".ts" : ".js";
|
|
17
|
+
const INTERNAL_MODULE_PATH = `${_pkgSrcDir}/server/internal${_ext}`;
|
|
18
|
+
const RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/server/runtime-env${_ext}`;
|
|
19
|
+
|
|
20
|
+
export interface EntryTemplateOptions {
|
|
21
|
+
buildId?: string;
|
|
22
|
+
extraContext?: string[];
|
|
23
|
+
extraImports?: string[];
|
|
24
|
+
headerComment: string;
|
|
25
|
+
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
26
|
+
rootPath: string;
|
|
27
|
+
routeMetadata?: Record<
|
|
28
|
+
string,
|
|
29
|
+
{
|
|
30
|
+
segmentBoundaries: Array<{
|
|
31
|
+
depth: number;
|
|
32
|
+
path: string;
|
|
33
|
+
errorPath?: string;
|
|
34
|
+
notFoundPath?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
>;
|
|
38
|
+
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
39
|
+
serverEntry: string;
|
|
40
|
+
ssgCache?: Record<string, SsgCacheEntry>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Unified options for generating a build entry (compile or disk-based). */
|
|
44
|
+
export interface BuildEntryOptions extends Omit<EntryTemplateOptions, "headerComment"> {
|
|
45
|
+
outDir: string;
|
|
46
|
+
headerComment?: string;
|
|
47
|
+
/** Embed mode: bundles client assets into the binary via `with { type: "file" }`. */
|
|
48
|
+
embed?: { clientDir: string };
|
|
49
|
+
publicDir?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function collectConventionPaths(
|
|
53
|
+
rootConventions: EntryTemplateOptions["rootConventions"],
|
|
54
|
+
routeMetadata: EntryTemplateOptions["routeMetadata"]
|
|
55
|
+
): string[] {
|
|
56
|
+
const paths: string[] = [];
|
|
57
|
+
if (rootConventions?.errorPath) {
|
|
58
|
+
paths.push(rootConventions.errorPath);
|
|
59
|
+
}
|
|
60
|
+
if (rootConventions?.notFoundPath) {
|
|
61
|
+
paths.push(rootConventions.notFoundPath);
|
|
62
|
+
}
|
|
63
|
+
if (routeMetadata) {
|
|
64
|
+
for (const meta of Object.values(routeMetadata)) {
|
|
65
|
+
for (const seg of meta.segmentBoundaries) {
|
|
66
|
+
if (seg.errorPath) {
|
|
67
|
+
paths.push(seg.errorPath);
|
|
68
|
+
}
|
|
69
|
+
if (seg.notFoundPath) {
|
|
70
|
+
paths.push(seg.notFoundPath);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [...new Set(paths)];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
79
|
+
const {
|
|
80
|
+
buildId,
|
|
81
|
+
headerComment,
|
|
82
|
+
rootPath,
|
|
83
|
+
routes,
|
|
84
|
+
serverEntry,
|
|
85
|
+
rootConventions,
|
|
86
|
+
routeMetadata,
|
|
87
|
+
ssgCache,
|
|
88
|
+
} = options;
|
|
89
|
+
let { extraImports, extraContext } = options;
|
|
90
|
+
if (extraImports === undefined) {
|
|
91
|
+
extraImports = [];
|
|
92
|
+
}
|
|
93
|
+
if (extraContext === undefined) {
|
|
94
|
+
extraContext = [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const allModulePaths = [
|
|
98
|
+
rootPath,
|
|
99
|
+
...routes.map((r) => r.path),
|
|
100
|
+
...collectConventionPaths(rootConventions, routeMetadata),
|
|
101
|
+
];
|
|
102
|
+
const moduleImports: string[] = [];
|
|
103
|
+
const moduleEntries: string[] = [];
|
|
104
|
+
|
|
105
|
+
for (let i = 0; i < allModulePaths.length; i++) {
|
|
106
|
+
const absPath = (allModulePaths[i] as string).replace(/\\/g, "/");
|
|
107
|
+
const varName = `_mod${i}`;
|
|
108
|
+
moduleImports.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
109
|
+
moduleEntries.push(` ${JSON.stringify(absPath)}: ${varName},`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const routeEntries = routes.map(
|
|
113
|
+
(r) =>
|
|
114
|
+
` { pattern: ${JSON.stringify(r.pattern)}, path: ${JSON.stringify(r.path.replace(/\\/g, "/"))}, mode: ${JSON.stringify(r.mode)} },`
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
const rootConventionsLine = rootConventions
|
|
118
|
+
? ` rootConventions: ${JSON.stringify(rootConventions)},`
|
|
119
|
+
: "";
|
|
120
|
+
const routeMetadataLine = routeMetadata
|
|
121
|
+
? ` routeMetadata: ${JSON.stringify(routeMetadata)},`
|
|
122
|
+
: "";
|
|
123
|
+
const ssgCacheLine = ssgCache ? ` ssgCache: ${JSON.stringify(ssgCache)},` : "";
|
|
124
|
+
|
|
125
|
+
const lines = [
|
|
126
|
+
headerComment,
|
|
127
|
+
`import { __setCompileContext } from ${JSON.stringify(INTERNAL_MODULE_PATH)};`,
|
|
128
|
+
`import { __setDevMode } from ${JSON.stringify(RUNTIME_ENV_MODULE_PATH)};`,
|
|
129
|
+
...moduleImports,
|
|
130
|
+
...(extraImports.length > 0 ? ["", ...extraImports] : []),
|
|
131
|
+
"",
|
|
132
|
+
"// Force production mode — Bun may inline process.env.NODE_ENV at bundle time.",
|
|
133
|
+
"__setDevMode(false);",
|
|
134
|
+
'process.env.NODE_ENV = "production";',
|
|
135
|
+
"",
|
|
136
|
+
"__setCompileContext({",
|
|
137
|
+
` buildId: ${JSON.stringify(buildId ?? "")},`,
|
|
138
|
+
` rootPath: ${JSON.stringify(rootPath.replace(/\\/g, "/"))},`,
|
|
139
|
+
rootConventionsLine,
|
|
140
|
+
" modules: {",
|
|
141
|
+
...moduleEntries,
|
|
142
|
+
" },",
|
|
143
|
+
" routes: [",
|
|
144
|
+
...routeEntries,
|
|
145
|
+
" ],",
|
|
146
|
+
routeMetadataLine,
|
|
147
|
+
ssgCacheLine,
|
|
148
|
+
...extraContext,
|
|
149
|
+
"});",
|
|
150
|
+
"",
|
|
151
|
+
`await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
152
|
+
"",
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
return lines.join("\n");
|
|
156
|
+
}
|
package/dist/build/hydrate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ResolvedRoute } from "../router";
|
|
1
|
+
import type { ResolvedRoute } from "../server/router/index.ts";
|
|
2
2
|
import type { BuildClientOptions } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Generates the client hydration entry.
|
|
@@ -14,11 +14,11 @@ import type { BuildClientOptions } from "./types";
|
|
|
14
14
|
* before matching routes, and passes `basePath` to `RouterProvider` so SPA
|
|
15
15
|
* navigation uses the correct physical URLs.
|
|
16
16
|
*/
|
|
17
|
-
export declare function generateHydrateEntry(routes: ResolvedRoute[], rootLayout: string, basePath: string): string;
|
|
17
|
+
export declare function generateHydrateEntry(routes: ResolvedRoute[], rootLayout: string, basePath: string, clientLogging: boolean): string;
|
|
18
18
|
/**
|
|
19
19
|
* Writes _hydrate.tsx + index.html to outDir for dev (Bun HMR) mode.
|
|
20
20
|
*
|
|
21
21
|
* Only rewrites a file when its content has actually changed so Bun's --hot
|
|
22
22
|
* watcher does not trigger a spurious reload on every server restart.
|
|
23
23
|
*/
|
|
24
|
-
export declare function writeDevFiles(routes: ResolvedRoute[], { outDir, rootLayout, basePath }: BuildClientOptions, projectRoot: string): void;
|
|
24
|
+
export declare function writeDevFiles(routes: ResolvedRoute[], { outDir, rootLayout, basePath, clientLogging }: BuildClientOptions, projectRoot: string): void;
|
package/dist/build/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { BuildAppOptions, BuildAppResult } from "./types";
|
|
|
2
2
|
export { buildClient } from "./client";
|
|
3
3
|
export { writeDevFiles } from "./hydrate";
|
|
4
4
|
export { patternToTypeString, schemaToTypeString, writeRouteTypes } from "./route-types";
|
|
5
|
+
export { buildSSGCacheSnapshot, type SSGCacheSnapshot } from "./ssg-cache";
|
|
5
6
|
export type { BuildAppOptions, BuildAppResult, BuildClientOptions, BuildManifest, BuildRouteManifestEntry, TargetBuildManifest, } from "./types";
|
|
6
7
|
export declare const BUILD_OUTPUT_DIR = ".furin/build";
|
|
7
8
|
export declare function buildApp(options: BuildAppOptions): Promise<BuildAppResult>;
|