@teyik0/furin 0.9.0-alpha.0 → 0.9.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/README.md +1 -1
- package/dist/adapter/runtime-build.d.ts +7 -3
- package/dist/adapter/vercel.js +31 -6
- package/dist/build/client.d.ts +1 -1
- package/dist/build/entry-template.d.ts +3 -12
- package/dist/build/entry-template.ts +3 -15
- package/dist/build/hydrate.d.ts +6 -1
- package/dist/build/index.d.ts +1 -1
- package/dist/build/index.js +565 -401
- package/dist/build/route-metadata.d.ts +2 -2
- package/dist/build/route-types.d.ts +1 -1
- package/dist/build/types.d.ts +10 -4
- package/dist/cli/dev-worker.ts +10 -4
- package/dist/cli/index.js +624 -445
- package/dist/client/chunks/{client-xy6g38kx.js → client-a7spxfnn.js} +24 -5
- package/dist/client/chunks/{client-rjhxgt64.js → client-d9v49jwz.js} +1 -1
- package/dist/client/chunks/{client-k29262a4.js → client-rdxyrw11.js} +1 -1
- package/dist/client/define-route.d.ts +14 -0
- package/dist/client/internal/runtime-types.d.ts +8 -0
- package/dist/client/link.js +20 -17
- package/dist/client/router/link-utils.d.ts +3 -2
- package/dist/client/router/search/index.js +2 -2
- package/dist/client/router/types.d.ts +9 -3
- package/dist/client.js +22 -6
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -1
- package/dist/define-route.d.ts +53 -12
- package/dist/furin.d.ts +13 -3
- package/dist/furin.js +815 -661
- package/dist/plugin/route-config.d.ts +3 -3
- package/dist/plugin/route-manifest.d.ts +46 -0
- package/dist/plugin/route-tree.d.ts +13 -29
- package/dist/routes.d.ts +2 -2
- package/dist/server/dev/runtime.d.ts +2 -1
- package/dist/server/internal.d.ts +6 -0
- package/dist/server/internal.js +97 -114
- package/dist/server/registrations.d.ts +4 -2
- package/dist/server/render/index.d.ts +0 -1
- package/dist/server/render/index.ts +0 -1
- package/dist/server/render/shell.d.ts +1 -13
- package/dist/server/render/shell.ts +1 -90
- package/dist/server/router/defined-route.d.ts +4 -0
- package/dist/server/router/discovery.d.ts +14 -4
- package/dist/server/router/hmr.d.ts +12 -12
- package/dist/server/router/patterns.d.ts +4 -12
- package/dist/server/router/types.d.ts +16 -1
- package/dist/server/static-export.js +128 -158
- package/dist/server/sync/drizzle/index.d.ts +8 -10
- package/dist/shared/not-found.d.ts +1 -1
- package/dist/shared/route-specificity.d.ts +10 -1
- package/package.json +8 -11
- package/src/adapter/package.ts +11 -37
- package/src/adapter/runtime-build.ts +5 -4
- package/src/adapter/static.ts +1 -1
- package/src/adapter/vercel.ts +2 -1
- package/src/build/client.ts +3 -3
- package/src/build/discover-pages-process.ts +1 -1
- package/src/build/elysia-aot.ts +2 -2
- package/src/build/entry-template.ts +3 -15
- package/src/build/hydrate.ts +12 -6
- package/src/build/index.ts +19 -9
- package/src/build/route-metadata.ts +15 -8
- package/src/build/route-types.ts +18 -43
- package/src/build/types.ts +12 -5
- package/src/cli/config.ts +6 -0
- package/src/cli/dev-worker.ts +10 -4
- package/src/cli/dev.ts +41 -26
- package/src/cli/index.ts +30 -14
- package/src/client/define-route.ts +29 -4
- package/src/client/internal/runtime-types.ts +8 -0
- package/src/client/link.tsx +21 -22
- package/src/client/router/context.ts +8 -7
- package/src/client/router/link-utils.ts +16 -8
- package/src/client/router/provider.tsx +5 -0
- package/src/client/router/types.ts +40 -14
- package/src/config.ts +5 -0
- package/src/define-route.ts +85 -16
- package/src/furin.ts +31 -7
- package/src/plugin/dev-routes.ts +8 -17
- package/src/plugin/route-config.ts +77 -62
- package/src/plugin/route-manifest.ts +437 -0
- package/src/plugin/route-modules.ts +6 -1
- package/src/plugin/route-registry.ts +7 -21
- package/src/plugin/route-tree.ts +71 -181
- package/src/routes.ts +2 -2
- package/src/server/dev/runtime.ts +16 -22
- package/src/server/internal.ts +4 -1
- package/src/server/registrations.ts +5 -2
- package/src/server/render/index.ts +0 -1
- package/src/server/render/shell.ts +1 -90
- package/src/server/render/static-params.ts +2 -10
- package/src/server/router/defined-route.ts +8 -0
- package/src/server/router/discovery.ts +237 -196
- package/src/server/router/hmr.ts +45 -63
- package/src/server/router/patterns.ts +41 -117
- package/src/server/router/types.ts +17 -1
- package/src/server/sync/drizzle/index.ts +18 -19
- package/src/shared/not-found.ts +1 -1
- package/src/shared/route-specificity.ts +34 -2
- package/src/shared/utils/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teyik0/furin",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.2",
|
|
4
4
|
"description": "React meta-framework powered by Elysia and Bun with file-based routing, SSR, SSG, and ISR.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -176,15 +176,15 @@
|
|
|
176
176
|
"tscheck": "bun run generate:sync-prisma && tsc --noEmit"
|
|
177
177
|
},
|
|
178
178
|
"dependencies": {
|
|
179
|
-
"@elysia/eden": "2.0.0-rc.1",
|
|
180
|
-
"@elysia/static": "2.0.0-rc.0",
|
|
179
|
+
"@elysia/eden": "^2.0.0-rc.1",
|
|
180
|
+
"@elysia/static": "^2.0.0-rc.0",
|
|
181
181
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
182
182
|
"@vercel/functions": "^3.10.1",
|
|
183
183
|
"cjs-module-lexer": "^2.3.0",
|
|
184
184
|
"magic-string": "^1.4.3",
|
|
185
185
|
"react-server-dom-webpack": "~19.3.1",
|
|
186
186
|
"seroval": "^1.6.11",
|
|
187
|
-
"typescript": "7.0.2",
|
|
187
|
+
"typescript": "^7.0.2",
|
|
188
188
|
"yuku-ast": "0.13.0",
|
|
189
189
|
"yuku-parser": "0.13.0"
|
|
190
190
|
},
|
|
@@ -194,25 +194,22 @@
|
|
|
194
194
|
"@prisma/client-runtime-utils": "7.10.1",
|
|
195
195
|
"@types/react": "^19.3.0",
|
|
196
196
|
"@types/react-dom": "^19.3.0",
|
|
197
|
-
"drizzle-orm": "0.
|
|
197
|
+
"drizzle-orm": "1.0.0-rc.5",
|
|
198
198
|
"exact-mirror": "1.2.6",
|
|
199
199
|
"expect-type": "^1.4.0",
|
|
200
200
|
"prisma": "7.10.1"
|
|
201
201
|
},
|
|
202
202
|
"peerDependencies": {
|
|
203
203
|
"@types/bun": ">=1.4.0",
|
|
204
|
-
"drizzle-orm": "^0.
|
|
205
|
-
"elysia": "2.0.0-rc.1",
|
|
204
|
+
"drizzle-orm": "^1.0.0-rc.4",
|
|
205
|
+
"elysia": "^2.0.0-rc.1",
|
|
206
206
|
"evlog": "^2.33.1",
|
|
207
207
|
"exact-mirror": ">=1.2.6",
|
|
208
208
|
"react": "^19.3.1",
|
|
209
209
|
"react-dom": "^19.3.1",
|
|
210
|
-
"typebox": "1.3.34"
|
|
210
|
+
"typebox": "^1.3.34"
|
|
211
211
|
},
|
|
212
212
|
"peerDependenciesMeta": {
|
|
213
|
-
"@types/bun": {
|
|
214
|
-
"optional": true
|
|
215
|
-
},
|
|
216
213
|
"drizzle-orm": {
|
|
217
214
|
"optional": true
|
|
218
215
|
}
|
package/src/adapter/package.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { existsSync, rmSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { join, relative, resolve } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
buildCompileMetadata,
|
|
5
|
+
createBuildFingerprint,
|
|
6
|
+
type RuntimeTargetApp,
|
|
7
|
+
} from "../adapter/runtime-build.ts";
|
|
4
8
|
import { PRODUCTION_DEFINE, runBunBuild } from "../build/bun-build.ts";
|
|
5
9
|
import { buildClient } from "../build/client.ts";
|
|
6
10
|
import { buildEntrySource, PRERENDER_SNAPSHOT_FILE } from "../build/entry-template.ts";
|
|
@@ -56,7 +60,7 @@ export async function buildPackageTarget(
|
|
|
56
60
|
metafilePath: options.analyze ? join(buildRoot, "analysis", "package-client.json") : undefined,
|
|
57
61
|
optimizeImports: options.optimizeImports,
|
|
58
62
|
outDir: targetDir,
|
|
59
|
-
pagesDir,
|
|
63
|
+
pages: { pagesDir, style: app.style },
|
|
60
64
|
routeRegistry: app.routeRegistry,
|
|
61
65
|
plugins: options.plugins,
|
|
62
66
|
preloadRouteChunks: options.preload?.routeChunks,
|
|
@@ -93,38 +97,7 @@ export async function buildPackageTarget(
|
|
|
93
97
|
const indexHtml = generateProdIndexHtml(entryChunk, cssChunks, buildId, undefined, false);
|
|
94
98
|
writeFileSync(join(clientDir, "index.html"), indexHtml);
|
|
95
99
|
|
|
96
|
-
const rootConventions =
|
|
97
|
-
root.errorPath || root.notFoundPath
|
|
98
|
-
? {
|
|
99
|
-
errorPath: root.errorPath ? toPosixPath(root.errorPath) : undefined,
|
|
100
|
-
notFoundPath: root.notFoundPath ? toPosixPath(root.notFoundPath) : undefined,
|
|
101
|
-
}
|
|
102
|
-
: undefined;
|
|
103
|
-
const routeMetadata: Record<
|
|
104
|
-
string,
|
|
105
|
-
{
|
|
106
|
-
requestKeys?: string[];
|
|
107
|
-
requestKeysByLoader?: string[][];
|
|
108
|
-
segmentBoundaries: Array<{
|
|
109
|
-
depth: number;
|
|
110
|
-
path: string;
|
|
111
|
-
errorPath?: string;
|
|
112
|
-
notFoundPath?: string;
|
|
113
|
-
}>;
|
|
114
|
-
}
|
|
115
|
-
> = {};
|
|
116
|
-
for (const route of routes) {
|
|
117
|
-
routeMetadata[toPosixPath(route.path)] = {
|
|
118
|
-
requestKeys: route.requestKeys,
|
|
119
|
-
requestKeysByLoader: route.requestKeysByLoader,
|
|
120
|
-
segmentBoundaries: route.segmentBoundaries.map((b) => ({
|
|
121
|
-
depth: b.depth,
|
|
122
|
-
errorPath: b.errorPath ? toPosixPath(b.errorPath) : undefined,
|
|
123
|
-
notFoundPath: b.notFoundPath ? toPosixPath(b.notFoundPath) : undefined,
|
|
124
|
-
path: toPosixPath(b.path),
|
|
125
|
-
})),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
100
|
+
const { rootConventions, routeMetadata } = buildCompileMetadata(root, routes);
|
|
128
101
|
|
|
129
102
|
// 1. register.ts — context registration side-effect module.
|
|
130
103
|
const registerSource = buildEntrySource({
|
|
@@ -194,7 +167,7 @@ const CLIENT_DIR = fileURLToPath(new URL("./client", import.meta.url));
|
|
|
194
167
|
* Mounts this packaged furin app as an Elysia plugin.
|
|
195
168
|
*
|
|
196
169
|
* @param {object} [options] Extra furin() options (logger, sync, ...) —
|
|
197
|
-
* pagesDir/prefix/clientDir are baked into the package and cannot be overridden.
|
|
170
|
+
* pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden.
|
|
198
171
|
* @returns {ReturnType<typeof import("@teyik0/furin").furin>}
|
|
199
172
|
*/
|
|
200
173
|
export function createFurinApp(options = {}) {
|
|
@@ -202,6 +175,7 @@ export function createFurinApp(options = {}) {
|
|
|
202
175
|
...options,
|
|
203
176
|
pagesDir: PAGES_DIR,
|
|
204
177
|
prefix: ${JSON.stringify(prefix)},
|
|
178
|
+
style: ${JSON.stringify(app.style)},
|
|
205
179
|
clientDir: CLIENT_DIR,
|
|
206
180
|
});
|
|
207
181
|
}
|
|
@@ -212,8 +186,8 @@ export const prefix = ${JSON.stringify(prefix)};
|
|
|
212
186
|
|
|
213
187
|
const dtsSource = `import type { FurinOptions, furin } from "@teyik0/furin";
|
|
214
188
|
|
|
215
|
-
/** Extra furin() options — pagesDir/prefix/clientDir are baked into the package and cannot be overridden. */
|
|
216
|
-
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "clientDir">;
|
|
189
|
+
/** Extra furin() options — pagesDir/prefix/style/clientDir are baked into the package and cannot be overridden. */
|
|
190
|
+
export type CreateFurinAppOptions = Omit<FurinOptions, "pagesDir" | "prefix" | "style" | "clientDir">;
|
|
217
191
|
export declare function createFurinApp(options?: CreateFurinAppOptions): ReturnType<typeof furin>;
|
|
218
192
|
export declare const prefix: string;
|
|
219
193
|
`;
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from "../build/route-metadata.ts";
|
|
13
13
|
import { toPosixPath } from "../build/shared.ts";
|
|
14
14
|
import type { BuildAppOptions } from "../build/types.ts";
|
|
15
|
+
import type { RouteInstanceSpec } from "../plugin/route-manifest.ts";
|
|
15
16
|
import type { RouteRegistrySnapshot } from "../plugin/route-registry.ts";
|
|
16
17
|
import { composableRouteModuleSpecifier } from "../plugin/route-registry.ts";
|
|
17
18
|
import { routeSourcePaths } from "../plugin/route-tree.ts";
|
|
@@ -275,11 +276,13 @@ export function buildCompileMetadata(root: BuildRoot | RootLayout, routes: Build
|
|
|
275
276
|
const routeMetadata: NonNullable<EntryAppContext["routeMetadata"]> = {};
|
|
276
277
|
for (const route of routes) {
|
|
277
278
|
routeMetadata[toPosixPath(route.path)] = {
|
|
279
|
+
layouts: route.layouts.map((layout) => ({ ...layout, path: toPosixPath(layout.path) })),
|
|
278
280
|
requestKeys: route.requestKeys,
|
|
279
281
|
requestKeysByLoader: route.requestKeysByLoader,
|
|
280
282
|
segmentBoundaries: route.segmentBoundaries.map((boundary) => ({
|
|
281
283
|
depth: boundary.depth,
|
|
282
284
|
errorPath: boundary.errorPath ? toPosixPath(boundary.errorPath) : undefined,
|
|
285
|
+
...(boundary.fromRoute ? { fromRoute: boundary.fromRoute } : {}),
|
|
283
286
|
notFoundPath: boundary.notFoundPath ? toPosixPath(boundary.notFoundPath) : undefined,
|
|
284
287
|
path: toPosixPath(boundary.path),
|
|
285
288
|
})),
|
|
@@ -290,9 +293,7 @@ export function buildCompileMetadata(root: BuildRoot | RootLayout, routes: Build
|
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
/** One mounted app's build input (root + routes scanned from its pagesDir). */
|
|
293
|
-
export interface RuntimeTargetApp {
|
|
294
|
-
pagesDir: string;
|
|
295
|
-
prefix: string;
|
|
296
|
+
export interface RuntimeTargetApp extends RouteInstanceSpec {
|
|
296
297
|
root: BuildRoot | RootLayout;
|
|
297
298
|
routeRegistry?: RouteRegistrySnapshot;
|
|
298
299
|
routes: BuildRouteInput[];
|
|
@@ -412,7 +413,7 @@ export async function buildRuntimeApp(
|
|
|
412
413
|
: undefined,
|
|
413
414
|
optimizeImports: options.optimizeImports,
|
|
414
415
|
outDir: targetDir,
|
|
415
|
-
pagesDir: app.pagesDir,
|
|
416
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
416
417
|
routeRegistry: app.routeRegistry,
|
|
417
418
|
plugins: options.plugins,
|
|
418
419
|
preloadRouteChunks: options.preload?.routeChunks,
|
package/src/adapter/static.ts
CHANGED
|
@@ -498,7 +498,7 @@ export async function buildStaticTarget(
|
|
|
498
498
|
metafilePath: options.analyze ? join(buildRoot, "analysis", "static-client.json") : undefined,
|
|
499
499
|
optimizeImports: options.optimizeImports,
|
|
500
500
|
outDir: targetDir,
|
|
501
|
-
pagesDir:
|
|
501
|
+
pages: { pagesDir: app.pagesDir, style: app.style },
|
|
502
502
|
routeRegistry: app.routeRegistry,
|
|
503
503
|
plugins: options.plugins,
|
|
504
504
|
preloadRouteChunks: options.preload?.routeChunks,
|
package/src/adapter/vercel.ts
CHANGED
|
@@ -158,7 +158,8 @@ function functionNameForPath(
|
|
|
158
158
|
return "[...splat]";
|
|
159
159
|
}
|
|
160
160
|
if (segment.startsWith(":")) {
|
|
161
|
-
|
|
161
|
+
// `:lang?` → `[[lang]]`: `?` is not portable in function directory names.
|
|
162
|
+
return segment.endsWith("?") ? `[[${segment.slice(1, -1)}]]` : `[${segment.slice(1)}]`;
|
|
162
163
|
}
|
|
163
164
|
const sanitized = segment.replace(UNSAFE_FUNCTION_PATH_RE, "-");
|
|
164
165
|
if (sanitized === segment && segment !== "." && segment !== "..") {
|
package/src/build/client.ts
CHANGED
|
@@ -54,7 +54,7 @@ export async function buildClient(
|
|
|
54
54
|
metafilePath,
|
|
55
55
|
optimizeImports,
|
|
56
56
|
reactCompiler,
|
|
57
|
-
|
|
57
|
+
pages,
|
|
58
58
|
routeRegistry,
|
|
59
59
|
}: BuildClientOptions
|
|
60
60
|
): Promise<BuildClientResult> {
|
|
@@ -136,8 +136,8 @@ export async function buildClient(
|
|
|
136
136
|
hydrateEntry.plugin,
|
|
137
137
|
...(plugins ?? []),
|
|
138
138
|
...(!clientLogging ? [routerLoggerPlugin] : []),
|
|
139
|
-
...(
|
|
140
|
-
? [createRoutesPlugin({ instances: [{
|
|
139
|
+
...(pages
|
|
140
|
+
? [createRoutesPlugin({ instances: [{ ...pages, prefix: basePath, routeRegistry }], target: "client" })]
|
|
141
141
|
: []),
|
|
142
142
|
createClientStripPlugin({ mode: "build" }),
|
|
143
143
|
],
|
|
@@ -134,7 +134,7 @@ Bun.plugin(isomorphicTransformPlugin("server"));
|
|
|
134
134
|
const discovered: DiscoveredApp[] = [];
|
|
135
135
|
process.env.ELYSIA_AOT_BUILD = "1";
|
|
136
136
|
for (const spec of apps) {
|
|
137
|
-
const { root, routes } = await scanPages(spec
|
|
137
|
+
const { root, routes } = await scanPages(spec);
|
|
138
138
|
discovered.push({
|
|
139
139
|
...spec,
|
|
140
140
|
routeRegistry: await snapshotRouteRegistry(spec),
|
package/src/build/elysia-aot.ts
CHANGED
|
@@ -58,10 +58,10 @@ export function handleWSResponse(){return e()}
|
|
|
58
58
|
`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function mountLabel(rootDir: string, { pagesDir, prefix }: RouteInstanceSpec): string {
|
|
61
|
+
function mountLabel(rootDir: string, { pagesDir, prefix, style }: RouteInstanceSpec): string {
|
|
62
62
|
const absolute = resolve(rootDir, pagesDir);
|
|
63
63
|
const path = existsSync(absolute) ? realpathSync(absolute) : absolute;
|
|
64
|
-
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative(rootDir, path) || "."})`;
|
|
64
|
+
return `prefix ${JSON.stringify(prefix || "/")} (pagesDir ${relative(rootDir, path) || "."}, style ${style})`;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
import type { CompileContextAdapter } from "../server/internal.ts";
|
|
4
|
+
import type { CompileContext, CompileContextAdapter } from "../server/internal.ts";
|
|
5
5
|
import type { ClientPreloadManifest } from "./preload-manifest.ts";
|
|
6
6
|
|
|
7
7
|
// import.meta.resolve() runs at runtime (not inlined at bundle time), resolves
|
|
@@ -31,7 +31,7 @@ export interface EntryAppContext {
|
|
|
31
31
|
clientLogging?: boolean;
|
|
32
32
|
/** Extra lines injected inside this app's `__setCompileContext({...})` call. */
|
|
33
33
|
extraContext?: string[];
|
|
34
|
-
/** Additional route modules such as filesystem-derived
|
|
34
|
+
/** Additional route modules such as filesystem-derived layouts. */
|
|
35
35
|
modulePaths?: string[];
|
|
36
36
|
/** Virtual module specifier exporting this app's composed Elysia route tree. */
|
|
37
37
|
nativeRoutes?: string;
|
|
@@ -41,19 +41,7 @@ export interface EntryAppContext {
|
|
|
41
41
|
preloadManifest?: ClientPreloadManifest;
|
|
42
42
|
rootConventions?: { errorPath?: string; notFoundPath?: string };
|
|
43
43
|
rootPath: string;
|
|
44
|
-
routeMetadata?:
|
|
45
|
-
string,
|
|
46
|
-
{
|
|
47
|
-
requestKeys?: string[];
|
|
48
|
-
requestKeysByLoader?: string[][];
|
|
49
|
-
segmentBoundaries: Array<{
|
|
50
|
-
depth: number;
|
|
51
|
-
path: string;
|
|
52
|
-
errorPath?: string;
|
|
53
|
-
notFoundPath?: string;
|
|
54
|
-
}>;
|
|
55
|
-
}
|
|
56
|
-
>;
|
|
44
|
+
routeMetadata?: CompileContext["routeMetadata"];
|
|
57
45
|
routes: Array<{ mode: "ssr" | "ssg" | "isr"; path: string; pattern: string }>;
|
|
58
46
|
/** In-memory production document template for filesystem-free runtimes. */
|
|
59
47
|
templateHtml?: string;
|
package/src/build/hydrate.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { join } from "node:path";
|
|
3
3
|
import { generateIndexHtml } from "../server/render/shell.ts";
|
|
4
4
|
import {
|
|
5
5
|
buildRouteRegex,
|
|
6
6
|
compareRouteSpecificity,
|
|
7
7
|
} from "../server/router/patterns.ts";
|
|
8
|
+
import type { RouteStyle } from "../plugin/route-manifest.ts";
|
|
8
9
|
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
9
10
|
import { type BuildRouteInput, routeBuildInfo } from "./route-metadata.ts";
|
|
10
11
|
import type { ClientBoundary } from "../rsc/build/discover.ts";
|
|
@@ -121,11 +122,14 @@ function hydrateEntry(
|
|
|
121
122
|
continue;
|
|
122
123
|
}
|
|
123
124
|
const parts = [`depth: ${seg.depth}`];
|
|
125
|
+
// TanStack style: `.error()` / `.notFound()` live on the route export.
|
|
126
|
+
const errorExport = seg.fromRoute ? "route.errorComponent" : "default";
|
|
127
|
+
const notFoundExport = seg.fromRoute ? "route.notFoundComponent" : "default";
|
|
124
128
|
if (errorIdent) {
|
|
125
|
-
parts.push(`error: ${errorIdent}
|
|
129
|
+
parts.push(`error: ${errorIdent}.${errorExport}`);
|
|
126
130
|
}
|
|
127
131
|
if (notFoundIdent) {
|
|
128
|
-
parts.push(`notFound: ${notFoundIdent}
|
|
132
|
+
parts.push(`notFound: ${notFoundIdent}.${notFoundExport}`);
|
|
129
133
|
}
|
|
130
134
|
if (seg.depth === 0 && seg.path.replaceAll("\\", "/") !== rootDirectory) {
|
|
131
135
|
parts.push("isRoot: false");
|
|
@@ -491,6 +495,7 @@ if (__deferred && __deferred._chunks) {
|
|
|
491
495
|
interface DevRouteTypesApp {
|
|
492
496
|
pagesDir: string;
|
|
493
497
|
routes: ResolvedRoute[];
|
|
498
|
+
style: RouteStyle;
|
|
494
499
|
}
|
|
495
500
|
|
|
496
501
|
/**
|
|
@@ -517,7 +522,7 @@ function writeDevRouteTypes(
|
|
|
517
522
|
return writeRouteTypes(
|
|
518
523
|
live.find(([appPrefix]) => appPrefix === "")?.[1].routes ?? [],
|
|
519
524
|
projectRoot,
|
|
520
|
-
live.map(([appPrefix, { pagesDir }]) => ({ pagesDir, prefix: appPrefix }))
|
|
525
|
+
live.map(([appPrefix, { pagesDir, style }]) => ({ pagesDir, prefix: appPrefix, style }))
|
|
521
526
|
);
|
|
522
527
|
}
|
|
523
528
|
|
|
@@ -536,8 +541,9 @@ export function writeDevFiles(
|
|
|
536
541
|
basePath,
|
|
537
542
|
clientLogging,
|
|
538
543
|
clientBoundaries,
|
|
544
|
+
pages,
|
|
539
545
|
prefix,
|
|
540
|
-
}: BuildClientOptions & { prefix: string },
|
|
546
|
+
}: BuildClientOptions & { pages: { pagesDir: string; style: RouteStyle }; prefix: string },
|
|
541
547
|
projectRoot: string,
|
|
542
548
|
serverSourceVersion?: string
|
|
543
549
|
): void {
|
|
@@ -571,7 +577,7 @@ export function writeDevFiles(
|
|
|
571
577
|
}
|
|
572
578
|
|
|
573
579
|
changed =
|
|
574
|
-
writeDevRouteTypes(projectRoot, prefix, {
|
|
580
|
+
writeDevRouteTypes(projectRoot, prefix, { ...pages, routes }) || changed;
|
|
575
581
|
|
|
576
582
|
if (changed) {
|
|
577
583
|
console.log(
|
package/src/build/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { FurinAdapter } from "../adapter/types.ts";
|
|
|
10
10
|
import { vercel } from "../adapter/vercel.ts";
|
|
11
11
|
import { BUILD_TARGETS, type BuildTarget, type FurinTarget } from "../config";
|
|
12
12
|
import { assertValidRouteConfig } from "../plugin/route-config.ts";
|
|
13
|
+
import type { RouteInstanceSpec } from "../plugin/route-manifest.ts";
|
|
13
14
|
import { normalizePrefix } from "../server/instance.ts";
|
|
14
15
|
import { assertNoPrefixSlugCollisions, assertOnePagesDirPerMount } from "../shared/prefix.ts";
|
|
15
16
|
import { withProductionBuild } from "../shared/production-build.ts";
|
|
@@ -65,14 +66,13 @@ const BUILD_OUTPUT_DIR = ".furin/build";
|
|
|
65
66
|
* Resolves the list of apps to build, in priority order:
|
|
66
67
|
* 1. explicit `apps` config (furin.config.ts),
|
|
67
68
|
* 2. explicit single `pagesDir` option (mounted at root),
|
|
68
|
-
* 3. every `furin({ pagesDir, prefix })` call made by evaluating the server entry
|
|
69
|
-
* 4. the `src/pages` default.
|
|
69
|
+
* 3. every `furin({ pagesDir, prefix, style })` call made by evaluating the server entry.
|
|
70
70
|
*/
|
|
71
71
|
async function resolveAppSpecs(
|
|
72
72
|
options: RouteTypegenOptions,
|
|
73
73
|
serverEntry: string | null,
|
|
74
74
|
rootDir: string
|
|
75
|
-
): Promise<
|
|
75
|
+
): Promise<RouteInstanceSpec[]> {
|
|
76
76
|
if (options.apps && options.apps.length > 0) {
|
|
77
77
|
// normalizePrefix is the choke point for config/CLI-provided prefixes:
|
|
78
78
|
// `"/"` → `""` (otherwise the bun target derives `publicPath: "//_client/"`,
|
|
@@ -81,21 +81,22 @@ async function resolveAppSpecs(
|
|
|
81
81
|
return options.apps.map((app) => ({
|
|
82
82
|
pagesDir: resolve(rootDir, app.pagesDir),
|
|
83
83
|
prefix: normalizePrefix(app.prefix),
|
|
84
|
+
style: app.style,
|
|
84
85
|
}));
|
|
85
86
|
}
|
|
86
|
-
if (options.pagesDir) {
|
|
87
|
-
return [{ pagesDir: resolve(rootDir, options.pagesDir), prefix: "" }];
|
|
88
|
-
}
|
|
89
87
|
if (serverEntry) {
|
|
90
88
|
const mounted = await discoverFurinMounts(serverEntry, rootDir);
|
|
91
89
|
if (mounted.length > 0) {
|
|
92
90
|
return mounted.map((app) => ({
|
|
93
91
|
pagesDir: resolve(rootDir, app.pagesDir),
|
|
94
92
|
prefix: app.prefix,
|
|
93
|
+
style: app.style,
|
|
95
94
|
}));
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
|
-
|
|
97
|
+
throw new Error(
|
|
98
|
+
`[furin] No app to build: ${serverEntry ? `${toPosixPath(relative(rootDir, serverEntry))} mounts no furin() plugin` : "no server entry found"}. Mount furin({ style }) in the server entry, or list the apps in furin.config.ts: apps: [{ pagesDir: "src/routes", style: "tanstack" }].`
|
|
99
|
+
);
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
/**
|
|
@@ -136,7 +137,7 @@ function writeAppRouteTypes(apps: RuntimeTargetApp[], rootDir: string): void {
|
|
|
136
137
|
/** Options for `generateRouteTypes()`, a subset of the build options. */
|
|
137
138
|
export type RouteTypegenOptions = Pick<
|
|
138
139
|
BuildAppOptions,
|
|
139
|
-
"apps" | "
|
|
140
|
+
"apps" | "plugins" | "rootDir" | "serverEntry"
|
|
140
141
|
>;
|
|
141
142
|
|
|
142
143
|
/**
|
|
@@ -156,6 +157,11 @@ export async function buildApp(options: BuildAppOptions): Promise<BuildAppResult
|
|
|
156
157
|
return withProductionBuild(() => buildAppInternal(options));
|
|
157
158
|
}
|
|
158
159
|
|
|
160
|
+
function existingServerEntry(options: BuildAppOptions, rootDir: string): string | null {
|
|
161
|
+
const entry = resolve(rootDir, options.serverEntry ?? "src/server.ts");
|
|
162
|
+
return existsSync(entry) ? entry : null;
|
|
163
|
+
}
|
|
164
|
+
|
|
159
165
|
async function buildAppInternal(options: BuildAppOptions): Promise<BuildAppResult> {
|
|
160
166
|
const rootDir = resolve(options.rootDir ?? process.cwd());
|
|
161
167
|
const buildRoot = join(rootDir, BUILD_OUTPUT_DIR);
|
|
@@ -179,7 +185,10 @@ async function buildAppInternal(options: BuildAppOptions): Promise<BuildAppResul
|
|
|
179
185
|
return entry;
|
|
180
186
|
})();
|
|
181
187
|
|
|
182
|
-
|
|
188
|
+
// Serverless targets bundle no server entry, but its furin({ style }) mounts
|
|
189
|
+
// still name the apps to build when config `apps` does not.
|
|
190
|
+
const mountEntry = serverEntry ?? existingServerEntry(options, rootDir);
|
|
191
|
+
const apps = await scanApps(options, mountEntry, rootDir);
|
|
183
192
|
// furin-env.d.ts is one file at the project root, owned by the root-mounted
|
|
184
193
|
// app — the same rule as the dev server, so builds keep types current too.
|
|
185
194
|
writeAppRouteTypes(apps, rootDir);
|
|
@@ -199,6 +208,7 @@ async function buildAppInternal(options: BuildAppOptions): Promise<BuildAppResul
|
|
|
199
208
|
apps: apps.map((app) => ({
|
|
200
209
|
pagesDir: toPosixPath(relative(rootDir, app.pagesDir)),
|
|
201
210
|
prefix: app.prefix,
|
|
211
|
+
style: app.style,
|
|
202
212
|
routes: app.routes.map((route) => toBuildRouteManifestEntry(route, rootDir)),
|
|
203
213
|
})),
|
|
204
214
|
targets: {},
|
|
@@ -25,11 +25,14 @@ interface RouteBuildInfo {
|
|
|
25
25
|
export interface BuildRoute
|
|
26
26
|
extends Pick<
|
|
27
27
|
ResolvedRoute,
|
|
28
|
-
"mode" | "path" | "pattern" | "requestKeys" | "requestKeysByLoader" | "tags"
|
|
28
|
+
"layouts" | "mode" | "path" | "pattern" | "requestKeys" | "requestKeysByLoader" | "tags"
|
|
29
29
|
> {
|
|
30
30
|
build: RouteBuildInfo;
|
|
31
31
|
routeChain: { layout: boolean; sourcePath?: string }[];
|
|
32
|
-
segmentBoundaries: Pick<
|
|
32
|
+
segmentBoundaries: Pick<
|
|
33
|
+
SegmentBoundary,
|
|
34
|
+
"depth" | "path" | "errorPath" | "fromRoute" | "notFoundPath"
|
|
35
|
+
>[];
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export type BuildRouteInput = BuildRoute | ResolvedRoute;
|
|
@@ -70,6 +73,7 @@ export function routeBuildInfo(route: BuildRouteInput): RouteBuildInfo {
|
|
|
70
73
|
export function buildRouteMetadata(route: ResolvedRoute): BuildRoute {
|
|
71
74
|
return {
|
|
72
75
|
build: routeBuildInfo(route),
|
|
76
|
+
layouts: route.layouts,
|
|
73
77
|
mode: route.mode,
|
|
74
78
|
path: route.path,
|
|
75
79
|
pattern: route.pattern,
|
|
@@ -79,12 +83,15 @@ export function buildRouteMetadata(route: ResolvedRoute): BuildRoute {
|
|
|
79
83
|
layout: !!entry.layout,
|
|
80
84
|
sourcePath: entry.sourcePath,
|
|
81
85
|
})),
|
|
82
|
-
segmentBoundaries: route.segmentBoundaries.map(
|
|
83
|
-
depth,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
segmentBoundaries: route.segmentBoundaries.map(
|
|
87
|
+
({ depth, path, errorPath, fromRoute, notFoundPath }) => ({
|
|
88
|
+
depth,
|
|
89
|
+
path,
|
|
90
|
+
errorPath,
|
|
91
|
+
...(fromRoute ? { fromRoute } : {}),
|
|
92
|
+
notFoundPath,
|
|
93
|
+
})
|
|
94
|
+
),
|
|
88
95
|
tags: route.tags,
|
|
89
96
|
};
|
|
90
97
|
}
|
package/src/build/route-types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { extname, join, relative, resolve } from "node:path";
|
|
3
|
-
import {
|
|
4
|
-
import { filePathToPattern, parseDynamicRouteSegment } from "../server/router/patterns.ts";
|
|
3
|
+
import { type RouteInstanceSpec, scanRouteManifest } from "../plugin/route-manifest.ts";
|
|
5
4
|
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
6
5
|
import { compareCodeUnits, routeMapDeclaration, type RouteMapEntry } from "../shared/route-map.ts";
|
|
7
6
|
|
|
@@ -22,55 +21,31 @@ function importSpecifier(path: string, projectRoot: string): string {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
|
-
* One `FileRoutes` entry per page and
|
|
26
|
-
* app's prefix
|
|
27
|
-
*
|
|
28
|
-
* a route module is broken.
|
|
24
|
+
* One `FileRoutes` entry per page and layout of an app, keyed by its
|
|
25
|
+
* TanStack Start id (the app's prefix included). Read from the route
|
|
26
|
+
* manifest alone, so the entries stay right while a route module is broken.
|
|
29
27
|
*/
|
|
30
28
|
function fileRouteEntries(
|
|
31
|
-
|
|
29
|
+
instance: RouteInstanceSpec,
|
|
32
30
|
projectRoot: string
|
|
33
31
|
): { id: string; lines: string }[] {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.map(({ base, path, relativePath, segments }) => {
|
|
46
|
-
const isLayout = base === "_route";
|
|
47
|
-
// Nearest `_route` in an enclosing directory, as discovery resolves it.
|
|
48
|
-
let parent = join(pages, "root.tsx");
|
|
49
|
-
for (let depth = isLayout ? segments.length - 1 : segments.length; depth > 0; depth -= 1) {
|
|
50
|
-
const layout = layouts.get(segments.slice(0, depth).join("/"));
|
|
51
|
-
if (layout) {
|
|
52
|
-
parent = layout;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const pathParams = [...segments, base].flatMap((segment) => {
|
|
57
|
-
const dynamic = parseDynamicRouteSegment(segment, path);
|
|
58
|
-
return dynamic ? [dynamic.catchAll ? '"*": string' : `${dynamic.name}: string`] : [];
|
|
59
|
-
});
|
|
60
|
-
const id = fileRouteId({ pagesDir: pages, prefix }, path);
|
|
61
|
-
const pattern = filePathToPattern(
|
|
62
|
-
isLayout ? segments.concat("index").join("/") : relativePath
|
|
63
|
-
);
|
|
64
|
-
return {
|
|
65
|
-
id,
|
|
66
|
-
lines: ` ${JSON.stringify(id)}: {
|
|
67
|
-
kind: "${isLayout ? "layout" : "page"}";
|
|
32
|
+
const { prefix } = instance;
|
|
33
|
+
const manifest = scanRouteManifest({ ...instance, pagesDir: resolve(instance.pagesDir) });
|
|
34
|
+
return manifest.routes.map(({ id, kind, params, parentPath, pattern }) => {
|
|
35
|
+
const parent = parentPath ?? manifest.rootPath;
|
|
36
|
+
const pathParams = params.map(
|
|
37
|
+
({ name, optional }) => `${name}${optional ? "?" : ""}: string`
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
lines: ` ${JSON.stringify(id)}: {
|
|
42
|
+
kind: "${kind}";
|
|
68
43
|
pattern: ${JSON.stringify(`${prefix}${pattern === "/" ? "" : pattern}` || "/")};
|
|
69
44
|
parent: typeof import(${JSON.stringify(importSpecifier(parent, projectRoot))}).route;
|
|
70
45
|
pathParams: {${pathParams.length > 0 ? ` ${pathParams.join("; ")} ` : ""}};
|
|
71
46
|
};`,
|
|
72
|
-
|
|
73
|
-
|
|
47
|
+
};
|
|
48
|
+
});
|
|
74
49
|
}
|
|
75
50
|
|
|
76
51
|
function fileRoutesDeclaration(apps: readonly RouteInstanceSpec[], projectRoot: string): string {
|
package/src/build/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AdapterTargetManifest } from "../adapter/types.ts";
|
|
2
2
|
import type { FurinTarget, StaticExportConfig } from "../config";
|
|
3
|
+
import type { RouteStyle } from "../plugin/route-manifest.ts";
|
|
3
4
|
import type { RouteRegistrySnapshot } from "../plugin/route-registry.ts";
|
|
4
5
|
import type { ResolvedRoute } from "../server/router/types.ts";
|
|
5
6
|
import type { ClientBoundary } from "../rsc/build/discover.ts";
|
|
@@ -27,7 +28,8 @@ export interface BuildClientOptions {
|
|
|
27
28
|
/** Package barrels Bun should parse on demand instead of loading in full. */
|
|
28
29
|
optimizeImports?: string[];
|
|
29
30
|
outDir: string;
|
|
30
|
-
|
|
31
|
+
/** The app whose route registry the client bundle embeds. */
|
|
32
|
+
pages?: { pagesDir: string; style: RouteStyle };
|
|
31
33
|
plugins?: Bun.BunPlugin[];
|
|
32
34
|
/** Record route chunks in the preload manifest. Defaults to true. */
|
|
33
35
|
preloadRouteChunks?: boolean;
|
|
@@ -83,11 +85,17 @@ interface BuildAppSpec {
|
|
|
83
85
|
pagesDir: string;
|
|
84
86
|
/** Mount prefix (`""` or absent = root). */
|
|
85
87
|
prefix?: string;
|
|
88
|
+
style: RouteStyle;
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
export interface BuildManifest {
|
|
89
92
|
/** Every mounted app built into this artifact (multi-instance). */
|
|
90
|
-
apps?: Array<{
|
|
93
|
+
apps?: Array<{
|
|
94
|
+
pagesDir: string;
|
|
95
|
+
prefix: string;
|
|
96
|
+
routes: BuildRouteManifestEntry[];
|
|
97
|
+
style: RouteStyle;
|
|
98
|
+
}>;
|
|
91
99
|
generatedAt: string;
|
|
92
100
|
pagesDir: string;
|
|
93
101
|
rootDir: string;
|
|
@@ -105,8 +113,8 @@ export interface BuildAppOptions {
|
|
|
105
113
|
/** Bun emits a listening server unless output is explicitly "app". */
|
|
106
114
|
bun?: { output?: "app" | "server" };
|
|
107
115
|
/**
|
|
108
|
-
* Explicit multi-app build (furin.config.ts `apps`). Overrides
|
|
109
|
-
*
|
|
116
|
+
* Explicit multi-app build (furin.config.ts `apps`). Overrides the mounts
|
|
117
|
+
* found by evaluating the server entry.
|
|
110
118
|
*/
|
|
111
119
|
apps?: BuildAppSpec[];
|
|
112
120
|
/** Inject the evlog client logger into the hydrate entry. Defaults to false. */
|
|
@@ -114,7 +122,6 @@ export interface BuildAppOptions {
|
|
|
114
122
|
compile?: "server" | "embed";
|
|
115
123
|
/** Package barrels Bun should parse on demand in production client bundles. */
|
|
116
124
|
optimizeImports?: string[];
|
|
117
|
-
pagesDir?: string;
|
|
118
125
|
plugins?: Bun.BunPlugin[];
|
|
119
126
|
/** Module preloading (furin.config.ts `preload`). */
|
|
120
127
|
preload?: { routeChunks?: boolean };
|
package/src/cli/config.ts
CHANGED
|
@@ -191,6 +191,12 @@ export async function loadCliConfig(
|
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
if (configToValidate.pagesDir !== undefined && configToValidate.style === undefined) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`[furin] Invalid config at ${configPath}: pagesDir needs its file-routing style: add style: "nextjs" or "tanstack".`
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
194
200
|
const resolvedRootDir = resolve(rootDir, configToValidate.rootDir ?? ".");
|
|
195
201
|
return {
|
|
196
202
|
...configToValidate,
|