@teyik0/furin 0.1.0-alpha.12 → 0.1.0-alpha.13
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 +251 -0
- package/dist/build/compile-entry.ts +129 -0
- package/dist/build/entry-template.ts +133 -0
- package/dist/build/index.js +110 -116
- package/dist/build/server-routes-entry.ts +55 -0
- package/dist/cli/index.js +114 -120
- package/dist/env.d.ts +50 -0
- package/dist/furin.js +11 -7
- package/dist/internal.js +17 -0
- package/dist/link.js +9 -7
- package/dist/plugin/index.js +9 -7
- package/dist/render/index.ts +870 -0
- package/dist/render/shell.ts +187 -0
- package/dist/router-provider.d.ts +2 -1
- package/dist/router.js +10 -2
- package/dist/router.ts +1034 -0
- package/dist/runtime-env.js +10 -0
- package/package.json +42 -13
- package/src/adapter/bun.ts +4 -1
- package/src/build/entry-template.ts +13 -6
- package/src/build/scan-server.ts +32 -3
- package/src/link.tsx +2 -1
- package/src/plugin/transform-client.ts +10 -8
- package/src/render/index.ts +4 -3
- package/src/router-provider.tsx +10 -8
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,251 @@
|
|
|
1
|
+
# Furin
|
|
2
|
+
|
|
3
|
+
React meta-framework powered by Elysia and Bun, with file-based routing, nested layouts, SSR, SSG, ISR, and full TypeScript inference.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- file-based routing from `src/pages`
|
|
8
|
+
- nested layouts with `_route.tsx`
|
|
9
|
+
- SSR, SSG, and ISR through `createRoute()`
|
|
10
|
+
- typed `params`, `query`, loader data, and `<Link />` search objects
|
|
11
|
+
- one process for API routes and frontend pages
|
|
12
|
+
- Bun-native development flow with Fast Refresh
|
|
13
|
+
|
|
14
|
+
## Quick Start
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun create furin@latest my-app
|
|
18
|
+
cd my-app
|
|
19
|
+
bun install
|
|
20
|
+
bun run dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For the shadcn/ui starter:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun create furin@latest my-app --template full
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## First App
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
// src/pages/root.tsx
|
|
33
|
+
import { createRoute } from "@teyik0/furin/client";
|
|
34
|
+
|
|
35
|
+
export const route = createRoute({
|
|
36
|
+
layout: ({ children }) => (
|
|
37
|
+
<html lang="en">
|
|
38
|
+
<head>
|
|
39
|
+
<meta charSet="utf-8" />
|
|
40
|
+
<meta content="width=device-width, initial-scale=1" name="viewport" />
|
|
41
|
+
</head>
|
|
42
|
+
<body>{children}</body>
|
|
43
|
+
</html>
|
|
44
|
+
),
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// src/pages/index.tsx
|
|
50
|
+
import { route } from "./root";
|
|
51
|
+
|
|
52
|
+
export default route.page({
|
|
53
|
+
component: () => <h1>Hello Furin</h1>,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
// src/server.ts
|
|
59
|
+
import { Elysia } from "elysia";
|
|
60
|
+
import { furin } from "@teyik0/furin";
|
|
61
|
+
|
|
62
|
+
const app = new Elysia()
|
|
63
|
+
.use(await furin({ pagesDir: "./src/pages" }))
|
|
64
|
+
.listen(3000);
|
|
65
|
+
|
|
66
|
+
export type App = typeof app;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Route API
|
|
70
|
+
|
|
71
|
+
Use `createRoute()` for route-level configuration:
|
|
72
|
+
|
|
73
|
+
- `parent`
|
|
74
|
+
- `mode`
|
|
75
|
+
- `revalidate`
|
|
76
|
+
- `params`
|
|
77
|
+
- `query`
|
|
78
|
+
- `loader`
|
|
79
|
+
- `layout`
|
|
80
|
+
|
|
81
|
+
Use `route.page()` for page-level configuration:
|
|
82
|
+
|
|
83
|
+
- `component`
|
|
84
|
+
- `loader`
|
|
85
|
+
- `head`
|
|
86
|
+
- `staticParams`
|
|
87
|
+
|
|
88
|
+
## Example: Nested Layout + Typed Data
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
// src/pages/dashboard/_route.tsx
|
|
92
|
+
import { createRoute } from "@teyik0/furin/client";
|
|
93
|
+
import { route as rootRoute } from "../root";
|
|
94
|
+
|
|
95
|
+
export const route = createRoute({
|
|
96
|
+
parent: rootRoute,
|
|
97
|
+
loader: async ({ request }) => {
|
|
98
|
+
const user = await getSession(request);
|
|
99
|
+
return { user };
|
|
100
|
+
},
|
|
101
|
+
layout: ({ children, user }) => (
|
|
102
|
+
<div>
|
|
103
|
+
<DashboardNav user={user} />
|
|
104
|
+
{children}
|
|
105
|
+
</div>
|
|
106
|
+
),
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
// src/pages/dashboard/index.tsx
|
|
112
|
+
import { route } from "./_route";
|
|
113
|
+
|
|
114
|
+
export default route.page({
|
|
115
|
+
loader: async ({ user }) => {
|
|
116
|
+
const stats = await getDashboardStats(user.id);
|
|
117
|
+
return { stats };
|
|
118
|
+
},
|
|
119
|
+
component: ({ stats, user }) => <Dashboard user={user} stats={stats} />,
|
|
120
|
+
});
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Rendering Modes
|
|
124
|
+
|
|
125
|
+
Rendering mode belongs to `createRoute()`:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { createRoute } from "@teyik0/furin/client";
|
|
129
|
+
|
|
130
|
+
const route = createRoute({
|
|
131
|
+
mode: "ssg",
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export default route.page({
|
|
135
|
+
component: () => <div>Static page</div>,
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
ISR uses `revalidate` on the route:
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
const route = createRoute({
|
|
143
|
+
mode: "isr",
|
|
144
|
+
revalidate: 60,
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Dynamic SSG pages enumerate paths with `staticParams()` on `route.page()`:
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
export default route.page({
|
|
152
|
+
staticParams: async () => {
|
|
153
|
+
const slugs = await getSlugs();
|
|
154
|
+
return slugs.map((slug) => ({ slug }));
|
|
155
|
+
},
|
|
156
|
+
component: ({ post }) => <Post post={post} />,
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## File-Based Routing
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
src/pages/
|
|
164
|
+
├── root.tsx
|
|
165
|
+
├── index.tsx
|
|
166
|
+
├── blog/
|
|
167
|
+
│ ├── _route.tsx
|
|
168
|
+
│ ├── index.tsx
|
|
169
|
+
│ └── [slug].tsx
|
|
170
|
+
└── docs/
|
|
171
|
+
├── _route.tsx
|
|
172
|
+
└── [...path].tsx
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
- pages are regular `.tsx` files
|
|
176
|
+
- `_route.tsx` files define layouts and route-level config
|
|
177
|
+
- dynamic params use `[slug]`
|
|
178
|
+
- catch-all routes use `[...path]`
|
|
179
|
+
|
|
180
|
+
## Typed Navigation
|
|
181
|
+
|
|
182
|
+
Furin generates `furin-env.d.ts` so `@teyik0/furin/link` can type valid paths and route search params.
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
import { Link } from "@teyik0/furin/link";
|
|
186
|
+
|
|
187
|
+
<Link to="/docs/rendering">Rendering</Link>;
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
When a route declares a `query` schema, `<Link search={...} />` is typed from that schema.
|
|
191
|
+
|
|
192
|
+
## API Routes
|
|
193
|
+
|
|
194
|
+
Elysia routes live alongside Furin pages in the same server:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import { Elysia } from "elysia";
|
|
198
|
+
import { furin } from "@teyik0/furin";
|
|
199
|
+
import { api } from "./api";
|
|
200
|
+
|
|
201
|
+
const app = new Elysia()
|
|
202
|
+
.use(api)
|
|
203
|
+
.use(await furin({ pagesDir: "./src/pages" }))
|
|
204
|
+
.listen(3000);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Build And Deployment
|
|
208
|
+
|
|
209
|
+
Today, the implemented production build target is Bun.
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
bunx furin build --target bun
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Output is written under:
|
|
216
|
+
|
|
217
|
+
```text
|
|
218
|
+
.furin/build/bun/
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Compile modes:
|
|
222
|
+
|
|
223
|
+
- `--compile server` keeps built client assets on disk next to the binary
|
|
224
|
+
- `--compile embed` embeds the client assets into the binary and removes the built client directory from the target output
|
|
225
|
+
|
|
226
|
+
The config type mentions `node`, `vercel`, and `cloudflare`, but those targets are planned and not implemented in the current build path.
|
|
227
|
+
|
|
228
|
+
## Workspace Commands
|
|
229
|
+
|
|
230
|
+
From this monorepo root:
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
bun run fix
|
|
234
|
+
bun run test
|
|
235
|
+
bun run tscheck
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
For the docs app:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
cd apps/docs
|
|
242
|
+
bun run dev
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Reference
|
|
246
|
+
|
|
247
|
+
- docs site: `apps/docs`
|
|
248
|
+
- example apps: `examples/task-manager`, `examples/weather`
|
|
249
|
+
- core package: `packages/core`
|
|
250
|
+
|
|
251
|
+
For the full docs experience, read the site in `apps/docs`.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { buildEntrySource } from "./entry-template";
|
|
4
|
+
import { collectFilesRecursive, ensureDir, toPosixPath } from "./shared";
|
|
5
|
+
|
|
6
|
+
export interface CompileEntryOptions {
|
|
7
|
+
buildId: string | undefined;
|
|
8
|
+
embed: { clientDir: string } | undefined;
|
|
9
|
+
outDir: string;
|
|
10
|
+
publicDir: string | undefined;
|
|
11
|
+
rootConventions: { errorPath: string | undefined; notFoundPath: string | undefined } | undefined;
|
|
12
|
+
rootPath: string;
|
|
13
|
+
routeMetadata:
|
|
14
|
+
| Record<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
segmentBoundaries: Array<{
|
|
18
|
+
depth: number;
|
|
19
|
+
path: string;
|
|
20
|
+
errorPath: string | undefined;
|
|
21
|
+
notFoundPath: string | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
>
|
|
25
|
+
| undefined;
|
|
26
|
+
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
27
|
+
serverEntry: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generates a single `_compile-entry.ts` that:
|
|
32
|
+
* 1. Statically imports every page module so Bun bundles them into the binary
|
|
33
|
+
* 2. Optionally embeds client assets via `with { type: "file" }` (embed mode)
|
|
34
|
+
* 3. Sets production mode and registers everything in a single CompileContext
|
|
35
|
+
* 4. Dynamically imports server.ts to boot the app
|
|
36
|
+
*/
|
|
37
|
+
export function generateCompileEntry(options: CompileEntryOptions): string {
|
|
38
|
+
const {
|
|
39
|
+
buildId,
|
|
40
|
+
outDir,
|
|
41
|
+
rootPath,
|
|
42
|
+
routes,
|
|
43
|
+
serverEntry,
|
|
44
|
+
embed,
|
|
45
|
+
publicDir,
|
|
46
|
+
rootConventions,
|
|
47
|
+
routeMetadata,
|
|
48
|
+
} = options;
|
|
49
|
+
ensureDir(outDir);
|
|
50
|
+
|
|
51
|
+
// Build embedded asset imports if embed mode
|
|
52
|
+
const assetImports: string[] = [];
|
|
53
|
+
let embeddedBlock: string[] = [];
|
|
54
|
+
if (embed) {
|
|
55
|
+
if (!existsSync(embed.clientDir)) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`[furin] Client directory not found: ${embed.clientDir}. Run the client build first.`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
const clientFiles = collectFilesRecursive(embed.clientDir);
|
|
61
|
+
const assetEntries: string[] = [];
|
|
62
|
+
let templateVarName: string | null = null;
|
|
63
|
+
|
|
64
|
+
let assetIndex = 0;
|
|
65
|
+
for (const file of clientFiles) {
|
|
66
|
+
const varName = `_asset${assetIndex++}`;
|
|
67
|
+
const relPath = toPosixPath(relative(outDir, file));
|
|
68
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
69
|
+
|
|
70
|
+
assetImports.push(
|
|
71
|
+
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const clientRelativePath = toPosixPath(relative(embed.clientDir, file));
|
|
75
|
+
if (clientRelativePath === "index.html") {
|
|
76
|
+
templateVarName = varName;
|
|
77
|
+
} else {
|
|
78
|
+
assetEntries.push(` ${JSON.stringify(`/_client/${clientRelativePath}`)}: ${varName},`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (templateVarName === null) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`[furin] Embed mode requires a client index.html at ${join(embed.clientDir, "index.html")}. Run the client build first.`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (publicDir && existsSync(publicDir)) {
|
|
89
|
+
const publicFiles = collectFilesRecursive(publicDir);
|
|
90
|
+
for (const file of publicFiles) {
|
|
91
|
+
const varName = `_asset${assetIndex++}`;
|
|
92
|
+
const relPath = toPosixPath(relative(outDir, file));
|
|
93
|
+
const importPath = relPath.startsWith(".") ? relPath : `./${relPath}`;
|
|
94
|
+
|
|
95
|
+
assetImports.push(
|
|
96
|
+
`import ${varName} from ${JSON.stringify(importPath)} with { type: "file" };`
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const publicRelativePath = toPosixPath(relative(publicDir, file));
|
|
100
|
+
assetEntries.push(` ${JSON.stringify(`/public/${publicRelativePath}`)}: ${varName},`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
embeddedBlock = [
|
|
105
|
+
" embedded: {",
|
|
106
|
+
` template: ${templateVarName},`,
|
|
107
|
+
" assets: {",
|
|
108
|
+
...assetEntries,
|
|
109
|
+
" },",
|
|
110
|
+
" },",
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const source = buildEntrySource({
|
|
115
|
+
buildId,
|
|
116
|
+
headerComment: "// Auto-generated by furin compile — do not edit",
|
|
117
|
+
rootPath,
|
|
118
|
+
routes,
|
|
119
|
+
serverEntry,
|
|
120
|
+
extraImports: assetImports,
|
|
121
|
+
extraContext: embeddedBlock,
|
|
122
|
+
rootConventions,
|
|
123
|
+
routeMetadata,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const entryPath = join(outDir, "_compile-entry.ts");
|
|
127
|
+
writeFileSync(entryPath, source);
|
|
128
|
+
return entryPath;
|
|
129
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
6
|
+
// through package exports, and is the Web-standard API.
|
|
7
|
+
const _pkgRoot = dirname(dirname(fileURLToPath(import.meta.resolve("@teyik0/furin"))));
|
|
8
|
+
const _pkgSrcDirRaw = existsSync(join(_pkgRoot, "src", "furin.ts"))
|
|
9
|
+
? join(_pkgRoot, "src")
|
|
10
|
+
: join(_pkgRoot, "dist");
|
|
11
|
+
// Normalize to forward slashes so endsWith checks and template paths work on Windows.
|
|
12
|
+
const _pkgSrcDir = _pkgSrcDirRaw.replace(/\\/g, "/");
|
|
13
|
+
const _ext = _pkgSrcDir.endsWith("/src") ? ".ts" : ".js";
|
|
14
|
+
const INTERNAL_MODULE_PATH = `${_pkgSrcDir}/internal${_ext}`;
|
|
15
|
+
const RUNTIME_ENV_MODULE_PATH = `${_pkgSrcDir}/runtime-env${_ext}`;
|
|
16
|
+
|
|
17
|
+
export interface EntryTemplateOptions {
|
|
18
|
+
buildId?: string;
|
|
19
|
+
extraContext?: string[];
|
|
20
|
+
extraImports?: string[];
|
|
21
|
+
headerComment: string;
|
|
22
|
+
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
23
|
+
rootPath: string;
|
|
24
|
+
routeMetadata?: Record<
|
|
25
|
+
string,
|
|
26
|
+
{
|
|
27
|
+
segmentBoundaries: Array<{
|
|
28
|
+
depth: number;
|
|
29
|
+
path: string;
|
|
30
|
+
errorPath?: string;
|
|
31
|
+
notFoundPath?: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
34
|
+
>;
|
|
35
|
+
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
36
|
+
serverEntry: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function collectConventionPaths(
|
|
40
|
+
rootConventions: EntryTemplateOptions["rootConventions"],
|
|
41
|
+
routeMetadata: EntryTemplateOptions["routeMetadata"]
|
|
42
|
+
): string[] {
|
|
43
|
+
const paths: string[] = [];
|
|
44
|
+
if (rootConventions?.errorPath) {
|
|
45
|
+
paths.push(rootConventions.errorPath);
|
|
46
|
+
}
|
|
47
|
+
if (rootConventions?.notFoundPath) {
|
|
48
|
+
paths.push(rootConventions.notFoundPath);
|
|
49
|
+
}
|
|
50
|
+
if (routeMetadata) {
|
|
51
|
+
for (const meta of Object.values(routeMetadata)) {
|
|
52
|
+
for (const seg of meta.segmentBoundaries) {
|
|
53
|
+
if (seg.errorPath) {
|
|
54
|
+
paths.push(seg.errorPath);
|
|
55
|
+
}
|
|
56
|
+
if (seg.notFoundPath) {
|
|
57
|
+
paths.push(seg.notFoundPath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return [...new Set(paths)];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function buildEntrySource(options: EntryTemplateOptions): string {
|
|
66
|
+
const { buildId, headerComment, rootPath, routes, serverEntry, rootConventions, routeMetadata } =
|
|
67
|
+
options;
|
|
68
|
+
let { extraImports, extraContext } = options;
|
|
69
|
+
if (extraImports === undefined) {
|
|
70
|
+
extraImports = [];
|
|
71
|
+
}
|
|
72
|
+
if (extraContext === undefined) {
|
|
73
|
+
extraContext = [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const allModulePaths = [
|
|
77
|
+
rootPath,
|
|
78
|
+
...routes.map((r) => r.path),
|
|
79
|
+
...collectConventionPaths(rootConventions, routeMetadata),
|
|
80
|
+
];
|
|
81
|
+
const moduleImports: string[] = [];
|
|
82
|
+
const moduleEntries: string[] = [];
|
|
83
|
+
|
|
84
|
+
for (let i = 0; i < allModulePaths.length; i++) {
|
|
85
|
+
const absPath = (allModulePaths[i] as string).replace(/\\/g, "/");
|
|
86
|
+
const varName = `_mod${i}`;
|
|
87
|
+
moduleImports.push(`import * as ${varName} from ${JSON.stringify(absPath)};`);
|
|
88
|
+
moduleEntries.push(` ${JSON.stringify(absPath)}: ${varName},`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const routeEntries = routes.map(
|
|
92
|
+
(r) =>
|
|
93
|
+
` { pattern: ${JSON.stringify(r.pattern)}, path: ${JSON.stringify(r.path.replace(/\\/g, "/"))}, mode: ${JSON.stringify(r.mode)} },`
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const rootConventionsLine = rootConventions
|
|
97
|
+
? ` rootConventions: ${JSON.stringify(rootConventions)},`
|
|
98
|
+
: "";
|
|
99
|
+
const routeMetadataLine = routeMetadata
|
|
100
|
+
? ` routeMetadata: ${JSON.stringify(routeMetadata)},`
|
|
101
|
+
: "";
|
|
102
|
+
|
|
103
|
+
const lines = [
|
|
104
|
+
headerComment,
|
|
105
|
+
`import { __setCompileContext } from ${JSON.stringify(INTERNAL_MODULE_PATH)};`,
|
|
106
|
+
`import { __setDevMode } from ${JSON.stringify(RUNTIME_ENV_MODULE_PATH)};`,
|
|
107
|
+
...moduleImports,
|
|
108
|
+
...(extraImports.length > 0 ? ["", ...extraImports] : []),
|
|
109
|
+
"",
|
|
110
|
+
"// Force production mode — Bun may inline process.env.NODE_ENV at bundle time.",
|
|
111
|
+
"__setDevMode(false);",
|
|
112
|
+
'process.env.NODE_ENV = "production";',
|
|
113
|
+
"",
|
|
114
|
+
"__setCompileContext({",
|
|
115
|
+
` buildId: ${JSON.stringify(buildId ?? "")},`,
|
|
116
|
+
` rootPath: ${JSON.stringify(rootPath.replace(/\\/g, "/"))},`,
|
|
117
|
+
rootConventionsLine,
|
|
118
|
+
" modules: {",
|
|
119
|
+
...moduleEntries,
|
|
120
|
+
" },",
|
|
121
|
+
" routes: [",
|
|
122
|
+
...routeEntries,
|
|
123
|
+
" ],",
|
|
124
|
+
routeMetadataLine,
|
|
125
|
+
...extraContext,
|
|
126
|
+
"});",
|
|
127
|
+
"",
|
|
128
|
+
`await import(${JSON.stringify(serverEntry.replace(/\\/g, "/"))});`,
|
|
129
|
+
"",
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
return lines.join("\n");
|
|
133
|
+
}
|