@teyik0/furin 0.9.0-alpha.1 → 0.9.0-alpha.3
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 +597 -445
- 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 +626 -466
- 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/dev-error-overlay.ts +18 -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 +771 -616
- package/dist/plugin/client-plugin.d.ts +1 -1
- package/dist/plugin/index.js +5 -4
- 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 +4 -7
- 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 +14 -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/dev-error-overlay.ts +18 -0
- 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/client-plugin.ts +13 -8
- 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 +11 -42
- 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/dev-page-plugin.ts +5 -2
- 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
package/src/plugin/route-tree.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
filePathToPattern,
|
|
5
|
-
parseDynamicRouteSegment,
|
|
6
|
-
routePatternKey,
|
|
7
|
-
routeSegmentToPattern,
|
|
8
|
-
} from "../server/router/patterns.ts";
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { type ManifestRoute, type RouteInstanceSpec, scanRouteManifest } from "./route-manifest.ts";
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
const ROUTE_CONVENTIONS = new Set(["error", "not-found", "root"]);
|
|
12
|
-
|
|
13
|
-
export interface RouteInstanceSpec {
|
|
14
|
-
pagesDir: string;
|
|
15
|
-
prefix: string;
|
|
16
|
-
}
|
|
5
|
+
export type { RouteInstanceSpec } from "./route-manifest.ts";
|
|
17
6
|
|
|
18
7
|
export function instanceKey(instance: RouteInstanceSpec): string {
|
|
19
8
|
return `${resolve(instance.pagesDir)}\0${instance.prefix}`;
|
|
@@ -25,167 +14,88 @@ export function routeModuleSpecifier(instance: RouteInstanceSpec): string {
|
|
|
25
14
|
|
|
26
15
|
export interface RouteFile {
|
|
27
16
|
id: string;
|
|
17
|
+
/** URL pattern of a page; `""` for a layout. */
|
|
28
18
|
path: string;
|
|
19
|
+
/** Mount prefix relative to the enclosing layout. */
|
|
20
|
+
prefix: string;
|
|
21
|
+
/** Native absolute path, as route modules are loaded and cached by it. */
|
|
29
22
|
sourcePath: string;
|
|
30
23
|
}
|
|
31
24
|
|
|
25
|
+
/** A layout and everything it wraps, following the manifest's parent links. */
|
|
32
26
|
export interface RouteTreeNode {
|
|
33
27
|
children: RouteTreeNode[];
|
|
34
|
-
|
|
35
|
-
indexRoute: RouteFile | undefined;
|
|
28
|
+
/** `undefined` for the root node: the root layout's Elysia is never mounted. */
|
|
36
29
|
layout: RouteFile | undefined;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
interface ScannedRouteFile {
|
|
41
|
-
base: string;
|
|
42
|
-
directorySegments: string[];
|
|
43
|
-
sourcePath: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function scanRouteFiles(
|
|
47
|
-
directory: string,
|
|
48
|
-
directorySegments: string[],
|
|
49
|
-
files: ScannedRouteFile[]
|
|
50
|
-
): void {
|
|
51
|
-
const entries = readdirSync(directory, { withFileTypes: true }).sort((left, right) =>
|
|
52
|
-
left.name.localeCompare(right.name)
|
|
53
|
-
);
|
|
54
|
-
for (const entry of entries) {
|
|
55
|
-
if (entry.isDirectory()) {
|
|
56
|
-
// Underscore-prefixed directories are co-located private folders
|
|
57
|
-
// (components, libs) — never route segments.
|
|
58
|
-
if (entry.name.startsWith("_")) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
scanRouteFiles(join(directory, entry.name), [...directorySegments, entry.name], files);
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const extension = extname(entry.name);
|
|
65
|
-
if (!ROUTE_EXTENSION.test(extension) || entry.name.endsWith(".d.ts")) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const base = entry.name.slice(0, -extension.length);
|
|
69
|
-
const sourcePath = join(directory, entry.name);
|
|
70
|
-
for (const segment of [...directorySegments, base]) {
|
|
71
|
-
parseDynamicRouteSegment(segment, sourcePath);
|
|
72
|
-
}
|
|
73
|
-
if (ROUTE_CONVENTIONS.has(base)) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
// Underscore-prefixed files are private co-located modules — except the
|
|
77
|
-
// `_route` layout convention, resolved downstream by buildRouteTree.
|
|
78
|
-
if (base.startsWith("_") && base !== "_route") {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
files.push({
|
|
82
|
-
base,
|
|
83
|
-
directorySegments,
|
|
84
|
-
sourcePath,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const INDEX_SUFFIX = /\/index$/;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Id of `defineRoute(id)`: the app's prefix, then the file's path under
|
|
93
|
-
* `pagesDir` with brackets and groups, `/index` dropped
|
|
94
|
-
* (`board/[boardId]/index.tsx` → `/board/[boardId]`, `board/_route.tsx` →
|
|
95
|
-
* `/board/_route`; `users.tsx` under the `/admin` prefix → `/admin/users`).
|
|
96
|
-
*/
|
|
97
|
-
export function fileRouteId({ pagesDir, prefix }: RouteInstanceSpec, sourcePath: string): string {
|
|
98
|
-
const path = relative(pagesDir, sourcePath).replaceAll("\\", "/").replace(ROUTE_EXTENSION, "");
|
|
99
|
-
return `${prefix}/${path}`.replace(INDEX_SUFFIX, "") || "/";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function segmentPath(segment: string): string {
|
|
103
|
-
return routeSegmentToPattern(segment);
|
|
30
|
+
pages: RouteFile[];
|
|
31
|
+
/** Mount prefix relative to the parent node. */
|
|
32
|
+
prefix: string;
|
|
104
33
|
}
|
|
105
34
|
|
|
106
|
-
function routeId(instanceId: string,
|
|
107
|
-
const
|
|
35
|
+
function routeId(instanceId: string, id: string): string {
|
|
36
|
+
const encodedId = Array.from(new TextEncoder().encode(id), (byte) =>
|
|
108
37
|
byte.toString(16).padStart(2, "0")
|
|
109
38
|
).join("");
|
|
110
|
-
return `_route_${instanceId}_${
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface RouteManifestFile {
|
|
114
|
-
base: string;
|
|
115
|
-
directorySegments: string[];
|
|
116
|
-
/** URL pattern of a page; `undefined` for a `_route` layout. */
|
|
117
|
-
pattern: string | undefined;
|
|
118
|
-
sourcePath: string;
|
|
39
|
+
return `_route_${instanceId}_${encodedId}`;
|
|
119
40
|
}
|
|
120
41
|
|
|
121
|
-
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
if (file.base === "_route") {
|
|
132
|
-
return { ...file, pattern: undefined };
|
|
133
|
-
}
|
|
134
|
-
const relativePath = relative(pagesDir, file.sourcePath).replaceAll("\\", "/");
|
|
135
|
-
const pattern = filePathToPattern(relativePath);
|
|
136
|
-
const patternKey = routePatternKey(pattern);
|
|
137
|
-
const previousPath = seenPatterns.get(patternKey);
|
|
138
|
-
if (previousPath !== undefined) {
|
|
139
|
-
throw new Error(
|
|
140
|
-
`[furin] Duplicate route pattern "${patternKey}" from "${previousPath}" and "${relativePath}".`
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
seenPatterns.set(patternKey, relativePath);
|
|
144
|
-
return { ...file, pattern };
|
|
145
|
-
});
|
|
42
|
+
/** `pattern` with the part its layout already mounts removed. */
|
|
43
|
+
function relativePrefix(pattern: string, parentPattern: string): string {
|
|
44
|
+
const own = pattern === "/" ? "" : pattern;
|
|
45
|
+
const parent = parentPattern === "/" ? "" : parentPattern;
|
|
46
|
+
if (!own.startsWith(parent)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`[furin] Route pattern "${pattern}" does not extend its layout's "${parentPattern}".`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return own.slice(parent.length);
|
|
146
52
|
}
|
|
147
53
|
|
|
148
|
-
export function buildRouteTree(
|
|
149
|
-
const
|
|
54
|
+
export function buildRouteTree(instance: RouteInstanceSpec, instanceId: string): RouteTreeNode {
|
|
55
|
+
const { routes } = scanRouteManifest(instance);
|
|
56
|
+
const byPath = new Map(routes.map((route) => [route.sourcePath, route]));
|
|
57
|
+
const root: RouteTreeNode = { children: [], layout: undefined, pages: [], prefix: "" };
|
|
58
|
+
const nodes = new Map<string | undefined, RouteTreeNode>([[undefined, root]]);
|
|
59
|
+
const parentPattern = (route: ManifestRoute): string =>
|
|
60
|
+
route.parentPath === undefined ? "/" : (byPath.get(route.parentPath)?.pattern ?? "/");
|
|
150
61
|
|
|
151
|
-
const ensureNode = (
|
|
152
|
-
const
|
|
153
|
-
const existing = nodes.get(key);
|
|
62
|
+
const ensureNode = (sourcePath: string | undefined): RouteTreeNode => {
|
|
63
|
+
const existing = nodes.get(sourcePath);
|
|
154
64
|
if (existing) {
|
|
155
65
|
return existing;
|
|
156
66
|
}
|
|
67
|
+
const layout = sourcePath === undefined ? undefined : byPath.get(sourcePath);
|
|
68
|
+
if (!layout) {
|
|
69
|
+
return root;
|
|
70
|
+
}
|
|
71
|
+
const prefix = relativePrefix(layout.pattern, parentPattern(layout));
|
|
157
72
|
const node: RouteTreeNode = {
|
|
158
73
|
children: [],
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
74
|
+
layout: {
|
|
75
|
+
id: routeId(instanceId, layout.id),
|
|
76
|
+
path: "",
|
|
77
|
+
prefix,
|
|
78
|
+
sourcePath: resolve(layout.sourcePath),
|
|
79
|
+
},
|
|
80
|
+
pages: [],
|
|
81
|
+
prefix,
|
|
163
82
|
};
|
|
164
|
-
nodes.set(
|
|
165
|
-
|
|
166
|
-
ensureNode(segments.slice(0, -1)).children.push(node);
|
|
167
|
-
}
|
|
83
|
+
nodes.set(sourcePath, node);
|
|
84
|
+
ensureNode(layout.parentPath).children.push(node);
|
|
168
85
|
return node;
|
|
169
86
|
};
|
|
170
|
-
const root = ensureNode([]);
|
|
171
87
|
|
|
172
|
-
for (const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const path = `/${file.directorySegments.map(segmentPath).join("/")}#layout`;
|
|
176
|
-
node.layout = { id: routeId(instanceId, path), path: "", sourcePath: file.sourcePath };
|
|
88
|
+
for (const route of routes) {
|
|
89
|
+
if (route.kind === "layout") {
|
|
90
|
+
ensureNode(route.sourcePath);
|
|
177
91
|
continue;
|
|
178
92
|
}
|
|
179
|
-
|
|
180
|
-
id: routeId(instanceId,
|
|
181
|
-
path:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
node.indexRoute = route;
|
|
186
|
-
} else {
|
|
187
|
-
node.fileRoutes.push(route);
|
|
188
|
-
}
|
|
93
|
+
ensureNode(route.parentPath).pages.push({
|
|
94
|
+
id: routeId(instanceId, route.id),
|
|
95
|
+
path: route.pattern,
|
|
96
|
+
prefix: relativePrefix(route.pattern, parentPattern(route)),
|
|
97
|
+
sourcePath: resolve(route.sourcePath),
|
|
98
|
+
});
|
|
189
99
|
}
|
|
190
100
|
return root;
|
|
191
101
|
}
|
|
@@ -201,48 +111,28 @@ export function collectRouteFiles(root: RouteTreeNode): RouteFile[] {
|
|
|
201
111
|
if (node.layout) {
|
|
202
112
|
files.push(node.layout);
|
|
203
113
|
}
|
|
204
|
-
|
|
205
|
-
files.push(node.indexRoute);
|
|
206
|
-
}
|
|
207
|
-
files.push(...node.fileRoutes);
|
|
114
|
+
files.push(...node.pages);
|
|
208
115
|
nodes.push(...node.children);
|
|
209
116
|
}
|
|
210
117
|
return files;
|
|
211
118
|
}
|
|
212
119
|
|
|
213
120
|
export function routeSourcePaths(instance: RouteInstanceSpec): string[] {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
.map(({ sourcePath }) => resolve(sourcePath))
|
|
121
|
+
return scanRouteManifest(instance)
|
|
122
|
+
.routes.map(({ sourcePath }) => resolve(sourcePath))
|
|
217
123
|
.toSorted((left, right) => left.localeCompare(right));
|
|
218
124
|
}
|
|
219
125
|
|
|
220
|
-
|
|
221
|
-
const paths: string[] = [];
|
|
222
|
-
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
223
|
-
if (entry.isDirectory()) {
|
|
224
|
-
if (!entry.name.startsWith("_")) {
|
|
225
|
-
paths.push(...conventionSourcePaths(join(directory, entry.name)));
|
|
226
|
-
}
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
const extension = extname(entry.name);
|
|
230
|
-
if (!ROUTE_EXTENSION.test(extension) || entry.name.endsWith(".d.ts")) {
|
|
231
|
-
continue;
|
|
232
|
-
}
|
|
233
|
-
const base = entry.name.slice(0, -extension.length);
|
|
234
|
-
if (base === "error" || base === "not-found") {
|
|
235
|
-
paths.push(resolve(directory, entry.name));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return paths;
|
|
239
|
-
}
|
|
240
|
-
|
|
126
|
+
/** Every file whose presence shapes the app: root, routes and boundary files. */
|
|
241
127
|
export function routeSnapshotSourcePaths(instance: RouteInstanceSpec): string[] {
|
|
242
|
-
const rootPath =
|
|
128
|
+
const { boundaries, rootPath, routes } = scanRouteManifest(instance);
|
|
243
129
|
return [
|
|
244
130
|
...(existsSync(rootPath) ? [rootPath] : []),
|
|
245
|
-
...
|
|
246
|
-
...
|
|
247
|
-
|
|
131
|
+
...routes.map(({ sourcePath }) => sourcePath),
|
|
132
|
+
...boundaries.flatMap(({ errorPath, notFoundPath }) =>
|
|
133
|
+
[errorPath, notFoundPath].filter((path) => path !== undefined)
|
|
134
|
+
),
|
|
135
|
+
]
|
|
136
|
+
.map((path) => resolve(path))
|
|
137
|
+
.toSorted((left, right) => left.localeCompare(right));
|
|
248
138
|
}
|
package/src/routes.ts
CHANGED
|
@@ -9,8 +9,8 @@ export interface RouteMap {}
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Typecheck fallback for `defineRoute(id)`. The generated
|
|
12
|
-
* furin-env.d.ts augments it with one entry per route file, keyed by its
|
|
13
|
-
* id (`"/board/
|
|
12
|
+
* furin-env.d.ts augments it with one entry per route file, keyed by its
|
|
13
|
+
* TanStack Start id (`"/board/$boardId/"`, `"/board"`): kind, URL pattern, parent
|
|
14
14
|
* layout and path params, read from the pages tree without importing modules.
|
|
15
15
|
*/
|
|
16
16
|
// biome-ignore lint/suspicious/noEmptyInterface: intentionally augmented by generated route types
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
3
|
import { staticPlugin } from "@elysia/static";
|
|
4
4
|
import { type AnyElysia, Elysia, file } from "elysia";
|
|
5
|
+
import type { RouteInstanceSpec, RouteStyle } from "../../plugin/route-manifest.ts";
|
|
5
6
|
import { prefixSlug } from "../../shared/prefix.ts";
|
|
6
7
|
import { invalidateDevLoaderCacheBySource } from "../cache/dev-loader.ts";
|
|
7
8
|
import { createInstrumentationPlugin } from "../devtools/instrumentation.ts";
|
|
@@ -14,18 +15,10 @@ import { createSearchRouteMetadata } from "../router/schemas.ts";
|
|
|
14
15
|
import type { ResolvedRoute, RootLayout } from "../router/types.ts";
|
|
15
16
|
import type { DevelopmentRouteSnapshot, DevGraph } from "./graph.ts";
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
* Routes never import their layouts, so the import graph can't tell.
|
|
22
|
-
*/
|
|
23
|
-
function wrapsRoute(sourcePath: string, routePath: string): boolean {
|
|
24
|
-
if (!LAYOUT_FILE_RE.test(basename(sourcePath))) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
const directory = dirname(sourcePath).replaceAll("\\", "/");
|
|
28
|
-
return routePath.replaceAll("\\", "/").startsWith(`${directory}/`);
|
|
18
|
+
/** Routes never import their layouts, so the import graph can't tell what wraps a page. */
|
|
19
|
+
function wrapsRoute(sourcePath: string, route: ResolvedRoute): boolean {
|
|
20
|
+
const normalized = sourcePath.replaceAll("\\", "/");
|
|
21
|
+
return route.layouts.some(({ path }) => path.replaceAll("\\", "/") === normalized);
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
function repairedDevelopmentRoutes(
|
|
@@ -41,7 +34,7 @@ function repairedDevelopmentRoutes(
|
|
|
41
34
|
route.path === sourcePath ||
|
|
42
35
|
snapshot.root.path === sourcePath ||
|
|
43
36
|
graph.dependsOn(route.path, sourcePath) ||
|
|
44
|
-
wrapsRoute(sourcePath, route
|
|
37
|
+
wrapsRoute(sourcePath, route)
|
|
45
38
|
)
|
|
46
39
|
) {
|
|
47
40
|
patterns.add(route.pattern);
|
|
@@ -84,9 +77,9 @@ function ownerAddsRouteHooks(app: AnyElysia, owner: AnyElysia): boolean {
|
|
|
84
77
|
);
|
|
85
78
|
}
|
|
86
79
|
|
|
87
|
-
async function loadDevelopmentRoutes(
|
|
80
|
+
async function loadDevelopmentRoutes(routeInstance: RouteInstanceSpec) {
|
|
88
81
|
const { scanPages } = await import("../router/discovery.ts");
|
|
89
|
-
return scanPages(
|
|
82
|
+
return scanPages(routeInstance);
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
function createDevelopmentRouteSnapshot(
|
|
@@ -116,6 +109,7 @@ function createDevelopmentRouteSnapshot(
|
|
|
116
109
|
export async function createDevRuntime(
|
|
117
110
|
instance: FurinInstance,
|
|
118
111
|
resolvedPagesDir: string,
|
|
112
|
+
style: RouteStyle,
|
|
119
113
|
options: ModeOptions
|
|
120
114
|
): Promise<ModeRuntime> {
|
|
121
115
|
const { prefix, syncPath } = instance;
|
|
@@ -138,7 +132,7 @@ export async function createDevRuntime(
|
|
|
138
132
|
"../../plugin/dev-routes.ts"
|
|
139
133
|
);
|
|
140
134
|
const { routeModuleSpecifier } = await import("../../plugin/route-tree.ts");
|
|
141
|
-
const routeInstance = { pagesDir: resolvedPagesDir, prefix };
|
|
135
|
+
const routeInstance: RouteInstanceSpec = { pagesDir: resolvedPagesDir, prefix, style };
|
|
142
136
|
registerDevRoutesPlugin([routeInstance]);
|
|
143
137
|
|
|
144
138
|
// Furin never rewrites route sources: it only fills empty route files and
|
|
@@ -154,7 +148,7 @@ export async function createDevRuntime(
|
|
|
154
148
|
const { furinShell } = (await import(routeModuleSpecifier(routeInstance))) as {
|
|
155
149
|
furinShell: AnyElysia;
|
|
156
150
|
};
|
|
157
|
-
const loaded = await loadDevelopmentRoutes(
|
|
151
|
+
const loaded = await loadDevelopmentRoutes(routeInstance);
|
|
158
152
|
return { nativeRoutesApp: furinShell, ...loaded };
|
|
159
153
|
});
|
|
160
154
|
const initialSnapshot = createDevelopmentRouteSnapshot(instance, root, routes);
|
|
@@ -260,6 +254,7 @@ export async function createDevRuntime(
|
|
|
260
254
|
clientLogging: clientLogging ?? false,
|
|
261
255
|
clientBoundaries,
|
|
262
256
|
outDir: furinDir,
|
|
257
|
+
pages: { pagesDir: resolvedPagesDir, style },
|
|
263
258
|
publicPath: `${prefix}/_client/`,
|
|
264
259
|
prefix,
|
|
265
260
|
rootLayout: snapshot.root.path,
|
|
@@ -278,7 +273,7 @@ export async function createDevRuntime(
|
|
|
278
273
|
try {
|
|
279
274
|
const previousSnapshot = currentSnapshot();
|
|
280
275
|
const repaired = repairedDevelopmentRoutes(previousSnapshot, changedSources, graph);
|
|
281
|
-
const next = await loadDevelopmentRoutes(
|
|
276
|
+
const next = await loadDevelopmentRoutes(routeInstance);
|
|
282
277
|
// Retain tags only for routes whose current module could not be loaded.
|
|
283
278
|
const nextRoutes = next.routes.map((route) =>
|
|
284
279
|
route.routeChain.length > 0
|
|
@@ -310,7 +305,7 @@ export async function createDevRuntime(
|
|
|
310
305
|
}
|
|
311
306
|
} catch (error) {
|
|
312
307
|
publishDevDiagnostic(error, {
|
|
313
|
-
entryPath:
|
|
308
|
+
entryPath: currentSnapshot().root.path,
|
|
314
309
|
phase: "import",
|
|
315
310
|
route: "*",
|
|
316
311
|
});
|
|
@@ -349,8 +344,7 @@ export async function createDevRuntime(
|
|
|
349
344
|
onSourceError: (error, sourcePath) => {
|
|
350
345
|
const route = currentSnapshot().routes.find(
|
|
351
346
|
(candidate) =>
|
|
352
|
-
graph.dependsOn(candidate.path, sourcePath) ||
|
|
353
|
-
wrapsRoute(sourcePath, candidate.path)
|
|
347
|
+
graph.dependsOn(candidate.path, sourcePath) || wrapsRoute(sourcePath, candidate)
|
|
354
348
|
);
|
|
355
349
|
withInstance(instance, () =>
|
|
356
350
|
publishDevDiagnostic(error, {
|
|
@@ -179,12 +179,15 @@ export function transformDevSource(
|
|
|
179
179
|
for (const graph of developmentGraphs()) {
|
|
180
180
|
graph.clearSourceErrors(filePath);
|
|
181
181
|
}
|
|
182
|
+
// The parsers reject a shebang (e.g. a workspace package's CLI entry). An imported module
|
|
183
|
+
// never needs one: keep it as a same-length comment so every offset and line stays put.
|
|
184
|
+
const source = raw.startsWith("#!") ? `//${raw.slice(2)}` : raw;
|
|
182
185
|
try {
|
|
183
186
|
if (!options.renderFragment) {
|
|
184
|
-
recordDevImports(
|
|
187
|
+
recordDevImports(source, filePath);
|
|
185
188
|
}
|
|
186
189
|
// CSS belongs to Bun's browser graph; importing it here also registers it with --hot.
|
|
187
|
-
const server = parseModule(
|
|
190
|
+
const server = parseModule(source, filePath);
|
|
188
191
|
for (const statement of server.program.body) {
|
|
189
192
|
if (
|
|
190
193
|
statement.type === "ImportDeclaration" &&
|
package/src/server/internal.ts
CHANGED
|
@@ -93,12 +93,15 @@ export interface CompileContext {
|
|
|
93
93
|
routeMetadata?: Record<
|
|
94
94
|
string,
|
|
95
95
|
{
|
|
96
|
+
/** Layouts wrapping the page, shallow → deep, from the route manifest. */
|
|
97
|
+
layouts: Array<{ path: string; pattern: string }>;
|
|
96
98
|
requestKeys?: string[];
|
|
97
99
|
requestKeysByLoader?: string[][];
|
|
98
100
|
segmentBoundaries: Array<{
|
|
99
101
|
depth: number;
|
|
100
102
|
path: string;
|
|
101
103
|
errorPath?: string;
|
|
104
|
+
fromRoute?: true;
|
|
102
105
|
notFoundPath?: string;
|
|
103
106
|
}>;
|
|
104
107
|
}
|
|
@@ -139,7 +142,7 @@ export function collectPrerenders(render: boolean): Promise<AppPrerender[]> {
|
|
|
139
142
|
}
|
|
140
143
|
|
|
141
144
|
// Contexts are keyed by (pagesDir, prefix) — pagesDir being the directory
|
|
142
|
-
// containing root
|
|
145
|
+
// containing the root layout, normalized to posix separators. The SAME pagesDir may
|
|
143
146
|
// legally be mounted under two different prefixes (assertPrefixAvailable only
|
|
144
147
|
// rejects same-prefix collisions), so pagesDir alone would let the second
|
|
145
148
|
// registration overwrite the first. Several packaged furin apps can each ship
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import type { RouteStyle } from "../plugin/route-manifest.ts";
|
|
2
|
+
|
|
3
|
+
/** A `furin({ pagesDir, prefix, style })` call, as declared by the application. */
|
|
2
4
|
export interface FurinRegistration {
|
|
3
|
-
/** pagesDir as declared (
|
|
5
|
+
/** pagesDir as declared (the style's default when omitted); relative to the project root. */
|
|
4
6
|
readonly pagesDir: string;
|
|
5
7
|
/** Normalized mount prefix (`""` for root). */
|
|
6
8
|
readonly prefix: string;
|
|
9
|
+
readonly style: RouteStyle;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
// Shared through globalThis: the build installs the collector before
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { dirname, relative } from "node:path";
|
|
2
1
|
import type { Context } from "elysia";
|
|
3
2
|
import type {
|
|
4
3
|
RuntimeData,
|
|
@@ -7,7 +6,6 @@ import type {
|
|
|
7
6
|
RuntimeStaticParams,
|
|
8
7
|
} from "../../client/internal/runtime-types.ts";
|
|
9
8
|
import { mapWithConcurrency } from "../../shared/utils/index.ts";
|
|
10
|
-
import { filePathToPattern } from "../router/patterns.ts";
|
|
11
9
|
import type { ResolvedRoute } from "../router/types.ts";
|
|
12
10
|
import { resolvePath } from "./assemble.ts";
|
|
13
11
|
import { runPublicLoaders } from "./loaders.ts";
|
|
@@ -39,17 +37,11 @@ function collectStaticParamsStages(route: ResolvedRoute): StaticParamsStage[] {
|
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
function ancestorPattern(route: ResolvedRoute, ancestors: RuntimeRoute[]): string {
|
|
42
|
-
const rootSourcePath = route.routeChain[0]?.sourcePath;
|
|
43
40
|
const ancestorSourcePath = ancestors.at(-1)?.sourcePath;
|
|
44
|
-
if (
|
|
45
|
-
return route.pattern;
|
|
46
|
-
}
|
|
47
|
-
const pagesDir = dirname(rootSourcePath);
|
|
48
|
-
const ancestorDir = dirname(ancestorSourcePath);
|
|
49
|
-
if (ancestorDir === pagesDir) {
|
|
41
|
+
if (ancestors.length <= 1) {
|
|
50
42
|
return "/";
|
|
51
43
|
}
|
|
52
|
-
return
|
|
44
|
+
return route.layouts.find(({ path }) => path === ancestorSourcePath)?.pattern ?? route.pattern;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
function createBuildContext(pattern: string, params: RuntimeParams, origin: string): Context {
|
|
@@ -1,15 +1,19 @@
|
|
|
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
|
|
|
5
7
|
interface DefinedRouteTerminal {
|
|
6
8
|
__type: "FURIN_ROUTE";
|
|
7
9
|
component: (...args: never[]) => React.ReactNode;
|
|
8
10
|
elysia: object;
|
|
11
|
+
errorComponent?: ErrorComponent;
|
|
9
12
|
head?: (...args: never[]) => HeadOptions;
|
|
10
13
|
layout?: (...args: never[]) => React.ReactNode;
|
|
11
14
|
loader?: (...args: never[]) => unknown;
|
|
12
15
|
mode?: RenderingMode;
|
|
16
|
+
notFoundComponent?: NotFoundComponent;
|
|
13
17
|
page?: (...args: never[]) => React.ReactNode;
|
|
14
18
|
remountDeps?: (context: never) => readonly RemountDependency[];
|
|
15
19
|
requestLoader?: (...args: never[]) => unknown;
|
|
@@ -44,9 +48,11 @@ export function adaptDefinedLayout(
|
|
|
44
48
|
const component = route.component as RuntimeRoute["layout"];
|
|
45
49
|
return {
|
|
46
50
|
__type: "FURIN_ROUTE",
|
|
51
|
+
errorComponent: route.errorComponent,
|
|
47
52
|
layout: component,
|
|
48
53
|
loader: route.loader as RuntimeRoute["loader"],
|
|
49
54
|
mode: route.mode,
|
|
55
|
+
notFoundComponent: route.notFoundComponent,
|
|
50
56
|
params: route.schemas?.params,
|
|
51
57
|
...(parent ? { parent } : {}),
|
|
52
58
|
query: route.schemas?.query,
|
|
@@ -72,9 +78,11 @@ export function adaptDefinedPage(route: DefinedRouteTerminal, parent: RuntimeRou
|
|
|
72
78
|
requestLoader: route.requestLoader as RuntimeRoute["requestLoader"],
|
|
73
79
|
},
|
|
74
80
|
component,
|
|
81
|
+
errorComponent: route.errorComponent,
|
|
75
82
|
head,
|
|
76
83
|
loader: route.loader as RuntimePage["loader"],
|
|
77
84
|
mode: route.mode,
|
|
85
|
+
notFoundComponent: route.notFoundComponent,
|
|
78
86
|
revalidate: route.revalidate,
|
|
79
87
|
staticParams: route.staticParams as RuntimePage["staticParams"],
|
|
80
88
|
tags: copyTags(route.tags),
|