@teyik0/furin 0.9.0-alpha.1 → 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/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/index.js +594 -422
- 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 +3 -3
- 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 +766 -614
- 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 +57 -76
- package/dist/server/registrations.d.ts +4 -2
- 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 +88 -120
- package/dist/server/sync/drizzle/index.d.ts +8 -10
- package/dist/shared/route-specificity.d.ts +10 -1
- package/package.json +3 -6
- 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/index.ts +30 -14
- package/src/client/define-route.ts +29 -4
- package/src/client/internal/runtime-types.ts +8 -0
- package/src/client/router/link-utils.ts +16 -8
- 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/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/route-specificity.ts +34 -2
- package/src/shared/utils/index.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DevDiagnosticStore } from "../server/dev/diagnostics.ts";
|
|
2
|
-
import { type RouteInstanceSpec } from "./route-
|
|
2
|
+
import { type RouteInstanceSpec } from "./route-manifest.ts";
|
|
3
3
|
/**
|
|
4
4
|
* Static route-config checks shared by the dev server and `furin build`.
|
|
5
5
|
* Furin never rewrites route sources: it reports what TypeScript cannot see
|
|
@@ -12,7 +12,7 @@ export interface RouteConfigIssue {
|
|
|
12
12
|
line: number;
|
|
13
13
|
message: string;
|
|
14
14
|
}
|
|
15
|
-
export declare function validateRouteConfig(
|
|
15
|
+
export declare function validateRouteConfig(spec: RouteInstanceSpec): RouteConfigIssue[];
|
|
16
16
|
export declare function formatRouteConfigIssue(issue: RouteConfigIssue): string;
|
|
17
17
|
/** Build and typegen: fails before route modules are imported. */
|
|
18
18
|
export declare function assertValidRouteConfig(instance: RouteInstanceSpec): void;
|
|
@@ -25,4 +25,4 @@ export declare function createRouteConfigReporter(instance: RouteInstanceSpec, s
|
|
|
25
25
|
* Writes a starter route, keyed by the file's id, into route files that are
|
|
26
26
|
* empty or whitespace-only, the only case where Furin writes to a source file.
|
|
27
27
|
*/
|
|
28
|
-
export declare function scaffoldEmptyRoutes(
|
|
28
|
+
export declare function scaffoldEmptyRoutes(spec: RouteInstanceSpec): string[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File-routing convention of one `furin()` app. Both styles produce the same
|
|
3
|
+
* manifest, keyed by TanStack Start ids, so switching style only renames files.
|
|
4
|
+
*/
|
|
5
|
+
export type RouteStyle = "nextjs" | "tanstack";
|
|
6
|
+
export interface RouteInstanceSpec {
|
|
7
|
+
pagesDir: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
style: RouteStyle;
|
|
10
|
+
}
|
|
11
|
+
export interface RouteParam {
|
|
12
|
+
/** `_splat` for a catch-all segment. */
|
|
13
|
+
name: string;
|
|
14
|
+
optional: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface ManifestRoute {
|
|
17
|
+
/** `defineRoute(id)`: the app prefix, then the TanStack id (`/board/$boardId/` for an index). */
|
|
18
|
+
id: string;
|
|
19
|
+
kind: "layout" | "page";
|
|
20
|
+
/** Path params of the route and its layouts, shallow → deep. */
|
|
21
|
+
params: RouteParam[];
|
|
22
|
+
/** Source of the parent layout; `undefined` when the root layout is the parent. */
|
|
23
|
+
parentPath: string | undefined;
|
|
24
|
+
/** URL pattern under the app prefix: `/board/:boardId`, `/docs/*`, `/:lang?/about`. */
|
|
25
|
+
pattern: string;
|
|
26
|
+
sourcePath: string;
|
|
27
|
+
}
|
|
28
|
+
/** A Next.js-style `error` / `not-found` pair declared in one directory. */
|
|
29
|
+
export interface ManifestBoundary {
|
|
30
|
+
directory: string;
|
|
31
|
+
errorPath: string | undefined;
|
|
32
|
+
notFoundPath: string | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface RouteManifest {
|
|
35
|
+
/** Directory boundaries, shallow → deep. Always empty in the TanStack style. */
|
|
36
|
+
boundaries: ManifestBoundary[];
|
|
37
|
+
/** Root layout module (`__root.tsx`, or `layout.tsx` at the top of a Next.js app). */
|
|
38
|
+
rootPath: string;
|
|
39
|
+
/** Layouts and pages in deterministic depth-first order. */
|
|
40
|
+
routes: ManifestRoute[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The single filesystem walk behind every route consumer (route tree,
|
|
44
|
+
* discovery, typegen, route-config checks, dev topology).
|
|
45
|
+
*/
|
|
46
|
+
export declare function scanRouteManifest({ pagesDir, prefix, style }: RouteInstanceSpec): RouteManifest;
|
|
@@ -1,43 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
prefix: string;
|
|
4
|
-
}
|
|
1
|
+
import { type RouteInstanceSpec } from "./route-manifest.ts";
|
|
2
|
+
export type { RouteInstanceSpec } from "./route-manifest.ts";
|
|
5
3
|
export declare function instanceKey(instance: RouteInstanceSpec): string;
|
|
6
4
|
export declare function routeModuleSpecifier(instance: RouteInstanceSpec): string;
|
|
7
5
|
export interface RouteFile {
|
|
8
6
|
id: string;
|
|
7
|
+
/** URL pattern of a page; `""` for a layout. */
|
|
9
8
|
path: string;
|
|
9
|
+
/** Mount prefix relative to the enclosing layout. */
|
|
10
|
+
prefix: string;
|
|
11
|
+
/** Native absolute path, as route modules are loaded and cached by it. */
|
|
10
12
|
sourcePath: string;
|
|
11
13
|
}
|
|
14
|
+
/** A layout and everything it wraps, following the manifest's parent links. */
|
|
12
15
|
export interface RouteTreeNode {
|
|
13
16
|
children: RouteTreeNode[];
|
|
14
|
-
|
|
15
|
-
indexRoute: RouteFile | undefined;
|
|
17
|
+
/** `undefined` for the root node: the root layout's Elysia is never mounted. */
|
|
16
18
|
layout: RouteFile | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Id of `defineRoute(id)`: the app's prefix, then the file's path under
|
|
21
|
-
* `pagesDir` with brackets and groups, `/index` dropped
|
|
22
|
-
* (`board/[boardId]/index.tsx` → `/board/[boardId]`, `board/_route.tsx` →
|
|
23
|
-
* `/board/_route`; `users.tsx` under the `/admin` prefix → `/admin/users`).
|
|
24
|
-
*/
|
|
25
|
-
export declare function fileRouteId({ pagesDir, prefix }: RouteInstanceSpec, sourcePath: string): string;
|
|
26
|
-
export declare function segmentPath(segment: string): string;
|
|
27
|
-
export interface RouteManifestFile {
|
|
28
|
-
base: string;
|
|
29
|
-
directorySegments: string[];
|
|
30
|
-
/** URL pattern of a page; `undefined` for a `_route` layout. */
|
|
31
|
-
pattern: string | undefined;
|
|
32
|
-
sourcePath: string;
|
|
19
|
+
pages: RouteFile[];
|
|
20
|
+
/** Mount prefix relative to the parent node. */
|
|
21
|
+
prefix: string;
|
|
33
22
|
}
|
|
34
|
-
|
|
35
|
-
* The single filesystem walk behind every route consumer (native route tree,
|
|
36
|
-
* `scanPages`, typegen, adapters): files in deterministic depth-first order,
|
|
37
|
-
* dynamic segments validated and duplicate URL patterns rejected.
|
|
38
|
-
*/
|
|
39
|
-
export declare function scanRouteManifest(pagesDir: string): RouteManifestFile[];
|
|
40
|
-
export declare function buildRouteTree(pagesDir: string, instanceId: string): RouteTreeNode;
|
|
23
|
+
export declare function buildRouteTree(instance: RouteInstanceSpec, instanceId: string): RouteTreeNode;
|
|
41
24
|
export declare function collectRouteFiles(root: RouteTreeNode): RouteFile[];
|
|
42
25
|
export declare function routeSourcePaths(instance: RouteInstanceSpec): string[];
|
|
26
|
+
/** Every file whose presence shapes the app: root, routes and boundary files. */
|
|
43
27
|
export declare function routeSnapshotSourcePaths(instance: RouteInstanceSpec): string[];
|
package/dist/routes.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export interface RouteMap {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Typecheck fallback for `defineRoute(id)`. The generated
|
|
11
|
-
* furin-env.d.ts augments it with one entry per route file, keyed by its
|
|
12
|
-
* id (`"/board/
|
|
11
|
+
* furin-env.d.ts augments it with one entry per route file, keyed by its
|
|
12
|
+
* TanStack Start id (`"/board/$boardId/"`, `"/board"`): kind, URL pattern, parent
|
|
13
13
|
* layout and path params, read from the pages tree without importing modules.
|
|
14
14
|
*/
|
|
15
15
|
export interface FileRoutes {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { RouteStyle } from "../../plugin/route-manifest.ts";
|
|
1
2
|
import { type FurinInstance } from "../instance.ts";
|
|
2
3
|
import type { ModeOptions, ModeRuntime } from "../mode.ts";
|
|
3
4
|
/** Serves a runtime from its page sources with Bun native HMR. */
|
|
4
|
-
export declare function createDevRuntime(instance: FurinInstance, resolvedPagesDir: string, options: ModeOptions): Promise<ModeRuntime>;
|
|
5
|
+
export declare function createDevRuntime(instance: FurinInstance, resolvedPagesDir: string, style: RouteStyle, options: ModeOptions): Promise<ModeRuntime>;
|
|
@@ -75,12 +75,18 @@ export interface CompileContext {
|
|
|
75
75
|
rootPath: string;
|
|
76
76
|
/** Per-route metadata including pre-computed segment boundaries. */
|
|
77
77
|
routeMetadata?: Record<string, {
|
|
78
|
+
/** Layouts wrapping the page, shallow → deep, from the route manifest. */
|
|
79
|
+
layouts: Array<{
|
|
80
|
+
path: string;
|
|
81
|
+
pattern: string;
|
|
82
|
+
}>;
|
|
78
83
|
requestKeys?: string[];
|
|
79
84
|
requestKeysByLoader?: string[][];
|
|
80
85
|
segmentBoundaries: Array<{
|
|
81
86
|
depth: number;
|
|
82
87
|
path: string;
|
|
83
88
|
errorPath?: string;
|
|
89
|
+
fromRoute?: true;
|
|
84
90
|
notFoundPath?: string;
|
|
85
91
|
}>;
|
|
86
92
|
}>;
|
package/dist/server/internal.js
CHANGED
|
@@ -151,7 +151,7 @@ function segmentSpecificity(segment) {
|
|
|
151
151
|
}
|
|
152
152
|
return segment.startsWith(":") ? 2 : 3;
|
|
153
153
|
}
|
|
154
|
-
function
|
|
154
|
+
function compareConcreteSpecificity(a, b) {
|
|
155
155
|
const aSegments = a.split("/").filter(Boolean);
|
|
156
156
|
const bSegments = b.split("/").filter(Boolean);
|
|
157
157
|
const length = Math.max(aSegments.length, bSegments.length);
|
|
@@ -171,6 +171,24 @@ function compareRouteSpecificity(a, b) {
|
|
|
171
171
|
}
|
|
172
172
|
return 0;
|
|
173
173
|
}
|
|
174
|
+
function expandOptionalSegments(pattern) {
|
|
175
|
+
let variants = [[]];
|
|
176
|
+
for (const segment of pattern.split("/").filter(Boolean)) {
|
|
177
|
+
if (segment.startsWith(":") && segment.endsWith("?")) {
|
|
178
|
+
const required = segment.slice(0, -1);
|
|
179
|
+
variants = variants.flatMap((variant) => [variant, [...variant, required]]);
|
|
180
|
+
} else {
|
|
181
|
+
variants = variants.map((variant) => [...variant, segment]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return variants.map((variant) => `/${variant.join("/")}`);
|
|
185
|
+
}
|
|
186
|
+
function mostSpecificVariant(pattern) {
|
|
187
|
+
return expandOptionalSegments(pattern).reduce((best, variant) => compareConcreteSpecificity(variant, best) > 0 ? variant : best);
|
|
188
|
+
}
|
|
189
|
+
function compareRouteSpecificity(a, b) {
|
|
190
|
+
return compareConcreteSpecificity(mostSpecificVariant(a), mostSpecificVariant(b));
|
|
191
|
+
}
|
|
174
192
|
|
|
175
193
|
// src/shared/search-params.ts
|
|
176
194
|
function isObject(value) {
|
|
@@ -3178,11 +3196,12 @@ function navigationHrefPolicy(href, currentOrigin) {
|
|
|
3178
3196
|
return url.origin === currentOrigin ? "internal" : "external";
|
|
3179
3197
|
}
|
|
3180
3198
|
function applyLinkParams(to, params) {
|
|
3181
|
-
|
|
3182
|
-
|
|
3199
|
+
const values = params ?? {};
|
|
3200
|
+
let url = to.replaceAll(/\/:([a-zA-Z0-9_]+)\?(?=\/|$)/g, (_match, name) => values[name] === undefined || values[name] === "" ? "" : `/${encodeURIComponent(String(values[name]))}`).replaceAll(/:([a-zA-Z0-9_]+)/g, (match, name) => (name in values) ? encodeURIComponent(String(values[name])) : match);
|
|
3201
|
+
if (url === "") {
|
|
3202
|
+
url = "/";
|
|
3183
3203
|
}
|
|
3184
|
-
|
|
3185
|
-
const wildcard = params["*"];
|
|
3204
|
+
const wildcard = values._splat;
|
|
3186
3205
|
if (wildcard !== undefined && url.includes("/*")) {
|
|
3187
3206
|
const encodedWildcard = String(wildcard).split("/").map(encodeURIComponent).join("/");
|
|
3188
3207
|
url = url.replace("/*", () => `/${encodedWildcard}`);
|
|
@@ -3662,7 +3681,6 @@ var init_graph = __esm(() => {
|
|
|
3662
3681
|
});
|
|
3663
3682
|
|
|
3664
3683
|
// src/server/router/patterns.ts
|
|
3665
|
-
import { parse } from "path";
|
|
3666
3684
|
function resolveRouteRevalidate(page) {
|
|
3667
3685
|
return page.revalidate ?? page._route.revalidate;
|
|
3668
3686
|
}
|
|
@@ -3672,47 +3690,6 @@ function resolveDocumentMode(route) {
|
|
|
3672
3690
|
}
|
|
3673
3691
|
return route.mode === "isr" || route.routeChain.some((entry) => entry.mode === "isr" && entry.loader !== undefined) ? "isr" : "ssg";
|
|
3674
3692
|
}
|
|
3675
|
-
function parseDynamicRouteSegment(segment, sourcePath) {
|
|
3676
|
-
if (!(segment.startsWith("[") && segment.endsWith("]"))) {
|
|
3677
|
-
return;
|
|
3678
|
-
}
|
|
3679
|
-
const inner = segment.slice(1, -1);
|
|
3680
|
-
const catchAll = inner.startsWith("...");
|
|
3681
|
-
const name = catchAll ? inner.slice(3) : inner;
|
|
3682
|
-
if (!DYNAMIC_PARAMETER_NAME_RE.test(name)) {
|
|
3683
|
-
throw new Error(`[furin] Invalid dynamic parameter ${JSON.stringify(name)} in ${JSON.stringify(sourcePath ?? segment)}. Parameter names must match ${DYNAMIC_PARAMETER_NAME_RE}.`);
|
|
3684
|
-
}
|
|
3685
|
-
return { catchAll, name };
|
|
3686
|
-
}
|
|
3687
|
-
function isRouteGroup(segment) {
|
|
3688
|
-
return ROUTE_GROUP_RE.test(segment);
|
|
3689
|
-
}
|
|
3690
|
-
function filePathToPattern(path) {
|
|
3691
|
-
const parts = path.replaceAll("\\", "/").split("/");
|
|
3692
|
-
const segments = [];
|
|
3693
|
-
const lastIndex = parts.length - 1;
|
|
3694
|
-
for (let idx = 0;idx < parts.length; idx += 1) {
|
|
3695
|
-
const part = parts[idx];
|
|
3696
|
-
if (part === undefined || part.length === 0) {
|
|
3697
|
-
continue;
|
|
3698
|
-
}
|
|
3699
|
-
const isFile = idx === lastIndex;
|
|
3700
|
-
const name = isFile ? parse(part).name : part;
|
|
3701
|
-
if (!isFile && isRouteGroup(name)) {
|
|
3702
|
-
continue;
|
|
3703
|
-
}
|
|
3704
|
-
if (isFile && name === "index") {
|
|
3705
|
-
continue;
|
|
3706
|
-
}
|
|
3707
|
-
const dynamic = parseDynamicRouteSegment(name, path);
|
|
3708
|
-
if (dynamic) {
|
|
3709
|
-
segments.push(dynamic.catchAll ? "*" : `:${dynamic.name}`);
|
|
3710
|
-
} else {
|
|
3711
|
-
segments.push(name);
|
|
3712
|
-
}
|
|
3713
|
-
}
|
|
3714
|
-
return `/${segments.join("/")}`;
|
|
3715
|
-
}
|
|
3716
3693
|
function escapeRegExp(value) {
|
|
3717
3694
|
return value.replace(REGEX_META_CHARS_RE, "\\$&");
|
|
3718
3695
|
}
|
|
@@ -3727,11 +3704,17 @@ function routePatternRegexSource(pattern, sources) {
|
|
|
3727
3704
|
while (i < pattern.length && pattern[i] !== "/") {
|
|
3728
3705
|
i += 1;
|
|
3729
3706
|
}
|
|
3730
|
-
|
|
3731
|
-
|
|
3707
|
+
const name = pattern.slice(start, i);
|
|
3708
|
+
if (name.endsWith("?") && source.endsWith("/")) {
|
|
3709
|
+
paramNames.push(name.slice(0, -1));
|
|
3710
|
+
source = `${source.slice(0, -1)}(?:/${sources.param})?`;
|
|
3711
|
+
} else {
|
|
3712
|
+
paramNames.push(name);
|
|
3713
|
+
source += sources.param;
|
|
3714
|
+
}
|
|
3732
3715
|
} else if (pattern[i] === "*") {
|
|
3733
|
-
paramNames.push(
|
|
3734
|
-
source
|
|
3716
|
+
paramNames.push(SPLAT_PARAM);
|
|
3717
|
+
source = source.endsWith("/") ? `${source.slice(0, -1)}(?:/${sources.catchAll})?` : source + sources.catchAll;
|
|
3735
3718
|
i += 1;
|
|
3736
3719
|
} else {
|
|
3737
3720
|
const ch = pattern[i];
|
|
@@ -3753,6 +3736,25 @@ function buildRouteRegex(pattern) {
|
|
|
3753
3736
|
regex: new RegExp(`^${source}${pattern === "/" || pattern.endsWith("/") ? "" : "/?"}$`)
|
|
3754
3737
|
};
|
|
3755
3738
|
}
|
|
3739
|
+
function decodeParam(value) {
|
|
3740
|
+
try {
|
|
3741
|
+
return decodeURIComponent(value);
|
|
3742
|
+
} catch {
|
|
3743
|
+
return value;
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
function matchedParams(paramNames, match) {
|
|
3747
|
+
const params = {};
|
|
3748
|
+
for (const [index, name] of paramNames.entries()) {
|
|
3749
|
+
const value = match[index + 1];
|
|
3750
|
+
if (value !== undefined) {
|
|
3751
|
+
params[name] = decodeParam(value);
|
|
3752
|
+
} else if (name === SPLAT_PARAM) {
|
|
3753
|
+
params[name] = "";
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
return params;
|
|
3757
|
+
}
|
|
3756
3758
|
function buildRouteMatcher(routes) {
|
|
3757
3759
|
const compiled = routes.map((route) => {
|
|
3758
3760
|
const { regex, paramNames } = buildRouteRegex(route.pattern);
|
|
@@ -3764,26 +3766,13 @@ function buildRouteMatcher(routes) {
|
|
|
3764
3766
|
if (!match) {
|
|
3765
3767
|
continue;
|
|
3766
3768
|
}
|
|
3767
|
-
|
|
3768
|
-
for (let i = 0;i < candidate.paramNames.length; i += 1) {
|
|
3769
|
-
const name = candidate.paramNames[i];
|
|
3770
|
-
if (name !== undefined) {
|
|
3771
|
-
try {
|
|
3772
|
-
params[name] = decodeURIComponent(match[i + 1] ?? "");
|
|
3773
|
-
} catch {
|
|
3774
|
-
params[name] = match[i + 1] ?? "";
|
|
3775
|
-
}
|
|
3776
|
-
}
|
|
3777
|
-
}
|
|
3778
|
-
return { params, route: candidate.route };
|
|
3769
|
+
return { params: matchedParams(candidate.paramNames, match), route: candidate.route };
|
|
3779
3770
|
}
|
|
3780
3771
|
return null;
|
|
3781
3772
|
};
|
|
3782
3773
|
}
|
|
3783
|
-
var
|
|
3774
|
+
var SPLAT_PARAM = "_splat", REGEX_META_CHARS_RE;
|
|
3784
3775
|
var init_patterns = __esm(() => {
|
|
3785
|
-
DYNAMIC_PARAMETER_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
3786
|
-
ROUTE_GROUP_RE = /^\([^()]+\)$/;
|
|
3787
3776
|
REGEX_META_CHARS_RE = /[.*+?^${}()|[\]\\]/g;
|
|
3788
3777
|
});
|
|
3789
3778
|
|
|
@@ -10532,8 +10521,6 @@ function renderForPath(route, params, root, origin, mode, basePath, searchRoutes
|
|
|
10532
10521
|
}
|
|
10533
10522
|
|
|
10534
10523
|
// src/server/render/static-params.ts
|
|
10535
|
-
import { dirname as dirname2, relative } from "path";
|
|
10536
|
-
init_patterns();
|
|
10537
10524
|
var STATIC_PARAMS_CONCURRENCY = 4;
|
|
10538
10525
|
var DYNAMIC_SEGMENT_RE = /\/:[^/]+|\/\*/;
|
|
10539
10526
|
function collectStaticParamsStages(route) {
|
|
@@ -10549,17 +10536,11 @@ function collectStaticParamsStages(route) {
|
|
|
10549
10536
|
return stages;
|
|
10550
10537
|
}
|
|
10551
10538
|
function ancestorPattern(route, ancestors) {
|
|
10552
|
-
const rootSourcePath = route.routeChain[0]?.sourcePath;
|
|
10553
10539
|
const ancestorSourcePath = ancestors.at(-1)?.sourcePath;
|
|
10554
|
-
if (
|
|
10555
|
-
return route.pattern;
|
|
10556
|
-
}
|
|
10557
|
-
const pagesDir = dirname2(rootSourcePath);
|
|
10558
|
-
const ancestorDir = dirname2(ancestorSourcePath);
|
|
10559
|
-
if (ancestorDir === pagesDir) {
|
|
10540
|
+
if (ancestors.length <= 1) {
|
|
10560
10541
|
return "/";
|
|
10561
10542
|
}
|
|
10562
|
-
return
|
|
10543
|
+
return route.layouts.find(({ path }) => path === ancestorSourcePath)?.pattern ?? route.pattern;
|
|
10563
10544
|
}
|
|
10564
10545
|
function createBuildContext(pattern, params, origin) {
|
|
10565
10546
|
const path = resolvePath(pattern, params);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { RouteStyle } from "../plugin/route-manifest.ts";
|
|
2
|
+
/** A `furin({ pagesDir, prefix, style })` call, as declared by the application. */
|
|
2
3
|
export interface FurinRegistration {
|
|
3
|
-
/** pagesDir as declared (
|
|
4
|
+
/** pagesDir as declared (the style's default when omitted); relative to the project root. */
|
|
4
5
|
readonly pagesDir: string;
|
|
5
6
|
/** Normalized mount prefix (`""` for root). */
|
|
6
7
|
readonly prefix: string;
|
|
8
|
+
readonly style: RouteStyle;
|
|
7
9
|
}
|
|
8
10
|
/** Starts recording `furin()` calls in this process. */
|
|
9
11
|
export declare function collectFurinRegistrations(discover: boolean): FurinRegistration[];
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
2
2
|
import type { HeadOptions, RenderingMode } from "../../client.ts";
|
|
3
|
+
import type { ErrorComponent } from "../../shared/error.ts";
|
|
4
|
+
import type { NotFoundComponent } from "../../shared/not-found.ts";
|
|
3
5
|
import type { RemountDependency } from "../../shared/page-key.ts";
|
|
4
6
|
interface DefinedRouteTerminal {
|
|
5
7
|
__type: "FURIN_ROUTE";
|
|
6
8
|
component: (...args: never[]) => React.ReactNode;
|
|
7
9
|
elysia: object;
|
|
10
|
+
errorComponent?: ErrorComponent;
|
|
8
11
|
head?: (...args: never[]) => HeadOptions;
|
|
9
12
|
layout?: (...args: never[]) => React.ReactNode;
|
|
10
13
|
loader?: (...args: never[]) => unknown;
|
|
11
14
|
mode?: RenderingMode;
|
|
15
|
+
notFoundComponent?: NotFoundComponent;
|
|
12
16
|
page?: (...args: never[]) => React.ReactNode;
|
|
13
17
|
remountDeps?: (context: never) => readonly RemountDependency[];
|
|
14
18
|
requestLoader?: (...args: never[]) => unknown;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
2
|
+
import { type ManifestRoute, type RouteInstanceSpec, type RouteManifest, type RouteStyle } from "../../plugin/route-manifest.ts";
|
|
2
3
|
import { type CompileContext } from "../internal.ts";
|
|
3
|
-
import type { ResolvedRoute, RootLayout } from "./types.ts";
|
|
4
|
+
import type { ResolvedLayout, ResolvedRoute, RootLayout, SegmentBoundary } from "./types.ts";
|
|
4
5
|
export declare function isModuleNotFoundError(err: unknown): boolean;
|
|
5
6
|
export declare function annotateScannedRequestKeys(routes: ResolvedRoute[]): Promise<void>;
|
|
6
7
|
/** @internal Exported for unit testing. */
|
|
@@ -10,9 +11,18 @@ export declare function loadProdRoutes(ctx: CompileContext): {
|
|
|
10
11
|
routes: ResolvedRoute[];
|
|
11
12
|
};
|
|
12
13
|
export declare function invalidNestedLayoutError(layoutPath: string): Error;
|
|
13
|
-
|
|
14
|
+
/** Layouts wrapping a manifest route, shallow → deep, the root excluded. */
|
|
15
|
+
export declare function manifestLayouts(manifest: RouteManifest, route: ManifestRoute): ResolvedLayout[];
|
|
16
|
+
export declare function scanPages(instance: RouteInstanceSpec): Promise<{
|
|
14
17
|
root: RootLayout;
|
|
15
18
|
routes: ResolvedRoute[];
|
|
16
19
|
}>;
|
|
17
|
-
export declare function scanRootLayout(pagesDir: string): Promise<RootLayout>;
|
|
18
|
-
|
|
20
|
+
export declare function scanRootLayout(manifest: RouteManifest, pagesDir: string, style: RouteStyle): Promise<RootLayout>;
|
|
21
|
+
/**
|
|
22
|
+
* TanStack-style boundaries come from `.error()` / `.notFound()` on the
|
|
23
|
+
* routes themselves. A route's boundary sits in its parent's outlet, so it
|
|
24
|
+
* also catches the route's own failure: depth = its chain index - 1. The
|
|
25
|
+
* root's sits inside the root layout (depth 0). `path` is the route file, so
|
|
26
|
+
* only the root's boundary is the root directory's.
|
|
27
|
+
*/
|
|
28
|
+
export declare function routeDefinedBoundaries(root: RootLayout, routeChain: readonly RuntimeRoute[], page: RuntimePage, pagePath: string): SegmentBoundary[];
|
|
@@ -13,14 +13,15 @@ type RouteModuleImport = (specifier: string) => Promise<CompiledModule>;
|
|
|
13
13
|
export declare function importStampedRouteModule(path: string, resolveImport: RouteModuleImport): Promise<CompiledModule>;
|
|
14
14
|
export declare function invalidateStampedRouteModules(): void;
|
|
15
15
|
/**
|
|
16
|
-
* Re-imports
|
|
17
|
-
* module identity, then patches the
|
|
18
|
-
* route-chain objects.
|
|
16
|
+
* Re-imports the page's layouts (`layoutPaths`, shallow → deep, as the route
|
|
17
|
+
* manifest lists them) with a versioned module identity, then patches the
|
|
18
|
+
* layout/loader references on the existing route-chain objects. `chain[0]`
|
|
19
|
+
* is the root, so layout `i` patches `chain[i + 1]`.
|
|
19
20
|
*
|
|
20
21
|
* The optional `importFn` parameter exists only for unit testing. In production
|
|
21
22
|
* it defaults to the real `import()`.
|
|
22
23
|
*/
|
|
23
|
-
export declare function refreshLayoutChain(chain: RuntimeRoute[],
|
|
24
|
+
export declare function refreshLayoutChain(chain: RuntimeRoute[], layoutPaths: readonly string[], importFn: ((specifier: string) => Promise<CompiledModule>) | undefined): Promise<void>;
|
|
24
25
|
/**
|
|
25
26
|
* Rebuilds a `ResolvedRoute` from freshly-imported `page` and `chain` so that
|
|
26
27
|
* `mode` reflects the CURRENT contents of the page module — not the value
|
|
@@ -54,16 +55,15 @@ export declare function resolveCurrentDevRoute(route: ResolvedRoute, root: RootL
|
|
|
54
55
|
export declare const developmentPagePorts: PagePorts;
|
|
55
56
|
/**
|
|
56
57
|
* @internal Lists every source file whose contents can affect the render
|
|
57
|
-
* output for a given page: the page itself,
|
|
58
|
-
*
|
|
58
|
+
* output for a given page: the page itself, its layouts, the root layout,
|
|
59
|
+
* and their local imports.
|
|
59
60
|
*
|
|
60
61
|
* Only paths that EXIST on disk are returned. `isDevLoaderCacheValid` treats
|
|
61
62
|
* a `statSync` throw as "invalid" (conservative on missing files), so listing
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* the next read and yield the same conservative miss.
|
|
63
|
+
* missing files here would force a permanent cache MISS. Renames and
|
|
64
|
+
* deletions of TRACKED deps are still detected: the path that previously
|
|
65
|
+
* existed will then `statSync`-throw on the next read and yield the same
|
|
66
|
+
* conservative miss.
|
|
67
67
|
*/
|
|
68
|
-
export declare function computeRouteDependencies(pagePath: string, rootPath: string): string[];
|
|
68
|
+
export declare function computeRouteDependencies(pagePath: string, rootPath: string, layoutPaths: readonly string[]): string[];
|
|
69
69
|
export {};
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import type { RuntimePage, RuntimeRoute } from "../../client/internal/runtime-types.ts";
|
|
2
2
|
import type { ResolvedRoute } from "./types.ts";
|
|
3
3
|
export { compareRouteSpecificity } from "../../shared/route-specificity.ts";
|
|
4
|
-
export declare function collectIntermediateLayoutDirs(pagePath: string, rootPath: string): string[];
|
|
5
4
|
export declare function resolveRouteRevalidate(page: RuntimePage): number | undefined;
|
|
6
5
|
export declare function resolveDocumentMode(route: ResolvedRoute): "ssr" | "ssg" | "isr";
|
|
7
6
|
export declare function resolveDocumentRevalidate(route: ResolvedRoute): number | undefined;
|
|
8
7
|
export declare function resolveMode(page: RuntimePage, routeChain: RuntimeRoute[]): "ssr" | "ssg" | "isr";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
name: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function parseDynamicRouteSegment(segment: string, sourcePath: string | undefined): DynamicRouteSegment | undefined;
|
|
14
|
-
export declare function routeSegmentToPattern(segment: string): string;
|
|
15
|
-
export declare function isRouteGroup(segment: string): boolean;
|
|
16
|
-
export declare function routePatternKey(pattern: string): string;
|
|
17
|
-
export declare function filePathToPattern(path: string): string;
|
|
8
|
+
/** Param name of a catch-all segment (`*` in patterns), as in TanStack Start. */
|
|
9
|
+
export declare const SPLAT_PARAM = "_splat";
|
|
18
10
|
export declare function escapeRegExp(value: string): string;
|
|
19
11
|
/**
|
|
20
12
|
* Unanchored regex source for a route pattern: literal characters (e.g. dots
|
|
21
13
|
* in `v1.0`) are escaped, each `:param` becomes `sources.param` and `*`
|
|
22
|
-
* becomes `sources.catchAll`. `paramNames` lists them in order (
|
|
23
|
-
* catch-all).
|
|
14
|
+
* becomes `sources.catchAll`. `paramNames` lists them in order (`_splat` for
|
|
15
|
+
* the catch-all).
|
|
24
16
|
*/
|
|
25
17
|
export declare function routePatternRegexSource(pattern: string, sources: {
|
|
26
18
|
catchAll: string;
|
|
@@ -21,18 +21,33 @@ export interface SegmentBoundary {
|
|
|
21
21
|
* can't survive the server→client boundary.
|
|
22
22
|
*/
|
|
23
23
|
errorPath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* TanStack style: the components are a route's `.error()` / `.notFound()`,
|
|
26
|
+
* read from `errorPath`'s `route` export instead of its default export.
|
|
27
|
+
*/
|
|
28
|
+
fromRoute?: true;
|
|
24
29
|
notFound?: NotFoundComponent;
|
|
25
30
|
/** Absolute path to the `not-found.tsx` module, when present. */
|
|
26
31
|
notFoundPath?: string;
|
|
27
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Absolute directory path; the route file for a `fromRoute` boundary,
|
|
34
|
+
* except the root's, which is the pages directory.
|
|
35
|
+
*/
|
|
28
36
|
path: string;
|
|
29
37
|
}
|
|
38
|
+
/** A layout wrapping a page, from the route manifest. */
|
|
39
|
+
export interface ResolvedLayout {
|
|
40
|
+
path: string;
|
|
41
|
+
pattern: string;
|
|
42
|
+
}
|
|
30
43
|
export interface ResolvedRoute {
|
|
31
44
|
isrCache?: {
|
|
32
45
|
html: string;
|
|
33
46
|
generatedAt: number;
|
|
34
47
|
revalidate: number;
|
|
35
48
|
};
|
|
49
|
+
/** Layouts wrapping the page, shallow → deep, the root excluded. */
|
|
50
|
+
layouts: ResolvedLayout[];
|
|
36
51
|
mode: "ssr" | "ssg" | "isr";
|
|
37
52
|
page: RuntimePage;
|
|
38
53
|
path: string;
|