@warlock.js/web 5.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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +125 -0
- package/esm/build/contribution.d.mts +55 -0
- package/esm/build/contribution.mjs +132 -0
- package/esm/build/contribution.mjs.map +1 -0
- package/esm/build/discover-pages.mjs +294 -0
- package/esm/build/discover-pages.mjs.map +1 -0
- package/esm/build/generate-client-registry.mjs +123 -0
- package/esm/build/generate-client-registry.mjs.map +1 -0
- package/esm/build/generate-pages-barrel.mjs +330 -0
- package/esm/build/generate-pages-barrel.mjs.map +1 -0
- package/esm/build/read-route-exports.mjs +212 -0
- package/esm/build/read-route-exports.mjs.map +1 -0
- package/esm/client/build-hydrated-tree.mjs +113 -0
- package/esm/client/build-hydrated-tree.mjs.map +1 -0
- package/esm/client/hydrate-page.mjs +73 -0
- package/esm/client/hydrate-page.mjs.map +1 -0
- package/esm/client/navigation/current-route.d.mts +91 -0
- package/esm/client/navigation/current-route.mjs +66 -0
- package/esm/client/navigation/current-route.mjs.map +1 -0
- package/esm/client/navigation/fetch-page-data.mjs +97 -0
- package/esm/client/navigation/fetch-page-data.mjs.map +1 -0
- package/esm/client/navigation/navigation-root.mjs +196 -0
- package/esm/client/navigation/navigation-root.mjs.map +1 -0
- package/esm/client/navigation/prefetch.mjs +110 -0
- package/esm/client/navigation/prefetch.mjs.map +1 -0
- package/esm/client/navigation/refresh.d.mts +40 -0
- package/esm/client/navigation/refresh.mjs +146 -0
- package/esm/client/navigation/refresh.mjs.map +1 -0
- package/esm/client/navigation/verbs.d.mts +55 -0
- package/esm/client/navigation/verbs.mjs +66 -0
- package/esm/client/navigation/verbs.mjs.map +1 -0
- package/esm/client/runtime/index.d.mts +4 -0
- package/esm/client/runtime/index.mjs +4 -0
- package/esm/client/runtime/manifest.d.mts +8 -0
- package/esm/client/runtime/manifest.mjs +77 -0
- package/esm/client/runtime/manifest.mjs.map +1 -0
- package/esm/client/runtime/matcher.d.mts +7 -0
- package/esm/client/runtime/matcher.mjs +169 -0
- package/esm/client/runtime/matcher.mjs.map +1 -0
- package/esm/client/runtime/types.d.mts +22 -0
- package/esm/components/default-app.mjs +32 -0
- package/esm/components/default-app.mjs.map +1 -0
- package/esm/components/document-context.d.mts +1 -0
- package/esm/components/document-context.mjs +24 -0
- package/esm/components/document-context.mjs.map +1 -0
- package/esm/components/head.d.mts +14 -0
- package/esm/components/head.mjs +63 -0
- package/esm/components/head.mjs.map +1 -0
- package/esm/components/link.d.mts +157 -0
- package/esm/components/link.mjs +194 -0
- package/esm/components/link.mjs.map +1 -0
- package/esm/components/scripts.d.mts +14 -0
- package/esm/components/scripts.mjs +21 -0
- package/esm/components/scripts.mjs.map +1 -0
- package/esm/connector/index.d.mts +6 -0
- package/esm/connector/index.mjs +7 -0
- package/esm/context.d.mts +107 -0
- package/esm/hydration/index.d.mts +1 -0
- package/esm/hydration/index.mjs +33 -0
- package/esm/hydration/index.mjs.map +1 -0
- package/esm/hydration-payload.d.mts +1 -0
- package/esm/hydration-payload.mjs +72 -0
- package/esm/hydration-payload.mjs.map +1 -0
- package/esm/index.d.mts +35 -0
- package/esm/index.mjs +12 -0
- package/esm/loaders.d.mts +47 -0
- package/esm/metadata.d.mts +54 -0
- package/esm/props.d.mts +42 -0
- package/esm/route.d.mts +30 -0
- package/esm/routing/compose-route-path.mjs +33 -0
- package/esm/routing/compose-route-path.mjs.map +1 -0
- package/esm/routing/data-request.mjs +52 -0
- package/esm/routing/data-request.mjs.map +1 -0
- package/esm/routing/layout-policy.mjs +78 -0
- package/esm/routing/layout-policy.mjs.map +1 -0
- package/esm/routing/navigator.mjs +21 -0
- package/esm/routing/navigator.mjs.map +1 -0
- package/esm/routing/query-string.d.mts +250 -0
- package/esm/routing/query-string.mjs +340 -0
- package/esm/routing/query-string.mjs.map +1 -0
- package/esm/routing/route-identity.mjs +68 -0
- package/esm/routing/route-identity.mjs.map +1 -0
- package/esm/routing/route-table.d.mts +34 -0
- package/esm/routing/route-table.mjs +182 -0
- package/esm/routing/route-table.mjs.map +1 -0
- package/esm/routing/router-events.d.mts +159 -0
- package/esm/routing/router-events.mjs +83 -0
- package/esm/routing/router-events.mjs.map +1 -0
- package/esm/server/buffered-response.mjs +115 -0
- package/esm/server/buffered-response.mjs.map +1 -0
- package/esm/server/build-hydration-payload.mjs +27 -0
- package/esm/server/build-hydration-payload.mjs.map +1 -0
- package/esm/server/client-asset-url-prefix.d.mts +22 -0
- package/esm/server/client-asset-url-prefix.mjs +23 -0
- package/esm/server/client-asset-url-prefix.mjs.map +1 -0
- package/esm/server/create-page-module-loader.mjs +49 -0
- package/esm/server/create-page-module-loader.mjs.map +1 -0
- package/esm/server/create-page-route-handler.mjs +107 -0
- package/esm/server/create-page-route-handler.mjs.map +1 -0
- package/esm/server/dev-server.mjs +167 -0
- package/esm/server/dev-server.mjs.map +1 -0
- package/esm/server/execute-page-request.d.mts +1 -0
- package/esm/server/execute-page-request.mjs +166 -0
- package/esm/server/execute-page-request.mjs.map +1 -0
- package/esm/server/execute-page-request.types.d.mts +1 -0
- package/esm/server/hydration-client-url.d.mts +37 -0
- package/esm/server/hydration-client-url.mjs +101 -0
- package/esm/server/hydration-client-url.mjs.map +1 -0
- package/esm/server/index.mjs +13 -0
- package/esm/server/install-page-routes-from-manifest.mjs +133 -0
- package/esm/server/install-page-routes-from-manifest.mjs.map +1 -0
- package/esm/server/install-page-routes.d.mts +1 -0
- package/esm/server/install-page-routes.mjs +6 -0
- package/esm/server/install-production-page-routes.mjs +55 -0
- package/esm/server/install-production-page-routes.mjs.map +1 -0
- package/esm/server/match-page-route.mjs +48 -0
- package/esm/server/match-page-route.mjs.map +1 -0
- package/esm/server/page-context.d.mts +1 -0
- package/esm/server/page-context.mjs +33 -0
- package/esm/server/page-context.mjs.map +1 -0
- package/esm/server/page-manifest.d.mts +102 -0
- package/esm/server/page-manifest.mjs +31 -0
- package/esm/server/page-manifest.mjs.map +1 -0
- package/esm/server/render-page.mjs +214 -0
- package/esm/server/render-page.mjs.map +1 -0
- package/esm/server/resolve-page-metadata.mjs +33 -0
- package/esm/server/resolve-page-metadata.mjs.map +1 -0
- package/esm/server/resolve-validation-data.mjs +27 -0
- package/esm/server/resolve-validation-data.mjs.map +1 -0
- package/esm/server/settle-page-response.d.mts +1 -0
- package/esm/server/settle-page-response.mjs +90 -0
- package/esm/server/settle-page-response.mjs.map +1 -0
- package/esm/server/stylesheet-urls.mjs +65 -0
- package/esm/server/stylesheet-urls.mjs.map +1 -0
- package/esm/server/web-connector-factory.d.mts +25 -0
- package/esm/server/web-connector-factory.mjs +121 -0
- package/esm/server/web-connector-factory.mjs.map +1 -0
- package/esm/server/web-connector.d.mts +34 -0
- package/esm/server/web-connector.mjs +516 -0
- package/esm/server/web-connector.mjs.map +1 -0
- package/esm/shared.d.mts +22 -0
- package/esm/shared.mjs +223 -0
- package/esm/shared.mjs.map +1 -0
- package/esm/validation.d.mts +31 -0
- package/esm/vite/app-convention-aliases.mjs +43 -0
- package/esm/vite/app-convention-aliases.mjs.map +1 -0
- package/esm/vite/build-client.d.mts +38 -0
- package/esm/vite/build-client.mjs +72 -0
- package/esm/vite/build-client.mjs.map +1 -0
- package/esm/vite/gate-a-resolve.d.mts +57 -0
- package/esm/vite/gate-a-resolve.mjs +834 -0
- package/esm/vite/gate-a-resolve.mjs.map +1 -0
- package/esm/vite/gate-b-secrets.d.mts +57 -0
- package/esm/vite/gate-b-secrets.mjs +299 -0
- package/esm/vite/gate-b-secrets.mjs.map +1 -0
- package/esm/vite/gate-c-verify.d.mts +118 -0
- package/esm/vite/gate-c-verify.mjs +263 -0
- package/esm/vite/gate-c-verify.mjs.map +1 -0
- package/esm/vite/hydration-entries.d.mts +17 -0
- package/esm/vite/hydration-entries.mjs +45 -0
- package/esm/vite/hydration-entries.mjs.map +1 -0
- package/esm/vite/index.d.mts +126 -0
- package/esm/vite/index.mjs +146 -0
- package/esm/vite/index.mjs.map +1 -0
- package/esm/vite/page-registry-plugin.d.mts +43 -0
- package/esm/vite/page-registry-plugin.mjs +138 -0
- package/esm/vite/page-registry-plugin.mjs.map +1 -0
- package/esm/vite/projection.d.mts +31 -0
- package/esm/vite/projection.mjs +384 -0
- package/esm/vite/projection.mjs.map +1 -0
- package/llms-full.txt +1041 -0
- package/llms.txt +21 -0
- package/package.json +77 -0
- package/skills/add-web-to-an-app/SKILL.md +103 -0
- package/skills/create-a-page/SKILL.md +141 -0
- package/skills/load-page-data/SKILL.md +183 -0
- package/skills/navigate-on-the-client/SKILL.md +182 -0
- package/skills/serve-styles/SKILL.md +145 -0
- package/skills/use-layouts/SKILL.md +121 -0
- package/skills/write-the-root/SKILL.md +131 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { composeRoutePath } from "../routing/compose-route-path.mjs";
|
|
2
|
+
import { NestedLayoutsNotSupportedError, selectPageLayout } from "../routing/layout-policy.mjs";
|
|
3
|
+
import { deriveFallbackRouteName } from "../routing/route-identity.mjs";
|
|
4
|
+
import { NonLiteralRouteExportError, readRouteExports } from "./read-route-exports.mjs";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { parse } from "@babel/parser";
|
|
8
|
+
|
|
9
|
+
//#region ../web/src/build/discover-pages.ts
|
|
10
|
+
/**
|
|
11
|
+
* Static discovery of the application's page graph — the ONE scan every
|
|
12
|
+
* provider shares.
|
|
13
|
+
*
|
|
14
|
+
* This module has a single responsibility: look at the filesystem and produce
|
|
15
|
+
* the recipe. It writes nothing, knows nothing about the generated barrel, and
|
|
16
|
+
* imports neither Vite nor a single application module. Everything that turns
|
|
17
|
+
* the recipe into an artefact (the production barrel, the dev plugin, the
|
|
18
|
+
* generated client entry) lives with that artefact and consumes
|
|
19
|
+
* {@link discoverPages}.
|
|
20
|
+
*
|
|
21
|
+
* The reason it is one module rather than one function per consumer: two
|
|
22
|
+
* scanners that agree today drift tomorrow, and a page that exists for the
|
|
23
|
+
* server but not the client is the silent failure that costs a day to find.
|
|
24
|
+
* Sharing the scan makes that disagreement impossible by construction instead
|
|
25
|
+
* of catchable by test.
|
|
26
|
+
*
|
|
27
|
+
* "Static" means WITHOUT RUNNING THE APPLICATION — this module globs
|
|
28
|
+
* `*.page.tsx`, `layout.tsx` and `root.tsx`, and reads each page's declared
|
|
29
|
+
* `route` and each layout's declared `prefix` by PARSING the source
|
|
30
|
+
* ({@link readRouteExports}). It still imports no application module.
|
|
31
|
+
*
|
|
32
|
+
* The route a page is served under is the one the page DECLARES, not the one
|
|
33
|
+
* its directory suggests, so that is the route discovery reports. The
|
|
34
|
+
* composition — EVERY layout `prefix` on the page's path, outermost first, plus
|
|
35
|
+
* the page's own `route` path — and the fallback used when a route omits its
|
|
36
|
+
* name are mirrored from the server's installer (`installPageRoutes`),
|
|
37
|
+
* deliberately and in one direction: build and boot agree because one of them
|
|
38
|
+
* copies the other, not because two conventions were written to match.
|
|
39
|
+
*
|
|
40
|
+
* Discovery also CLASSIFIES each layout — does its module have a default
|
|
41
|
+
* export, does it export `middleware` — because the layout policy
|
|
42
|
+
* ({@link "../routing/layout-policy.ts"}) owns the rule but may not touch a
|
|
43
|
+
* filesystem to learn the facts the rule needs. That classification is another
|
|
44
|
+
* parse, never an import: a layout is read exactly the way a page's `route` is.
|
|
45
|
+
*/
|
|
46
|
+
/** Raised when two pages claim one route name. */
|
|
47
|
+
var DuplicatePageRouteNameError = class extends Error {
|
|
48
|
+
routeName;
|
|
49
|
+
firstFile;
|
|
50
|
+
secondFile;
|
|
51
|
+
constructor(routeName, firstFile, secondFile) {
|
|
52
|
+
super(`Two pages resolve to the same route name "${routeName}": "${firstFile}" and "${secondFile}". A route name identifies exactly one page, so the second page would be unreachable. To fix: rename one of the files, or move it so its directory gives it a different route name.`);
|
|
53
|
+
this.routeName = routeName;
|
|
54
|
+
this.firstFile = firstFile;
|
|
55
|
+
this.secondFile = secondFile;
|
|
56
|
+
this.name = "DuplicatePageRouteNameError";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function toPosix(value) {
|
|
60
|
+
return value.replace(/\\/g, "/");
|
|
61
|
+
}
|
|
62
|
+
function isDirectory(candidate) {
|
|
63
|
+
try {
|
|
64
|
+
return fs.statSync(candidate).isDirectory();
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function isFile(candidate) {
|
|
70
|
+
try {
|
|
71
|
+
return fs.statSync(candidate).isFile();
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The two page roots: the global `src/web/**` tree and each
|
|
78
|
+
* module's `src/app/<module>/web/**` tree. Both are optional; a project with
|
|
79
|
+
* neither has zero pages, which is a legal empty state.
|
|
80
|
+
*/
|
|
81
|
+
function discoverWebRoots(srcRoot) {
|
|
82
|
+
const roots = [];
|
|
83
|
+
const globalRoot = path.join(srcRoot, "web");
|
|
84
|
+
if (isDirectory(globalRoot)) roots.push(globalRoot);
|
|
85
|
+
const appDir = path.join(srcRoot, "app");
|
|
86
|
+
if (isDirectory(appDir)) for (const entry of fs.readdirSync(appDir, { withFileTypes: true }).sort(byName)) {
|
|
87
|
+
if (!entry.isDirectory()) continue;
|
|
88
|
+
const moduleWebRoot = path.join(appDir, entry.name, "web");
|
|
89
|
+
if (isDirectory(moduleWebRoot)) roots.push(moduleWebRoot);
|
|
90
|
+
}
|
|
91
|
+
return roots;
|
|
92
|
+
}
|
|
93
|
+
function byName(left, right) {
|
|
94
|
+
return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;
|
|
95
|
+
}
|
|
96
|
+
/** Every file under `dir` (recursive) whose name matches `predicate`. */
|
|
97
|
+
function walkFiles(dir, predicate) {
|
|
98
|
+
const found = [];
|
|
99
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort(byName)) {
|
|
100
|
+
const full = path.join(dir, entry.name);
|
|
101
|
+
if (entry.isDirectory()) found.push(...walkFiles(full, predicate));
|
|
102
|
+
else if (entry.isFile() && predicate(entry.name)) found.push(full);
|
|
103
|
+
}
|
|
104
|
+
return found;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A page's layout chain: every `layout.tsx` in the directories from its web
|
|
108
|
+
* root down to its own directory, OUTERMOST FIRST.
|
|
109
|
+
*
|
|
110
|
+
* Dev's installer reads only the nearest layout today, because its page module
|
|
111
|
+
* triple holds a single layout; the recipe carries the whole chain so the
|
|
112
|
+
* runtime side can compose
|
|
113
|
+
* nested layouts without a second discovery pass. The nearest layout is always
|
|
114
|
+
* the LAST element, so a consumer that still wants dev's one-layout behaviour
|
|
115
|
+
* reads `layouts.at(-1)`.
|
|
116
|
+
*/
|
|
117
|
+
function layoutChainFor(pageFile, webRoot) {
|
|
118
|
+
const chain = [];
|
|
119
|
+
const relativeDir = path.relative(webRoot, path.dirname(pageFile));
|
|
120
|
+
const segments = relativeDir === "" ? [] : relativeDir.split(path.sep);
|
|
121
|
+
let current = webRoot;
|
|
122
|
+
for (let index = 0; index <= segments.length; index++) {
|
|
123
|
+
if (index > 0) current = path.join(current, segments[index - 1]);
|
|
124
|
+
const candidate = path.join(current, "layout.tsx");
|
|
125
|
+
if (isFile(candidate)) chain.push(candidate);
|
|
126
|
+
}
|
|
127
|
+
return chain;
|
|
128
|
+
}
|
|
129
|
+
function compareStrings(left, right) {
|
|
130
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The total order every consumer sees, and the reason discovery returns an
|
|
134
|
+
* array rather than a set: the page's SOURCE FILE PATH, lexicographic, POSIX.
|
|
135
|
+
*
|
|
136
|
+
* Serialization order only; matching precedence is a property of the route
|
|
137
|
+
* grammar, not of this array.
|
|
138
|
+
*
|
|
139
|
+
* The file path rather than the route path, now that the route is the declared
|
|
140
|
+
* one: a page's route can be rewritten by editing one line, which would reorder
|
|
141
|
+
* an artefact that has not otherwise changed, while the file it lives in is the
|
|
142
|
+
* stable identity the artefact is built from. It also carries no suggestion of
|
|
143
|
+
* precedence — nobody reads "sorted by file name" as "most specific first",
|
|
144
|
+
* which is the misreading a route-path order invites.
|
|
145
|
+
*
|
|
146
|
+
* Lexicographic because it is byte-comparable output across every provider,
|
|
147
|
+
* which keeps diffs stable and keeps filesystem enumeration order out of the
|
|
148
|
+
* artefact: two machines that list a directory differently must still produce
|
|
149
|
+
* byte-identical output, or a build is only reproducible by luck.
|
|
150
|
+
*/
|
|
151
|
+
function comparePages(left, right) {
|
|
152
|
+
return compareStrings(toPosix(left.pageFile), toPosix(right.pageFile));
|
|
153
|
+
}
|
|
154
|
+
function assertUniqueRouteNames(pages, appRoot) {
|
|
155
|
+
const fileByRouteName = /* @__PURE__ */ new Map();
|
|
156
|
+
for (const page of pages) {
|
|
157
|
+
const existing = fileByRouteName.get(page.routeName);
|
|
158
|
+
const relative = toPosix(path.relative(appRoot, page.pageFile));
|
|
159
|
+
if (existing !== void 0) throw new DuplicatePageRouteNameError(page.routeName, existing, relative);
|
|
160
|
+
fileByRouteName.set(page.routeName, relative);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Raised when a `*.page.tsx` declares no `route` export. */
|
|
164
|
+
var MissingRouteExportError = class extends Error {
|
|
165
|
+
pageFile;
|
|
166
|
+
constructor(pageFile) {
|
|
167
|
+
super(`"${pageFile}" is a page file but declares no \`route\` export. A page with no route is a page the dev server would still serve and production would 404 on, so the build refuses it instead. For example: export const route = "/list";`);
|
|
168
|
+
this.pageFile = pageFile;
|
|
169
|
+
this.name = "MissingRouteExportError";
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* The declared exports of one file, or a thrown
|
|
174
|
+
* {@link NonLiteralRouteExportError} when they cannot be read without running
|
|
175
|
+
* the application. Layouts are read once per run and remembered: a layout is
|
|
176
|
+
* the nearest one for every page beside it, and parsing it once per page would
|
|
177
|
+
* be the same answer bought repeatedly.
|
|
178
|
+
*/
|
|
179
|
+
function readDeclarations(sourceFile, cache) {
|
|
180
|
+
let result = cache.get(sourceFile);
|
|
181
|
+
if (result === void 0) {
|
|
182
|
+
result = readRouteExports(sourceFile);
|
|
183
|
+
cache.set(sourceFile, result);
|
|
184
|
+
}
|
|
185
|
+
if (!result.ok) throw new NonLiteralRouteExportError(result.rejection);
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Parses one layout and reports its shape. Remembered per run for the same
|
|
190
|
+
* reason declarations are: a layout is on the path of every page beneath it.
|
|
191
|
+
*/
|
|
192
|
+
function readLayoutShape(layoutFile, cache) {
|
|
193
|
+
const cached = cache.get(layoutFile);
|
|
194
|
+
if (cached !== void 0) return cached;
|
|
195
|
+
const source = fs.readFileSync(layoutFile, "utf-8");
|
|
196
|
+
let program;
|
|
197
|
+
try {
|
|
198
|
+
program = parse(source, {
|
|
199
|
+
sourceType: "module",
|
|
200
|
+
plugins: ["typescript", "jsx"],
|
|
201
|
+
errorRecovery: false
|
|
202
|
+
}).program;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new Error(`Cannot read the exports of "${layoutFile}": the file could not be parsed (${error.message}). Fix the syntax error and the build will continue.`);
|
|
205
|
+
}
|
|
206
|
+
const shape = {
|
|
207
|
+
renders: false,
|
|
208
|
+
hasMiddleware: false
|
|
209
|
+
};
|
|
210
|
+
for (const statement of program.body) {
|
|
211
|
+
if (statement.type === "ExportDefaultDeclaration") {
|
|
212
|
+
shape.renders = true;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (statement.type === "ExportAllDeclaration") {
|
|
216
|
+
shape.hasMiddleware = true;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
|
|
220
|
+
for (const specifier of statement.specifiers) {
|
|
221
|
+
if (specifier.type !== "ExportSpecifier" || specifier.exportKind === "type") continue;
|
|
222
|
+
const exported = specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value;
|
|
223
|
+
if (exported === "default") shape.renders = true;
|
|
224
|
+
if (exported === "middleware") shape.hasMiddleware = true;
|
|
225
|
+
}
|
|
226
|
+
const { declaration } = statement;
|
|
227
|
+
if (declaration === null || declaration === void 0) continue;
|
|
228
|
+
if (declaration.type === "VariableDeclaration") {
|
|
229
|
+
for (const declarator of declaration.declarations) if (declarator.id.type === "Identifier" && declarator.id.name === "middleware") shape.hasMiddleware = true;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if ((declaration.type === "FunctionDeclaration" || declaration.type === "ClassDeclaration") && declaration.id?.name === "middleware") shape.hasMiddleware = true;
|
|
233
|
+
}
|
|
234
|
+
cache.set(layoutFile, shape);
|
|
235
|
+
return shape;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Scans both web roots and returns the pages in a defined total order.
|
|
239
|
+
*
|
|
240
|
+
* Zero pages is a legal result, not an error: a project may be configured
|
|
241
|
+
* with web and have nothing to serve yet. What is an error is a `*.page.tsx`
|
|
242
|
+
* with no `route` export, which is refused rather than silently omitted — an
|
|
243
|
+
* artefact that leaves a page out is a page the dev server still serves and
|
|
244
|
+
* production 404s on; two pages claiming one route name, which this refuses
|
|
245
|
+
* to return at all — the alternative is an artefact in which one of them is
|
|
246
|
+
* silently unreachable; a `route` or `prefix` that cannot be read without
|
|
247
|
+
* running the application, which is refused before any page is reported at
|
|
248
|
+
* all; and a page whose layout chain holds more than one RENDERING layout, which
|
|
249
|
+
* the production installer would refuse anyway — discovery refuses it first so
|
|
250
|
+
* that artefact is never produced.
|
|
251
|
+
*/
|
|
252
|
+
function discoverPages(options) {
|
|
253
|
+
const { appRoot } = options;
|
|
254
|
+
const srcRoot = path.join(appRoot, options.srcDir ?? "src");
|
|
255
|
+
const webRoots = discoverWebRoots(srcRoot);
|
|
256
|
+
const appFile = path.join(srcRoot, "web", "root.tsx");
|
|
257
|
+
const hasAppFile = isFile(appFile);
|
|
258
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
259
|
+
const layoutShapes = /* @__PURE__ */ new Map();
|
|
260
|
+
const relativeToApp = (file) => toPosix(path.relative(appRoot, file));
|
|
261
|
+
const pages = [];
|
|
262
|
+
for (const webRoot of webRoots) for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(".page.tsx"))) {
|
|
263
|
+
const { route } = readDeclarations(pageFile, declarations);
|
|
264
|
+
if (route === void 0) throw new MissingRouteExportError(relativeToApp(pageFile));
|
|
265
|
+
const layouts = layoutChainFor(pageFile, webRoot);
|
|
266
|
+
const shapes = layouts.map((layoutFile) => readLayoutShape(layoutFile, layoutShapes));
|
|
267
|
+
const selection = selectPageLayout(layouts.map((layout, index) => ({
|
|
268
|
+
layout,
|
|
269
|
+
renders: shapes[index].renders
|
|
270
|
+
})));
|
|
271
|
+
if (selection.type === "rejected") throw new NestedLayoutsNotSupportedError(relativeToApp(pageFile), selection.layouts.map(relativeToApp));
|
|
272
|
+
const middlewareLayouts = layouts.filter((_, index) => shapes[index].hasMiddleware);
|
|
273
|
+
const layoutPrefix = layouts.reduce((composed, layoutFile) => composeRoutePath(composed, readDeclarations(layoutFile, declarations).prefix ?? "/"), "/");
|
|
274
|
+
pages.push({
|
|
275
|
+
routeName: route.name ?? deriveFallbackRouteName({
|
|
276
|
+
routePath: route.path,
|
|
277
|
+
sourceFile: relativeToApp(pageFile)
|
|
278
|
+
}),
|
|
279
|
+
routePath: composeRoutePath(layoutPrefix, route.path),
|
|
280
|
+
pageFile,
|
|
281
|
+
webRoot,
|
|
282
|
+
layouts,
|
|
283
|
+
middlewareLayouts,
|
|
284
|
+
...hasAppFile ? { appFile } : {}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
pages.sort(comparePages);
|
|
288
|
+
assertUniqueRouteNames(pages, appRoot);
|
|
289
|
+
return pages;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
//#endregion
|
|
293
|
+
export { DuplicatePageRouteNameError, discoverPages, discoverWebRoots, isFile, layoutChainFor, toPosix, walkFiles };
|
|
294
|
+
//# sourceMappingURL=discover-pages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-pages.mjs","names":[],"sources":["../../../../../../../web/src/build/discover-pages.ts"],"sourcesContent":["/**\n * Static discovery of the application's page graph — the ONE scan every\n * provider shares.\n *\n * This module has a single responsibility: look at the filesystem and produce\n * the recipe. It writes nothing, knows nothing about the generated barrel, and\n * imports neither Vite nor a single application module. Everything that turns\n * the recipe into an artefact (the production barrel, the dev plugin, the\n * generated client entry) lives with that artefact and consumes\n * {@link discoverPages}.\n *\n * The reason it is one module rather than one function per consumer: two\n * scanners that agree today drift tomorrow, and a page that exists for the\n * server but not the client is the silent failure that costs a day to find.\n * Sharing the scan makes that disagreement impossible by construction instead\n * of catchable by test.\n *\n * \"Static\" means WITHOUT RUNNING THE APPLICATION — this module globs\n * `*.page.tsx`, `layout.tsx` and `root.tsx`, and reads each page's declared\n * `route` and each layout's declared `prefix` by PARSING the source\n * ({@link readRouteExports}). It still imports no application module.\n *\n * The route a page is served under is the one the page DECLARES, not the one\n * its directory suggests, so that is the route discovery reports. The\n * composition — EVERY layout `prefix` on the page's path, outermost first, plus\n * the page's own `route` path — and the fallback used when a route omits its\n * name are mirrored from the server's installer (`installPageRoutes`),\n * deliberately and in one direction: build and boot agree because one of them\n * copies the other, not because two conventions were written to match.\n *\n * Discovery also CLASSIFIES each layout — does its module have a default\n * export, does it export `middleware` — because the layout policy\n * ({@link \"../routing/layout-policy.ts\"}) owns the rule but may not touch a\n * filesystem to learn the facts the rule needs. That classification is another\n * parse, never an import: a layout is read exactly the way a page's `route` is.\n */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { parse } from \"@babel/parser\";\nimport { composeRoutePath } from \"../routing/compose-route-path\";\nimport { NestedLayoutsNotSupportedError, selectPageLayout } from \"../routing/layout-policy\";\nimport { deriveFallbackRouteName } from \"../routing/route-identity\";\nimport type { RouteExportsReadResult } from \"./read-route-exports\";\nimport { NonLiteralRouteExportError, readRouteExports } from \"./read-route-exports\";\n\nexport type DiscoverPagesOptions = {\n /** Absolute path to the application root (where `package.json` lives). */\n appRoot: string;\n /** Source directory name under `appRoot`; defaults to `\"src\"`. */\n srcDir?: string;\n};\n\nexport type DiscoveredPage = {\n /**\n * The page's route name: the `name` its `route` export declares, or the\n * server's own fallback derivation — `<module>.<declared path with dots>` for\n * a page in a module's web tree, the dotted path alone for one in the global\n * tree, and `index` when neither has anything to say.\n *\n * Unique across the whole graph — {@link discoverPages} refuses to return a\n * result where it is not.\n */\n routeName: string;\n /**\n * The page's EFFECTIVE route path: the declared `prefix` of EVERY layout on\n * its path — outermost first, wherever in the ancestry each lives — composed\n * in order with the page's own declared `route` path, which is the path the\n * server registers it under. A layout that declares no `prefix` contributes\n * nothing. Always `/`-prefixed.\n *\n * Every layout, not just the rendering one: a `prefix`-only layout is a real\n * segment of the URL its subtree lives under, and skipping it would serve the\n * subtree from a path nobody wrote down.\n */\n routePath: string;\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root this page was found under — the root its layout chain climbs to. */\n webRoot: string;\n /** Absolute paths of every `layout.tsx` from the web root down to the page's own directory, OUTERMOST FIRST. */\n layouts: string[];\n /**\n * The page's middleware chain: the subset of {@link layouts} whose modules\n * export `middleware`, OUTERMOST FIRST — the order they must run in.\n *\n * Source files rather than the middleware values themselves, because\n * discovery never runs application code: this says WHICH layouts contribute a\n * guard, and the consumer that already loads those modules reads the values\n * off them.\n *\n * Empty when no layout on the path declares middleware, which is the common\n * case; a page with no layouts always has an empty chain.\n */\n middlewareLayouts: string[];\n /** Absolute path to the global `root.tsx` every page renders inside, when it exists. */\n appFile?: string;\n};\n\n/** Raised when two pages claim one route name. */\nexport class DuplicatePageRouteNameError extends Error {\n public constructor(\n public readonly routeName: string,\n public readonly firstFile: string,\n public readonly secondFile: string,\n ) {\n super(\n `Two pages resolve to the same route name \"${routeName}\": \"${firstFile}\" and ` +\n `\"${secondFile}\". A route name identifies exactly one page, so the second ` +\n \"page would be unreachable. To fix: rename one of the files, or move it so \" +\n \"its directory gives it a different route name.\",\n );\n this.name = \"DuplicatePageRouteNameError\";\n }\n}\n\nexport function toPosix(value: string): string {\n return value.replace(/\\\\/g, \"/\");\n}\n\nfunction isDirectory(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isDirectory();\n } catch {\n return false;\n }\n}\n\nexport function isFile(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * The two page roots: the global `src/web/**` tree and each\n * module's `src/app/<module>/web/**` tree. Both are optional; a project with\n * neither has zero pages, which is a legal empty state.\n */\nexport function discoverWebRoots(srcRoot: string): string[] {\n const roots: string[] = [];\n const globalRoot = path.join(srcRoot, \"web\");\n\n if (isDirectory(globalRoot)) {\n roots.push(globalRoot);\n }\n\n const appDir = path.join(srcRoot, \"app\");\n\n if (isDirectory(appDir)) {\n for (const entry of fs.readdirSync(appDir, { withFileTypes: true }).sort(byName)) {\n if (!entry.isDirectory()) continue;\n\n const moduleWebRoot = path.join(appDir, entry.name, \"web\");\n\n if (isDirectory(moduleWebRoot)) {\n roots.push(moduleWebRoot);\n }\n }\n }\n\n return roots;\n}\n\nfunction byName(left: { name: string }, right: { name: string }): number {\n return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;\n}\n\nexport type DiscoveredPageFile = {\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root ({@link discoverWebRoots}) this page was found under. */\n webRoot: string;\n};\n\n/**\n * The subject list: every `*.page.tsx` under BOTH web roots, one call for the\n * whole graph.\n *\n * Unlike {@link discoverPages}, this reads no `route` or `prefix` export and\n * throws on nothing — it answers only \"which page files exist\", so a provider\n * that still resolves a page's route by its own means (dev's\n * `ssrLoadModule`-driven installer, chiefly) can share the walk without\n * inheriting the static-parsing refusals that answering \"what route is this\"\n * requires.\n */\nexport function discoverPageFiles(srcRoot: string): DiscoveredPageFile[] {\n const found: DiscoveredPageFile[] = [];\n\n for (const webRoot of discoverWebRoots(srcRoot)) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n found.push({ pageFile, webRoot });\n }\n }\n\n return found;\n}\n\n/** Every file under `dir` (recursive) whose name matches `predicate`. */\nexport function walkFiles(dir: string, predicate: (fileName: string) => boolean): string[] {\n const found: string[] = [];\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort(byName)) {\n const full = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n found.push(...walkFiles(full, predicate));\n } else if (entry.isFile() && predicate(entry.name)) {\n found.push(full);\n }\n }\n\n return found;\n}\n\n/**\n * A page's layout chain: every `layout.tsx` in the directories from its web\n * root down to its own directory, OUTERMOST FIRST.\n *\n * Dev's installer reads only the nearest layout today, because its page module\n * triple holds a single layout; the recipe carries the whole chain so the\n * runtime side can compose\n * nested layouts without a second discovery pass. The nearest layout is always\n * the LAST element, so a consumer that still wants dev's one-layout behaviour\n * reads `layouts.at(-1)`.\n */\nexport function layoutChainFor(pageFile: string, webRoot: string): string[] {\n const chain: string[] = [];\n const relativeDir = path.relative(webRoot, path.dirname(pageFile));\n const segments = relativeDir === \"\" ? [] : relativeDir.split(path.sep);\n\n let current = webRoot;\n\n for (let index = 0; index <= segments.length; index++) {\n if (index > 0) {\n current = path.join(current, segments[index - 1]);\n }\n\n const candidate = path.join(current, \"layout.tsx\");\n\n if (isFile(candidate)) {\n chain.push(candidate);\n }\n }\n\n return chain;\n}\n\nfunction compareStrings(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\n/**\n * The total order every consumer sees, and the reason discovery returns an\n * array rather than a set: the page's SOURCE FILE PATH, lexicographic, POSIX.\n *\n * Serialization order only; matching precedence is a property of the route\n * grammar, not of this array.\n *\n * The file path rather than the route path, now that the route is the declared\n * one: a page's route can be rewritten by editing one line, which would reorder\n * an artefact that has not otherwise changed, while the file it lives in is the\n * stable identity the artefact is built from. It also carries no suggestion of\n * precedence — nobody reads \"sorted by file name\" as \"most specific first\",\n * which is the misreading a route-path order invites.\n *\n * Lexicographic because it is byte-comparable output across every provider,\n * which keeps diffs stable and keeps filesystem enumeration order out of the\n * artefact: two machines that list a directory differently must still produce\n * byte-identical output, or a build is only reproducible by luck.\n */\nfunction comparePages(left: DiscoveredPage, right: DiscoveredPage): number {\n return compareStrings(toPosix(left.pageFile), toPosix(right.pageFile));\n}\n\nfunction assertUniqueRouteNames(pages: readonly DiscoveredPage[], appRoot: string): void {\n const fileByRouteName = new Map<string, string>();\n\n for (const page of pages) {\n const existing = fileByRouteName.get(page.routeName);\n const relative = toPosix(path.relative(appRoot, page.pageFile));\n\n if (existing !== undefined) {\n throw new DuplicatePageRouteNameError(page.routeName, existing, relative);\n }\n\n fileByRouteName.set(page.routeName, relative);\n }\n}\n\n/** Raised when a `*.page.tsx` declares no `route` export. */\nexport class MissingRouteExportError extends Error {\n public constructor(public readonly pageFile: string) {\n super(\n `\"${pageFile}\" is a page file but declares no \\`route\\` export. A page with no route is a ` +\n \"page the dev server would still serve and production would 404 on, so the build refuses \" +\n `it instead. For example: export const route = \"/list\";`,\n );\n this.name = \"MissingRouteExportError\";\n }\n}\n\n/**\n * The declared exports of one file, or a thrown\n * {@link NonLiteralRouteExportError} when they cannot be read without running\n * the application. Layouts are read once per run and remembered: a layout is\n * the nearest one for every page beside it, and parsing it once per page would\n * be the same answer bought repeatedly.\n */\nfunction readDeclarations(sourceFile: string, cache: Map<string, RouteExportsReadResult>) {\n let result = cache.get(sourceFile);\n\n if (result === undefined) {\n result = readRouteExports(sourceFile);\n cache.set(sourceFile, result);\n }\n\n if (!result.ok) {\n throw new NonLiteralRouteExportError(result.rejection);\n }\n\n return result;\n}\n\n/**\n * What a layout DOES, read by parsing it — the facts the layout policy's rule\n * needs and, being a pure module, cannot go and find for itself.\n */\ntype LayoutShape = {\n /**\n * Whether the module has a default export — the export that puts an element\n * in the document, and therefore the one thing that makes a layout count\n * against the single-rendering-layout rule.\n */\n renders: boolean;\n /** Whether the module exports `middleware`, or might via a re-export this cannot see through. */\n hasMiddleware: boolean;\n};\n\n/**\n * Parses one layout and reports its shape. Remembered per run for the same\n * reason declarations are: a layout is on the path of every page beneath it.\n */\nfunction readLayoutShape(layoutFile: string, cache: Map<string, LayoutShape>): LayoutShape {\n const cached = cache.get(layoutFile);\n\n if (cached !== undefined) return cached;\n\n const source = fs.readFileSync(layoutFile, \"utf-8\");\n let program: ReturnType<typeof parse>[\"program\"];\n\n try {\n program = parse(source, {\n sourceType: \"module\",\n // Every file this reads is a layout, i.e. `.tsx`.\n plugins: [\"typescript\", \"jsx\"],\n errorRecovery: false,\n }).program;\n } catch (error) {\n throw new Error(\n `Cannot read the exports of \"${layoutFile}\": the file could not be parsed ` +\n `(${(error as Error).message}). Fix the syntax error and the build will continue.`,\n );\n }\n\n const shape: LayoutShape = { renders: false, hasMiddleware: false };\n\n for (const statement of program.body) {\n if (statement.type === \"ExportDefaultDeclaration\") {\n shape.renders = true;\n continue;\n }\n\n // `export * from \"./guard\"` cannot re-export a default — the language\n // excludes it — but it CAN contribute `middleware`, and no parse can see\n // through it without resolving and reading another module. Reading it as\n // \"no middleware here\" is exactly the silent unguarding this slice exists\n // to prevent, so it is read as \"possibly\" and fails loudly downstream.\n if (statement.type === \"ExportAllDeclaration\") {\n shape.hasMiddleware = true;\n continue;\n }\n\n if (statement.type !== \"ExportNamedDeclaration\" || statement.exportKind === \"type\") continue;\n\n for (const specifier of statement.specifiers) {\n if (specifier.type !== \"ExportSpecifier\" || specifier.exportKind === \"type\") continue;\n\n const exported =\n specifier.exported.type === \"Identifier\"\n ? specifier.exported.name\n : specifier.exported.value;\n\n if (exported === \"default\") shape.renders = true;\n if (exported === \"middleware\") shape.hasMiddleware = true;\n }\n\n const { declaration } = statement;\n\n if (declaration === null || declaration === undefined) continue;\n\n if (declaration.type === \"VariableDeclaration\") {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === \"Identifier\" && declarator.id.name === \"middleware\") {\n shape.hasMiddleware = true;\n }\n }\n\n continue;\n }\n\n if (\n (declaration.type === \"FunctionDeclaration\" || declaration.type === \"ClassDeclaration\") &&\n declaration.id?.name === \"middleware\"\n ) {\n shape.hasMiddleware = true;\n }\n }\n\n cache.set(layoutFile, shape);\n\n return shape;\n}\n\n/**\n * Scans both web roots and returns the pages in a defined total order.\n *\n * Zero pages is a legal result, not an error: a project may be configured\n * with web and have nothing to serve yet. What is an error is a `*.page.tsx`\n * with no `route` export, which is refused rather than silently omitted — an\n * artefact that leaves a page out is a page the dev server still serves and\n * production 404s on; two pages claiming one route name, which this refuses\n * to return at all — the alternative is an artefact in which one of them is\n * silently unreachable; a `route` or `prefix` that cannot be read without\n * running the application, which is refused before any page is reported at\n * all; and a page whose layout chain holds more than one RENDERING layout, which\n * the production installer would refuse anyway — discovery refuses it first so\n * that artefact is never produced.\n */\nexport function discoverPages(options: DiscoverPagesOptions): DiscoveredPage[] {\n const { appRoot } = options;\n const srcRoot = path.join(appRoot, options.srcDir ?? \"src\");\n const webRoots = discoverWebRoots(srcRoot);\n const appFile = path.join(srcRoot, \"web\", \"root.tsx\");\n const hasAppFile = isFile(appFile);\n const declarations = new Map<string, RouteExportsReadResult>();\n const layoutShapes = new Map<string, LayoutShape>();\n const relativeToApp = (file: string) => toPosix(path.relative(appRoot, file));\n\n const pages: DiscoveredPage[] = [];\n\n for (const webRoot of webRoots) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n const { route } = readDeclarations(pageFile, declarations);\n\n if (route === undefined) {\n throw new MissingRouteExportError(relativeToApp(pageFile));\n }\n\n // The policy decides which layout the page RENDERS INSIDE, from the FULL\n // enumerated chain: a layout anywhere on the ancestry path counts, not\n // just one in the page's own directory. Discovery supplies the one fact\n // the rule needs and the pure policy cannot learn — whether each layout\n // renders anything at all.\n const layouts = layoutChainFor(pageFile, webRoot);\n const shapes = layouts.map((layoutFile) => readLayoutShape(layoutFile, layoutShapes));\n const selection = selectPageLayout(\n layouts.map((layout, index) => ({ layout, renders: shapes[index].renders })),\n );\n\n if (selection.type === \"rejected\") {\n throw new NestedLayoutsNotSupportedError(\n relativeToApp(pageFile),\n selection.layouts.map(relativeToApp),\n );\n }\n\n // Every layout that declares a guard, outermost first. Both installers\n // now CONCATENATE the whole chain into the pipeline's single layout slot\n // (`../server/install-page-routes.ts`, `../server/install-page-routes-from-manifest.ts`),\n // so a guard anywhere on the path runs, in this order — which is why the\n // temporary refusal that used to stand here is gone rather than relaxed.\n const middlewareLayouts = layouts.filter((_, index) => shapes[index].hasMiddleware);\n\n // EVERY prefix on the path, outermost first: a `prefix`-only layout is\n // still a segment of the URL, and composing only the rendering layout's\n // would serve the subtree from a path nobody declared.\n const layoutPrefix = layouts.reduce(\n (composed, layoutFile) =>\n composeRoutePath(composed, readDeclarations(layoutFile, declarations).prefix ?? \"/\"),\n \"/\",\n );\n\n pages.push({\n routeName:\n route.name ??\n deriveFallbackRouteName({\n routePath: route.path,\n sourceFile: relativeToApp(pageFile),\n }),\n routePath: composeRoutePath(layoutPrefix, route.path),\n pageFile,\n webRoot,\n layouts,\n middlewareLayouts,\n ...(hasAppFile ? { appFile } : {}),\n });\n }\n }\n\n pages.sort(comparePages);\n\n assertUniqueRouteNames(pages, appRoot);\n\n return pages;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmGA,IAAa,8BAAb,cAAiD,MAAM;CAEnC;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,WAChB,AAAgB,WAChB,AAAgB,YAChB;EACA,MACE,6CAA6C,UAAU,MAAM,UAAU,SACjE,WAAW,oLAGnB;EATgB;EACA;EACA;EAQhB,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,QAAQ,OAAuB;CAC7C,OAAO,MAAM,QAAQ,OAAO,GAAG;AACjC;AA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C,CAAC,UAAU,GAAG,GACrF,GACF;EAEA,MAAM,KAAK;GACT,WACE,MAAM,QACN,wBAAwB;IACtB,WAAW,MAAM;IACjB,YAAY,cAAc,QAAQ;GACpC,CAAC;GACH,WAAW,iBAAiB,cAAc,MAAM,IAAI;GACpD;GACA;GACA;GACA;GACA,GAAI,aAAa,EAAE,QAAQ,IAAI,CAAC;EAClC,CAAC;CACH;CAGF,MAAM,KAAK,YAAY;CAEvB,uBAAuB,OAAO,OAAO;CAErC,OAAO;AACT"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
//#region ../web/src/build/generate-client-registry.ts
|
|
2
|
+
/** The name of the array the generated module exports. */
|
|
3
|
+
const CLIENT_REGISTRY_EXPORT_NAME = "pages";
|
|
4
|
+
/** The specifier the generated module imports its entry type from. */
|
|
5
|
+
const CLIENT_RUNTIME_SPECIFIER = "@warlock.js/web/client/runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Raised when two pages claim one route name.
|
|
8
|
+
*
|
|
9
|
+
* `discoverPages` promises uniqueness already (`discover-pages.ts:370`). This
|
|
10
|
+
* asserts it anyway: the alternative is trusting an upstream promise and
|
|
11
|
+
* emitting a registry in which one page is silently unreachable, which costs
|
|
12
|
+
* far more to diagnose than the check costs to run.
|
|
13
|
+
*/
|
|
14
|
+
var DuplicateClientPageNameError = class extends Error {
|
|
15
|
+
routeName;
|
|
16
|
+
firstPageFile;
|
|
17
|
+
secondPageFile;
|
|
18
|
+
constructor(routeName, firstPageFile, secondPageFile) {
|
|
19
|
+
super(`Two pages claim the client route name "${routeName}": "${firstPageFile}" and "${secondPageFile}". A route name identifies exactly one page, so the second page would be unreachable in the browser. To fix: rename one page's \`route\` export, or move the file so its directory gives it a different route name.`);
|
|
20
|
+
this.routeName = routeName;
|
|
21
|
+
this.firstPageFile = firstPageFile;
|
|
22
|
+
this.secondPageFile = secondPageFile;
|
|
23
|
+
this.name = "DuplicateClientPageNameError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Every literal the generator emits goes through here, without exception.
|
|
28
|
+
* Windows separators, quotes and backslashes are all in scope, and a
|
|
29
|
+
* hand-quoted literal that gets one of them wrong fails at bundle time with a
|
|
30
|
+
* parse error no user can act on.
|
|
31
|
+
*/
|
|
32
|
+
function quote(value) {
|
|
33
|
+
return JSON.stringify(value);
|
|
34
|
+
}
|
|
35
|
+
const HEADER = [
|
|
36
|
+
"// AUTO-GENERATED by @warlock.js/web — do not edit.",
|
|
37
|
+
"// The page graph, compiled into the CLIENT bundle.",
|
|
38
|
+
"//",
|
|
39
|
+
"// `name` and `path` are baked in as data so the client runtime can match a",
|
|
40
|
+
"// route before loading anything; every module reference is a dynamic",
|
|
41
|
+
"// `import()` so a page's code is downloaded only when that page is rendered.",
|
|
42
|
+
`import type { ClientPageEntry } from ${quote(CLIENT_RUNTIME_SPECIFIER)};`
|
|
43
|
+
];
|
|
44
|
+
function assertUniqueNames(pages) {
|
|
45
|
+
const pageFileByName = /* @__PURE__ */ new Map();
|
|
46
|
+
for (const page of pages) {
|
|
47
|
+
const existing = pageFileByName.get(page.routeName);
|
|
48
|
+
if (existing !== void 0) throw new DuplicateClientPageNameError(page.routeName, existing, page.pageFile);
|
|
49
|
+
pageFileByName.set(page.routeName, page.pageFile);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* One entry's `load`.
|
|
54
|
+
*
|
|
55
|
+
* It memoises NOTHING and holds no one-shot state: the runtime calls it again
|
|
56
|
+
* on re-navigation to the same route, and a loader that works once and returns
|
|
57
|
+
* undefined the second time is a silent blank page. Dynamic `import()` is
|
|
58
|
+
* already module-cached by the bundler, so the correct implementation is to
|
|
59
|
+
* let the cache do the caching.
|
|
60
|
+
*/
|
|
61
|
+
function loadSource(page, toImportSpecifier) {
|
|
62
|
+
const bindings = ["Page"];
|
|
63
|
+
const specifiers = [toImportSpecifier(page.pageFile)];
|
|
64
|
+
const layoutBindings = page.layouts.map((layoutFile, index) => {
|
|
65
|
+
bindings.push(`layout${index}`);
|
|
66
|
+
specifiers.push(toImportSpecifier(layoutFile));
|
|
67
|
+
return `layout${index}`;
|
|
68
|
+
});
|
|
69
|
+
if (page.appFile !== void 0) {
|
|
70
|
+
bindings.push("App");
|
|
71
|
+
specifiers.push(toImportSpecifier(page.appFile));
|
|
72
|
+
}
|
|
73
|
+
const app = page.appFile === void 0 ? "" : ", App";
|
|
74
|
+
return [
|
|
75
|
+
" load: async () => {",
|
|
76
|
+
` const [${bindings.join(", ")}] = await Promise.all([`,
|
|
77
|
+
...specifiers.map((specifier) => ` import(${quote(specifier)}),`),
|
|
78
|
+
" ]);",
|
|
79
|
+
"",
|
|
80
|
+
` return { Page, layouts: [${layoutBindings.join(", ")}]${app} };`,
|
|
81
|
+
" },"
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
function entrySource(page, toImportSpecifier) {
|
|
85
|
+
return [
|
|
86
|
+
" {",
|
|
87
|
+
" type: \"page\",",
|
|
88
|
+
` name: ${quote(page.routeName)},`,
|
|
89
|
+
` path: ${quote(page.routePath)},`,
|
|
90
|
+
...loadSource(page, toImportSpecifier),
|
|
91
|
+
" },"
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Returns the SOURCE of the client page registry module. Writes nothing.
|
|
96
|
+
*
|
|
97
|
+
* Zero pages is a legal result, not an error, and it is emitted as an explicit
|
|
98
|
+
* empty registry: "built with web, no pages" must reach the runtime as a fact
|
|
99
|
+
* rather than as a missing module.
|
|
100
|
+
*/
|
|
101
|
+
function generateClientRegistry(options) {
|
|
102
|
+
const { pages, toImportSpecifier } = options;
|
|
103
|
+
assertUniqueNames(pages);
|
|
104
|
+
const declaration = `export const ${CLIENT_REGISTRY_EXPORT_NAME}: readonly ClientPageEntry[] =`;
|
|
105
|
+
if (pages.length === 0) return [
|
|
106
|
+
...HEADER,
|
|
107
|
+
"",
|
|
108
|
+
`${declaration} [];`,
|
|
109
|
+
""
|
|
110
|
+
].join("\n");
|
|
111
|
+
return [
|
|
112
|
+
...HEADER,
|
|
113
|
+
"",
|
|
114
|
+
`${declaration} [`,
|
|
115
|
+
...pages.flatMap((page) => entrySource(page, toImportSpecifier)),
|
|
116
|
+
"];",
|
|
117
|
+
""
|
|
118
|
+
].join("\n");
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
//#endregion
|
|
122
|
+
export { generateClientRegistry };
|
|
123
|
+
//# sourceMappingURL=generate-client-registry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-client-registry.mjs","names":[],"sources":["../../../../../../../web/src/build/generate-client-registry.ts"],"sourcesContent":["/**\n * The CLIENT half of the build→runtime handoff: the source of a generated\n * module that carries the page graph into the BROWSER.\n *\n * `generate-pages-barrel.ts` is the server half. The two are deliberately not\n * one function, because they want opposite things from the same recipe: the\n * server barrel emits STATIC `import * as` so every page lands in the one\n * server bundle and its route can be read off the module at boot, while the\n * browser must never download page B to render page A — so every module\n * reference here is a dynamic `import()`, and `name`/`path` are baked in as\n * DATA so the client runtime can match a route before loading anything.\n *\n * This function is PURE. It reads no filesystem, writes no file, and does not\n * call {@link discoverPages} — the caller passes the already-discovered graph\n * in. That is what keeps the \"one discovery run, one graph\" invariant: names\n * and paths agree with the server's because there is only ever one scan, not\n * because two scanners were written to match.\n *\n * Module RESOLUTION is the one thing that legitimately differs between the dev\n * provider and the production provider, so it is injected as\n * {@link GenerateClientRegistryOptions.toImportSpecifier} rather than computed\n * here. No provider-specific data — no Vite ids, no `/@fs/` prefixes, no\n * hashed chunk urls, no HMR metadata — reaches the emitted entry, and every\n * other property stays testable with a trivial mapper.\n */\nimport type { DiscoveredPage } from \"./discover-pages\";\n\nexport type GenerateClientRegistryOptions = {\n /**\n * The discovered page graph, IN THE ORDER DISCOVERY GAVE IT.\n *\n * `discoverPages` already sorts by POSIX source-file path\n * (`discover-pages.ts:368`, comparator at `discover-pages.ts:248-250`), so\n * this emitter preserves that order rather than imposing a second one: two\n * orderings of one graph is exactly the drift the shared scan exists to\n * prevent. Serialization stability only — nothing emitted here implies\n * matching precedence, which is a property of the route grammar.\n */\n pages: readonly DiscoveredPage[];\n /** Maps an absolute source file path to the specifier the emitted module will import. */\n toImportSpecifier: (absoluteFilePath: string) => string;\n};\n\n/** The name of the array the generated module exports. */\nexport const CLIENT_REGISTRY_EXPORT_NAME = \"pages\";\n\n/** The specifier the generated module imports its entry type from. */\nconst CLIENT_RUNTIME_SPECIFIER = \"@warlock.js/web/client/runtime\";\n\n/**\n * Raised when two pages claim one route name.\n *\n * `discoverPages` promises uniqueness already (`discover-pages.ts:370`). This\n * asserts it anyway: the alternative is trusting an upstream promise and\n * emitting a registry in which one page is silently unreachable, which costs\n * far more to diagnose than the check costs to run.\n */\nexport class DuplicateClientPageNameError extends Error {\n public constructor(\n public readonly routeName: string,\n public readonly firstPageFile: string,\n public readonly secondPageFile: string,\n ) {\n super(\n `Two pages claim the client route name \"${routeName}\": \"${firstPageFile}\" and ` +\n `\"${secondPageFile}\". A route name identifies exactly one page, so the second ` +\n \"page would be unreachable in the browser. To fix: rename one page's `route` \" +\n \"export, or move the file so its directory gives it a different route name.\",\n );\n this.name = \"DuplicateClientPageNameError\";\n }\n}\n\n/**\n * Every literal the generator emits goes through here, without exception.\n * Windows separators, quotes and backslashes are all in scope, and a\n * hand-quoted literal that gets one of them wrong fails at bundle time with a\n * parse error no user can act on.\n */\nfunction quote(value: string): string {\n return JSON.stringify(value);\n}\n\nconst HEADER = [\n \"// AUTO-GENERATED by @warlock.js/web — do not edit.\",\n \"// The page graph, compiled into the CLIENT bundle.\",\n \"//\",\n \"// `name` and `path` are baked in as data so the client runtime can match a\",\n \"// route before loading anything; every module reference is a dynamic\",\n \"// `import()` so a page's code is downloaded only when that page is rendered.\",\n `import type { ClientPageEntry } from ${quote(CLIENT_RUNTIME_SPECIFIER)};`,\n];\n\nfunction assertUniqueNames(pages: readonly DiscoveredPage[]): void {\n const pageFileByName = new Map<string, string>();\n\n for (const page of pages) {\n const existing = pageFileByName.get(page.routeName);\n\n if (existing !== undefined) {\n throw new DuplicateClientPageNameError(page.routeName, existing, page.pageFile);\n }\n\n pageFileByName.set(page.routeName, page.pageFile);\n }\n}\n\n/**\n * One entry's `load`.\n *\n * It memoises NOTHING and holds no one-shot state: the runtime calls it again\n * on re-navigation to the same route, and a loader that works once and returns\n * undefined the second time is a silent blank page. Dynamic `import()` is\n * already module-cached by the bundler, so the correct implementation is to\n * let the cache do the caching.\n */\nfunction loadSource(page: DiscoveredPage, toImportSpecifier: (file: string) => string): string[] {\n const bindings = [\"Page\"];\n const specifiers = [toImportSpecifier(page.pageFile)];\n\n // Outermost first, exactly as discovery enumerated the chain — the order IS\n // the nesting, so reordering it would silently reparent the page.\n const layoutBindings = page.layouts.map((layoutFile, index) => {\n bindings.push(`layout${index}`);\n specifiers.push(toImportSpecifier(layoutFile));\n\n return `layout${index}`;\n });\n\n if (page.appFile !== undefined) {\n bindings.push(\"App\");\n specifiers.push(toImportSpecifier(page.appFile));\n }\n\n // `App` is OMITTED, never emitted as `App: undefined`: the runtime validator\n // reads an own `App` key as a promise that a module namespace is behind it.\n const app = page.appFile === undefined ? \"\" : \", App\";\n\n return [\n \" load: async () => {\",\n ` const [${bindings.join(\", \")}] = await Promise.all([`,\n ...specifiers.map((specifier) => ` import(${quote(specifier)}),`),\n \" ]);\",\n \"\",\n ` return { Page, layouts: [${layoutBindings.join(\", \")}]${app} };`,\n \" },\",\n ];\n}\n\nfunction entrySource(\n page: DiscoveredPage,\n toImportSpecifier: (file: string) => string,\n): string[] {\n return [\n \" {\",\n ' type: \"page\",',\n // Verbatim from discovery, both of them. `routePath` in particular is NOT\n // re-derived or re-normalised here: discovery already composed the layout\n // prefix with the declared route, and a second composition is a second\n // convention waiting to disagree with the server's.\n ` name: ${quote(page.routeName)},`,\n ` path: ${quote(page.routePath)},`,\n ...loadSource(page, toImportSpecifier),\n \" },\",\n ];\n}\n\n/**\n * Returns the SOURCE of the client page registry module. Writes nothing.\n *\n * Zero pages is a legal result, not an error, and it is emitted as an explicit\n * empty registry: \"built with web, no pages\" must reach the runtime as a fact\n * rather than as a missing module.\n */\nexport function generateClientRegistry(options: GenerateClientRegistryOptions): string {\n const { pages, toImportSpecifier } = options;\n\n assertUniqueNames(pages);\n\n const declaration = `export const ${CLIENT_REGISTRY_EXPORT_NAME}: readonly ClientPageEntry[] =`;\n\n if (pages.length === 0) {\n return [...HEADER, \"\", `${declaration} [];`, \"\"].join(\"\\n\");\n }\n\n return [\n ...HEADER,\n \"\",\n `${declaration} [`,\n ...pages.flatMap((page) => entrySource(page, toImportSpecifier)),\n \"];\",\n \"\",\n ].join(\"\\n\");\n}\n"],"mappings":";;AA4CA,MAAa,8BAA8B;;AAG3C,MAAM,2BAA2B;;;;;;;;;AAUjC,IAAa,+BAAb,cAAkD,MAAM;CAEpC;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,WAChB,AAAgB,eAChB,AAAgB,gBAChB;EACA,MACE,0CAA0C,UAAU,MAAM,cAAc,SAClE,eAAe,oNAGvB;EATgB;EACA;EACA;EAQhB,KAAK,OAAO;CACd;AACF;;;;;;;AAQA,SAAS,MAAM,OAAuB;CACpC,OAAO,KAAK,UAAU,KAAK;AAC7B;AAEA,MAAM,SAAS;CACb;CACA;CACA;CACA;CACA;CACA;CACA,wCAAwC,MAAM,wBAAwB,EAAE;AAC1E;AAEA,SAAS,kBAAkB,OAAwC;CACjE,MAAM,iCAAiB,IAAI,IAAoB;CAE/C,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,eAAe,IAAI,KAAK,SAAS;EAElD,IAAI,aAAa,QACf,MAAM,IAAI,6BAA6B,KAAK,WAAW,UAAU,KAAK,QAAQ;EAGhF,eAAe,IAAI,KAAK,WAAW,KAAK,QAAQ;CAClD;AACF;;;;;;;;;;AAWA,SAAS,WAAW,MAAsB,mBAAuD;CAC/F,MAAM,WAAW,CAAC,MAAM;CACxB,MA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