@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
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { relative, resolve } from "node:path";
|
|
3
3
|
import type { CallExpression, Node, ObjectExpression, ObjectProperty, Program } from "yuku-parser";
|
|
4
4
|
import type { DevDiagnosticStore } from "../server/dev/diagnostics.ts";
|
|
5
5
|
import { detectLangFromPath, unwrapTSExpression } from "../server/lang-detect.ts";
|
|
6
|
-
import { parseDynamicRouteSegment } from "../server/router/patterns.ts";
|
|
7
6
|
import { parseSource } from "../shared/parser.ts";
|
|
8
7
|
import { collectDefineRouteBindings, exportedRouteChain } from "./route-chains.ts";
|
|
9
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
type ManifestRoute,
|
|
10
|
+
type RouteInstanceSpec,
|
|
11
|
+
type RouteManifest,
|
|
12
|
+
type RouteParam,
|
|
13
|
+
scanRouteManifest,
|
|
14
|
+
} from "./route-manifest.ts";
|
|
10
15
|
|
|
11
16
|
/**
|
|
12
17
|
* Static route-config checks shared by the dev server and `furin build`.
|
|
@@ -21,9 +26,7 @@ export interface RouteConfigIssue {
|
|
|
21
26
|
message: string;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
const EXTENSION_RE = /\.(?:[cm]?[jt]sx?)$/;
|
|
25
29
|
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
26
|
-
const PATH_SEPARATOR_RE = /[\\/]/;
|
|
27
30
|
|
|
28
31
|
interface Import {
|
|
29
32
|
imported: string;
|
|
@@ -46,10 +49,6 @@ interface ParsedRoute {
|
|
|
46
49
|
source: string;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
function withoutExtension(path: string): string {
|
|
50
|
-
return path.replace(EXTENSION_RE, "");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
52
|
function propertyName(key: Node | null): string | undefined {
|
|
54
53
|
if (key?.type === "Identifier") {
|
|
55
54
|
return key.name;
|
|
@@ -149,11 +148,11 @@ function issueAt(file: string, parsed: ParsedRoute, node: Node, message: string)
|
|
|
149
148
|
*/
|
|
150
149
|
function checkKey(
|
|
151
150
|
file: string,
|
|
152
|
-
|
|
151
|
+
route: ManifestRoute,
|
|
153
152
|
parsed: ParsedRoute
|
|
154
153
|
): RouteConfigIssue | undefined {
|
|
155
154
|
const { config, head, id } = parsed.route;
|
|
156
|
-
const expected =
|
|
155
|
+
const expected = route.id;
|
|
157
156
|
if (!id) {
|
|
158
157
|
return issueAt(
|
|
159
158
|
file,
|
|
@@ -200,11 +199,11 @@ function suggestedMode(route: RouteExport, isRoot: boolean): string {
|
|
|
200
199
|
|
|
201
200
|
function checkFactory(
|
|
202
201
|
file: string,
|
|
203
|
-
|
|
202
|
+
manifestRoute: ManifestRoute | undefined,
|
|
204
203
|
parsed: ParsedRoute
|
|
205
204
|
): RouteConfigIssue | undefined {
|
|
206
205
|
const { route } = parsed;
|
|
207
|
-
const isRoot =
|
|
206
|
+
const isRoot = manifestRoute === undefined;
|
|
208
207
|
if (isRoot === route.isRootFactory) {
|
|
209
208
|
return;
|
|
210
209
|
}
|
|
@@ -214,14 +213,14 @@ function checkFactory(
|
|
|
214
213
|
file,
|
|
215
214
|
parsed,
|
|
216
215
|
route.head,
|
|
217
|
-
`root
|
|
216
|
+
`The root layout must use defineRootRoute(), which has no parent layout:\n import { defineRootRoute } from "@teyik0/furin";\n export const route = defineRootRoute().config({ mode: "${mode}" })`
|
|
218
217
|
);
|
|
219
218
|
}
|
|
220
219
|
return issueAt(
|
|
221
220
|
file,
|
|
222
221
|
parsed,
|
|
223
222
|
route.head,
|
|
224
|
-
`defineRootRoute() is reserved for root.
|
|
223
|
+
`defineRootRoute() is reserved for the root layout. Use defineRoute with this file's id:\n import { defineRoute } from "@teyik0/furin";\n export const route = defineRoute("${manifestRoute.id}").config({ mode: "${mode}" })`
|
|
225
224
|
);
|
|
226
225
|
}
|
|
227
226
|
|
|
@@ -269,24 +268,15 @@ function declaredParams(route: RouteExport): Set<string> | true {
|
|
|
269
268
|
return new Set(keys.filter((key) => key !== undefined));
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
/**
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
pagesDir: string,
|
|
276
|
-
declared: Set<string> | true
|
|
277
|
-
): { key: string; segment: string }[] {
|
|
278
|
-
return withoutExtension(relative(pagesDir, file))
|
|
279
|
-
.split(PATH_SEPARATOR_RE)
|
|
280
|
-
.flatMap((segment) => {
|
|
281
|
-
const dynamic = parseDynamicRouteSegment(segment, file);
|
|
282
|
-
return dynamic ? [{ key: dynamic.catchAll ? "*" : dynamic.name, segment }] : [];
|
|
283
|
-
})
|
|
284
|
-
.filter(({ key }) => declared !== true && !declared.has(key));
|
|
271
|
+
/** Path params of the route missing from `declared`. */
|
|
272
|
+
function undeclaredParams(route: ManifestRoute, declared: Set<string> | true): RouteParam[] {
|
|
273
|
+
return route.params.filter(({ name }) => declared !== true && !declared.has(name));
|
|
285
274
|
}
|
|
286
275
|
|
|
287
|
-
function paramsSchema(
|
|
288
|
-
const fields =
|
|
289
|
-
({
|
|
276
|
+
function paramsSchema(params: RouteParam[]): string {
|
|
277
|
+
const fields = params.map(
|
|
278
|
+
({ name, optional }) =>
|
|
279
|
+
`${IDENTIFIER_RE.test(name) ? name : JSON.stringify(name)}: ${optional ? "t.Optional(t.String())" : "t.String()"}`
|
|
290
280
|
);
|
|
291
281
|
return `params: t.Object({ ${fields.join(", ")} })`;
|
|
292
282
|
}
|
|
@@ -294,10 +284,10 @@ function paramsSchema(segments: { key: string }[]): string {
|
|
|
294
284
|
/** Static twin of `validateRouteParams()`, which rejects the page once its module loads. */
|
|
295
285
|
function checkParams(
|
|
296
286
|
file: string,
|
|
297
|
-
|
|
287
|
+
route: ManifestRoute,
|
|
298
288
|
parsed: ParsedRoute
|
|
299
289
|
): RouteConfigIssue | undefined {
|
|
300
|
-
const missing =
|
|
290
|
+
const missing = undeclaredParams(route, declaredParams(parsed.route));
|
|
301
291
|
if (missing.length === 0) {
|
|
302
292
|
return;
|
|
303
293
|
}
|
|
@@ -308,43 +298,68 @@ function checkParams(
|
|
|
308
298
|
file,
|
|
309
299
|
parsed,
|
|
310
300
|
parsed.route.config ?? parsed.route.head,
|
|
311
|
-
`The
|
|
301
|
+
`The path param${plural ? "s" : ""} ${missing.map(({ name }) => name).join(", ")} ${plural ? "are" : "is"} missing from this page's params schema. Each page declares every dynamic segment of its path, including those of its layouts. Add to config():${tImport}\n ${paramsSchema(missing)}`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/** Next.js-style apps declare boundaries as files, TanStack-style ones on the route. */
|
|
306
|
+
function checkBoundaryMethods(
|
|
307
|
+
file: string,
|
|
308
|
+
instance: RouteInstanceSpec,
|
|
309
|
+
parsed: ParsedRoute
|
|
310
|
+
): RouteConfigIssue | undefined {
|
|
311
|
+
const method = ["error", "notFound"].find((name) => parsed.route.methods.has(name));
|
|
312
|
+
if (instance.style !== "nextjs" || method === undefined) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const convention = method === "error" ? "an error.tsx" : "a not-found.tsx";
|
|
316
|
+
return issueAt(
|
|
317
|
+
file,
|
|
318
|
+
parsed,
|
|
319
|
+
parsed.route.head,
|
|
320
|
+
`.${method}() is the TanStack style. In the nextjs style, default-export the component from ${convention} next to this route.`
|
|
312
321
|
);
|
|
313
322
|
}
|
|
314
323
|
|
|
315
324
|
function checkRoute(
|
|
316
325
|
file: string,
|
|
317
326
|
instance: RouteInstanceSpec,
|
|
327
|
+
route: ManifestRoute | undefined,
|
|
318
328
|
parsed: ParsedRoute
|
|
319
329
|
): (RouteConfigIssue | undefined)[] {
|
|
320
|
-
const factory = checkFactory(file,
|
|
330
|
+
const factory = checkFactory(file, route, parsed);
|
|
321
331
|
if (factory) {
|
|
322
332
|
return [factory];
|
|
323
333
|
}
|
|
324
|
-
const isLayout = basename(withoutExtension(file)) === "_route";
|
|
325
334
|
return [
|
|
326
335
|
checkConfig(file, parsed),
|
|
327
|
-
|
|
336
|
+
route === undefined ? undefined : checkKey(file, route, parsed),
|
|
328
337
|
checkMode(file, parsed),
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
: checkParams(file, instance.pagesDir, parsed),
|
|
338
|
+
route === undefined || route.kind === "layout" ? undefined : checkParams(file, route, parsed),
|
|
339
|
+
checkBoundaryMethods(file, instance, parsed),
|
|
332
340
|
];
|
|
333
341
|
}
|
|
334
342
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
343
|
+
/** The root layout (`undefined` route) and every route file, sorted. */
|
|
344
|
+
function routeFiles(manifest: RouteManifest): [string, ManifestRoute | undefined][] {
|
|
345
|
+
// Issues and scaffolded files report native paths, as the editor opens them.
|
|
346
|
+
const files: [string, ManifestRoute | undefined][] = manifest.routes.map((route) => [
|
|
347
|
+
resolve(route.sourcePath),
|
|
348
|
+
route,
|
|
349
|
+
]);
|
|
350
|
+
if (existsSync(manifest.rootPath)) {
|
|
351
|
+
files.push([resolve(manifest.rootPath), undefined]);
|
|
352
|
+
}
|
|
353
|
+
return files.toSorted(([left], [right]) => left.localeCompare(right));
|
|
341
354
|
}
|
|
342
355
|
|
|
343
|
-
export function validateRouteConfig(
|
|
344
|
-
const instance = { pagesDir: resolve(pagesDir)
|
|
345
|
-
return routeFiles(instance
|
|
356
|
+
export function validateRouteConfig(spec: RouteInstanceSpec): RouteConfigIssue[] {
|
|
357
|
+
const instance = { ...spec, pagesDir: resolve(spec.pagesDir) };
|
|
358
|
+
return routeFiles(scanRouteManifest(instance)).flatMap(([file, route]) => {
|
|
346
359
|
const parsed = parseRoute(file);
|
|
347
|
-
return parsed
|
|
360
|
+
return parsed
|
|
361
|
+
? checkRoute(file, instance, route, parsed).filter((issue) => issue !== undefined)
|
|
362
|
+
: [];
|
|
348
363
|
});
|
|
349
364
|
}
|
|
350
365
|
|
|
@@ -420,15 +435,15 @@ export const route = defineRootRoute()
|
|
|
420
435
|
));
|
|
421
436
|
`;
|
|
422
437
|
|
|
423
|
-
function scaffoldTemplate(
|
|
424
|
-
if (
|
|
438
|
+
function scaffoldTemplate(route: ManifestRoute | undefined): string {
|
|
439
|
+
if (route === undefined) {
|
|
425
440
|
return ROOT_TEMPLATE;
|
|
426
441
|
}
|
|
427
|
-
const isLayout =
|
|
428
|
-
const params =
|
|
442
|
+
const isLayout = route.kind === "layout";
|
|
443
|
+
const { params } = route;
|
|
429
444
|
return `import { defineRoute } from "@teyik0/furin";${params.length > 0 ? '\nimport { t } from "elysia";' : ""}
|
|
430
445
|
|
|
431
|
-
export const route = defineRoute("${
|
|
446
|
+
export const route = defineRoute("${route.id}")
|
|
432
447
|
.config({ mode: "${isLayout ? "ssr" : "ssg"}"${params.length > 0 ? `, ${paramsSchema(params)}` : ""} })
|
|
433
448
|
.${isLayout ? "layout(({ children }) => children)" : "page(() => null)"};
|
|
434
449
|
`;
|
|
@@ -438,14 +453,14 @@ export const route = defineRoute("${fileRouteId(instance, file)}")
|
|
|
438
453
|
* Writes a starter route, keyed by the file's id, into route files that are
|
|
439
454
|
* empty or whitespace-only, the only case where Furin writes to a source file.
|
|
440
455
|
*/
|
|
441
|
-
export function scaffoldEmptyRoutes(
|
|
442
|
-
const instance = { pagesDir: resolve(pagesDir)
|
|
456
|
+
export function scaffoldEmptyRoutes(spec: RouteInstanceSpec): string[] {
|
|
457
|
+
const instance = { ...spec, pagesDir: resolve(spec.pagesDir) };
|
|
443
458
|
const written: string[] = [];
|
|
444
|
-
for (const file of routeFiles(instance
|
|
445
|
-
(
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
459
|
+
for (const [file, route] of routeFiles(scanRouteManifest(instance))) {
|
|
460
|
+
if (readSource(file)?.trim() === "") {
|
|
461
|
+
writeFileSync(file, scaffoldTemplate(route));
|
|
462
|
+
written.push(file);
|
|
463
|
+
}
|
|
449
464
|
}
|
|
450
465
|
return written;
|
|
451
466
|
}
|