@teyik0/furin 0.2.0-alpha.3 → 0.2.0-alpha.5
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 -21
- package/README.md +37 -33
- package/dist/adapter/bun.d.ts +17 -1
- package/dist/adapter/package.d.ts +26 -0
- package/dist/build/client.d.ts +1 -1
- package/dist/build/compile-entry.d.ts +3 -3
- package/dist/build/compile-entry.ts +114 -109
- package/dist/build/entry-template.d.ts +35 -9
- package/dist/build/entry-template.ts +206 -156
- package/dist/build/hydrate.d.ts +1 -1
- package/dist/build/index.js +643 -247
- package/dist/build/scan-server.d.ts +10 -4
- package/dist/build/server-routes-entry.d.ts +3 -3
- package/dist/build/server-routes-entry.ts +30 -36
- package/dist/build/ssg-cache.d.ts +1 -1
- package/dist/build/types.d.ts +36 -1
- package/dist/cli/config.d.ts +6 -1
- package/dist/cli/index.js +662 -260
- package/dist/client/link.js +163 -16
- package/dist/client/router/abort.d.ts +1 -0
- package/dist/client/router/sync-catch-up.d.ts +29 -0
- package/dist/config.d.ts +11 -2
- package/dist/config.js +5 -1
- package/dist/furin.d.ts +37 -19
- package/dist/furin.js +982 -378
- package/dist/server/auto-invalidate/registry.d.ts +8 -1
- package/dist/server/cache/dev-loader.d.ts +3 -2
- package/dist/server/cache/invalidation.d.ts +19 -0
- package/dist/server/cache/isr.d.ts +6 -2
- package/dist/server/cache/registry.d.ts +3 -3
- package/dist/server/cache/ssg.d.ts +6 -2
- package/dist/server/cache/store-view.d.ts +11 -0
- package/dist/server/instance.d.ts +86 -0
- package/dist/server/internal.d.ts +16 -1
- package/dist/server/internal.js +72 -5
- package/dist/server/render/template.d.ts +3 -2
- package/dist/server/sync/adapter.d.ts +62 -0
- package/dist/server/sync/config.d.ts +11 -0
- package/dist/server/sync/fingerprint.d.ts +6 -0
- package/dist/server/sync/index.d.ts +2 -2
- package/dist/server/sync/memory-adapter.d.ts +17 -0
- package/dist/server/sync/plugin.d.ts +12 -195
- package/dist/server/sync/response.d.ts +4 -0
- package/dist/server/sync/stream.d.ts +24 -5
- package/dist/shared/prefix.d.ts +15 -0
- package/package.json +6 -1
- package/src/adapter/README.md +13 -13
- package/src/adapter/bun.ts +113 -50
- package/src/adapter/package.ts +206 -0
- package/src/build/client.ts +158 -152
- package/src/build/compile-entry.ts +114 -109
- package/src/build/entry-template.ts +206 -156
- package/src/build/hydrate.ts +342 -340
- package/src/build/index.ts +223 -152
- package/src/build/route-types.ts +145 -145
- package/src/build/scan-server.ts +111 -95
- package/src/build/server-routes-entry.ts +30 -36
- package/src/build/shared.ts +80 -80
- package/src/build/ssg-cache.ts +36 -32
- package/src/build/types.ts +125 -89
- package/src/cli/config.ts +9 -3
- package/src/cli/index.ts +21 -3
- package/src/client/router/abort.ts +5 -0
- package/src/client/router/link-utils.ts +184 -184
- package/src/client/router/provider.tsx +883 -804
- package/src/client/router/sync-catch-up.ts +113 -0
- package/src/client/router/types.ts +276 -276
- package/src/client/sync.ts +98 -98
- package/src/client.ts +369 -369
- package/src/config.ts +14 -1
- package/src/furin.ts +619 -465
- package/src/server/auto-invalidate/registry.ts +23 -1
- package/src/server/auto-invalidate/runtime.ts +159 -134
- package/src/server/cache/dev-loader.ts +77 -38
- package/src/server/cache/invalidation.ts +71 -30
- package/src/server/cache/isr.ts +20 -5
- package/src/server/cache/registry.ts +17 -20
- package/src/server/cache/ssg.ts +19 -4
- package/src/server/cache/store-view.ts +30 -0
- package/src/server/dev-page-plugin.ts +454 -454
- package/src/server/instance.ts +252 -0
- package/src/server/internal.ts +100 -5
- package/src/server/render/assemble.ts +160 -160
- package/src/server/render/isr.ts +323 -323
- package/src/server/render/not-found.ts +9 -3
- package/src/server/render/ssr.ts +603 -585
- package/src/server/render/template.ts +57 -24
- package/src/server/router/plugin.ts +384 -384
- package/src/server/sync/adapter.ts +65 -0
- package/src/server/sync/config.ts +60 -29
- package/src/server/sync/fingerprint.ts +44 -0
- package/src/server/sync/index.ts +15 -14
- package/src/server/sync/memory-adapter.ts +196 -0
- package/src/server/sync/plugin.ts +199 -108
- package/src/server/sync/response.ts +77 -0
- package/src/server/sync/stream.ts +162 -144
- package/src/shared/deferred-ndjson.ts +7 -0
- package/src/shared/prefix.ts +38 -0
package/LICENSE
CHANGED
|
@@ -1,21 +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.
|
|
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
CHANGED
|
@@ -1,33 +1,37 @@
|
|
|
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/)**.
|
|
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/)**.
|
|
34
|
+
|
|
35
|
+
## Replayable mutations
|
|
36
|
+
|
|
37
|
+
Install `furinSync()` on an Elysia API plugin to make mutations idempotent and replayable by default. Send an `Idempotency-Key` on every mutation handled by `furinSync()`; routes using `sync: false` or `furinInvalidate()` without `furinSync()` do not require one. Use `sync: false` for payments, uploads, streams, and other non-replayable effects. The built-in adapter is process-local memory and does not survive restarts or span across replicas.
|
package/dist/adapter/bun.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
import type { BuildAppOptions, TargetBuildManifest } from "../build/types.ts";
|
|
2
2
|
import type { ResolvedRoute, RootLayout } from "../server/router/index.ts";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Deterministic build-ID input covering everything that can change rendered
|
|
5
|
+
* output: client chunks, route shape, route/root/error/not-found source
|
|
6
|
+
* contents and the framework's own render pipeline sources. Shared with the
|
|
7
|
+
* package target so packaged apps get the same stale-deploy detection —
|
|
8
|
+
* SSR-only changes (loader/page code that never reaches the client bundle)
|
|
9
|
+
* must still produce a new build ID.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createBuildFingerprint(entryChunk: string, cssChunks: string[], routes: ResolvedRoute[], root: RootLayout, serverEntry: string | null): Promise<string>;
|
|
12
|
+
/** One mounted app's build input (root + routes scanned from its pagesDir). */
|
|
13
|
+
export interface BunTargetApp {
|
|
14
|
+
pagesDir: string;
|
|
15
|
+
prefix: string;
|
|
16
|
+
root: RootLayout;
|
|
17
|
+
routes: ResolvedRoute[];
|
|
18
|
+
}
|
|
19
|
+
export declare function buildBunTarget(apps: BunTargetApp[], rootDir: string, buildRoot: string, serverEntry: string | null, options: BuildAppOptions): Promise<TargetBuildManifest>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type BunTargetApp } from "../adapter/bun.ts";
|
|
2
|
+
import type { BuildAppOptions, PackageTargetBuildManifest } from "../build/types.ts";
|
|
3
|
+
/**
|
|
4
|
+
* `--target package` — builds a furin app as a PUBLISHABLE Elysia plugin
|
|
5
|
+
* instead of a bootable server. Output (`.furin/build/package/`):
|
|
6
|
+
*
|
|
7
|
+
* - `client/` content-hashed chunks + index.html SSR template
|
|
8
|
+
* - `register.js` side-effect module registering the app's CompileContext;
|
|
9
|
+
* page modules are bundled in, but everything from
|
|
10
|
+
* node_modules (incl. @teyik0/furin itself) stays external so
|
|
11
|
+
* the host and the register module share ONE furin runtime
|
|
12
|
+
* - `index.js` `createFurinApp()` factory the host `.use()`es
|
|
13
|
+
* - `index.d.ts` minimal typings for the factory
|
|
14
|
+
*
|
|
15
|
+
* The host composes it like any Elysia plugin:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { createFurinApp as admin } from "@org/admin/furin";
|
|
19
|
+
* new Elysia().use(await furin({...})).use(await admin()).listen(3000)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* In a monorepo the baked relative `pagesDir` still points at real sources,
|
|
23
|
+
* so the same factory works under `bun --hot` (dev scans live). A published
|
|
24
|
+
* package without sources is production-only; its context is found by prefix.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildPackageTarget(app: BunTargetApp, rootDir: string, buildRoot: string, options: BuildAppOptions): Promise<PackageTargetBuildManifest>;
|
package/dist/build/client.d.ts
CHANGED
|
@@ -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, clientLogging }: BuildClientOptions): Promise<BuildClientResult>;
|
|
25
|
+
export declare function buildClient(routes: ResolvedRoute[], { outDir, rootLayout, plugins, publicPath, basePath, clientLogging, clientDirName }: BuildClientOptions): Promise<BuildClientResult>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type BuildEntryOptions } from "./entry-template";
|
|
2
2
|
/**
|
|
3
3
|
* Generates a single `_compile-entry.ts` that:
|
|
4
|
-
* 1. Statically imports every page module so Bun bundles them
|
|
4
|
+
* 1. Statically imports every page module of every app so Bun bundles them
|
|
5
5
|
* 2. Optionally embeds client assets via `with { type: "file" }` (embed mode)
|
|
6
|
-
* 3. Sets production mode and registers
|
|
7
|
-
* 4. Dynamically imports server.ts to boot the app
|
|
6
|
+
* 3. Sets production mode and registers one CompileContext PER APP
|
|
7
|
+
* 4. Dynamically imports server.ts to boot the composed app
|
|
8
8
|
*/
|
|
9
9
|
export declare function generateCompileEntry(options: BuildEntryOptions): string;
|
|
@@ -1,109 +1,114 @@
|
|
|
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
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
1
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { buildEntrySource, type BuildEntryOptions, type EntryAppContext } from "./entry-template";
|
|
4
|
+
import { collectFilesRecursive, ensureDir, toPosixPath } from "./shared";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Builds one app's embedded-asset import lines + `embedded:` context block.
|
|
8
|
+
* Asset keys stay UNPREFIXED (`/_client/...`) — the instance's Elysia prefix
|
|
9
|
+
* strips the mount path before lookup at runtime.
|
|
10
|
+
*/
|
|
11
|
+
function buildEmbeddedAssets(
|
|
12
|
+
outDir: string,
|
|
13
|
+
clientDir: string,
|
|
14
|
+
publicDir: string | undefined,
|
|
15
|
+
varPrefix: string
|
|
16
|
+
): { extraContext: string[]; extraImports: string[] } {
|
|
17
|
+
if (!existsSync(clientDir)) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
`[furin] Client directory not found: ${clientDir}. Run the client build first.`
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const clientFiles = collectFilesRecursive(clientDir).filter((file) => !file.endsWith(".map"));
|
|
23
|
+
const assetImports: string[] = [];
|
|
24
|
+
const assetEntries: string[] = [];
|
|
25
|
+
let templateVarName: string | null = null;
|
|
26
|
+
|
|
27
|
+
let assetIndex = 0;
|
|
28
|
+
const importAsset = (file: string): string => {
|
|
29
|
+
const varName = `${varPrefix}asset${assetIndex++}`;
|
|
30
|
+
const relPath = toPosixPath(relative(outDir, file));
|
|
31
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
32
|
+
assetImports.push(
|
|
33
|
+
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
34
|
+
);
|
|
35
|
+
return varName;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
for (const file of clientFiles) {
|
|
39
|
+
const varName = importAsset(file);
|
|
40
|
+
const clientRelativePath = toPosixPath(relative(clientDir, file));
|
|
41
|
+
if (clientRelativePath === "index.html") {
|
|
42
|
+
templateVarName = varName;
|
|
43
|
+
} else {
|
|
44
|
+
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (templateVarName === null) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`[furin] Embed mode requires a client index.html at ${join(clientDir, "index.html")}. Run the client build first.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (publicDir && existsSync(publicDir)) {
|
|
55
|
+
const publicFiles = collectFilesRecursive(publicDir);
|
|
56
|
+
for (const file of publicFiles) {
|
|
57
|
+
const varName = importAsset(file);
|
|
58
|
+
const publicRelativePath = toPosixPath(relative(publicDir, file));
|
|
59
|
+
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const extraContext = [
|
|
64
|
+
" embedded: {",
|
|
65
|
+
` template: ${templateVarName},`,
|
|
66
|
+
" assets: {",
|
|
67
|
+
...assetEntries,
|
|
68
|
+
" },",
|
|
69
|
+
" },",
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
return { extraContext, extraImports: assetImports };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Generates a single `_compile-entry.ts` that:
|
|
77
|
+
* 1. Statically imports every page module of every app so Bun bundles them
|
|
78
|
+
* 2. Optionally embeds client assets via `with { type: "file" }` (embed mode)
|
|
79
|
+
* 3. Sets production mode and registers one CompileContext PER APP
|
|
80
|
+
* 4. Dynamically imports server.ts to boot the composed app
|
|
81
|
+
*/
|
|
82
|
+
export function generateCompileEntry(options: BuildEntryOptions): string {
|
|
83
|
+
const { apps, outDir, serverEntry, publicDir } = options;
|
|
84
|
+
ensureDir(outDir);
|
|
85
|
+
|
|
86
|
+
const preparedApps: EntryAppContext[] = apps.map((app, appIndex) => {
|
|
87
|
+
const { embed, ...context } = app;
|
|
88
|
+
if (!embed) {
|
|
89
|
+
return context;
|
|
90
|
+
}
|
|
91
|
+
const varPrefix = apps.length === 1 ? "_" : `_a${appIndex}_`;
|
|
92
|
+
// Every app gets the project-level public/ dir: each instance serves only
|
|
93
|
+
// from its own `embedded.assets`, so `/public/*` (and `/favicon.ico`) would
|
|
94
|
+
// 404 on non-first apps otherwise. This only duplicates the string keys —
|
|
95
|
+
// each app imports the same file via the same relative path, and Bun
|
|
96
|
+
// dedupes identical `with { type: "file" }` modules into one embedded blob.
|
|
97
|
+
const embedded = buildEmbeddedAssets(outDir, embed.clientDir, publicDir, varPrefix);
|
|
98
|
+
return {
|
|
99
|
+
...context,
|
|
100
|
+
extraContext: [...(context.extraContext ?? []), ...embedded.extraContext],
|
|
101
|
+
extraImports: [...(context.extraImports ?? []), ...embedded.extraImports],
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const source = buildEntrySource({
|
|
106
|
+
apps: preparedApps,
|
|
107
|
+
headerComment: options.headerComment ?? "// Auto-generated by furin compile — do not edit",
|
|
108
|
+
serverEntry,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const entryPath = join(outDir, "_compile-entry.ts");
|
|
112
|
+
writeFileSync(entryPath, source);
|
|
113
|
+
return entryPath;
|
|
114
|
+
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { SsgCacheEntry } from "../server/cache/index.ts";
|
|
2
|
-
|
|
2
|
+
/** One app's compile context payload — the generated entry can carry several. */
|
|
3
|
+
export interface EntryAppContext {
|
|
3
4
|
buildId?: string;
|
|
5
|
+
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
4
6
|
extraContext?: string[];
|
|
7
|
+
/** Extra import lines this app needs (embedded asset imports). */
|
|
5
8
|
extraImports?: string[];
|
|
6
|
-
|
|
9
|
+
/** Mount prefix baked into the context for runtime lookup (`""` = root). */
|
|
10
|
+
prefix?: string;
|
|
7
11
|
rootConventions?: {
|
|
8
12
|
errorPath?: string;
|
|
9
13
|
notFoundPath?: string;
|
|
@@ -22,17 +26,39 @@ export interface EntryTemplateOptions {
|
|
|
22
26
|
path: string;
|
|
23
27
|
pattern: string;
|
|
24
28
|
}>;
|
|
25
|
-
serverEntry: string;
|
|
26
29
|
ssgCache?: Record<string, SsgCacheEntry>;
|
|
27
30
|
}
|
|
31
|
+
export interface EntryTemplateOptions {
|
|
32
|
+
apps: EntryAppContext[];
|
|
33
|
+
headerComment: string;
|
|
34
|
+
/**
|
|
35
|
+
* - "boot" (default): forces production mode and dynamically imports the
|
|
36
|
+
* server entry after registering contexts — the whole app's entrypoint.
|
|
37
|
+
* - "register": ONLY registers contexts. Emitted by `--target package` as a
|
|
38
|
+
* side-effect module the HOST app imports; it must not touch dev mode or
|
|
39
|
+
* NODE_ENV (the host decides), and it imports furin internals via the
|
|
40
|
+
* package specifier so the host and the register module share ONE copy of
|
|
41
|
+
* the context registry (`packages: "external"` keeps it unbundled).
|
|
42
|
+
*/
|
|
43
|
+
mode?: "boot" | "register";
|
|
44
|
+
/**
|
|
45
|
+
* Server entry to boot after context registration. Omitted in package
|
|
46
|
+
* (register-module) mode where the entry only registers contexts.
|
|
47
|
+
*/
|
|
48
|
+
serverEntry?: string;
|
|
49
|
+
}
|
|
28
50
|
/** Unified options for generating a build entry (compile or disk-based). */
|
|
29
|
-
export interface BuildEntryOptions
|
|
30
|
-
|
|
51
|
+
export interface BuildEntryOptions {
|
|
52
|
+
apps: Array<EntryAppContext & {
|
|
53
|
+
/** Embed mode: bundles this app's client assets via `with { type: "file" }`. */
|
|
54
|
+
embed?: {
|
|
55
|
+
clientDir: string;
|
|
56
|
+
};
|
|
57
|
+
}>;
|
|
31
58
|
headerComment?: string;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
clientDir: string;
|
|
35
|
-
};
|
|
59
|
+
outDir: string;
|
|
60
|
+
/** Project-level public/ dir — embedded into EVERY app's assets (keys only; Bun dedupes the file payloads). */
|
|
36
61
|
publicDir?: string;
|
|
62
|
+
serverEntry?: string;
|
|
37
63
|
}
|
|
38
64
|
export declare function buildEntrySource(options: EntryTemplateOptions): string;
|