@k8ordo/framework 2.3.1 → 4.0.0
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 +28 -13
- package/dist/cli.mjs +3 -3
- package/dist/generated.d.mts +13 -13
- package/dist/headers-BxB_jJVk.mjs +73 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +1 -1
- package/dist/paths-type-DXpmjaOr.d.mts +43 -0
- package/dist/runtime/app-router.mjs +21 -8
- package/dist/runtime/browser-payloads.mjs +1 -1
- package/dist/runtime/client-files.d.mts +6 -5
- package/dist/runtime/client-files.mjs +17 -9
- package/dist/runtime/client-ready.d.mts +7 -1
- package/dist/runtime/client-ready.mjs +2 -1
- package/dist/runtime/cookies.d.mts +2 -0
- package/dist/runtime/cookies.mjs +2 -1
- package/dist/runtime/ended.d.mts +7 -0
- package/dist/runtime/ended.mjs +14 -0
- package/dist/runtime/entry.browser.mjs +1 -1
- package/dist/runtime/entry.rsc.d.mts +38 -2
- package/dist/runtime/entry.rsc.mjs +97 -31
- package/dist/runtime/entry.ssr.d.mts +7 -1
- package/dist/runtime/entry.ssr.mjs +12 -6
- package/dist/runtime/guard.d.mts +15 -10
- package/dist/runtime/guard.mjs +8 -2
- package/dist/runtime/mount.mjs +1 -1
- package/dist/runtime/page-boundary.mjs +2 -2
- package/dist/runtime/params.d.mts +5 -4
- package/dist/runtime/params.mjs +2 -2
- package/dist/runtime/payload.d.mts +19 -4
- package/dist/runtime/payload.mjs +20 -5
- package/dist/runtime/prefetch.d.mts +29 -8
- package/dist/runtime/prefetch.mjs +95 -24
- package/dist/runtime/redirect.d.mts +13 -7
- package/dist/runtime/redirect.mjs +25 -9
- package/dist/runtime/request-scope.d.mts +37 -2
- package/dist/runtime/request-scope.mjs +60 -3
- package/dist/runtime/request.d.mts +6 -1
- package/dist/runtime/request.mjs +7 -2
- package/dist/runtime/route.d.mts +4 -2
- package/dist/runtime/route.mjs +13 -5
- package/dist/runtime/server.d.mts +5 -5
- package/dist/runtime/server.mjs +2 -2
- package/dist/runtime/shell.d.mts +2 -1
- package/dist/serve.d.mts +4 -0
- package/dist/serve.mjs +29 -14
- package/dist/static-Be3xIqd8.d.mts +62 -0
- package/dist/{static-file-BAjwBMMl.mjs → static-file-BS-WEiwu.mjs} +311 -134
- package/dist/{static-host-B-1fAfAw.mjs → static-host-tIDLqV8c.mjs} +1 -1
- package/dist/vercel.d.mts +18 -1
- package/dist/vercel.mjs +131 -19
- package/dist/vite.d.mts +6 -3
- package/dist/vite.mjs +366 -156
- package/docs/GUIDE.md +173 -46
- package/docs/llms.txt +129 -65
- package/docs/references/actions.md +14 -5
- package/docs/references/boundaries.md +23 -2
- package/docs/references/csp.md +91 -2
- package/docs/references/deploy.md +154 -25
- package/docs/references/errors.md +57 -12
- package/docs/references/guards.md +100 -29
- package/docs/references/params.md +234 -126
- package/docs/references/routing.md +358 -75
- package/package.json +18 -13
- package/dist/shared-dir-CNXFRZgP.mjs +0 -9
- package/dist/static-DnbgGIoy.d.mts +0 -61
|
@@ -11,10 +11,12 @@ const CONVENTION = {
|
|
|
11
11
|
"guard.ts": "guard",
|
|
12
12
|
"route.ts": "route",
|
|
13
13
|
"loading.tsx": "loading",
|
|
14
|
-
"fallback.tsx": "fallback"
|
|
14
|
+
"fallback.tsx": "fallback",
|
|
15
|
+
"paths.ts": "paths"
|
|
15
16
|
};
|
|
16
17
|
const ROUTE_FILES = Object.keys(CONVENTION).join(", ");
|
|
17
18
|
const PARAM = /^\[([A-Za-z_][A-Za-z0-9_]*)\]$/u;
|
|
19
|
+
const REST = /^\[\.\.\.([A-Za-z_][A-Za-z0-9_]*)\]$/u;
|
|
18
20
|
const GROUP = /^\(([A-Za-z0-9_-]+)\)$/u;
|
|
19
21
|
const LITERAL = /^[A-Za-z0-9._~-]+$/u;
|
|
20
22
|
/**
|
|
@@ -36,6 +38,17 @@ const slotOf = (file) => {
|
|
|
36
38
|
if (basename === void 0) return null;
|
|
37
39
|
return CONVENTION[basename] ?? null;
|
|
38
40
|
};
|
|
41
|
+
/**
|
|
42
|
+
* The `[...name]` directory a route file sits in, relative to the routes
|
|
43
|
+
* root — `null` for a file in none, or one the grammar does not read. One
|
|
44
|
+
* module at a time, like `slotOf`.
|
|
45
|
+
*/
|
|
46
|
+
const restDirOf = (file) => {
|
|
47
|
+
const segments = file.split("/").filter((segment) => segment !== "");
|
|
48
|
+
if (segments.some((segment) => isHidden(segment))) return null;
|
|
49
|
+
const index = segments.slice(0, -1).findIndex((segment) => REST.test(segment));
|
|
50
|
+
return index === -1 ? null : segments.slice(0, index + 1).join("/");
|
|
51
|
+
};
|
|
39
52
|
const emptyDir = () => ({
|
|
40
53
|
files: /* @__PURE__ */ new Map(),
|
|
41
54
|
dirs: /* @__PURE__ */ new Map()
|
|
@@ -67,12 +80,22 @@ const classify = (name, path, problems) => {
|
|
|
67
80
|
key: `/:${param[1]}`,
|
|
68
81
|
param: param[1]
|
|
69
82
|
};
|
|
83
|
+
const rest = REST.exec(name);
|
|
84
|
+
if (rest !== null) return {
|
|
85
|
+
kind: "rest",
|
|
86
|
+
key: `/:${rest[1]}+`,
|
|
87
|
+
param: rest[1]
|
|
88
|
+
};
|
|
70
89
|
if (GROUP.exec(name) !== null) return {
|
|
71
90
|
kind: "group",
|
|
72
91
|
key: `/${name}`,
|
|
73
92
|
param: null
|
|
74
93
|
};
|
|
75
|
-
if (name.startsWith("[")
|
|
94
|
+
if (name.startsWith("[...")) problems.push({
|
|
95
|
+
path,
|
|
96
|
+
message: `"${name}" is not a valid rest directory — use [...name] with a letter or underscore first`
|
|
97
|
+
});
|
|
98
|
+
else if (name.startsWith("[") || name.endsWith("]")) problems.push({
|
|
76
99
|
path,
|
|
77
100
|
message: `"${name}" is not a valid param directory — use [name] with a letter or underscore first`
|
|
78
101
|
});
|
|
@@ -116,11 +139,28 @@ const convert = (raw, name, path, kind, key, problems) => {
|
|
|
116
139
|
path: slots.route,
|
|
117
140
|
message: `"${here}" cannot both redirect and answer from route.ts — keep one`
|
|
118
141
|
});
|
|
142
|
+
if (slots.paths !== void 0 && kind !== "param") problems.push({
|
|
143
|
+
path: slots.paths,
|
|
144
|
+
message: `paths.ts gives the values of its directory's parameter, and "${here}" is not a [param] directory — move it into the parameter's directory`
|
|
145
|
+
});
|
|
146
|
+
if (kind === "rest" && slots.notFound !== void 0) problems.push({
|
|
147
|
+
path: slots.notFound,
|
|
148
|
+
message: `not-found.tsx answers what nothing below its directory did, and nothing is below "${here}" — [...${name.slice(4, -1)}] takes the rest of the pathname; move it one directory up`
|
|
149
|
+
});
|
|
119
150
|
const children = [...raw.dirs.entries()].map(([childName, childRaw]) => {
|
|
120
151
|
const childPath = path === "" ? childName : `${path}/${childName}`;
|
|
152
|
+
if (kind === "rest") problems.push({
|
|
153
|
+
path: childPath,
|
|
154
|
+
message: `"${name}" takes the rest of the pathname, so it is the last directory of its path — move "${childName}" out of "${here}"`
|
|
155
|
+
});
|
|
121
156
|
const classified = classify(childName, childPath, problems);
|
|
122
157
|
return convert(childRaw, childName, childPath, classified.kind, classified.key, problems);
|
|
123
158
|
});
|
|
159
|
+
const rests = children.filter((child) => child.kind === "rest");
|
|
160
|
+
for (const other of rests.slice(1)) problems.push({
|
|
161
|
+
path: other.path,
|
|
162
|
+
message: `"${other.name}" cannot sit beside "${rests[0]?.name ?? ""}" — each takes the rest of the pathname below "${here}"; keep one`
|
|
163
|
+
});
|
|
124
164
|
return {
|
|
125
165
|
name,
|
|
126
166
|
kind,
|
|
@@ -135,9 +175,16 @@ const convert = (raw, name, path, kind, key, problems) => {
|
|
|
135
175
|
guard: slots.guard ?? null,
|
|
136
176
|
route: slots.route ?? null,
|
|
137
177
|
fallback: slots.fallback ?? null,
|
|
178
|
+
paths: slots.paths ?? null,
|
|
138
179
|
children
|
|
139
180
|
};
|
|
140
181
|
};
|
|
182
|
+
/** The param a directory names — `id` for `[id]`, `path` for `[...path]` — or `null`. */
|
|
183
|
+
const paramOf = (dir) => {
|
|
184
|
+
if (dir.kind === "param") return dir.key.slice(2);
|
|
185
|
+
if (dir.kind === "rest") return dir.key.slice(2, -1);
|
|
186
|
+
return null;
|
|
187
|
+
};
|
|
141
188
|
const declaresRoute = (dir) => dir.page !== null || dir.route !== null || dir.notFound !== null || dir.redirect !== null || dir.children.some(declaresRoute);
|
|
142
189
|
/**
|
|
143
190
|
* Walks the tree the way the router's own table walk does, so the patterns
|
|
@@ -154,17 +201,35 @@ const eachPattern = (dir, prefix, visit) => {
|
|
|
154
201
|
eachPattern(child, next, visit);
|
|
155
202
|
}
|
|
156
203
|
};
|
|
204
|
+
/**
|
|
205
|
+
* Every `paths.ts` in a parameter's directory, outermost first. One in any
|
|
206
|
+
* other directory is a problem the parse reports, and is not listed.
|
|
207
|
+
*/
|
|
208
|
+
const pathsFiles = (tree) => {
|
|
209
|
+
const found = [];
|
|
210
|
+
const walk = (dir, prefix) => {
|
|
211
|
+
const here = dir.kind === "root" ? "" : prefix;
|
|
212
|
+
if (dir.paths !== null && dir.kind === "param") found.push({
|
|
213
|
+
file: dir.paths,
|
|
214
|
+
pattern: here
|
|
215
|
+
});
|
|
216
|
+
for (const child of dir.children) walk(child, child.kind === "group" ? here : `${here}${child.key}`);
|
|
217
|
+
};
|
|
218
|
+
walk(tree, "");
|
|
219
|
+
return found;
|
|
220
|
+
};
|
|
157
221
|
const checkFallback = (dir, file, pattern, params, above) => {
|
|
158
222
|
const here = dir.path === "" ? "/" : dir.path;
|
|
159
223
|
const refuse = (message) => ({ problem: {
|
|
160
224
|
path: file,
|
|
161
225
|
message
|
|
162
226
|
} });
|
|
227
|
+
if (dir.kind === "rest") return refuse(`fallback.tsx is the shell a build into files answers a parameter's unwritten values with, and "${here}" is a [...name] directory, which no build into files writes; remove it`);
|
|
163
228
|
if (dir.page === null) return refuse(`fallback.tsx stands in for the page.tsx beside it, and "${here}" has none`);
|
|
164
229
|
if (dir.layout !== null) return refuse(`fallback.tsx cannot sit beside layout.tsx — that layout receives every parameter of "${here}", so no shell could leave one to the browser; move the layout one directory up, or into page.tsx and fallback.tsx`);
|
|
165
230
|
if (params.length === 0) return refuse(`fallback.tsx stands in for values the build did not write, and "${pattern}" has no parameter; remove it`);
|
|
166
231
|
const open = params.filter((name) => !(above?.params ?? []).includes(name));
|
|
167
|
-
if (open.length === 0 && above !== null) return refuse(`fallback.tsx has nothing to leave to the browser — ${above.file} receives every parameter of "${pattern}"; remove fallback.tsx and
|
|
232
|
+
if (open.length === 0 && above !== null) return refuse(`fallback.tsx has nothing to leave to the browser — ${above.file} receives every parameter of "${pattern}"; remove fallback.tsx and return the values from a paths.ts`);
|
|
168
233
|
return { shape: {
|
|
169
234
|
pattern,
|
|
170
235
|
file,
|
|
@@ -186,7 +251,8 @@ const checkFallbacks = (tree) => {
|
|
|
186
251
|
const walk = (dir, prefix, inherited, above) => {
|
|
187
252
|
if (!declaresRoute(dir)) return;
|
|
188
253
|
const here = dir.kind === "root" ? "" : prefix;
|
|
189
|
-
const
|
|
254
|
+
const own = paramOf(dir);
|
|
255
|
+
const params = own === null ? inherited : [...inherited, own];
|
|
190
256
|
if (dir.fallback !== null) found.push(checkFallback(dir, dir.fallback, here === "" ? "/" : here, params, above));
|
|
191
257
|
const below = dir.layout === null ? above : {
|
|
192
258
|
file: dir.layout,
|
|
@@ -206,8 +272,8 @@ const fallbackShapes = (tree) => checkFallbacks(tree).flatMap((each) => each.sha
|
|
|
206
272
|
const validate = (root, problems) => {
|
|
207
273
|
const walk = (dir, inherited) => {
|
|
208
274
|
let params = inherited;
|
|
209
|
-
|
|
210
|
-
|
|
275
|
+
const name = paramOf(dir);
|
|
276
|
+
if (name !== null) {
|
|
211
277
|
if (params.includes(name)) problems.push({
|
|
212
278
|
path: dir.path,
|
|
213
279
|
message: `":${name}" is already taken by an ancestor — params must be unique within a path`
|
|
@@ -250,6 +316,14 @@ const parseRouteTree = (files) => {
|
|
|
250
316
|
problems
|
|
251
317
|
};
|
|
252
318
|
};
|
|
319
|
+
// ../framework-engine/dist/host.mjs
|
|
320
|
+
/**
|
|
321
|
+
* The package the application actually installed. This engine is bundled
|
|
322
|
+
* into it rather than published on its own, so it is the only name
|
|
323
|
+
* resolvable from the project root: anything the optimizer is asked to
|
|
324
|
+
* prebundle is addressed through it, and the generated files name it.
|
|
325
|
+
*/
|
|
326
|
+
const FRAMEWORK = "@k8ordo/framework";
|
|
253
327
|
// ../framework-engine/dist/runtime/route.mjs
|
|
254
328
|
/** The request methods a `route.ts` answers by exporting a function named so. */
|
|
255
329
|
const ROUTE_METHODS = [
|
|
@@ -261,14 +335,6 @@ const ROUTE_METHODS = [
|
|
|
261
335
|
"DELETE",
|
|
262
336
|
"OPTIONS"
|
|
263
337
|
];
|
|
264
|
-
// ../framework-engine/dist/host.mjs
|
|
265
|
-
/**
|
|
266
|
-
* The package the application actually installed. This engine is bundled
|
|
267
|
-
* into it rather than published on its own, so it is the only name
|
|
268
|
-
* resolvable from the project root: anything the optimizer is asked to
|
|
269
|
-
* prebundle is addressed through it, and the generated files name it.
|
|
270
|
-
*/
|
|
271
|
-
const FRAMEWORK = "@k8ordo/framework";
|
|
272
338
|
// ../framework-engine/dist/generate/emit.mjs
|
|
273
339
|
/** What answers a directory's own URL: its page, or its route.ts. */
|
|
274
340
|
const ownFile = (dir) => dir.page ?? dir.route;
|
|
@@ -286,22 +352,25 @@ const placeOf = (dir) => ownFile(dir) ?? dir.redirect;
|
|
|
286
352
|
*/
|
|
287
353
|
const isLeaf = (dir) => dir.kind !== "group" && placeOf(dir) !== null && dir.layout === null && dir.error === null && dir.loading === null && dir.notFound === null && dir.children.length === 0;
|
|
288
354
|
/**
|
|
289
|
-
* What a subtree offers the matcher first: a literal, a parameter,
|
|
290
|
-
* catch-all. A group contributes its children's URLs
|
|
291
|
-
* own, so it ranks as whatever the best of them is —
|
|
292
|
-
* tucked inside a group would still be tried before a
|
|
355
|
+
* What a subtree offers the matcher first: a literal, a parameter, a rest
|
|
356
|
+
* parameter, or only a catch-all. A group contributes its children's URLs
|
|
357
|
+
* rather than one of its own, so it ranks as whatever the best of them is —
|
|
358
|
+
* otherwise a `[slug]` tucked inside a group would still be tried before a
|
|
359
|
+
* literal sibling.
|
|
293
360
|
*/
|
|
294
361
|
const rank = (dir) => {
|
|
295
362
|
if (dir.kind === "param") return 1;
|
|
363
|
+
if (dir.kind === "rest") return 2;
|
|
296
364
|
if (dir.kind !== "group") return 0;
|
|
297
365
|
const children = dir.children.map(rank);
|
|
298
366
|
if (dir.page !== null) children.push(0);
|
|
299
|
-
if (dir.notFound !== null) children.push(
|
|
300
|
-
return Math.min(...children,
|
|
367
|
+
if (dir.notFound !== null) children.push(3);
|
|
368
|
+
return Math.min(...children, 3);
|
|
301
369
|
};
|
|
302
370
|
/**
|
|
303
|
-
* Literal segments before parameters,
|
|
304
|
-
*
|
|
371
|
+
* Literal segments before parameters, a parameter before a rest parameter —
|
|
372
|
+
* `[...path]` also takes the one segment `[id]` takes, so it comes after or
|
|
373
|
+
* `[id]` never answers — and otherwise the order the directories came in. The table matches in declaration order, and the directories arrive
|
|
305
374
|
* sorted by name — under which `[slug]` precedes `about`, because `[` sorts
|
|
306
375
|
* before letters. Left alone, the most ordinary layout there is would make
|
|
307
376
|
* `/about` unreachable behind `/:slug`.
|
|
@@ -401,6 +470,8 @@ const ROUTE_REQUEST_FROM = `${FRAMEWORK}/server`;
|
|
|
401
470
|
const I18N = "@k8ordo/i18n";
|
|
402
471
|
/** Where an application declares its locale set, from its root. */
|
|
403
472
|
const LOCALES_MODULE = "src/i18n.ts";
|
|
473
|
+
/** Where an application's route files live, from its root. */
|
|
474
|
+
const ROUTES_DIR = "src/routes";
|
|
404
475
|
const bannerFrom = (...sources) => `// Generated by ${FRAMEWORK} from ${sources.join(" and ")}. Do not edit.`;
|
|
405
476
|
const sanitize = (path) => {
|
|
406
477
|
const base = path.replace(/\.[jt]sx?$/u, "").replaceAll(/[^A-Za-z0-9]+/gu, "_").replaceAll(/^_+|_+$/gu, "");
|
|
@@ -454,7 +525,9 @@ const believed = (name, asserted) => {
|
|
|
454
525
|
* the render's context and never refuse it — a catch-all answers what nothing
|
|
455
526
|
* else did, so its params stay strings. A fallback's carries the layouts'
|
|
456
527
|
* above it too: a shell runs them over the params it fills, and its page's
|
|
457
|
-
* own never, since a shell has no value.
|
|
528
|
+
* own never, since a shell has no value. A paths.ts's carries only the
|
|
529
|
+
* layouts' above its directory: a layout in its own directory, and the page
|
|
530
|
+
* beside it, may read the parameter it is asked for, which has no value yet.
|
|
458
531
|
*/
|
|
459
532
|
const beliefs = (tree, withParams) => {
|
|
460
533
|
const found = /* @__PURE__ */ new Map();
|
|
@@ -493,6 +566,11 @@ const beliefs = (tree, withParams) => {
|
|
|
493
566
|
kind: "fallback",
|
|
494
567
|
schemas: layoutSchemas
|
|
495
568
|
});
|
|
569
|
+
if (dir.paths !== null) found.set(dir.paths, {
|
|
570
|
+
pattern: own,
|
|
571
|
+
kind: "paths",
|
|
572
|
+
schemas: inherited
|
|
573
|
+
});
|
|
496
574
|
for (const child of dir.children) walk(child, child.kind === "group" ? here : `${here}${child.key}`, layoutSchemas);
|
|
497
575
|
};
|
|
498
576
|
walk(tree, "", []);
|
|
@@ -540,7 +618,8 @@ const LATE = /* @__PURE__ */ new Set([
|
|
|
540
618
|
"page",
|
|
541
619
|
"notFound",
|
|
542
620
|
"route",
|
|
543
|
-
"fallback"
|
|
621
|
+
"fallback",
|
|
622
|
+
"paths"
|
|
544
623
|
]);
|
|
545
624
|
const isLate = (file) => {
|
|
546
625
|
const slot = slotOf(file);
|
|
@@ -560,6 +639,9 @@ const emitRoutesModule = (tree, options) => {
|
|
|
560
639
|
}));
|
|
561
640
|
const shells = options.mode === "static" ? fallbackShapes(tree) : [];
|
|
562
641
|
for (const shape of shells) namer.take(shape.file);
|
|
642
|
+
const typedSupplies = pathsFiles(tree);
|
|
643
|
+
const supplies = options.mode === "static" ? typedSupplies : [];
|
|
644
|
+
for (const supply of supplies) namer.take(supply.file);
|
|
563
645
|
const guarded = guardsOf(tree);
|
|
564
646
|
const guardStacks = new Map([...guarded.stacks].map(([pattern, files]) => [pattern, files.map((file) => namer.take(file))]));
|
|
565
647
|
const guardChecks = [...guarded.own].map(([file, pattern]) => `${pad(1)}Checked<typeof ${namer.take(file)}, Guard<'${pattern}'>>,`);
|
|
@@ -604,8 +686,14 @@ const emitRoutesModule = (tree, options) => {
|
|
|
604
686
|
});
|
|
605
687
|
const routeChecks = routeFiles.map(({ pattern, name }) => stacks.has(pattern) ? `${pad(1)}Checked<Loaded<typeof ${name}>, RouteModule<'${pattern}', ParamSchemas['${pattern}']>>,` : `${pad(1)}Checked<Loaded<typeof ${name}>, RouteModule<'${pattern}'>>,`);
|
|
606
688
|
const fallbackChecks = shells.map(({ file }) => `${pad(1)}Checked<Loaded<typeof ${namer.take(file)}>['default'], ComponentType>,`);
|
|
607
|
-
const
|
|
608
|
-
const
|
|
689
|
+
const pathsChecks = supplies.map(({ pattern, file }) => `${pad(1)}Checked<Loaded<typeof ${namer.take(file)}>['default'], Paths<'${pattern}'>>,`);
|
|
690
|
+
const layoutSchemasOf = (file) => byFile.get(file).schemas.map((layout) => schemaName(namer.take(layout)));
|
|
691
|
+
const pathsSchemas = [...Map.groupBy(typedSupplies, ({ pattern }) => pattern)].map(([pattern, files]) => {
|
|
692
|
+
const tuples = new Set(files.map(({ file }) => `[${layoutSchemasOf(file).map((schema) => `typeof ${schema}`).join(", ")}]`));
|
|
693
|
+
return `${pad(1)}'${pattern}': ${[...tuples].join(" | ")};`;
|
|
694
|
+
});
|
|
695
|
+
const hasChecks = schemaChecks.length + routeChecks.length + fallbackChecks.length + pathsChecks.length + guardChecks.length > 0;
|
|
696
|
+
const readsLate = routeFiles.length > 0 || shells.length > 0 || supplies.length > 0 || searchReaders.size > 0 || [...namer.names.keys()].some((file) => withParams.has(file) && isLate(file));
|
|
609
697
|
const hasRoutes = routeFiles.length > 0;
|
|
610
698
|
const hasError = [...asserted.values()].includes("ErrorComponent");
|
|
611
699
|
const withRequest = options.mode === "server";
|
|
@@ -621,6 +709,7 @@ const emitRoutesModule = (tree, options) => {
|
|
|
621
709
|
...hasLayout ? ["ParamsOf"] : [],
|
|
622
710
|
...schemaChecks.length > 0 ? ["ParamsSchemaFor"] : [],
|
|
623
711
|
"ParsedParams",
|
|
712
|
+
...supplies.length > 0 ? ["Paths"] : [],
|
|
624
713
|
...redirects.length > 0 ? ["RedirectTarget"] : []
|
|
625
714
|
];
|
|
626
715
|
return [
|
|
@@ -790,7 +879,7 @@ const emitRoutesModule = (tree, options) => {
|
|
|
790
879
|
`${pad(1)}'${pattern}': {`,
|
|
791
880
|
`${pad(2)}load: ${namer.take(file)},`,
|
|
792
881
|
`${pad(2)}open: [${open.map((param) => `'${param}'`).join(", ")}],`,
|
|
793
|
-
`${pad(2)}schemas: [${
|
|
882
|
+
`${pad(2)}schemas: [${layoutSchemasOf(file).join(", ")}],`,
|
|
794
883
|
`${pad(1)}},`
|
|
795
884
|
]),
|
|
796
885
|
"} as const;",
|
|
@@ -803,6 +892,34 @@ const emitRoutesModule = (tree, options) => {
|
|
|
803
892
|
] : []
|
|
804
893
|
] : ["// A running server renders every value with its page: no shells.", "export const fallbacks = {} as const;"],
|
|
805
894
|
"",
|
|
895
|
+
...options.mode === "static" ? [
|
|
896
|
+
"// Per paths.ts, by its file: what reads the values its directory's",
|
|
897
|
+
"// parameter takes, and the schemas of the layouts above its directory,",
|
|
898
|
+
"// which read the params above before it is asked. The build and",
|
|
899
|
+
"// `vite dev` ask through `pathValues`.",
|
|
900
|
+
"export const paths = {",
|
|
901
|
+
...supplies.flatMap(({ file }) => [
|
|
902
|
+
`${pad(1)}'${file}': {`,
|
|
903
|
+
`${pad(2)}load: ${namer.take(file)},`,
|
|
904
|
+
`${pad(2)}schemas: [${layoutSchemasOf(file).join(", ")}],`,
|
|
905
|
+
`${pad(1)}},`
|
|
906
|
+
]),
|
|
907
|
+
"} as const;",
|
|
908
|
+
...pathsChecks.length > 0 ? [
|
|
909
|
+
"",
|
|
910
|
+
"// The paths.ts files, each checked against the pattern of its directory.",
|
|
911
|
+
"export type PathsChecks = [",
|
|
912
|
+
...pathsChecks,
|
|
913
|
+
"];"
|
|
914
|
+
] : []
|
|
915
|
+
] : ["// A running server renders whatever value arrives: no values to list.", "export const paths = {} as const;"],
|
|
916
|
+
"",
|
|
917
|
+
"// What a paths.ts receives, by its directory's pattern: the params above",
|
|
918
|
+
"// it as the layouts above its directory read them.",
|
|
919
|
+
"export type PathsSchemas = {",
|
|
920
|
+
...pathsSchemas,
|
|
921
|
+
"};",
|
|
922
|
+
"",
|
|
806
923
|
"export const routes = defineRoutes({",
|
|
807
924
|
...body,
|
|
808
925
|
"});",
|
|
@@ -810,15 +927,13 @@ const emitRoutesModule = (tree, options) => {
|
|
|
810
927
|
].join("\n");
|
|
811
928
|
};
|
|
812
929
|
/**
|
|
813
|
-
*
|
|
814
|
-
*
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
* held to it.
|
|
930
|
+
* The router reads the app's route table through declaration merging, so the
|
|
931
|
+
* app gets typed links everywhere without writing the ceremony itself. Its
|
|
932
|
+
* `Register` is augmented through the framework's re-export of it, which
|
|
933
|
+
* TypeScript merges into the router's own declaration. The locale set reaches
|
|
934
|
+
* `@k8ordo/i18n`'s `Register` the same way, so every message is held to it.
|
|
819
935
|
*/
|
|
820
936
|
const emitRegisterModule = (options) => {
|
|
821
|
-
const wantsState = options.stateModule !== null && options.stateModule !== void 0;
|
|
822
937
|
const localesModule = options.localesModule ?? null;
|
|
823
938
|
const withRequest = options.mode === "server";
|
|
824
939
|
const lines = [
|
|
@@ -827,22 +942,22 @@ const emitRegisterModule = (options) => {
|
|
|
827
942
|
`import type { ParsedParamsMap } from '${GENERATED_FROM}';`,
|
|
828
943
|
...withRequest ? [`import type { RouteRequest } from '${ROUTE_REQUEST_FROM}';`] : [],
|
|
829
944
|
...localesModule === null ? [] : [`import type { LocaleOf } from '${I18N}';`],
|
|
830
|
-
...wantsState ? [`import type {} from '${options.stateModule}';`] : [],
|
|
831
945
|
...localesModule === null ? [] : [`import type { locales } from '${localesModule}';`],
|
|
832
|
-
`import type { ParamSchemas, routes, SearchReads } from '${options.routesModule}';`,
|
|
946
|
+
`import type { ParamSchemas, PathsSchemas, routes, SearchReads } from '${options.routesModule}';`,
|
|
833
947
|
"",
|
|
834
948
|
`declare module '${GENERATED_FROM}' {`,
|
|
835
949
|
" interface Register {",
|
|
836
950
|
" routes: typeof routes;",
|
|
837
951
|
" // A link takes a param as the page receives it — typed by its schema.",
|
|
838
952
|
" params: ParsedParamsMap<ParamSchemas>;",
|
|
953
|
+
" // A paths.ts receives the params above it as the layouts above read them.",
|
|
954
|
+
" pathsParams: ParsedParamsMap<PathsSchemas>;",
|
|
839
955
|
" // A page that exports `search` receives what it reads.",
|
|
840
956
|
" search: SearchReads;",
|
|
841
957
|
...withRequest ? [" // A route file receives the request: this is a running server.", " request: RouteRequest;"] : [],
|
|
842
958
|
" }",
|
|
843
959
|
"}"
|
|
844
960
|
];
|
|
845
|
-
if (wantsState) lines.push("", `declare module '${options.stateModule}' {`, " interface Register {", " routes: typeof routes;", " }", "}");
|
|
846
961
|
if (localesModule !== null) lines.push("", `declare module '${I18N}' {`, " interface Register {", " locale: LocaleOf<typeof locales>;", " }", "}");
|
|
847
962
|
lines.push("");
|
|
848
963
|
return lines.join("\n");
|
|
@@ -908,20 +1023,30 @@ const CLIENT_DEPS_HEADER = "x-k8ordo-client-deps";
|
|
|
908
1023
|
/** What `clientDepsHeader` said. */
|
|
909
1024
|
const readClientDeps = (value) => JSON.parse(decodeURIComponent(value));
|
|
910
1025
|
/**
|
|
911
|
-
*
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
1026
|
+
* Said by the handler under mode: 'static' alone, on a page's HTML: every
|
|
1027
|
+
* stylesheet the Server Components of the payload it rendered link
|
|
1028
|
+
* (`serverStylesheetsHeader`), which the build lists in `CLIENT_FILES_PATH`
|
|
1029
|
+
* beside the client modules' files.
|
|
1030
|
+
*/
|
|
1031
|
+
const SERVER_STYLESHEETS_HEADER = "x-k8ordo-server-stylesheets";
|
|
1032
|
+
/** What `serverStylesheetsHeader` said. */
|
|
1033
|
+
const readServerStylesheets = (value) => JSON.parse(decodeURIComponent(value));
|
|
1034
|
+
/**
|
|
1035
|
+
* Where a static build lists the files each page needs beyond its payload —
|
|
1036
|
+
* its client components' scripts and stylesheets, and its Server Components'
|
|
1037
|
+
* stylesheets — at the root of the site under Vite's `base`. A navigation
|
|
1038
|
+
* links them as it asks for the payload, instead of once the payload has
|
|
1039
|
+
* named them — a round trip sooner.
|
|
915
1040
|
*/
|
|
916
1041
|
const CLIENT_FILES_PATH = "/client-files.json";
|
|
917
1042
|
// src/paths.ts
|
|
918
1043
|
/**
|
|
919
|
-
* Every pattern the table declares
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
* file the site writes.
|
|
1044
|
+
* Every pattern the table declares that answers a URL of its own — pages,
|
|
1045
|
+
* route.ts and redirects, not the catch-alls — in the order the matcher
|
|
1046
|
+
* will try them. The engine's one walk, so the build and the prerenderer
|
|
1047
|
+
* agree; a redirect is a URL the site has, so it is a file the site writes.
|
|
923
1048
|
*/
|
|
924
|
-
const
|
|
1049
|
+
const answeringPatterns = (dir) => declaredPatterns(dir).filter((each) => each.kind !== "notFound");
|
|
925
1050
|
/** A `:name` segment: a parameter a pattern, or a shell location, leaves open. */
|
|
926
1051
|
const PARAM_SEGMENT = /^:[A-Za-z_]\w*$/u;
|
|
927
1052
|
const isParamSegment = (segment) => PARAM_SEGMENT.test(segment);
|
|
@@ -936,7 +1061,7 @@ const isConcrete = (pattern) => !pattern.includes("*") && !pattern.split("/").so
|
|
|
936
1061
|
* be represented: whichever one the build picked, the other would never be
|
|
937
1062
|
* served. The build says so rather than choosing.
|
|
938
1063
|
*/
|
|
939
|
-
const catchAllPatterns = (dir) =>
|
|
1064
|
+
const catchAllPatterns = (dir) => declaredPatterns(dir).filter((each) => each.kind === "notFound").map((each) => each.pattern);
|
|
940
1065
|
/** A table with more than one catch-all, which no static host can serve. */
|
|
941
1066
|
const catchAllRefusals = (dir) => {
|
|
942
1067
|
const catchAlls = catchAllPatterns(dir);
|
|
@@ -959,7 +1084,7 @@ const catchAllPath = (dir) => {
|
|
|
959
1084
|
const [pattern] = catchAllPatterns(dir);
|
|
960
1085
|
if (pattern === void 0) return null;
|
|
961
1086
|
const prefix = pattern.slice(0, -2).split("/").filter(Boolean).map((segment) => segment.startsWith(":") ? NOT_FOUND_SEGMENT : segment);
|
|
962
|
-
const depth = Math.max(prefix.length + 1, ...
|
|
1087
|
+
const depth = Math.max(prefix.length + 1, ...answeringPatterns(dir).map(({ pattern: each }) => each.split("/").filter(Boolean).length + 1));
|
|
963
1088
|
const filler = Array.from({ length: depth - prefix.length }, () => NOT_FOUND_SEGMENT);
|
|
964
1089
|
return `/${[...prefix, ...filler].join("/")}`;
|
|
965
1090
|
};
|
|
@@ -967,7 +1092,7 @@ const catchAllPath = (dir) => {
|
|
|
967
1092
|
* The patterns the build cannot answer on its own. A catch-all is excluded:
|
|
968
1093
|
* it is rendered as the not-found file, never as a page of its own.
|
|
969
1094
|
*/
|
|
970
|
-
const patternsNeedingPaths = (dir) =>
|
|
1095
|
+
const patternsNeedingPaths = (dir) => answeringPatterns(dir).map((each) => each.pattern).filter((pattern) => !isConcrete(pattern));
|
|
971
1096
|
/**
|
|
972
1097
|
* A shell location's pathname: each segment it leaves to the browser replaced
|
|
973
1098
|
* by the reserved one. `/ja/posts/:id` → `/ja/posts/!fallback`.
|
|
@@ -976,21 +1101,6 @@ const shellPathname = (location) => location.split("/").map((segment) => isParam
|
|
|
976
1101
|
/** The params a shell location still holds, in order. */
|
|
977
1102
|
const unknownOf = (location) => location.split("/").filter((segment) => isParamSegment(segment)).map((segment) => segment.slice(1));
|
|
978
1103
|
/**
|
|
979
|
-
* Whether a location is one the pattern answers, segment by segment: a
|
|
980
|
-
* literal needs the same literal; a parameter takes a value, or the same
|
|
981
|
-
* `:name` left open — any `:name`, when names are not compared.
|
|
982
|
-
*/
|
|
983
|
-
const fits = (pattern, location, byName = true) => {
|
|
984
|
-
const wanted = pattern.split("/");
|
|
985
|
-
const given = location.split("/");
|
|
986
|
-
if (wanted.length !== given.length) return false;
|
|
987
|
-
return wanted.every((segment, index) => {
|
|
988
|
-
const at = given[index];
|
|
989
|
-
if (!isParamSegment(segment)) return segment === at;
|
|
990
|
-
return !isParamSegment(at) || !byName || at === segment;
|
|
991
|
-
});
|
|
992
|
-
};
|
|
993
|
-
/**
|
|
994
1104
|
* Static rendering cannot invent parameter values, and quietly shipping a
|
|
995
1105
|
* site missing half its pages is worse than refusing to build one. Every
|
|
996
1106
|
* parameterised pattern must be covered by a supplied path — or, for a page
|
|
@@ -998,82 +1108,54 @@ const fits = (pattern, location, byName = true) => {
|
|
|
998
1108
|
* build did not write.
|
|
999
1109
|
*
|
|
1000
1110
|
* The other direction counts too: a supplied path nothing matched is a typo
|
|
1001
|
-
* that would cost exactly the page it was meant to add,
|
|
1002
|
-
* that still contains a parameter (`/ja/blog/:slug` — what expanding only one
|
|
1003
|
-
* of two parameters leaves behind) would be written to disk as a directory
|
|
1004
|
-
* literally named `:slug` — unless its page has a fallback.tsx, when it is
|
|
1005
|
-
* where that shell stands. URLPattern accepts both, so this has to say no.
|
|
1006
|
-
*
|
|
1007
|
-
* A location goes to the first pattern in table order it fits, which is the
|
|
1008
|
-
* pattern whose URLs a host's rule for it will catch.
|
|
1111
|
+
* that would cost exactly the page it was meant to add, so it is named.
|
|
1009
1112
|
*/
|
|
1010
1113
|
const planPaths = (tree, supplied) => {
|
|
1011
|
-
const
|
|
1012
|
-
const declared = declaredPatterns(tree).filter((each) => each.kind !== "notFound");
|
|
1114
|
+
const declared = answeringPatterns(tree);
|
|
1013
1115
|
const shapes = new Map(fallbackShapes(tree).map((shape) => [shape.pattern, shape]));
|
|
1014
|
-
const paths =
|
|
1116
|
+
const paths = declared.map((each) => each.pattern).filter((pattern) => isConcrete(pattern));
|
|
1015
1117
|
const unresolved = [];
|
|
1016
1118
|
const unusable = [];
|
|
1017
|
-
const held = [];
|
|
1018
|
-
const misnamed = [];
|
|
1019
1119
|
const closed = [];
|
|
1020
1120
|
const reserved = [];
|
|
1021
1121
|
const located = /* @__PURE__ */ new Map();
|
|
1022
1122
|
const offered = /* @__PURE__ */ new Set();
|
|
1123
|
+
const keptForShells = (path) => path.split("/").some((segment) => decodePathname(segment) === FALLBACK_SEGMENT);
|
|
1023
1124
|
const usable = [];
|
|
1024
|
-
for (const raw of supplied) {
|
|
1125
|
+
for (const raw of supplied.paths) {
|
|
1025
1126
|
const path = normalizePathname(raw);
|
|
1026
|
-
if (path
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
}
|
|
1034
|
-
if (path.includes("*")) {
|
|
1035
|
-
unusable.push(path);
|
|
1036
|
-
continue;
|
|
1037
|
-
}
|
|
1038
|
-
const first = declared.find((each) => fits(each.pattern, path));
|
|
1039
|
-
if (first === void 0) {
|
|
1040
|
-
const loosely = declared.find((each) => fits(each.pattern, path, false));
|
|
1041
|
-
if (loosely === void 0) unusable.push(path);
|
|
1042
|
-
else misnamed.push({
|
|
1043
|
-
location: path,
|
|
1044
|
-
pattern: loosely.pattern
|
|
1045
|
-
});
|
|
1046
|
-
continue;
|
|
1047
|
-
}
|
|
1048
|
-
const shape = shapes.get(first.pattern);
|
|
1049
|
-
if (shape === void 0) {
|
|
1050
|
-
held.push({
|
|
1051
|
-
location: path,
|
|
1052
|
-
file: first.file
|
|
1053
|
-
});
|
|
1127
|
+
if (keptForShells(path)) reserved.push(path);
|
|
1128
|
+
else usable.push(path);
|
|
1129
|
+
}
|
|
1130
|
+
for (const { location: raw, pattern } of supplied.shells) {
|
|
1131
|
+
const location = normalizePathname(raw);
|
|
1132
|
+
if (keptForShells(location)) {
|
|
1133
|
+
reserved.push(location);
|
|
1054
1134
|
continue;
|
|
1055
1135
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1136
|
+
const shape = shapes.get(pattern);
|
|
1137
|
+
if (shape === void 0) throw new TypeError(`${location} is a shell location for ${pattern}, whose page has no fallback.tsx`);
|
|
1138
|
+
offered.add(pattern);
|
|
1139
|
+
const outside = unknownOf(location).filter((name) => !shape.open.includes(name));
|
|
1058
1140
|
if (outside.length > 0) {
|
|
1059
1141
|
closed.push({
|
|
1060
|
-
location
|
|
1142
|
+
location,
|
|
1061
1143
|
params: outside,
|
|
1062
1144
|
layout: shape.layout ?? "",
|
|
1063
1145
|
supplied: true
|
|
1064
1146
|
});
|
|
1065
1147
|
continue;
|
|
1066
1148
|
}
|
|
1067
|
-
located.set(
|
|
1068
|
-
pattern
|
|
1069
|
-
location
|
|
1070
|
-
pathname: shellPathname(
|
|
1149
|
+
located.set(pattern, [...located.get(pattern) ?? [], {
|
|
1150
|
+
pattern,
|
|
1151
|
+
location,
|
|
1152
|
+
pathname: shellPathname(location)
|
|
1071
1153
|
}]);
|
|
1072
1154
|
}
|
|
1073
1155
|
const used = new Set(paths);
|
|
1074
1156
|
const shells = [];
|
|
1075
|
-
for (const pattern of
|
|
1076
|
-
if (isConcrete(pattern)
|
|
1157
|
+
for (const { pattern } of declared) {
|
|
1158
|
+
if (isConcrete(pattern)) continue;
|
|
1077
1159
|
const matcher = new URLPattern({ pathname: pattern });
|
|
1078
1160
|
const covered = usable.filter((path) => matcher.test({ pathname: path }));
|
|
1079
1161
|
paths.push(...covered);
|
|
@@ -1108,13 +1190,108 @@ const planPaths = (tree, supplied) => {
|
|
|
1108
1190
|
shells: shells.filter((shell, index) => shells.findIndex((each) => each.pathname === shell.pathname) === index),
|
|
1109
1191
|
unresolved,
|
|
1110
1192
|
unusable,
|
|
1111
|
-
held,
|
|
1112
|
-
misnamed,
|
|
1113
1193
|
closed,
|
|
1114
1194
|
reserved
|
|
1115
1195
|
};
|
|
1116
1196
|
};
|
|
1117
1197
|
/**
|
|
1198
|
+
* A value as the segment of a pathname. Past `encodeURIComponent`, the two
|
|
1199
|
+
* characters this module reads a pathname by: `*`, and the `:` that would
|
|
1200
|
+
* make a value starting with one a parameter left open.
|
|
1201
|
+
*/
|
|
1202
|
+
const segmentOf = (spelling) => encodeURIComponent(spelling).replaceAll("*", "%2A").replaceAll(":", "%3A");
|
|
1203
|
+
const isValue = (value) => typeof value === "string" && value !== "" || typeof value === "number" || typeof value === "bigint" || typeof value === "boolean";
|
|
1204
|
+
const spellingsFrom = (returned) => Array.isArray(returned) && returned.every(isValue) ? [...new Set(returned.map(String))] : null;
|
|
1205
|
+
/**
|
|
1206
|
+
* What the `paths.ts` files say the site holds: each is asked for its
|
|
1207
|
+
* directory's parameter, once per combination of the values above it, and
|
|
1208
|
+
* the values multiply down the tree — to the pages, and to the route.ts and
|
|
1209
|
+
* redirect.ts files, that sit below.
|
|
1210
|
+
*
|
|
1211
|
+
* A parameter no paths.ts gives values to stays open (`:name`), and an open
|
|
1212
|
+
* location is offered only where a fallback.tsx stands in for the page: that
|
|
1213
|
+
* is where its shell goes. So with `[locale]/paths.ts` and a fallback.tsx
|
|
1214
|
+
* under `[id]`, the shells stand at `/ja/posts/:id` and `/en/posts/:id`,
|
|
1215
|
+
* and `/fr/posts/1` is nobody's. A directory with both lists its values and
|
|
1216
|
+
* keeps a shell for the rest. Everything else is left for `planPaths` to
|
|
1217
|
+
* call unresolved.
|
|
1218
|
+
*
|
|
1219
|
+
* A value is what a link to the page takes, and is spelled here as `href`
|
|
1220
|
+
* spells it. A paths.ts below is handed the spellings above it, so
|
|
1221
|
+
* `valuesOf` can read them as the layouts above its directory do — not the
|
|
1222
|
+
* values as returned, which no page ever receives — and a paths.ts under
|
|
1223
|
+
* values one of those refuses is a problem, as a shell there is.
|
|
1224
|
+
*/
|
|
1225
|
+
const suppliedFrom = async (tree, valuesOf) => {
|
|
1226
|
+
const paths = [];
|
|
1227
|
+
const shells = [];
|
|
1228
|
+
const problems = /* @__PURE__ */ new Set();
|
|
1229
|
+
const refused = [];
|
|
1230
|
+
const walk = async (dir, ats, pattern) => {
|
|
1231
|
+
const answers = dir.page ?? dir.route ?? dir.redirect;
|
|
1232
|
+
const shell = dir.page !== null && dir.fallback !== null;
|
|
1233
|
+
if (answers !== null) {
|
|
1234
|
+
for (const at of ats) if (at.open) {
|
|
1235
|
+
if (shell) shells.push({
|
|
1236
|
+
location: at.path,
|
|
1237
|
+
pattern
|
|
1238
|
+
});
|
|
1239
|
+
} else if (Object.keys(at.params).length > 0) paths.push(at.path);
|
|
1240
|
+
}
|
|
1241
|
+
await Promise.all(dir.children.map(async (child) => {
|
|
1242
|
+
if (child.kind === "group") return walk(child, ats, pattern);
|
|
1243
|
+
const below = `${pattern === "/" ? "" : pattern}${child.key}`;
|
|
1244
|
+
if (child.kind !== "param") return walk(child, ats.map((at) => ({
|
|
1245
|
+
...at,
|
|
1246
|
+
path: `${at.path}${child.key}`
|
|
1247
|
+
})), below);
|
|
1248
|
+
const name = child.key.slice(2);
|
|
1249
|
+
const opened = (at) => ({
|
|
1250
|
+
...at,
|
|
1251
|
+
path: `${at.path}/:${name}`,
|
|
1252
|
+
open: true
|
|
1253
|
+
});
|
|
1254
|
+
const { paths: file } = child;
|
|
1255
|
+
if (file === null) return walk(child, ats.map(opened), below);
|
|
1256
|
+
const reached = await Promise.all(ats.map(async (at) => {
|
|
1257
|
+
if (at.open) {
|
|
1258
|
+
problems.add(`${file} is asked for its values once per value of the parameters above it, and ${at.path} still holds one — give that parameter's directory a paths.ts too`);
|
|
1259
|
+
return [];
|
|
1260
|
+
}
|
|
1261
|
+
const asked = await valuesOf(file, at.params);
|
|
1262
|
+
if (asked === null) {
|
|
1263
|
+
refused.push(`${at.path}/:${name} (${file})`);
|
|
1264
|
+
return [];
|
|
1265
|
+
}
|
|
1266
|
+
const spellings = spellingsFrom(asked.values);
|
|
1267
|
+
if (spellings === null) {
|
|
1268
|
+
problems.add(`${file} has to return an array of the values of :${name}, each a non-empty string, a number, a bigint or a boolean`);
|
|
1269
|
+
return [];
|
|
1270
|
+
}
|
|
1271
|
+
return [...spellings.map((spelling) => ({
|
|
1272
|
+
path: `${at.path}/${segmentOf(spelling)}`,
|
|
1273
|
+
params: {
|
|
1274
|
+
...at.params,
|
|
1275
|
+
[name]: spelling
|
|
1276
|
+
},
|
|
1277
|
+
open: false
|
|
1278
|
+
})), ...child.page !== null && child.fallback !== null ? [opened(at)] : []];
|
|
1279
|
+
}));
|
|
1280
|
+
return walk(child, reached.flat(), below);
|
|
1281
|
+
}));
|
|
1282
|
+
};
|
|
1283
|
+
await walk(tree, [{
|
|
1284
|
+
path: "",
|
|
1285
|
+
params: {},
|
|
1286
|
+
open: false
|
|
1287
|
+
}], "/");
|
|
1288
|
+
return {
|
|
1289
|
+
paths,
|
|
1290
|
+
shells,
|
|
1291
|
+
problems: [...problems, ...refused.length > 0 ? [`the paths.ts files stand where a params schema refuses the values above them, so they were not asked: ${refused.toSorted().join(", ")}`] : []]
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
/**
|
|
1118
1295
|
* Shells whose host rule would answer URLs the table gives a pattern declared
|
|
1119
1296
|
* before theirs — a page, route.ts or redirect.ts with a parameter and no
|
|
1120
1297
|
* fallback.tsx of its own. A host matches the shell's location alone, so the
|
|
@@ -1123,7 +1300,7 @@ const planPaths = (tree, supplied) => {
|
|
|
1123
1300
|
* URL, only when the build did not write it, since the written file answers.
|
|
1124
1301
|
*/
|
|
1125
1302
|
const shadowedShells = (tree, shells, built) => {
|
|
1126
|
-
const declared =
|
|
1303
|
+
const declared = answeringPatterns(tree);
|
|
1127
1304
|
const shapes = new Map(fallbackShapes(tree).map((shape) => [shape.pattern, shape]));
|
|
1128
1305
|
const found = [];
|
|
1129
1306
|
for (const shell of shells) {
|
|
@@ -1177,14 +1354,12 @@ const planRefusals = (plan, shadowed) => {
|
|
|
1177
1354
|
const bare = plan.closed.filter((each) => !each.supplied);
|
|
1178
1355
|
const suppliedClosed = plan.closed.filter((each) => each.supplied);
|
|
1179
1356
|
return [
|
|
1180
|
-
...plan.unresolved.length > 0 ? [`static build needs
|
|
1181
|
-
...plan.unusable.length > 0 ? [`the
|
|
1182
|
-
...
|
|
1183
|
-
...
|
|
1184
|
-
...
|
|
1185
|
-
...
|
|
1186
|
-
...plan.reserved.length > 0 ? [`the "paths" option supplied pathnames with a segment named ${FALLBACK_SEGMENT}, which the build keeps for shells: ${plan.reserved.join(", ")}`] : [],
|
|
1187
|
-
...shadowed.length > 0 ? [shadowed.map(({ location, fallback, pattern, file, url }) => url === null ? `the shell for ${location} (${fallback}) would also answer URLs ${pattern} (${file}) is declared first for — ${isPage(file) ? `give ${file} a fallback.tsx too, or supply` : "supply"} shell locations it cannot match` : `the shell for ${location} (${fallback}) would also answer ${url}, which ${file} is declared first for and the build did not write — list ${url} in "paths", or supply shell locations it cannot match`).join("\n")] : []
|
|
1357
|
+
...plan.unresolved.length > 0 ? [`static build needs the values of ${plan.unresolved.join(", ")} — a paths.ts in each parameter's directory returns them, and a fallback.tsx beside a page answers the ones the build does not write`] : [],
|
|
1358
|
+
...plan.unusable.length > 0 ? [`the paths.ts files returned pathnames no route wants: ${plan.unusable.join(", ")}`] : [],
|
|
1359
|
+
...suppliedClosed.length > 0 ? [`these shells leave out a parameter a layout above their fallback.tsx receives, so its directory needs a paths.ts: ${suppliedClosed.map(({ location, params, layout }) => `${location} (${paramList(params)}, received by ${layout})`).join(", ")}`] : [],
|
|
1360
|
+
...bare.length > 0 ? [bare.map(({ location, params, layout }) => `static build needs the values of ${paramList(params)} for the shell of ${location} — ${layout} receives ${params.length === 1 ? "it" : "them"}, so ${params.length === 1 ? "that parameter's directory needs" : "those parameters' directories need"} a paths.ts, which puts the shell at ${location.split("/").map((segment) => params.some((name) => segment === `:${name}`) ? `<${segment.slice(1)}>` : segment).join("/")}`).join("\n")] : [],
|
|
1361
|
+
...plan.reserved.length > 0 ? [`a paths.ts returned ${FALLBACK_SEGMENT}, which the build keeps for shells: ${plan.reserved.join(", ")}`] : [],
|
|
1362
|
+
...shadowed.length > 0 ? [shadowed.map(({ location, fallback, pattern, file, url }) => url === null ? `the shell for ${location} (${fallback}) would also answer URLs ${pattern} (${file}) is declared first for — ${isPage(file) ? `give ${file} a fallback.tsx too, or put` : "put"} the shell where it cannot match, with a paths.ts above it` : `the shell for ${location} (${fallback}) would also answer ${url}, which ${file} is declared first for and the build did not write — return its value from that parameter's paths.ts, or put the shell where it cannot match, with a paths.ts above it`).join("\n")] : []
|
|
1188
1363
|
];
|
|
1189
1364
|
};
|
|
1190
1365
|
/**
|
|
@@ -1197,19 +1372,21 @@ const planRefusals = (plan, shadowed) => {
|
|
|
1197
1372
|
*/
|
|
1198
1373
|
const dirFor = (pathname) => {
|
|
1199
1374
|
const decoded = decodePathname(pathname);
|
|
1200
|
-
if (decoded === null) throw new Error(`
|
|
1201
|
-
if (decoded.split("/").some((segment) => segment === "..")) throw new Error(`
|
|
1375
|
+
if (decoded === null) throw new Error(`a pathname to write has a malformed escape: ${pathname}`);
|
|
1376
|
+
if (decoded.split("/").some((segment) => segment === "..")) throw new Error(`a pathname to write leaves the output: ${pathname}`);
|
|
1202
1377
|
return decoded;
|
|
1203
1378
|
};
|
|
1204
1379
|
/** Where a pathname's file lands inside the client build, `/`-separated. */
|
|
1205
1380
|
const fileAt = (pathname, name = "") => posix.join(dirFor(pathname), name).slice(1);
|
|
1381
|
+
/** Where the build's own sitemap goes, unless a route.ts answers there. */
|
|
1382
|
+
const SITEMAP_PATHNAME = "/sitemap.xml";
|
|
1206
1383
|
/**
|
|
1207
1384
|
* What answers each pathname the build writes: the first declared pattern
|
|
1208
1385
|
* that matches it, in the matcher's order. The catch-all never answers a
|
|
1209
1386
|
* pathname the build was given.
|
|
1210
1387
|
*/
|
|
1211
1388
|
const answersOf = (dir, pathnames) => {
|
|
1212
|
-
const declared =
|
|
1389
|
+
const declared = answeringPatterns(dir);
|
|
1213
1390
|
return new Map(pathnames.flatMap((pathname) => {
|
|
1214
1391
|
const answer = declared.find((each) => new URLPattern({ pathname: each.pattern }).test({ pathname }));
|
|
1215
1392
|
return answer === void 0 ? [] : [[pathname, answer]];
|
|
@@ -1220,9 +1397,10 @@ const answersOf = (dir, pathnames) => {
|
|
|
1220
1397
|
* message: at `/`, below which every file goes; where something else is
|
|
1221
1398
|
* written below it; or where the build writes a file of its own, after the
|
|
1222
1399
|
* routes' files — a page's beside them — so one would replace the other
|
|
1223
|
-
* without a word.
|
|
1400
|
+
* without a word. `sitemap.xml` is not among those: the build leaves it to a
|
|
1401
|
+
* route.ts that writes it.
|
|
1224
1402
|
*/
|
|
1225
|
-
const routeFileRefusals = (tree, plan, answers, {
|
|
1403
|
+
const routeFileRefusals = (tree, plan, answers, { named }) => {
|
|
1226
1404
|
const written = /* @__PURE__ */ new Map();
|
|
1227
1405
|
for (const [pathname, answer] of answers) {
|
|
1228
1406
|
if (answer.kind === "route") continue;
|
|
@@ -1232,8 +1410,7 @@ const routeFileRefusals = (tree, plan, answers, { site, named }) => {
|
|
|
1232
1410
|
}
|
|
1233
1411
|
const notFound = declaredPatterns(tree).find((each) => each.kind === "notFound");
|
|
1234
1412
|
if (notFound !== void 0) written.set("404.html", `${named(notFound.file)} is written there`);
|
|
1235
|
-
|
|
1236
|
-
written.set(CLIENT_FILES_PATH.slice(1), "the build lists there what each page’s client components need");
|
|
1413
|
+
written.set(CLIENT_FILES_PATH.slice(1), "the build lists there what each page loads beyond its payload");
|
|
1237
1414
|
if (plan.shells.length > 0) {
|
|
1238
1415
|
const fallbacks = fallbackShapes(tree).filter((shape) => plan.shells.some((shell) => shell.pattern === shape.pattern)).map((shape) => named(shape.file));
|
|
1239
1416
|
written.set("_redirects", `the shells of ${fallbacks.join(", ")} are reached through it — rules of your own go in public/_redirects, which the build adds to its own`);
|
|
@@ -1271,4 +1448,4 @@ const isFile = async (candidate) => {
|
|
|
1271
1448
|
return false;
|
|
1272
1449
|
}
|
|
1273
1450
|
};
|
|
1274
|
-
export {
|
|
1451
|
+
export { emitRegisterModule as A, SHELL_HEADER as C, decodePathname as D, FALLBACK_SEGMENT as E, fallbackShapes as F, parseRouteTree as I, restDirOf as L, unreachableRoutes as M, ROUTE_METHODS as N, LOCALES_MODULE as O, FRAMEWORK as P, slotOf as R, SERVER_STYLESHEETS_HEADER as S, readServerStylesheets as T, suppliedFrom as _, answersOf as a, NONCE_HEADER as b, dirFor as c, isParamSegment as d, patternsNeedingPaths as f, shadowedShells as g, routeFileRefusals as h, answeringPatterns as i, emitRoutesModule as j, ROUTES_DIR as k, fileAt as l, planRefusals as m, safeJoin as n, catchAllPath as o, planPaths as p, SITEMAP_PATHNAME as r, catchAllRefusals as s, isFile as t, isConcrete as u, CLIENT_DEPS_HEADER as v, readClientDeps as w, NOT_FOUND_HEADER as x, CLIENT_FILES_PATH as y };
|