@warlock.js/web 5.5.0 → 5.7.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.
Files changed (153) hide show
  1. package/CHANGELOG.md +53 -5
  2. package/esm/build/contribution.d.mts +2 -2
  3. package/esm/build/contribution.mjs +1 -1
  4. package/esm/build/contribution.mjs.map +1 -1
  5. package/esm/build/discover-pages.mjs +130 -208
  6. package/esm/build/discover-pages.mjs.map +1 -1
  7. package/esm/build/generate-pages-barrel.mjs +7 -5
  8. package/esm/build/generate-pages-barrel.mjs.map +1 -1
  9. package/esm/build/page-routes-manifest.mjs +1 -1
  10. package/esm/build/public-files.mjs +30 -2
  11. package/esm/build/public-files.mjs.map +1 -1
  12. package/esm/build/read-metadata-keys.mjs +225 -0
  13. package/esm/build/read-metadata-keys.mjs.map +1 -0
  14. package/esm/build/read-route-exports.mjs.map +1 -1
  15. package/esm/client/build-hydrated-tree.mjs +1 -1
  16. package/esm/client/build-hydrated-tree.mjs.map +1 -1
  17. package/esm/client/navigation/document-metadata.mjs +108 -0
  18. package/esm/client/navigation/document-metadata.mjs.map +1 -0
  19. package/esm/client/navigation/fetch-page-data.mjs +3 -10
  20. package/esm/client/navigation/fetch-page-data.mjs.map +1 -1
  21. package/esm/client/navigation/navigation-root.mjs +24 -104
  22. package/esm/client/navigation/navigation-root.mjs.map +1 -1
  23. package/esm/client/navigation/scroll-to-fragment.mjs.map +1 -1
  24. package/esm/client/navigation/use-query-string.d.mts +35 -0
  25. package/esm/client/navigation/use-query-string.mjs +68 -0
  26. package/esm/client/navigation/use-query-string.mjs.map +1 -0
  27. package/esm/client/runtime/index.d.mts +1 -1
  28. package/esm/client/runtime/index.mjs +1 -1
  29. package/esm/client/runtime/manifest.mjs.map +1 -1
  30. package/esm/client/runtime/matcher.mjs.map +1 -1
  31. package/esm/client/runtime/types.d.mts +1 -1
  32. package/esm/components/link.mjs.map +1 -1
  33. package/esm/core/src/router/normalize-route-path.mjs +33 -0
  34. package/esm/core/src/router/normalize-route-path.mjs.map +1 -0
  35. package/esm/{hydration → entry}/index.mjs +1 -1
  36. package/esm/entry/index.mjs.map +1 -0
  37. package/esm/hydration-payload.mjs +19 -10
  38. package/esm/hydration-payload.mjs.map +1 -1
  39. package/esm/index.d.mts +3 -2
  40. package/esm/index.mjs +3 -2
  41. package/esm/loaders.d.mts +13 -1
  42. package/esm/localization.mjs.map +1 -1
  43. package/esm/metadata.d.mts +4 -4
  44. package/esm/metadata.mjs.map +1 -1
  45. package/esm/node_modules/.pnpm/@mongez_concat-route@1.2.0/node_modules/@mongez/concat-route/esm/index.mjs +33 -0
  46. package/esm/node_modules/.pnpm/@mongez_concat-route@1.2.0/node_modules/@mongez/concat-route/esm/index.mjs.map +1 -0
  47. package/esm/{runtime/register-modules.d.mts → register-modules.d.mts} +1 -1
  48. package/esm/{runtime/register-modules.mjs → register-modules.mjs} +1 -1
  49. package/esm/register-modules.mjs.map +1 -0
  50. package/esm/route.d.mts +9 -0
  51. package/esm/routing/duplicate-route-path.mjs +22 -0
  52. package/esm/routing/duplicate-route-path.mjs.map +1 -0
  53. package/esm/routing/layout-level.mjs +50 -0
  54. package/esm/routing/layout-level.mjs.map +1 -0
  55. package/esm/routing/layout-policy.mjs.map +1 -1
  56. package/esm/routing/query-string.d.mts +23 -1
  57. package/esm/routing/query-string.mjs +23 -1
  58. package/esm/routing/query-string.mjs.map +1 -1
  59. package/esm/routing/route-identity.mjs +27 -2
  60. package/esm/routing/route-identity.mjs.map +1 -1
  61. package/esm/routing/route-table.mjs.map +1 -1
  62. package/esm/routing/router-events.d.mts +5 -4
  63. package/esm/routing/router-events.mjs.map +1 -1
  64. package/esm/server/create-page-route-handler.d.mts +2 -2
  65. package/esm/server/create-page-route-handler.mjs +18 -12
  66. package/esm/server/create-page-route-handler.mjs.map +1 -1
  67. package/esm/server/{dev-server.mjs → dev-error-transport.mjs} +2 -2
  68. package/esm/server/dev-error-transport.mjs.map +1 -0
  69. package/esm/server/execute-page-request.mjs +91 -35
  70. package/esm/server/execute-page-request.mjs.map +1 -1
  71. package/esm/server/execute-page-request.types.d.mts +21 -1
  72. package/esm/server/fold-layout-loaders.mjs +36 -0
  73. package/esm/server/fold-layout-loaders.mjs.map +1 -0
  74. package/esm/server/hydration-client-url.mjs +3 -3
  75. package/esm/server/hydration-client-url.mjs.map +1 -1
  76. package/esm/server/index.d.mts +4 -3
  77. package/esm/server/index.mjs +6 -6
  78. package/esm/server/install-page-routes-from-manifest.d.mts +10 -1
  79. package/esm/server/install-page-routes-from-manifest.mjs +61 -58
  80. package/esm/server/install-page-routes-from-manifest.mjs.map +1 -1
  81. package/esm/server/install-page-routes.d.mts +24 -26
  82. package/esm/server/install-page-routes.mjs +149 -60
  83. package/esm/server/install-page-routes.mjs.map +1 -1
  84. package/esm/server/install-production-page-routes.mjs.map +1 -1
  85. package/esm/server/match-page-route.mjs +6 -10
  86. package/esm/server/match-page-route.mjs.map +1 -1
  87. package/esm/server/not-found-page.d.mts +1 -0
  88. package/esm/server/not-found-page.mjs +8 -1
  89. package/esm/server/not-found-page.mjs.map +1 -1
  90. package/esm/server/page-file-change.mjs +1 -1
  91. package/esm/server/page-file-change.mjs.map +1 -1
  92. package/esm/server/page-module-shapes.d.mts +24 -0
  93. package/esm/server/page-route-reload.mjs +4 -3
  94. package/esm/server/page-route-reload.mjs.map +1 -1
  95. package/esm/server/register-production-public-files.mjs +26 -2
  96. package/esm/server/register-production-public-files.mjs.map +1 -1
  97. package/esm/server/render-page.d.mts +13 -49
  98. package/esm/server/render-page.mjs +14 -55
  99. package/esm/server/render-page.mjs.map +1 -1
  100. package/esm/server/resolve-page-metadata.mjs.map +1 -1
  101. package/esm/server/resolve-route-validation-input.mjs +11 -0
  102. package/esm/server/resolve-route-validation-input.mjs.map +1 -0
  103. package/esm/server/resolve-validation-data.mjs +1 -1
  104. package/esm/server/resolve-validation-data.mjs.map +1 -1
  105. package/esm/server/settle-page-response.mjs +5 -3
  106. package/esm/server/settle-page-response.mjs.map +1 -1
  107. package/esm/server/stylesheet-urls.mjs +78 -19
  108. package/esm/server/stylesheet-urls.mjs.map +1 -1
  109. package/esm/server/unregistered-pages.mjs +2 -1
  110. package/esm/server/unregistered-pages.mjs.map +1 -1
  111. package/esm/server/web-connector-factory.mjs +1 -1
  112. package/esm/server/web-connector-factory.mjs.map +1 -1
  113. package/esm/server/web-connector.mjs +25 -322
  114. package/esm/server/web-connector.mjs.map +1 -1
  115. package/esm/shared/module-key.mjs +15 -0
  116. package/esm/shared/module-key.mjs.map +1 -0
  117. package/esm/shared/to-posix.mjs +13 -0
  118. package/esm/shared/to-posix.mjs.map +1 -0
  119. package/esm/shared.mjs +24 -0
  120. package/esm/shared.mjs.map +1 -1
  121. package/esm/validation.d.mts +12 -1
  122. package/esm/vite/build-client.mjs +1 -1
  123. package/esm/vite/build-client.mjs.map +1 -1
  124. package/esm/vite/dev-server-config.mjs +240 -0
  125. package/esm/vite/dev-server-config.mjs.map +1 -0
  126. package/esm/vite/gate-a-resolve.d.mts +5 -4
  127. package/esm/vite/gate-a-resolve.mjs +32 -71
  128. package/esm/vite/gate-a-resolve.mjs.map +1 -1
  129. package/esm/vite/gate-b-secrets.mjs.map +1 -1
  130. package/esm/vite/gate-c-verify.d.mts +1 -1
  131. package/esm/vite/gate-c-verify.mjs +1 -1
  132. package/esm/vite/gate-c-verify.mjs.map +1 -1
  133. package/esm/vite/hydration-entries.mjs +6 -8
  134. package/esm/vite/hydration-entries.mjs.map +1 -1
  135. package/esm/vite/index.d.mts +1 -1
  136. package/esm/vite/index.mjs +4 -110
  137. package/esm/vite/index.mjs.map +1 -1
  138. package/esm/vite/page-registry-plugin.mjs +9 -26
  139. package/esm/vite/page-registry-plugin.mjs.map +1 -1
  140. package/esm/vite/projection.mjs.map +1 -1
  141. package/esm/vite/react-refresh-preamble.mjs +90 -0
  142. package/esm/vite/react-refresh-preamble.mjs.map +1 -0
  143. package/esm/vite/ssr-client-view.mjs +135 -0
  144. package/esm/vite/ssr-client-view.mjs.map +1 -0
  145. package/llms-full.txt +564 -482
  146. package/llms.txt +2 -2
  147. package/package.json +6 -6
  148. package/skills/create-a-page/SKILL.md +354 -295
  149. package/skills/navigate-on-the-client/SKILL.md +212 -189
  150. package/esm/hydration/index.mjs.map +0 -1
  151. package/esm/runtime/register-modules.mjs.map +0 -1
  152. package/esm/server/dev-server.mjs.map +0 -1
  153. /package/esm/{hydration → entry}/index.d.mts +0 -0
@@ -1,15 +1,18 @@
1
1
  import { publishRouteTable } from "../routing/route-table.mjs";
2
- import { isLoaderShortCircuit } from "./settle-page-response.mjs";
3
2
  import { composeRoutePath } from "../routing/compose-route-path.mjs";
3
+ import { DuplicateNotFoundPageError, NOT_FOUND_ROUTE_NAME, NOT_FOUND_ROUTE_PATH, NotFoundPageDeclaresRouteError, isNotFoundPageFile, registerNotFoundPageRoute } from "./not-found-page.mjs";
4
+ import { PageFileSegmentNotSupportedError } from "../routing/page-file-segment.mjs";
4
5
  import { deriveFilesystemRoutePath } from "../routing/filesystem-route.mjs";
5
- import { NestedLayoutsNotSupportedError, selectPageLayout } from "../routing/layout-policy.mjs";
6
- import { canonicalizeRouteExport, resolvePageRouteCache, resolvePageRouteName } from "../routing/route-identity.mjs";
6
+ import { resolvePageRouteCache, resolvePageRouteIdentity, resolvePageRouteName } from "../routing/route-identity.mjs";
7
+ import { NonLiteralRouteExportError, readRouteExports } from "../build/read-route-exports.mjs";
8
+ import { toPosix } from "../shared/to-posix.mjs";
9
+ import { ErrorPageDeclaresRouteError, discoverPageFiles, isErrorPageFile, layoutChainFor } from "../build/discover-pages.mjs";
10
+ import { duplicateRoutePathMessage } from "../routing/duplicate-route-path.mjs";
11
+ import { resolveLayoutLevel as resolveLayoutLevel$1 } from "../routing/layout-level.mjs";
7
12
  import { createPageRouteHandler } from "./create-page-route-handler.mjs";
13
+ import { foldLayoutLoaders } from "./fold-layout-loaders.mjs";
8
14
  import { devHandlerStylesheetUrls } from "./stylesheet-urls.mjs";
9
- import { DuplicateNotFoundPageError, NOT_FOUND_ROUTE_NAME, NOT_FOUND_ROUTE_PATH, NotFoundPageDeclaresRouteError, createNotFoundRouteHandler, isNotFoundPageFile } from "./not-found-page.mjs";
10
- import { NonLiteralRouteExportError, readRouteExports } from "../build/read-route-exports.mjs";
11
- import { ErrorPageDeclaresRouteError, discoverPageFiles, isErrorPageFile, layoutChainFor, toPosix } from "../build/discover-pages.mjs";
12
- import { Response } from "@warlock.js/core";
15
+ import "@warlock.js/core";
13
16
  import path from "node:path";
14
17
 
15
18
  //#region ../web/src/server/install-page-routes.ts
@@ -20,10 +23,10 @@ import path from "node:path";
20
23
  * the sanctioned dev-server dispatch path (server matching is Warlock's
21
24
  * router; there is no second server matcher) — picks
22
25
  * it up. Replaces the two hand-rolled `fastify.get()` calls this file's
23
- * sibling, `dev-server.ts`, used to make directly.
26
+ * sibling, `dev-error-transport.ts`, used to make directly.
24
27
  *
25
28
  * DELIBERATE EXCEPTION to "web has no core dependency", same
26
- * reasoning `dev-server.ts`'s own header comment records: this module is not
29
+ * reasoning `dev-error-transport.ts`'s own header comment records: this module is not
27
30
  * exported from either package barrel and is not part of `web/package.json`'s
28
31
  * dependency graph — dev/CLI bootstrap only.
29
32
  *
@@ -45,6 +48,24 @@ import path from "node:path";
45
48
  * through Vite (`vite.ssrLoadModule`), never read statically, because a dev
46
49
  * page module must be the one Vite serves, warm cache and all.
47
50
  */
51
+ /** Raised at boot when a page still uses the withdrawn `route.middleware` export. */
52
+ var RouteMiddlewareRemovedError = class extends Error {
53
+ pageFile;
54
+ constructor(pageFile) {
55
+ super(`"${pageFile}" declares \`route.middleware\`, which no longer runs — it was withdrawn after 5.6.0. Move it to the page's own top-level \`middleware\` export instead: \`export const middleware = [...]\`.`);
56
+ this.pageFile = pageFile;
57
+ this.name = "RouteMiddlewareRemovedError";
58
+ }
59
+ };
60
+ /** Raised at boot when a page still uses the withdrawn `route.validate` export. */
61
+ var RouteValidationRemovedError = class extends Error {
62
+ pageFile;
63
+ constructor(pageFile) {
64
+ super(`"${pageFile}" declares \`route.validate\`, which no longer runs — it was withdrawn after 5.6.0. Move it to the page's top-level \`validation\` export instead: \`export const validation = { params: ..., query: ... }\`.`);
65
+ this.pageFile = pageFile;
66
+ this.name = "RouteValidationRemovedError";
67
+ }
68
+ };
48
69
  /**
49
70
  * Ownership key for the framework's fallback 404 route. A NUL-prefixed value
50
71
  * cannot be a real filesystem path, so it cannot collide with an app page's
@@ -63,34 +84,82 @@ function filesystemPageFileFor(pageFile, appSrcRoot) {
63
84
  return toPosix(path.relative(path.join(appSrcRoot, "web"), pageFile));
64
85
  }
65
86
  /**
66
- * Resolve the stable identity used to distinguish a route-export edit from an
67
- * ordinary component-body edit. The declared path is retained before layout
68
- * composition so `/settings` under `/admin` compares with the next declared
69
- * `/settings`, not with the effective `/admin/settings` route.
87
+ * Raised when a page's own module fails to load in dev (`vite.ssrLoadModule`
88
+ * rejects on the page file itself never a layout, which this class does not
89
+ * cover).
90
+ *
91
+ * Before this class existed, that rejection propagated straight out of
92
+ * `installPageRoutes`'s loop and failed the WHOLE install: every other page's
93
+ * route went unregistered along with the broken one, and the failure named
94
+ * neither the page file nor which module actually threw. One bad page taking
95
+ * every other page down with it is a worse outage than the bad page alone, so
96
+ * this error is what the broken page's own route now fails with instead —
97
+ * named, with its cause attached, while the rest of the application keeps
98
+ * serving.
99
+ */
100
+ var PageModuleLoadError = class extends Error {
101
+ pageFile;
102
+ constructor(pageFile, cause) {
103
+ const rawCause = cause instanceof Error ? cause.message : String(cause);
104
+ const causeMessage = /[.!?]$/.test(rawCause.trim()) ? rawCause.trim() : `${rawCause.trim()}.`;
105
+ super(`"${pageFile}" failed to load: ${causeMessage} Every other page still installed and is still serving; fix the error in this page's module and it will start serving again.`, { cause });
106
+ this.pageFile = pageFile;
107
+ this.name = "PageModuleLoadError";
108
+ }
109
+ };
110
+ /**
111
+ * Registers a page whose OWN module failed to load at its filesystem-derived
112
+ * URL, so a request there reports {@link PageModuleLoadError} — naming the
113
+ * page file and the underlying cause — instead of a bare 404 that explains
114
+ * nothing.
115
+ *
116
+ * Only the filesystem-derived path is attempted: the page's `route` export
117
+ * cannot be read (that requires the very module that failed to load), and its
118
+ * layout chain is not resolved either, so no layout prefix composes into this
119
+ * path. When the filesystem path itself is not derivable
120
+ * (`deriveFilesystemRoutePath` rejects a segment), there is no path left to
121
+ * register a route at, so nothing is registered — the caller reports both
122
+ * failures loudly at boot and moves on.
70
123
  */
71
- function resolvePageRouteIdentity(routeExport, pageFile, appSrcRoot) {
124
+ async function registerFailedPageRoute(input) {
125
+ const { router, pageFile, appSrcRoot, loadError, fileByPath } = input;
126
+ const attributed = new PageModuleLoadError(pageFile, loadError);
72
127
  const filesystemPageFile = filesystemPageFileFor(pageFile, appSrcRoot);
73
- if (routeExport === void 0) return {
74
- declaredPath: deriveFilesystemRoutePath({ pageFile: filesystemPageFile }),
75
- name: resolvePageRouteName(routeExport, filesystemPageFile)
76
- };
77
- return {
78
- declaredPath: canonicalizeRouteExport(routeExport, pageFile).path,
79
- name: resolvePageRouteName(routeExport, filesystemPageFile)
80
- };
128
+ let effectivePath;
129
+ try {
130
+ effectivePath = deriveFilesystemRoutePath({ pageFile: filesystemPageFile });
131
+ } catch (segmentError) {
132
+ if (!(segmentError instanceof PageFileSegmentNotSupportedError)) throw segmentError;
133
+ console.error(attributed.message);
134
+ console.error(segmentError.message);
135
+ return;
136
+ }
137
+ const existingFile = fileByPath.get(effectivePath);
138
+ if (existingFile) throw new Error(duplicateRoutePathMessage({
139
+ effectivePath,
140
+ existingFile,
141
+ newFile: pageFile
142
+ }));
143
+ fileByPath.set(effectivePath, pageFile);
144
+ await router.withSourceFile(canonicalSourceFileFor(pageFile, appSrcRoot), () => router.get(effectivePath, async () => {
145
+ throw attributed;
146
+ }, {
147
+ name: resolvePageRouteName(void 0, filesystemPageFile),
148
+ isPage: true
149
+ }));
81
150
  }
82
151
  async function resolveLayoutLevel(pageFile, webRoot, loadLayout) {
83
152
  const chain = layoutChainFor(pageFile, webRoot);
84
153
  const modules = await Promise.all(chain.map(loadLayout));
85
- const selection = selectPageLayout(chain.map((layout, index) => ({
86
- layout,
87
- renders: typeof modules[index].default !== "undefined"
154
+ const level = resolveLayoutLevel$1(pageFile, chain.map((layoutFile, index) => ({
155
+ id: layoutFile,
156
+ renders: typeof modules[index].default !== "undefined",
157
+ prefix: modules[index].prefix
88
158
  })));
89
- if (selection.type === "rejected") throw new NestedLayoutsNotSupportedError(pageFile, selection.layouts);
90
159
  return {
91
160
  chain,
92
- layoutFile: selection.type === "selected" ? selection.layout : chain.at(-1),
93
- prefix: modules.reduce((composed, layoutModule) => composeRoutePath(composed, layoutModule.prefix ?? "/"), "/"),
161
+ layoutFile: level.hostId,
162
+ prefix: level.prefix,
94
163
  prefixesByDirectory: Object.fromEntries(chain.flatMap((layoutFile, index) => {
95
164
  const prefix = modules[index].prefix;
96
165
  return prefix === void 0 ? [] : [[toPosix(path.relative(webRoot, path.dirname(layoutFile))), prefix]];
@@ -113,15 +182,7 @@ async function composeLayoutLevel(level, loadLayout) {
113
182
  return {
114
183
  ...modules[hostIndex],
115
184
  middleware: modules.flatMap((layoutModule) => [...layoutModule.middleware ?? []]),
116
- loader: async (context) => {
117
- let hostData;
118
- for (let index = 0; index < modules.length; index++) {
119
- const value = await modules[index].loader?.(context);
120
- if (value instanceof Response || isLoaderShortCircuit(value)) return value;
121
- if (index === hostIndex) hostData = value;
122
- }
123
- return hostData;
124
- }
185
+ loader: foldLayoutLoaders(modules.map((layoutModule) => layoutModule.loader), hostIndex)
125
186
  };
126
187
  }
127
188
  /**
@@ -134,7 +195,8 @@ async function composeLayoutLevel(level, loadLayout) {
134
195
  * below `src/web`, using the same pure filesystem-routing helper as the build.
135
196
  */
136
197
  async function installPageRoutes(options) {
137
- const { router, vite, appSrcRoot, appFile, hydrationClientModuleUrl } = options;
198
+ const { router, vite, appSrcRoot, appFile, hydrationClientModuleUrl, httpServer } = options;
199
+ const httpServerOption = httpServer === void 0 ? {} : { httpServer };
138
200
  const stylesheetRoot = options.appRoot ?? path.dirname(appSrcRoot);
139
201
  const discovered = [...discoverPageFiles(appSrcRoot)].sort((left, right) => left.pageFile < right.pageFile ? -1 : left.pageFile > right.pageFile ? 1 : 0);
140
202
  const errorPageFiles = discovered.filter((page) => isErrorPageFile(page.pageFile));
@@ -152,9 +214,26 @@ async function installPageRoutes(options) {
152
214
  const installed = [];
153
215
  const fileByPath = /* @__PURE__ */ new Map();
154
216
  for (const { pageFile, webRoot } of pageFiles) {
155
- const pageModule = await vite.ssrLoadModule(pageFile);
217
+ let pageModule;
218
+ try {
219
+ pageModule = await vite.ssrLoadModule(pageFile);
220
+ } catch (loadError) {
221
+ await registerFailedPageRoute({
222
+ router,
223
+ pageFile,
224
+ appSrcRoot,
225
+ loadError,
226
+ fileByPath
227
+ });
228
+ continue;
229
+ }
230
+ const route = pageModule.route;
231
+ if (typeof route === "object" && route !== null) {
232
+ if ("middleware" in route) throw new RouteMiddlewareRemovedError(pageFile);
233
+ if ("validate" in route) throw new RouteValidationRemovedError(pageFile);
234
+ }
156
235
  const sourceFile = canonicalSourceFileFor(pageFile, appSrcRoot);
157
- const { declaredPath: routePath, name } = resolvePageRouteIdentity(pageModule.route, pageFile, appSrcRoot);
236
+ const { path: routePath, name } = resolvePageRouteIdentity(pageModule.route, filesystemPageFileFor(pageFile, appSrcRoot), pageFile);
158
237
  const cache = resolvePageRouteCache(pageModule.route, pageFile);
159
238
  const loadLayout = (layoutFile) => vite.ssrLoadModule(layoutFile);
160
239
  const layoutLevel = await resolveLayoutLevel(pageFile, webRoot, loadLayout);
@@ -164,13 +243,21 @@ async function installPageRoutes(options) {
164
243
  layoutPrefixes: layoutLevel.prefixesByDirectory
165
244
  }) : composeRoutePath(layoutPrefix, routePath);
166
245
  const existingFile = fileByPath.get(effectivePath);
167
- if (existingFile) throw new Error(`installPageRoutes: composed route path "${effectivePath}" (layout prefix "${layoutPrefix}" + route.path "${routePath}") is declared by two pages (web/src/server/install-page-routes.ts) — "${existingFile}" and "${pageFile}". Every page's composed route path must be unique.`);
246
+ if (existingFile) throw new Error(duplicateRoutePathMessage({
247
+ effectivePath,
248
+ existingFile,
249
+ newFile: pageFile,
250
+ composition: {
251
+ layoutPrefix,
252
+ routePath
253
+ }
254
+ }));
168
255
  fileByPath.set(effectivePath, pageFile);
169
256
  const stylesheetUrls = devHandlerStylesheetUrls(stylesheetRoot, [
170
257
  appFile,
171
258
  ...layoutLevel.chain,
172
259
  pageFile
173
- ]);
260
+ ], vite.moduleGraph);
174
261
  await router.withSourceFile(sourceFile, () => router.get(effectivePath, createPageRouteHandler({
175
262
  path: effectivePath,
176
263
  name,
@@ -185,7 +272,8 @@ async function installPageRoutes(options) {
185
272
  hydrationClientModuleUrl,
186
273
  loadErrorPage,
187
274
  stylesheetUrls,
188
- cache
275
+ cache,
276
+ ...httpServerOption
189
277
  }), {
190
278
  name,
191
279
  isPage: true
@@ -203,22 +291,23 @@ async function installPageRoutes(options) {
203
291
  if (notFoundPageFile !== void 0) {
204
292
  if ((await vite.ssrLoadModule(notFoundPageFile)).route !== void 0) throw new NotFoundPageDeclaresRouteError(notFoundPageFile);
205
293
  }
206
- const registerNotFoundRoute = () => router.get("*", createNotFoundRouteHandler({ renderPage: notFoundPageFile === void 0 ? void 0 : createPageRouteHandler({
207
- path: "*",
208
- name: NOT_FOUND_ROUTE_NAME,
209
- appFile,
210
- pageFile: notFoundPageFile,
211
- layoutFile: void 0,
212
- loadModule: (moduleId) => vite.ssrLoadModule(moduleId),
213
- hydrationClientModuleUrl,
214
- loadErrorPage,
215
- stylesheetUrls: devHandlerStylesheetUrls(stylesheetRoot, [appFile, notFoundPageFile]),
216
- matchPath: (requestPath) => requestPath,
217
- statusForRenderedOk: 404,
218
- skipPageLoader: true
219
- }) }), {
220
- name: NOT_FOUND_ROUTE_NAME,
221
- isPage: true
294
+ const registerNotFoundRoute = () => registerNotFoundPageRoute({
295
+ router,
296
+ renderPage: notFoundPageFile === void 0 ? void 0 : createPageRouteHandler({
297
+ path: "*",
298
+ name: NOT_FOUND_ROUTE_NAME,
299
+ appFile,
300
+ pageFile: notFoundPageFile,
301
+ layoutFile: void 0,
302
+ loadModule: (moduleId) => vite.ssrLoadModule(moduleId),
303
+ hydrationClientModuleUrl,
304
+ loadErrorPage,
305
+ stylesheetUrls: devHandlerStylesheetUrls(stylesheetRoot, [appFile, notFoundPageFile], vite.moduleGraph),
306
+ matchPath: (requestPath) => requestPath,
307
+ statusForRenderedOk: 404,
308
+ skipPageLoader: true,
309
+ ...httpServerOption
310
+ })
222
311
  });
223
312
  if (notFoundPageFile === void 0) await router.withSourceFile(FRAMEWORK_DEFAULT_NOT_FOUND_SOURCE_FILE, registerNotFoundRoute);
224
313
  else await router.withSourceFile(canonicalSourceFileFor(notFoundPageFile, appSrcRoot), registerNotFoundRoute);
@@ -228,5 +317,5 @@ async function installPageRoutes(options) {
228
317
  }
229
318
 
230
319
  //#endregion
231
- export { installPageRoutes, resolvePageRouteIdentity };
320
+ export { RouteMiddlewareRemovedError, filesystemPageFileFor, installPageRoutes };
232
321
  //# sourceMappingURL=install-page-routes.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"install-page-routes.mjs","names":[],"sources":["../../../../../../../web/src/server/install-page-routes.ts"],"sourcesContent":["/**\r\n * Registers every page {@link discoverPageFiles} finds under `<appSrcRoot>`\r\n * into Warlock's router (`router.get`, `core/src/router/router.ts:359-361`)\r\n * so `router.scanDevServer(fastify)` —\r\n * the sanctioned dev-server dispatch path (server matching is Warlock's\r\n * router; there is no second server matcher) — picks\r\n * it up. Replaces the two hand-rolled `fastify.get()` calls this file's\r\n * sibling, `dev-server.ts`, used to make directly.\r\n *\r\n * DELIBERATE EXCEPTION to \"web has no core dependency\", same\r\n * reasoning `dev-server.ts`'s own header comment records: this module is not\r\n * exported from either package barrel and is not part of `web/package.json`'s\r\n * dependency graph — dev/CLI bootstrap only.\r\n *\r\n * Scope note: a page's\r\n * `route.path` is now composed with the `prefix` export of EVERY `layout.tsx`\r\n * on its path — outermost first (`composeRoutePath` below) — before\r\n * registration and before the collision check, so `home.page.tsx`\r\n * (`path: \"/\"`, main layout `prefix: \"/\"`) resolves to `/` and\r\n * `products.page.tsx` (`path: \"/\"`, products layout `prefix: \"/products\"`)\r\n * resolves to `/products` — no collision. A page with no `layout.tsx` on its\r\n * path composes against the implicit root prefix `\"/\"` (e.g. `/contact-us`,\r\n * `/hydration-demo`, both unaffected by composition).\r\n *\r\n * WHICH PAGES EXIST is answered by {@link discoverPageFiles}\r\n * (`web/src/build/discover-pages.ts`) — the same walk production's build\r\n * shares — so this file owns no directory-walking of its own; it serves the\r\n * page root (`<appSrcRoot>/web/**`) exactly as discovery enumerates it. WHAT\r\n * ROUTE A PAGE ANSWERS ON stays this file's own job: each page and its nearest layout are still evaluated\r\n * through Vite (`vite.ssrLoadModule`), never read statically, because a dev\r\n * page module must be the one Vite serves, warm cache and all.\r\n */\r\nimport path from \"node:path\";\r\nimport type { ViteDevServer } from \"vite\";\r\nimport {\r\n discoverPageFiles,\r\n ErrorPageDeclaresRouteError,\r\n isErrorPageFile,\r\n layoutChainFor,\r\n toPosix,\r\n} from \"../build/discover-pages\";\r\nimport { NonLiteralRouteExportError, readRouteExports } from \"../build/read-route-exports\";\r\nimport { composeRoutePath } from \"../routing/compose-route-path\";\r\nimport { deriveFilesystemRoutePath } from \"../routing/filesystem-route\";\r\nimport { NestedLayoutsNotSupportedError, selectPageLayout } from \"../routing/layout-policy\";\r\nimport {\r\n canonicalizeRouteExport,\r\n resolvePageRouteCache,\r\n resolvePageRouteName,\r\n type PageCacheOptIn,\r\n} from \"../routing/route-identity\";\r\nimport { publishRouteTable } from \"../routing/route-table\";\r\nimport { Response, type Router } from \"@warlock.js/core\";\r\nimport { createPageRouteHandler } from \"./create-page-route-handler\";\r\nimport type { ErrorPageModule } from \"./error-page\";\r\nimport type { PipelineLoader, PipelineMiddleware } from \"./execute-page-request\";\r\nimport { isLoaderShortCircuit } from \"./settle-page-response\";\r\nimport { devHandlerStylesheetUrls } from \"./stylesheet-urls\";\r\nimport {\r\n createNotFoundRouteHandler,\r\n DuplicateNotFoundPageError,\r\n isNotFoundPageFile,\r\n NotFoundPageDeclaresRouteError,\r\n NOT_FOUND_ROUTE_NAME,\r\n NOT_FOUND_ROUTE_PATH,\r\n type RegisteredRouteShape,\r\n} from \"./not-found-page\";\r\n\r\n/** Re-exported so `web/src/server/index.ts`'s existing barrel export keeps resolving. */\r\nexport { composeRoutePath };\r\n\r\nexport type PageRouteExport = string | { path: string; name?: string; cache?: PageCacheOptIn };\r\n\r\nexport type PageModuleShape = {\r\n route?: PageRouteExport;\r\n};\r\n\r\nexport type InstalledPageRoute = {\r\n /** The canonical declared route path, before layout-prefix composition. */\r\n declaredPath: string;\r\n path: string;\r\n name: string;\r\n file: string;\r\n layoutFile: string | undefined;\r\n};\r\n\r\n/**\r\n * Ownership key for the framework's fallback 404 route. A NUL-prefixed value\r\n * cannot be a real filesystem path, so it cannot collide with an app page's\r\n * canonical source-file key.\r\n */\r\nexport const FRAMEWORK_DEFAULT_NOT_FOUND_SOURCE_FILE = \"\\0warlock:framework-default-404\";\r\n\r\n/**\r\n * The page's application-source-relative POSIX source path used as the router's\r\n * stable ownership key. `appSrcRoot`'s own basename preserves the existing\r\n * `src/web/...` source-file convention.\r\n */\r\nfunction canonicalSourceFileFor(pageFile: string, appSrcRoot: string): string {\r\n return `${path.basename(appSrcRoot)}/${toPosix(path.relative(appSrcRoot, pageFile))}`;\r\n}\r\n\r\nfunction filesystemPageFileFor(pageFile: string, appSrcRoot: string): string {\r\n return toPosix(path.relative(path.join(appSrcRoot, \"web\"), pageFile));\r\n}\r\n\r\n/**\r\n * Resolve the stable identity used to distinguish a route-export edit from an\r\n * ordinary component-body edit. The declared path is retained before layout\r\n * composition so `/settings` under `/admin` compares with the next declared\r\n * `/settings`, not with the effective `/admin/settings` route.\r\n */\r\nexport function resolvePageRouteIdentity(\r\n routeExport: PageRouteExport | undefined,\r\n pageFile: string,\r\n appSrcRoot: string,\r\n): Pick<InstalledPageRoute, \"declaredPath\" | \"name\"> {\r\n const filesystemPageFile = filesystemPageFileFor(pageFile, appSrcRoot);\r\n\r\n if (routeExport === undefined) {\r\n return {\r\n declaredPath: deriveFilesystemRoutePath({ pageFile: filesystemPageFile }),\r\n name: resolvePageRouteName(routeExport, filesystemPageFile),\r\n };\r\n }\r\n\r\n return {\r\n declaredPath: canonicalizeRouteExport(routeExport, pageFile).path,\r\n name: resolvePageRouteName(routeExport, filesystemPageFile),\r\n };\r\n}\r\n\r\nexport type LayoutModuleShape = {\r\n /** Universal registration hook; invoked on this real namespace, never a composed wrapper. */\r\n register?: () => unknown;\r\n prefix?: string;\r\n /**\r\n * The default export — the thing that puts an element in the document, and\r\n * therefore the ONLY export that decides whether a layout counts against the\r\n * single-rendering-layout rule (`../routing/layout-policy.ts`). In dev the\r\n * module is loaded, so this is a fact rather than a guess.\r\n */\r\n default?: unknown;\r\n /** The layout's guards, in the order it declared them. */\r\n middleware?: readonly PipelineMiddleware[];\r\n loader?: PipelineLoader;\r\n};\r\n\r\n/** How this module gets a layout module namespace — `vite.ssrLoadModule`, in practice. */\r\ntype LoadLayout = (layoutFile: string) => Promise<LayoutModuleShape>;\r\n\r\n/**\r\n * The page's layout LEVEL, resolved from its whole chain rather than from the\r\n * one layout nearest to it.\r\n *\r\n * The render pipeline has exactly one layout slot per page\r\n * (`execute-page-request.ts`'s `PageRouteEntry[\"triple\"]`), so the chain has to\r\n * be collapsed into one module before it reaches a handler. Two things collapse\r\n * differently and both matter:\r\n *\r\n * - RENDERING is a selection: at most one layout on the chain may render, and\r\n * the policy picks it. `renders` is read off the loaded module\r\n * (`typeof module.default !== \"undefined\"`), never off the filename — a\r\n * `middleware`-only layout has no default export and is not a wrapper, and\r\n * passing a bare path to `selectPageLayout` would have it read as a rendering\r\n * one, which is the conservative default and the wrong answer here.\r\n * - MIDDLEWARE and PREFIX are compositions: every layout on the path\r\n * contributes, outermost first. A guard on an outer layout that the page's\r\n * own directory knows nothing about is exactly the guard that must still run,\r\n * and a prefix nobody composed is a URL nobody wrote down.\r\n */\r\ntype LayoutLevel = {\r\n /** Every `layout.tsx` from the web root down to the page's directory, outermost first. */\r\n chain: string[];\r\n /**\r\n * The module id the handler's layout slot is registered under, or `undefined`\r\n * when the page has no layout at all: the layout that RENDERS, or — when none\r\n * does — the nearest one, which is the slot dev has always used and so the\r\n * choice that changes nothing but the middleware for a chain with no wrapper\r\n * in it.\r\n */\r\n layoutFile: string | undefined;\r\n /** Every layout's `prefix`, composed outermost first — `discoverPages`' own reduction. */\r\n prefix: string;\r\n /** Declared prefixes keyed by layout directory relative to this page's web root. */\r\n prefixesByDirectory: Readonly<Record<string, string>>;\r\n};\r\n\r\nasync function resolveLayoutLevel(\r\n pageFile: string,\r\n webRoot: string,\r\n loadLayout: LoadLayout,\r\n): Promise<LayoutLevel> {\r\n const chain = layoutChainFor(pageFile, webRoot);\r\n const modules = await Promise.all(chain.map(loadLayout));\r\n const selection = selectPageLayout(\r\n chain.map((layout, index) => ({\r\n layout,\r\n renders: typeof modules[index].default !== \"undefined\",\r\n })),\r\n );\r\n\r\n if (selection.type === \"rejected\") {\r\n throw new NestedLayoutsNotSupportedError(pageFile, selection.layouts);\r\n }\r\n\r\n return {\r\n chain,\r\n layoutFile: selection.type === \"selected\" ? selection.layout : chain.at(-1),\r\n prefix: modules.reduce(\r\n (composed, layoutModule) => composeRoutePath(composed, layoutModule.prefix ?? \"/\"),\r\n \"/\",\r\n ),\r\n prefixesByDirectory: Object.fromEntries(\r\n chain.flatMap((layoutFile, index) => {\r\n const prefix = modules[index].prefix;\r\n\r\n return prefix === undefined\r\n ? []\r\n : [[toPosix(path.relative(webRoot, path.dirname(layoutFile))), prefix]];\r\n }),\r\n ),\r\n };\r\n}\r\n\r\n/**\r\n * The layout slot's module for ONE request: the slot host's own namespace, with\r\n * the whole chain's middleware in place of its own — outermost first, which is\r\n * the order stage 3 runs the array in (`execute-page-request.ts:519-524`) and\r\n * the order an outer `optionalAuth` needs in order to have resolved an identity\r\n * before an inner `gate()` checks it.\r\n *\r\n * Loaded per call, not once at install time: a dev layout module must be the\r\n * one Vite is currently serving, edits and all.\r\n */\r\nasync function composeLayoutLevel(\r\n level: LayoutLevel & { layoutFile: string },\r\n loadLayout: LoadLayout,\r\n): Promise<LayoutModuleShape> {\r\n const modules = await Promise.all(level.chain.map(loadLayout));\r\n const hostIndex = level.chain.indexOf(level.layoutFile);\r\n const host = modules[hostIndex];\r\n\r\n return {\r\n ...host,\r\n middleware: modules.flatMap((layoutModule) => [...(layoutModule.middleware ?? [])]),\r\n loader: async (context) => {\r\n let hostData: unknown;\r\n\r\n for (let index = 0; index < modules.length; index++) {\r\n const value = await modules[index].loader?.(context);\r\n\r\n if (value instanceof Response || isLoaderShortCircuit(value)) return value;\r\n if (index === hostIndex) hostData = value;\r\n }\r\n\r\n return hostData;\r\n },\r\n };\r\n}\r\n\r\nexport type InstallPageRoutesOptions = {\r\n router: Router;\r\n vite: ViteDevServer;\r\n /** v5/app/src — pages live under \"<appSrcRoot>/web/**\". */\r\n appSrcRoot: string;\r\n /** v5/app/src/web/root.tsx — the single global app-root file. */\r\n appFile: string;\r\n /**\r\n * The application root Vite's dev server serves from — `dev-server.ts`'s\r\n * `paths.appRoot`, i.e. `<appRoot>/src === appSrcRoot` by default. Every\r\n * handler's stylesheet URLs are expressed relative to THIS, because that is\r\n * the root Vite's dev server actually resolves `/…` URLs against\r\n * (`stylesheet-urls.ts`'s `devStylesheetUrls`) — not `appSrcRoot`, which is\r\n * one directory level in.\r\n *\r\n * OPTIONAL and defaulted to `path.dirname(appSrcRoot)`: the caller that\r\n * wires dev boot (`web-connector.ts`) does not pass this field today, and\r\n * that default is exactly the relationship it constructs `appSrcRoot` from\r\n * (`appSrcRoot = path.join(appRoot, \"src\")`) — correct for every actual\r\n * deployment, and overridable by a caller with a non-default layout.\r\n */\r\n appRoot?: string;\r\n /** Browser module loaded after the server-rendered application and payload. */\r\n hydrationClientModuleUrl?: string;\r\n /**\r\n * UNUSED. Retained on this type only because `web-connector.ts` still builds\r\n * an options object naming it (`devStylesheetUrls(paths.appRoot,\r\n * paths.appFile)`, computed once for the whole application). Each handler\r\n * now computes its OWN stylesheet chain — `[root, ...outer-to-inner matched\r\n * layouts, page]`, via `devHandlerStylesheetUrls` — inside the registration\r\n * loop below, because a single application-wide list cannot express \"this\r\n * page's own CSS\" without also carrying every other page's.\r\n */\r\n stylesheetUrls?: readonly string[];\r\n /** Same helper `dev-server.ts` exports — passed in, not imported, to avoid a dev-server.ts <-> this-file cycle. */\r\n};\r\n\r\n/**\r\n * Registers every discoverable page into `options.router`. Throws\r\n * IMMEDIATELY, naming both files, the moment two pages declare the same\r\n * `route.path` — a registration-time failure, not a runtime 404 one of them\r\n * silently loses.\r\n *\r\n * Pages with no `route` export derive their path and name from their location\r\n * below `src/web`, using the same pure filesystem-routing helper as the build.\r\n */\r\nexport async function installPageRoutes(\r\n options: InstallPageRoutesOptions,\r\n): Promise<InstalledPageRoute[]> {\r\n const { router, vite, appSrcRoot, appFile, hydrationClientModuleUrl } = options;\r\n // See `InstallPageRoutesOptions.appRoot` for why this default, not\r\n // `appSrcRoot` itself, is the root every handler's CSS is resolved against.\r\n const stylesheetRoot = options.appRoot ?? path.dirname(appSrcRoot);\r\n const discovered = [...discoverPageFiles(appSrcRoot)].sort((left, right) =>\r\n left.pageFile < right.pageFile ? -1 : left.pageFile > right.pageFile ? 1 : 0,\r\n );\r\n\r\n // THE NOT-FOUND PAGE IS TAKEN OUT OF THE ORDINARY LOOP, not filtered inside\r\n // it. It has no `route` export to read, no path to compose and no collision\r\n // to check — every step below is about a page with a URL, and `404.page.tsx`\r\n // does not have one. Registering it here would put it at `/404`, which is not\r\n // a page anybody asked to be able to visit.\r\n const errorPageFiles = discovered.filter((page) => isErrorPageFile(page.pageFile));\r\n const notFoundPageFiles = discovered.filter((page) => isNotFoundPageFile(page.pageFile));\r\n const pageFiles = discovered.filter(\r\n (page) => !isNotFoundPageFile(page.pageFile) && !isErrorPageFile(page.pageFile),\r\n );\r\n\r\n if (errorPageFiles.length > 1) {\r\n throw new Error(\r\n `Two error pages were found: ${errorPageFiles.map((page) => page.pageFile).join(\", \")}.`,\r\n );\r\n }\r\n\r\n const errorPageFile = errorPageFiles[0]?.pageFile;\r\n\r\n // Parse only: the error boundary must remain lazy until a request actually\r\n // fails, while a route export is still rejected at install time.\r\n if (errorPageFile !== undefined) {\r\n const declarations = readRouteExports(errorPageFile);\r\n if (!declarations.ok) throw new NonLiteralRouteExportError(declarations.rejection);\r\n if (declarations.route !== undefined) throw new ErrorPageDeclaresRouteError(errorPageFile);\r\n }\r\n const loadErrorPage =\r\n errorPageFile === undefined\r\n ? undefined\r\n : () => vite.ssrLoadModule(errorPageFile) as Promise<ErrorPageModule>;\r\n\r\n if (notFoundPageFiles.length > 1) {\r\n throw new DuplicateNotFoundPageError(notFoundPageFiles.map((page) => page.pageFile));\r\n }\r\n\r\n const installed: InstalledPageRoute[] = [];\r\n const fileByPath = new Map<string, string>();\r\n\r\n for (const { pageFile, webRoot } of pageFiles) {\r\n const pageModule = (await vite.ssrLoadModule(pageFile)) as PageModuleShape;\r\n\r\n const sourceFile = canonicalSourceFileFor(pageFile, appSrcRoot);\r\n\r\n // Route identity is explicit when declared and filesystem-derived otherwise.\r\n const { declaredPath: routePath, name } = resolvePageRouteIdentity(\r\n pageModule.route,\r\n pageFile,\r\n appSrcRoot,\r\n );\r\n\r\n // Validated at INSTALL time, with everything else — a malformed `cache`\r\n // opt-in fails boot, not the first request that would have served it.\r\n const cache = resolvePageRouteCache(pageModule.route, pageFile);\r\n\r\n const loadLayout: LoadLayout = (layoutFile) =>\r\n vite.ssrLoadModule(layoutFile) as Promise<LayoutModuleShape>;\r\n const layoutLevel = await resolveLayoutLevel(pageFile, webRoot, loadLayout);\r\n const { layoutFile, prefix: layoutPrefix } = layoutLevel;\r\n\r\n const effectivePath =\r\n pageModule.route === undefined\r\n ? deriveFilesystemRoutePath({\r\n pageFile: filesystemPageFileFor(pageFile, appSrcRoot),\r\n layoutPrefixes: layoutLevel.prefixesByDirectory,\r\n })\r\n : composeRoutePath(layoutPrefix, routePath);\r\n\r\n const existingFile = fileByPath.get(effectivePath);\r\n\r\n if (existingFile) {\r\n throw new Error(\r\n `installPageRoutes: composed route path \"${effectivePath}\" (layout ` +\r\n `prefix \"${layoutPrefix}\" + route.path \"${routePath}\") is declared by two ` +\r\n `pages (web/src/server/install-page-routes.ts) — \"${existingFile}\" and ` +\r\n `\"${pageFile}\". Every page's composed route path must be unique.`,\r\n );\r\n }\r\n\r\n fileByPath.set(effectivePath, pageFile);\r\n\r\n // Every registered handler gets ITS OWN immutable, ordered, deduped CSS\r\n // chain: root, then every matched layout outer to inner\r\n // (`layoutLevel.chain`), then the page — the same order the render\r\n // pipeline loads that chain in, so cascade order matches load order.\r\n // Computed once here, at registration, not per request: dev re-registers\r\n // on every restart, so a stale chain cannot outlive the source edit that\r\n // changed it.\r\n const stylesheetUrls = devHandlerStylesheetUrls(stylesheetRoot, [\r\n appFile,\r\n ...layoutLevel.chain,\r\n pageFile,\r\n ]);\r\n\r\n await router.withSourceFile(sourceFile, () =>\r\n router.get(\r\n effectivePath,\r\n // The handler itself is `createPageRouteHandler`\r\n // (`web/src/server/create-page-route-handler.ts`) — a named seam a\r\n // future `type: \"page\"` route can bind to, and testable without a Vite\r\n // server. Vite appears here only as the dev answer to \"how do I load a\r\n // module\"; the handler takes that as an input and knows nothing else\r\n // about it.\r\n createPageRouteHandler({\r\n path: effectivePath,\r\n name,\r\n appFile,\r\n pageFile,\r\n layoutFile,\r\n // The layout slot's id resolves to the COMPOSED level — every layout's\r\n // middleware, in chain order — and every other id goes straight to\r\n // Vite. A one-layout chain has nothing to compose, so it is left to\r\n // resolve as the exact module Vite hands back, untouched.\r\n loadModule:\r\n layoutLevel.chain.length > 1 && layoutFile !== undefined\r\n ? (moduleId) =>\r\n moduleId === layoutFile\r\n ? composeLayoutLevel({ ...layoutLevel, layoutFile }, loadLayout)\r\n : vite.ssrLoadModule(moduleId)\r\n : (moduleId) => vite.ssrLoadModule(moduleId),\r\n // Registration tracks real module namespaces, not the composed\r\n // layout wrapper above. Loading the raw chain per request also lets\r\n // Vite hand over a replacement namespace after an HMR update; the\r\n // helper's WeakSet then gives that new identity its one invocation.\r\n loadRegistrationLayouts: () => Promise.all(layoutLevel.chain.map(loadLayout)),\r\n hydrationClientModuleUrl,\r\n loadErrorPage,\r\n stylesheetUrls,\r\n cache,\r\n }),\r\n // `isPage` marks this route as SSR-served. Pages and API routes share one\r\n // router and one route-name namespace, so the router's duplicate-name\r\n // error reads this flag to say which claimant is the page.\r\n { name, isPage: true },\r\n ),\r\n );\r\n\r\n installed.push({\r\n declaredPath: routePath,\r\n path: effectivePath,\r\n name,\r\n file: pageFile,\r\n layoutFile,\r\n });\r\n }\r\n\r\n /*\r\n THE CATCH-ALL, registered LAST and only when this application has a page\r\n surface at all. \"Configured with web, no pages yet\" is a legal state, and an\r\n application serving no pages has no page 404 to answer with — its unmatched\r\n URLs stay core's to answer, exactly as they are today.\r\n\r\n Registered even when the application ships no `404.page.tsx`: the framework\r\n default still answers 404, so an application that has not written one yet\r\n gets the right STATUS from the first request, and adding the file later\r\n changes the body and nothing else.\r\n */\r\n if (pageFiles.length > 0 || notFoundPageFiles.length > 0) {\r\n const notFoundPageFile = notFoundPageFiles[0]?.pageFile;\r\n\r\n // Read at INSTALL time, so a `route` export on the not-found page is\r\n // refused at boot with everything else — not on the first request that\r\n // misses, which is the one request nobody is watching.\r\n if (notFoundPageFile !== undefined) {\r\n const notFoundModule = (await vite.ssrLoadModule(notFoundPageFile)) as PageModuleShape;\r\n\r\n if (notFoundModule.route !== undefined) {\r\n throw new NotFoundPageDeclaresRouteError(notFoundPageFile);\r\n }\r\n }\r\n\r\n const registerNotFoundRoute = () =>\r\n router.get(\r\n NOT_FOUND_ROUTE_PATH,\r\n createNotFoundRouteHandler({\r\n renderPage:\r\n notFoundPageFile === undefined\r\n ? undefined\r\n : createPageRouteHandler({\r\n path: NOT_FOUND_ROUTE_PATH,\r\n name: NOT_FOUND_ROUTE_NAME,\r\n appFile,\r\n pageFile: notFoundPageFile,\r\n // NO LAYOUT, deliberately, and it is the same trade as \"no\r\n // loader on the 404 page\": a layout brings its whole chain's\r\n // middleware with it, and a guard that redirects or throws on\r\n // the not-found path turns a missing page into an incident. The\r\n // page renders inside the application root and nothing else.\r\n layoutFile: undefined,\r\n loadModule: (moduleId) => vite.ssrLoadModule(moduleId),\r\n hydrationClientModuleUrl,\r\n loadErrorPage,\r\n // NO LAYOUT means no layout CSS either — just root and the\r\n // not-found page's own stylesheets, same reasoning as above.\r\n stylesheetUrls: devHandlerStylesheetUrls(stylesheetRoot, [\r\n appFile,\r\n notFoundPageFile,\r\n ]),\r\n // The URL that missed IS this route's pattern for this request.\r\n matchPath: (requestPath) => requestPath,\r\n statusForRenderedOk: 404,\r\n skipPageLoader: true,\r\n }),\r\n }),\r\n // `isPage` for the same reason every other page route carries it: the\r\n // router's duplicate-name error reads the flag to say which claimant is\r\n // the page.\r\n { name: NOT_FOUND_ROUTE_NAME, isPage: true },\r\n );\r\n\r\n if (notFoundPageFile === undefined) {\r\n await router.withSourceFile(FRAMEWORK_DEFAULT_NOT_FOUND_SOURCE_FILE, registerNotFoundRoute);\r\n } else {\r\n await router.withSourceFile(\r\n canonicalSourceFileFor(notFoundPageFile, appSrcRoot),\r\n registerNotFoundRoute,\r\n );\r\n }\r\n }\r\n\r\n /*\r\n Published from the SAME loop that registered the routes, so `href()` and the\r\n router cannot disagree about where a name points. It happens here rather\r\n than in the caller because a caller that forgets leaves every `<Link>` on\r\n the server throwing at render — and dev republishes on every restart, which\r\n is why the table replaces wholesale instead of merging: a deleted page's\r\n name has to stop resolving.\r\n */\r\n publishRouteTable(installed, \"installPageRoutes (dev)\");\r\n\r\n return installed;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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{"version":3,"file":"install-page-routes.mjs","names":["resolveComposedLayoutLevel"],"sources":["../../../../../../../web/src/server/install-page-routes.ts"],"sourcesContent":["/**\r\n * Registers every page {@link discoverPageFiles} finds under `<appSrcRoot>`\r\n * into Warlock's router (`router.get`, `core/src/router/router.ts:359-361`)\r\n * so `router.scanDevServer(fastify)` —\r\n * the sanctioned dev-server dispatch path (server matching is Warlock's\r\n * router; there is no second server matcher) — picks\r\n * it up. Replaces the two hand-rolled `fastify.get()` calls this file's\r\n * sibling, `dev-error-transport.ts`, used to make directly.\r\n *\r\n * DELIBERATE EXCEPTION to \"web has no core dependency\", same\r\n * reasoning `dev-error-transport.ts`'s own header comment records: this module is not\r\n * exported from either package barrel and is not part of `web/package.json`'s\r\n * dependency graph — dev/CLI bootstrap only.\r\n *\r\n * Scope note: a page's\r\n * `route.path` is now composed with the `prefix` export of EVERY `layout.tsx`\r\n * on its path — outermost first (`composeRoutePath` below) — before\r\n * registration and before the collision check, so `home.page.tsx`\r\n * (`path: \"/\"`, main layout `prefix: \"/\"`) resolves to `/` and\r\n * `products.page.tsx` (`path: \"/\"`, products layout `prefix: \"/products\"`)\r\n * resolves to `/products` — no collision. A page with no `layout.tsx` on its\r\n * path composes against the implicit root prefix `\"/\"` (e.g. `/contact-us`,\r\n * `/hydration-demo`, both unaffected by composition).\r\n *\r\n * WHICH PAGES EXIST is answered by {@link discoverPageFiles}\r\n * (`web/src/build/discover-pages.ts`) — the same walk production's build\r\n * shares — so this file owns no directory-walking of its own; it serves the\r\n * page root (`<appSrcRoot>/web/**`) exactly as discovery enumerates it. WHAT\r\n * ROUTE A PAGE ANSWERS ON stays this file's own job: each page and its nearest layout are still evaluated\r\n * through Vite (`vite.ssrLoadModule`), never read statically, because a dev\r\n * page module must be the one Vite serves, warm cache and all.\r\n */\r\nimport path from \"node:path\";\r\nimport type { ViteDevServer } from \"vite\";\r\nimport {\r\n discoverPageFiles,\r\n ErrorPageDeclaresRouteError,\r\n isErrorPageFile,\r\n layoutChainFor,\r\n} from \"../build/discover-pages\";\r\nimport { NonLiteralRouteExportError, readRouteExports } from \"../build/read-route-exports\";\r\nimport { composeRoutePath } from \"../routing/compose-route-path\";\r\nimport { duplicateRoutePathMessage } from \"../routing/duplicate-route-path\";\r\nimport { deriveFilesystemRoutePath } from \"../routing/filesystem-route\";\r\nimport { resolveLayoutLevel as resolveComposedLayoutLevel } from \"../routing/layout-level\";\r\nimport { PageFileSegmentNotSupportedError } from \"../routing/page-file-segment\";\r\nimport { toPosix } from \"../shared/to-posix\";\r\nimport {\r\n resolvePageRouteCache,\r\n resolvePageRouteIdentity,\r\n resolvePageRouteName,\r\n} from \"../routing/route-identity\";\r\nimport { publishRouteTable } from \"../routing/route-table\";\r\nimport { type FastifyInstance, type Router } from \"@warlock.js/core\";\r\nimport { createPageRouteHandler } from \"./create-page-route-handler\";\r\nimport type { ErrorPageModule } from \"./error-page\";\r\nimport type { PipelineLoader, PipelineMiddleware } from \"./execute-page-request\";\r\nimport { foldLayoutLoaders } from \"./fold-layout-loaders\";\r\nimport { devHandlerStylesheetUrls } from \"./stylesheet-urls\";\r\nimport {\r\n DuplicateNotFoundPageError,\r\n isNotFoundPageFile,\r\n NotFoundPageDeclaresRouteError,\r\n NOT_FOUND_ROUTE_NAME,\r\n NOT_FOUND_ROUTE_PATH,\r\n registerNotFoundPageRoute,\r\n} from \"./not-found-page\";\r\nimport type { LayoutModuleShape, PageModuleShape, PageRouteExport } from \"./page-module-shapes\";\r\n\r\nexport type { LayoutModuleShape, PageModuleShape, PageRouteExport } from \"./page-module-shapes\";\r\n\r\n/** Re-exported so `web/src/server/index.ts`'s existing barrel export keeps resolving. */\r\nexport { composeRoutePath };\r\n\r\n/** Raised at boot when a page still uses the withdrawn `route.middleware` export. */\r\nexport class RouteMiddlewareRemovedError extends Error {\r\n public constructor(public readonly pageFile: string) {\r\n super(\r\n `\"${pageFile}\" declares \\`route.middleware\\`, which no longer runs — it was withdrawn after 5.6.0. ` +\r\n \"Move it to the page's own top-level `middleware` export instead: `export const middleware = [...]`.\",\r\n );\r\n this.name = \"RouteMiddlewareRemovedError\";\r\n }\r\n}\r\n\r\n/** Raised at boot when a page still uses the withdrawn `route.validate` export. */\r\nexport class RouteValidationRemovedError extends Error {\r\n public constructor(public readonly pageFile: string) {\r\n super(\r\n `\"${pageFile}\" declares \\`route.validate\\`, which no longer runs — it was withdrawn after 5.6.0. ` +\r\n \"Move it to the page's top-level `validation` export instead: `export const validation = { params: ..., query: ... }`.\",\r\n );\r\n this.name = \"RouteValidationRemovedError\";\r\n }\r\n}\r\n\r\nexport type InstalledPageRoute = {\r\n /** The canonical declared route path, before layout-prefix composition. */\r\n declaredPath: string;\r\n path: string;\r\n name: string;\r\n file: string;\r\n layoutFile: string | undefined;\r\n};\r\n\r\n/**\r\n * Ownership key for the framework's fallback 404 route. A NUL-prefixed value\r\n * cannot be a real filesystem path, so it cannot collide with an app page's\r\n * canonical source-file key.\r\n */\r\nexport const FRAMEWORK_DEFAULT_NOT_FOUND_SOURCE_FILE = \"\\0warlock:framework-default-404\";\r\n\r\n/**\r\n * The page's application-source-relative POSIX source path used as the router's\r\n * stable ownership key. `appSrcRoot`'s own basename preserves the existing\r\n * `src/web/...` source-file convention.\r\n */\r\nfunction canonicalSourceFileFor(pageFile: string, appSrcRoot: string): string {\r\n return `${path.basename(appSrcRoot)}/${toPosix(path.relative(appSrcRoot, pageFile))}`;\r\n}\r\n\r\nexport function filesystemPageFileFor(pageFile: string, appSrcRoot: string): string {\r\n return toPosix(path.relative(path.join(appSrcRoot, \"web\"), pageFile));\r\n}\r\n\r\n/**\r\n * Raised when a page's own module fails to load in dev (`vite.ssrLoadModule`\r\n * rejects on the page file itself — never a layout, which this class does not\r\n * cover).\r\n *\r\n * Before this class existed, that rejection propagated straight out of\r\n * `installPageRoutes`'s loop and failed the WHOLE install: every other page's\r\n * route went unregistered along with the broken one, and the failure named\r\n * neither the page file nor which module actually threw. One bad page taking\r\n * every other page down with it is a worse outage than the bad page alone, so\r\n * this error is what the broken page's own route now fails with instead —\r\n * named, with its cause attached, while the rest of the application keeps\r\n * serving.\r\n */\r\nexport class PageModuleLoadError extends Error {\r\n public constructor(\r\n public readonly pageFile: string,\r\n cause: unknown,\r\n ) {\r\n const rawCause = cause instanceof Error ? cause.message : String(cause);\r\n // The cause is someone else's text — a bundler's, a module resolver's — so\r\n // it may or may not end in punctuation. Without this it runs straight into\r\n // the next sentence, and the seam is exactly where a reader stops trusting\r\n // the message.\r\n const causeMessage = /[.!?]$/.test(rawCause.trim()) ? rawCause.trim() : `${rawCause.trim()}.`;\r\n\r\n super(\r\n `\"${pageFile}\" failed to load: ${causeMessage} Every other page still installed and is ` +\r\n \"still serving; fix the error in this page's module and it will start serving again.\",\r\n { cause },\r\n );\r\n this.name = \"PageModuleLoadError\";\r\n }\r\n}\r\n\r\n/**\r\n * Registers a page whose OWN module failed to load at its filesystem-derived\r\n * URL, so a request there reports {@link PageModuleLoadError} — naming the\r\n * page file and the underlying cause — instead of a bare 404 that explains\r\n * nothing.\r\n *\r\n * Only the filesystem-derived path is attempted: the page's `route` export\r\n * cannot be read (that requires the very module that failed to load), and its\r\n * layout chain is not resolved either, so no layout prefix composes into this\r\n * path. When the filesystem path itself is not derivable\r\n * (`deriveFilesystemRoutePath` rejects a segment), there is no path left to\r\n * register a route at, so nothing is registered — the caller reports both\r\n * failures loudly at boot and moves on.\r\n */\r\nasync function registerFailedPageRoute(input: {\r\n router: Router;\r\n pageFile: string;\r\n appSrcRoot: string;\r\n loadError: unknown;\r\n fileByPath: Map<string, string>;\r\n}): Promise<void> {\r\n const { router, pageFile, appSrcRoot, loadError, fileByPath } = input;\r\n const attributed = new PageModuleLoadError(pageFile, loadError);\r\n const filesystemPageFile = filesystemPageFileFor(pageFile, appSrcRoot);\r\n\r\n let effectivePath: string;\r\n\r\n try {\r\n effectivePath = deriveFilesystemRoutePath({ pageFile: filesystemPageFile });\r\n } catch (segmentError) {\r\n if (!(segmentError instanceof PageFileSegmentNotSupportedError)) throw segmentError;\r\n\r\n // No filesystem path to register a route at, so this page cannot answer\r\n // its own URL with the attributed error — the request that would have hit\r\n // it 404s instead, unregistered, and the existing unregistered-page\r\n // reporter (`web/src/server/unregistered-pages.ts`) is what explains that\r\n // 404 to whoever is looking. Reported loudly here so the underlying load\r\n // failure is not lost as well.\r\n console.error(attributed.message);\r\n console.error(segmentError.message);\r\n\r\n return;\r\n }\r\n\r\n const existingFile = fileByPath.get(effectivePath);\r\n\r\n if (existingFile) {\r\n throw new Error(duplicateRoutePathMessage({ effectivePath, existingFile, newFile: pageFile }));\r\n }\r\n\r\n fileByPath.set(effectivePath, pageFile);\r\n\r\n await router.withSourceFile(canonicalSourceFileFor(pageFile, appSrcRoot), () =>\r\n router.get(\r\n effectivePath,\r\n async () => {\r\n throw attributed;\r\n },\r\n { name: resolvePageRouteName(undefined, filesystemPageFile), isPage: true },\r\n ),\r\n );\r\n}\r\n\r\n/* Moved to page-module-shapes.ts so both installers consume one contract.\r\n * Universal registration hook; invoked on this real namespace, never a composed wrapper.\r\n register?: () => unknown;\r\n prefix?: string;\r\n *\r\n * The default export — the thing that puts an element in the document, and\r\n * therefore the ONLY export that decides whether a layout counts against the\r\n * single-rendering-layout rule (`../routing/layout-policy.ts`). In dev the\r\n * module is loaded, so this is a fact rather than a guess.\r\n *\r\n default?: unknown;\r\n * The layout's guards, in declaration order.\r\n middleware?: readonly PipelineMiddleware[];\r\n loader?: PipelineLoader;\r\n*/\r\n\r\n/** How this module gets a layout module namespace — `vite.ssrLoadModule`, in practice. */\r\ntype LoadLayout = (layoutFile: string) => Promise<LayoutModuleShape>;\r\n\r\n/**\r\n * The page's layout LEVEL, resolved from its whole chain rather than from the\r\n * one layout nearest to it.\r\n *\r\n * The render pipeline has exactly one layout slot per page\r\n * (`execute-page-request.ts`'s `PageRouteEntry[\"triple\"]`), so the chain has to\r\n * be collapsed into one module before it reaches a handler. Two things collapse\r\n * differently and both matter:\r\n *\r\n * - RENDERING is a selection: at most one layout on the chain may render, and\r\n * the policy picks it. `renders` is read off the loaded module\r\n * (`typeof module.default !== \"undefined\"`), never off the filename — a\r\n * `middleware`-only layout has no default export and is not a wrapper, and\r\n * passing a bare path to the policy would have it read as a rendering one,\r\n * which is the conservative default and the wrong answer here.\r\n * - MIDDLEWARE and PREFIX are compositions: every layout on the path\r\n * contributes, outermost first. A guard on an outer layout that the page's\r\n * own directory knows nothing about is exactly the guard that must still run,\r\n * and a prefix nobody composed is a URL nobody wrote down.\r\n *\r\n * The selection and prefix composition rules themselves do not depend on\r\n * where a layout's module came from, so they are not re-derived here — see\r\n * `../routing/layout-level.ts`'s `resolveLayoutLevel`, which production's\r\n * installer calls against the same rules. This function's own job is\r\n * everything that DOES depend on the source: walking the chain\r\n * (`layoutChainFor`), loading each module (`loadLayout`) and keying declared\r\n * prefixes by filesystem directory for {@link deriveFilesystemRoutePath}.\r\n */\r\ntype LayoutLevel = {\r\n /** Every `layout.tsx` from the web root down to the page's directory, outermost first. */\r\n chain: string[];\r\n /**\r\n * The module id the handler's layout slot is registered under, or `undefined`\r\n * when the page has no layout at all: the layout that RENDERS, or — when none\r\n * does — the nearest one, which is the slot dev has always used and so the\r\n * choice that changes nothing but the middleware for a chain with no wrapper\r\n * in it.\r\n */\r\n layoutFile: string | undefined;\r\n /** Every layout's `prefix`, composed outermost first — `discoverPages`' own reduction. */\r\n prefix: string;\r\n /** Declared prefixes keyed by layout directory relative to this page's web root. */\r\n prefixesByDirectory: Readonly<Record<string, string>>;\r\n};\r\n\r\nasync function resolveLayoutLevel(\r\n pageFile: string,\r\n webRoot: string,\r\n loadLayout: LoadLayout,\r\n): Promise<LayoutLevel> {\r\n const chain = layoutChainFor(pageFile, webRoot);\r\n const modules = await Promise.all(chain.map(loadLayout));\r\n const level = resolveComposedLayoutLevel(\r\n pageFile,\r\n chain.map((layoutFile, index) => ({\r\n id: layoutFile,\r\n renders: typeof modules[index].default !== \"undefined\",\r\n prefix: modules[index].prefix,\r\n })),\r\n );\r\n\r\n return {\r\n chain,\r\n layoutFile: level.hostId,\r\n prefix: level.prefix,\r\n prefixesByDirectory: Object.fromEntries(\r\n chain.flatMap((layoutFile, index) => {\r\n const prefix = modules[index].prefix;\r\n\r\n return prefix === undefined\r\n ? []\r\n : [[toPosix(path.relative(webRoot, path.dirname(layoutFile))), prefix]];\r\n }),\r\n ),\r\n };\r\n}\r\n\r\n/**\r\n * The layout slot's module for ONE request: the slot host's own namespace, with\r\n * the whole chain's middleware in place of its own — outermost first, which is\r\n * the order stage 3 runs the array in (`execute-page-request.ts:519-524`) and\r\n * the order an outer `optionalAuth` needs in order to have resolved an identity\r\n * before an inner `gate()` checks it.\r\n *\r\n * Loaded per call, not once at install time: a dev layout module must be the\r\n * one Vite is currently serving, edits and all.\r\n */\r\nasync function composeLayoutLevel(\r\n level: LayoutLevel & { layoutFile: string },\r\n loadLayout: LoadLayout,\r\n): Promise<LayoutModuleShape> {\r\n const modules = await Promise.all(level.chain.map(loadLayout));\r\n const hostIndex = level.chain.indexOf(level.layoutFile);\r\n const host = modules[hostIndex];\r\n\r\n return {\r\n ...host,\r\n middleware: modules.flatMap((layoutModule) => [...(layoutModule.middleware ?? [])]),\r\n loader: foldLayoutLoaders(\r\n modules.map((layoutModule) => layoutModule.loader),\r\n hostIndex,\r\n ),\r\n };\r\n}\r\n\r\nexport type InstallPageRoutesOptions = {\r\n router: Router;\r\n vite: ViteDevServer;\r\n /** v5/app/src — pages live under \"<appSrcRoot>/web/**\". */\r\n appSrcRoot: string;\r\n /** v5/app/src/web/root.tsx — the single global app-root file. */\r\n appFile: string;\r\n /**\r\n * The application root Vite's dev server serves from — `dev-error-transport.ts`'s\r\n * `paths.appRoot`, i.e. `<appRoot>/src === appSrcRoot` by default. Every\r\n * handler's stylesheet URLs are expressed relative to THIS, because that is\r\n * the root Vite's dev server actually resolves `/…` URLs against\r\n * (`stylesheet-urls.ts`'s `devStylesheetUrls`) — not `appSrcRoot`, which is\r\n * one directory level in.\r\n *\r\n * OPTIONAL and defaulted to `path.dirname(appSrcRoot)`: the caller that\r\n * wires dev boot (`web-connector.ts`) does not pass this field today, and\r\n * that default is exactly the relationship it constructs `appSrcRoot` from\r\n * (`appSrcRoot = path.join(appRoot, \"src\")`) — correct for every actual\r\n * deployment, and overridable by a caller with a non-default layout.\r\n */\r\n appRoot?: string;\r\n /** Browser module loaded after the server-rendered application and payload. */\r\n hydrationClientModuleUrl?: string;\r\n /**\r\n * UNUSED. Retained on this type only because `web-connector.ts` still builds\r\n * an options object naming it (`devStylesheetUrls(paths.appRoot,\r\n * paths.appFile)`, computed once for the whole application). Each handler\r\n * now computes its OWN stylesheet chain — `[root, ...outer-to-inner matched\r\n * layouts, page]`, via `devHandlerStylesheetUrls` — inside the registration\r\n * loop below, because a single application-wide list cannot express \"this\r\n * page's own CSS\" without also carrying every other page's.\r\n */\r\n stylesheetUrls?: readonly string[];\r\n /**\r\n * The Fastify instance `HttpConnector.boot()` published, resolved by the\r\n * caller on the NODE side (`web-connector.ts`) and forwarded to every\r\n * `createPageRouteHandler` call below instead of letting that factory read\r\n * `container.get(\"http.server\")` for itself.\r\n *\r\n * Load-bearing, not a convenience: Vite's SSR module runner\r\n * (`vite.ssrLoadModule`, used throughout this file) evaluates\r\n * `create-page-route-handler.ts` as a SECOND copy of `@warlock.js/core`, with\r\n * its own `container` that `HttpConnector.boot()` never wrote to. Reading the\r\n * container from inside that SSR graph therefore always misses, however\r\n * early or late this file calls it — the value has to arrive as a plain\r\n * argument from a caller on the Node side, where the real container lives.\r\n *\r\n * OPTIONAL so existing callers (and this file's own unit tests, which seed\r\n * `container.set(\"http.server\", …)` instead) keep resolving through the\r\n * container exactly as before — omitted here means \"not supplied\", the same\r\n * distinction `createPageRouteHandler` itself draws from `PageRouteHandlerOptions.httpServer`.\r\n */\r\n httpServer?: FastifyInstance;\r\n};\r\n\r\n/**\r\n * Registers every discoverable page into `options.router`. Throws\r\n * IMMEDIATELY, naming both files, the moment two pages declare the same\r\n * `route.path` — a registration-time failure, not a runtime 404 one of them\r\n * silently loses.\r\n *\r\n * Pages with no `route` export derive their path and name from their location\r\n * below `src/web`, using the same pure filesystem-routing helper as the build.\r\n */\r\nexport async function installPageRoutes(\r\n options: InstallPageRoutesOptions,\r\n): Promise<InstalledPageRoute[]> {\r\n const { router, vite, appSrcRoot, appFile, hydrationClientModuleUrl, httpServer } = options;\r\n // Spread conditionally, never as a bare `httpServer,` property: an explicit\r\n // `httpServer: undefined` key is its own signal to `createPageRouteHandler`\r\n // (`\"httpServer\" in options\"`, `create-page-route-handler.ts`) — \"no server,\r\n // on purpose\" — and this file must not manufacture that signal on behalf of\r\n // a caller (this file's own unit tests, most callers) that never supplied\r\n // one and means to fall back to the container instead.\r\n const httpServerOption = httpServer === undefined ? {} : { httpServer };\r\n // See `InstallPageRoutesOptions.appRoot` for why this default, not\r\n // `appSrcRoot` itself, is the root every handler's CSS is resolved against.\r\n const stylesheetRoot = options.appRoot ?? path.dirname(appSrcRoot);\r\n const discovered = [...discoverPageFiles(appSrcRoot)].sort((left, right) =>\r\n left.pageFile < right.pageFile ? -1 : left.pageFile > right.pageFile ? 1 : 0,\r\n );\r\n\r\n // THE NOT-FOUND PAGE IS TAKEN OUT OF THE ORDINARY LOOP, not filtered inside\r\n // it. It has no `route` export to read, no path to compose and no collision\r\n // to check — every step below is about a page with a URL, and `404.page.tsx`\r\n // does not have one. Registering it here would put it at `/404`, which is not\r\n // a page anybody asked to be able to visit.\r\n const errorPageFiles = discovered.filter((page) => isErrorPageFile(page.pageFile));\r\n const notFoundPageFiles = discovered.filter((page) => isNotFoundPageFile(page.pageFile));\r\n const pageFiles = discovered.filter(\r\n (page) => !isNotFoundPageFile(page.pageFile) && !isErrorPageFile(page.pageFile),\r\n );\r\n\r\n if (errorPageFiles.length > 1) {\r\n throw new Error(\r\n `Two error pages were found: ${errorPageFiles.map((page) => page.pageFile).join(\", \")}.`,\r\n );\r\n }\r\n\r\n const errorPageFile = errorPageFiles[0]?.pageFile;\r\n\r\n // Parse only: the error boundary must remain lazy until a request actually\r\n // fails, while a route export is still rejected at install time.\r\n if (errorPageFile !== undefined) {\r\n const declarations = readRouteExports(errorPageFile);\r\n if (!declarations.ok) throw new NonLiteralRouteExportError(declarations.rejection);\r\n if (declarations.route !== undefined) throw new ErrorPageDeclaresRouteError(errorPageFile);\r\n }\r\n const loadErrorPage =\r\n errorPageFile === undefined\r\n ? undefined\r\n : () => vite.ssrLoadModule(errorPageFile) as Promise<ErrorPageModule>;\r\n\r\n if (notFoundPageFiles.length > 1) {\r\n throw new DuplicateNotFoundPageError(notFoundPageFiles.map((page) => page.pageFile));\r\n }\r\n\r\n const installed: InstalledPageRoute[] = [];\r\n const fileByPath = new Map<string, string>();\r\n\r\n for (const { pageFile, webRoot } of pageFiles) {\r\n let pageModule: PageModuleShape;\r\n\r\n try {\r\n pageModule = (await vite.ssrLoadModule(pageFile)) as PageModuleShape;\r\n } catch (loadError) {\r\n // THE PAGE ITSELF MUST NOT ABORT THE INSTALL: every other page still\r\n // needs to install and serve. Layout loading is deliberately NOT\r\n // wrapped here — a broken layout is a different failure with a\r\n // different blast radius (it can affect more than one page) and is out\r\n // of this card's scope.\r\n await registerFailedPageRoute({ router, pageFile, appSrcRoot, loadError, fileByPath });\r\n\r\n continue;\r\n }\r\n\r\n const route = pageModule.route as unknown;\r\n\r\n if (typeof route === \"object\" && route !== null) {\r\n if (\"middleware\" in route) throw new RouteMiddlewareRemovedError(pageFile);\r\n if (\"validate\" in route) throw new RouteValidationRemovedError(pageFile);\r\n }\r\n\r\n const sourceFile = canonicalSourceFileFor(pageFile, appSrcRoot);\r\n\r\n // Route identity is explicit when declared and filesystem-derived otherwise.\r\n const { path: routePath, name } = resolvePageRouteIdentity(\r\n pageModule.route,\r\n filesystemPageFileFor(pageFile, appSrcRoot),\r\n pageFile,\r\n );\r\n\r\n // Validated at INSTALL time, with everything else — a malformed `cache`\r\n // opt-in fails boot, not the first request that would have served it.\r\n const cache = resolvePageRouteCache(pageModule.route, pageFile);\r\n\r\n const loadLayout: LoadLayout = (layoutFile) =>\r\n vite.ssrLoadModule(layoutFile) as Promise<LayoutModuleShape>;\r\n const layoutLevel = await resolveLayoutLevel(pageFile, webRoot, loadLayout);\r\n const { layoutFile, prefix: layoutPrefix } = layoutLevel;\r\n\r\n const effectivePath =\r\n pageModule.route === undefined\r\n ? deriveFilesystemRoutePath({\r\n pageFile: filesystemPageFileFor(pageFile, appSrcRoot),\r\n layoutPrefixes: layoutLevel.prefixesByDirectory,\r\n })\r\n : composeRoutePath(layoutPrefix, routePath);\r\n\r\n const existingFile = fileByPath.get(effectivePath);\r\n\r\n if (existingFile) {\r\n throw new Error(\r\n duplicateRoutePathMessage({\r\n effectivePath,\r\n existingFile,\r\n newFile: pageFile,\r\n composition: { layoutPrefix, routePath },\r\n }),\r\n );\r\n }\r\n\r\n fileByPath.set(effectivePath, pageFile);\r\n\r\n // Every registered handler gets ITS OWN immutable, ordered, deduped CSS\r\n // chain: root, then every matched layout outer to inner\r\n // (`layoutLevel.chain`), then the page — the same order the render\r\n // pipeline loads that chain in, so cascade order matches load order.\r\n // Computed once here, at registration, not per request: dev re-registers\r\n // on every restart, so a stale chain cannot outlive the source edit that\r\n // changed it.\r\n const stylesheetUrls = devHandlerStylesheetUrls(\r\n stylesheetRoot,\r\n [appFile, ...layoutLevel.chain, pageFile],\r\n vite.moduleGraph,\r\n );\r\n\r\n await router.withSourceFile(sourceFile, () =>\r\n router.get(\r\n effectivePath,\r\n // The handler itself is `createPageRouteHandler`\r\n // (`web/src/server/create-page-route-handler.ts`) — a named seam a\r\n // future `type: \"page\"` route can bind to, and testable without a Vite\r\n // server. Vite appears here only as the dev answer to \"how do I load a\r\n // module\"; the handler takes that as an input and knows nothing else\r\n // about it.\r\n createPageRouteHandler({\r\n path: effectivePath,\r\n name,\r\n appFile,\r\n pageFile,\r\n layoutFile,\r\n // The layout slot's id resolves to the COMPOSED level — every layout's\r\n // middleware, in chain order — and every other id goes straight to\r\n // Vite. A one-layout chain has nothing to compose, so it is left to\r\n // resolve as the exact module Vite hands back, untouched.\r\n loadModule:\r\n layoutLevel.chain.length > 1 && layoutFile !== undefined\r\n ? (moduleId) =>\r\n moduleId === layoutFile\r\n ? composeLayoutLevel({ ...layoutLevel, layoutFile }, loadLayout)\r\n : vite.ssrLoadModule(moduleId)\r\n : (moduleId) => vite.ssrLoadModule(moduleId),\r\n // Registration tracks real module namespaces, not the composed\r\n // layout wrapper above. Loading the raw chain per request also lets\r\n // Vite hand over a replacement namespace after an HMR update; the\r\n // helper's WeakSet then gives that new identity its one invocation.\r\n loadRegistrationLayouts: () => Promise.all(layoutLevel.chain.map(loadLayout)),\r\n hydrationClientModuleUrl,\r\n loadErrorPage,\r\n stylesheetUrls,\r\n cache,\r\n ...httpServerOption,\r\n }),\r\n // `isPage` marks this route as SSR-served. Pages and API routes share one\r\n // router and one route-name namespace, so the router's duplicate-name\r\n // error reads this flag to say which claimant is the page.\r\n { name, isPage: true },\r\n ),\r\n );\r\n\r\n installed.push({\r\n declaredPath: routePath,\r\n path: effectivePath,\r\n name,\r\n file: pageFile,\r\n layoutFile,\r\n });\r\n }\r\n\r\n /*\r\n THE CATCH-ALL, registered LAST and only when this application has a page\r\n surface at all. \"Configured with web, no pages yet\" is a legal state, and an\r\n application serving no pages has no page 404 to answer with — its unmatched\r\n URLs stay core's to answer, exactly as they are today.\r\n\r\n Registered even when the application ships no `404.page.tsx`: the framework\r\n default still answers 404, so an application that has not written one yet\r\n gets the right STATUS from the first request, and adding the file later\r\n changes the body and nothing else.\r\n */\r\n if (pageFiles.length > 0 || notFoundPageFiles.length > 0) {\r\n const notFoundPageFile = notFoundPageFiles[0]?.pageFile;\r\n\r\n // Read at INSTALL time, so a `route` export on the not-found page is\r\n // refused at boot with everything else — not on the first request that\r\n // misses, which is the one request nobody is watching.\r\n if (notFoundPageFile !== undefined) {\r\n const notFoundModule = (await vite.ssrLoadModule(notFoundPageFile)) as PageModuleShape;\r\n\r\n if (notFoundModule.route !== undefined) {\r\n throw new NotFoundPageDeclaresRouteError(notFoundPageFile);\r\n }\r\n }\r\n\r\n const registerNotFoundRoute = () =>\r\n registerNotFoundPageRoute({\r\n router,\r\n renderPage:\r\n notFoundPageFile === undefined\r\n ? undefined\r\n : createPageRouteHandler({\r\n path: NOT_FOUND_ROUTE_PATH,\r\n name: NOT_FOUND_ROUTE_NAME,\r\n appFile,\r\n pageFile: notFoundPageFile,\r\n // NO LAYOUT, deliberately, and it is the same trade as \"no\r\n // loader on the 404 page\": a layout brings its whole chain's\r\n // middleware with it, and a guard that redirects or throws on\r\n // the not-found path turns a missing page into an incident. The\r\n // page renders inside the application root and nothing else.\r\n layoutFile: undefined,\r\n loadModule: (moduleId) => vite.ssrLoadModule(moduleId),\r\n hydrationClientModuleUrl,\r\n loadErrorPage,\r\n // NO LAYOUT means no layout CSS either — just root and the\r\n // not-found page's own stylesheets, same reasoning as above.\r\n stylesheetUrls: devHandlerStylesheetUrls(\r\n stylesheetRoot,\r\n [appFile, notFoundPageFile],\r\n vite.moduleGraph,\r\n ),\r\n // The URL that missed IS this route's pattern for this request.\r\n matchPath: (requestPath) => requestPath,\r\n statusForRenderedOk: 404,\r\n skipPageLoader: true,\r\n ...httpServerOption,\r\n }),\r\n });\r\n\r\n if (notFoundPageFile === undefined) {\r\n await router.withSourceFile(FRAMEWORK_DEFAULT_NOT_FOUND_SOURCE_FILE, registerNotFoundRoute);\r\n } else {\r\n await router.withSourceFile(\r\n canonicalSourceFileFor(notFoundPageFile, appSrcRoot),\r\n registerNotFoundRoute,\r\n );\r\n }\r\n }\r\n\r\n /*\r\n Published from the SAME loop that registered the routes, so `href()` and the\r\n router cannot disagree about where a name points. It happens here rather\r\n than in the caller because a caller that forgets leaves every `<Link>` on\r\n the server throwing at render — and dev republishes on every restart, which\r\n is why the table replaces wholesale instead of merging: a deleted page's\r\n name has to stop resolving.\r\n */\r\n publishRouteTable(installed, \"installPageRoutes (dev)\");\r\n\r\n return installed;\r\n}\r\n"],"mappings":";;;;;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GACA;GACA;GACA;GAKA,YACE,YAAY,MAAM,SAAS,KAAK,eAAe,UAC1C,aACC,aAAa,aACT,mBAAmB;IAAE,GAAG;IAAa;GAAW,GAAG,UAAU,IAC7D,KAAK,cAAc,QAAQ,KAChC,aAAa,KAAK,cAAc,QAAQ;GAK/C,+BAA+B,QAAQ,IAAI,YAAY,MAAM,IAAI,UAAU,CAAC;GAC5E;GACA;GACA;GACA;GACA,GAAG;EACL,CAAC,GAID;GAAE;GAAM,QAAQ;EAAK,CACvB,CACF;EAEA,UAAU,KAAK;GACb,cAAc;GACd,MAAM;GACN;GACA,MAAM;GACN;EACF,CAAC;CACH;CAaA,IAAI,UAAU,SAAS,KAAK,kBAAkB,SAAS,GAAG;EACxD,MAAM,mBAAmB,kBAAkB,EAAE,EAAE;EAK/C,IAAI,qBAAqB,QAGvB;QAAI,MAF0B,KAAK,cAAc,gBAAgB,EAE/C,CAAC,UAAU,QAC3B,MAAM,IAAI,+BAA+B,gBAAgB;EAC3D;EAGF,MAAM,8BACJ,0BAA0B;GACxB;GACA,YACE,qBAAqB,SACjB,SACA,uBAAuB;IACrB;IACA,MAAM;IACN;IACA,UAAU;IAMV,YAAY;IACZ,aAAa,aAAa,KAAK,cAAc,QAAQ;IACrD;IACA;IAGA,gBAAgB,yBACd,gBACA,CAAC,SAAS,gBAAgB,GAC1B,KAAK,WACP;IAEA,YAAY,gBAAgB;IAC5B,qBAAqB;IACrB,gBAAgB;IAChB,GAAG;GACL,CAAC;EACT,CAAC;EAEH,IAAI,qBAAqB,QACvB,MAAM,OAAO,eAAe,yCAAyC,qBAAqB;OAE1F,MAAM,OAAO,eACX,uBAAuB,kBAAkB,UAAU,GACnD,qBACF;CAEJ;CAUA,kBAAkB,WAAW,yBAAyB;CAEtD,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"install-production-page-routes.mjs","names":[],"sources":["../../../../../../../web/src/server/install-production-page-routes.ts"],"sourcesContent":["/**\r\n * Standing up page serving for a BUILT application — the production half of\r\n * `WebConnector.boot()`, kept out of the connector so the mode branch there\r\n * stays one `if` and this path stays readable on its own.\r\n *\r\n * The development path answers \"which pages exist?\" by walking `app/` and\r\n * \"what is this module?\" by asking Vite to evaluate it. A production process\r\n * can ask neither question: there is no source tree beside the bundle and no\r\n * Vite. Both answers arrived at import time instead, in the generated pages\r\n * barrel's {@link PageManifest}, and everything below is what remains once\r\n * those two questions are already answered — a guard, a wiring step and a\r\n * registration step.\r\n *\r\n * NOTHING HERE REACHES FOR VITE, transitively included. `vite` is an optional\r\n * peer, so a production install does not carry it; an import that only ever\r\n * runs in development still fails at module load in production, which is why\r\n * the one import that has to happen at boot is a dynamic one and why it names\r\n * the pipeline barrel and nothing else.\r\n */\r\nimport type { Router } from \"@warlock.js/core\";\r\nimport type { SharedStoreResolver } from \"../shared\";\r\nimport type { PageContextRunner } from \"./execute-page-request\";\r\nimport type { InstalledManifestPageRoute } from \"./install-page-routes-from-manifest\";\r\nimport type { PageManifest } from \"./page-manifest\";\r\n\r\nexport type InstallProductionPageRoutesOptions = {\r\n router: Router;\r\n /** The table the generated production barrel provided at import time. */\r\n manifest: PageManifest;\r\n /**\r\n * Core's per-request context, handed over rather than imported: core is a\r\n * type-only peer of web, and two copies of core would mean two\r\n * AsyncLocalStorage stores and a page pipeline reading an empty one.\r\n */\r\n pageContext: PageContextRunner;\r\n /** Reads the current request's store out of {@link pageContext}. */\r\n sharedStore: SharedStoreResolver;\r\n /** Same helper `dev-server.ts` exports — passed in, never imported. */\r\n /**\r\n * Where the browser fetches the hydration entry from.\r\n *\r\n * A THUNK, not a value: the URL is read out of the client build's manifest,\r\n * and a build that discovered no pages has no hydration entry for that read\r\n * to find. Deferring it means a page-free production bundle boots without\r\n * demanding a file it had no reason to emit.\r\n */\r\n resolveHydrationClientModuleUrl: () => string;\r\n /**\r\n * Where the client build wrote its output. Forwarded to\r\n * `installPageRoutesFromManifest`, never read here: every registered\r\n * handler needs its OWN stylesheet chain\r\n * (`[root, ...outer-to-inner matched layouts, page]`), and the installer is\r\n * the one place that already walks the manifest's per-page layout chains to\r\n * build one.\r\n *\r\n * OPTIONAL for the same reason `PageManifest.clientDir` is: a build that\r\n * discovered zero pages emits no client bundle, so there is no directory to\r\n * name — and no page that could need a stylesheet either.\r\n */\r\n clientDir?: string;\r\n};\r\n\r\n/**\r\n * Register every page the manifest carries, and connect the pipeline the\r\n * handlers will run in.\r\n *\r\n * An empty table registers nothing and is not an error: \"built with web, no\r\n * pages\" is a legal state of a built application, and it is also the one state\r\n * where there is no pipeline to connect and no hydration entry to point at, so\r\n * it returns before doing either.\r\n */\r\nexport async function installProductionPageRoutes(\r\n options: InstallProductionPageRoutesOptions,\r\n): Promise<InstalledManifestPageRoute[]> {\r\n const {\r\n router,\r\n manifest,\r\n pageContext,\r\n sharedStore,\r\n resolveHydrationClientModuleUrl,\r\n clientDir,\r\n } = options;\r\n\r\n if (manifest.pages.length === 0) return [];\r\n\r\n // Loaded at boot rather than statically, and through the BARREL: production\r\n // has one module graph, so the barrel's instance of the pipeline is the same\r\n // instance the manifest's page modules were linked against, and connecting\r\n // the request context on it connects it for every handler registered below.\r\n // Development cannot do this — its modules live in Vite's separate graph, and\r\n // it wires the same two seams on the copy Vite evaluated.\r\n const webServer = await import(\"./index\");\r\n\r\n webServer.connectSharedStore(sharedStore);\r\n webServer.connectPageContext(pageContext);\r\n\r\n return webServer.installPageRoutesFromManifest({\r\n router,\r\n manifest,\r\n hydrationClientModuleUrl: resolveHydrationClientModuleUrl(),\r\n clientDir,\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;;AAuEA,eAAsB,4BACpB,SACuC;CACvC,MAAM,EACJ,QACA,UACA,aACA,aACA,iCACA,cACE;CAEJ,IAAI,SAAS,MAAM,WAAW,GAAG,OAAO,CAAC;CAQzC,MAAM,YAAY,MAAM,OAAO;CAE/B,UAAU,mBAAmB,WAAW;CACxC,UAAU,mBAAmB,WAAW;CAExC,OAAO,UAAU,8BAA8B;EAC7C;EACA;EACA,0BAA0B,gCAAgC;EAC1D;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"install-production-page-routes.mjs","names":[],"sources":["../../../../../../../web/src/server/install-production-page-routes.ts"],"sourcesContent":["/**\r\n * Standing up page serving for a BUILT application — the production half of\r\n * `WebConnector.boot()`, kept out of the connector so the mode branch there\r\n * stays one `if` and this path stays readable on its own.\r\n *\r\n * The development path answers \"which pages exist?\" by walking `app/` and\r\n * \"what is this module?\" by asking Vite to evaluate it. A production process\r\n * can ask neither question: there is no source tree beside the bundle and no\r\n * Vite. Both answers arrived at import time instead, in the generated pages\r\n * barrel's {@link PageManifest}, and everything below is what remains once\r\n * those two questions are already answered — a guard, a wiring step and a\r\n * registration step.\r\n *\r\n * NOTHING HERE REACHES FOR VITE, transitively included. `vite` is an optional\r\n * peer, so a production install does not carry it; an import that only ever\r\n * runs in development still fails at module load in production, which is why\r\n * the one import that has to happen at boot is a dynamic one and why it names\r\n * the pipeline barrel and nothing else.\r\n */\r\nimport type { Router } from \"@warlock.js/core\";\r\nimport type { SharedStoreResolver } from \"../shared\";\r\nimport type { PageContextRunner } from \"./execute-page-request\";\r\nimport type { InstalledManifestPageRoute } from \"./install-page-routes-from-manifest\";\r\nimport type { PageManifest } from \"./page-manifest\";\r\n\r\nexport type InstallProductionPageRoutesOptions = {\r\n router: Router;\r\n /** The table the generated production barrel provided at import time. */\r\n manifest: PageManifest;\r\n /**\r\n * Core's per-request context, handed over rather than imported: core is a\r\n * type-only peer of web, and two copies of core would mean two\r\n * AsyncLocalStorage stores and a page pipeline reading an empty one.\r\n */\r\n pageContext: PageContextRunner;\r\n /** Reads the current request's store out of {@link pageContext}. */\r\n sharedStore: SharedStoreResolver;\r\n /** Same helper `dev-error-transport.ts` exports — passed in, never imported. */\r\n /**\r\n * Where the browser fetches the hydration entry from.\r\n *\r\n * A THUNK, not a value: the URL is read out of the client build's manifest,\r\n * and a build that discovered no pages has no hydration entry for that read\r\n * to find. Deferring it means a page-free production bundle boots without\r\n * demanding a file it had no reason to emit.\r\n */\r\n resolveHydrationClientModuleUrl: () => string;\r\n /**\r\n * Where the client build wrote its output. Forwarded to\r\n * `installPageRoutesFromManifest`, never read here: every registered\r\n * handler needs its OWN stylesheet chain\r\n * (`[root, ...outer-to-inner matched layouts, page]`), and the installer is\r\n * the one place that already walks the manifest's per-page layout chains to\r\n * build one.\r\n *\r\n * OPTIONAL for the same reason `PageManifest.clientDir` is: a build that\r\n * discovered zero pages emits no client bundle, so there is no directory to\r\n * name — and no page that could need a stylesheet either.\r\n */\r\n clientDir?: string;\r\n};\r\n\r\n/**\r\n * Register every page the manifest carries, and connect the pipeline the\r\n * handlers will run in.\r\n *\r\n * An empty table registers nothing and is not an error: \"built with web, no\r\n * pages\" is a legal state of a built application, and it is also the one state\r\n * where there is no pipeline to connect and no hydration entry to point at, so\r\n * it returns before doing either.\r\n */\r\nexport async function installProductionPageRoutes(\r\n options: InstallProductionPageRoutesOptions,\r\n): Promise<InstalledManifestPageRoute[]> {\r\n const { router, manifest, pageContext, sharedStore, resolveHydrationClientModuleUrl, clientDir } =\r\n options;\r\n\r\n if (manifest.pages.length === 0) return [];\r\n\r\n // Loaded at boot rather than statically, and through the BARREL: production\r\n // has one module graph, so the barrel's instance of the pipeline is the same\r\n // instance the manifest's page modules were linked against, and connecting\r\n // the request context on it connects it for every handler registered below.\r\n // Development cannot do this — its modules live in Vite's separate graph, and\r\n // it wires the same two seams on the copy Vite evaluated.\r\n const webServer = await import(\"./index\");\r\n\r\n webServer.connectSharedStore(sharedStore);\r\n webServer.connectPageContext(pageContext);\r\n\r\n return webServer.installPageRoutesFromManifest({\r\n router,\r\n manifest,\r\n hydrationClientModuleUrl: resolveHydrationClientModuleUrl(),\r\n clientDir,\r\n });\r\n}\r\n"],"mappings":";;;;;;;;;;AAuEA,eAAsB,4BACpB,SACuC;CACvC,MAAM,EAAE,QAAQ,UAAU,aAAa,aAAa,iCAAiC,cACnF;CAEF,IAAI,SAAS,MAAM,WAAW,GAAG,OAAO,CAAC;CAQzC,MAAM,YAAY,MAAM,OAAO;CAE/B,UAAU,mBAAmB,WAAW;CACxC,UAAU,mBAAmB,WAAW;CAExC,OAAO,UAAU,8BAA8B;EAC7C;EACA;EACA,0BAA0B,gCAAgC;EAC1D;CACF,CAAC;AACH"}
@@ -2,17 +2,13 @@
2
2
  /**
3
3
  * Stage 1 — turn a URL into a route entry plus its params.
4
4
  *
5
- * ⚠ **This is a SECOND matcher, and on the HTTP path it is redundant.** Core's
6
- * router has already matched by the time a page handler runs, and
7
- * `create-page-route-handler.ts` ignores the match it is handed. The one caller
8
- * that genuinely needs this is `renderPage(name, options)`, which synthesizes a
9
- * URL with no HTTP request behind it — and that path is not wired up
10
- * (`connectPageRoutes()` is never called).
5
+ * This matches only URL-driven render requests that have no HTTP router result
6
+ * to carry through. On the live HTTP path core has already selected the route
7
+ * and decoded its params; `create-page-route-handler.ts` passes that match into
8
+ * the pipeline rather than re-running this matcher.
11
9
  *
12
- * Removing it from the HTTP path is carded. Two things must be proven first:
13
- * that these params agree with core's, since `bundle.route.params` reaches the
14
- * hydration payload; and that dropping `bundle.route.query` — a public type
15
- * member — is announced rather than slipped in.
10
+ * `match-page-route.parity.spec.ts` keeps the param contract gated, including
11
+ * a multi-segment URL and the param-free page catch-all convention.
16
12
  */
17
13
  function splitSegments(path) {
18
14
  return path.split("/").filter((segment) => segment.length > 0);
@@ -1 +1 @@
1
- {"version":3,"file":"match-page-route.mjs","names":[],"sources":["../../../../../../../web/src/server/match-page-route.ts"],"sourcesContent":["import type { PageRouteEntry } from \"./execute-page-request.types\";\n\n/**\n * Stage 1 — turn a URL into a route entry plus its params.\n *\n * ⚠ **This is a SECOND matcher, and on the HTTP path it is redundant.** Core's\n * router has already matched by the time a page handler runs, and\n * `create-page-route-handler.ts` ignores the match it is handed. The one caller\n * that genuinely needs this is `renderPage(name, options)`, which synthesizes a\n * URL with no HTTP request behind it — and that path is not wired up\n * (`connectPageRoutes()` is never called).\n *\n * Removing it from the HTTP path is carded. Two things must be proven first:\n * that these params agree with core's, since `bundle.route.params` reaches the\n * hydration payload; and that dropping `bundle.route.query` — a public type\n * member is announced rather than slipped in.\n */\n\nfunction splitSegments(path: string): string[] {\n return path.split(\"/\").filter(segment => segment.length > 0);\n}\n\nexport function matchPath(\n pattern: string,\n pathname: string,\n): Record<string, string> | undefined {\n const patternSegments = splitSegments(pattern);\n const pathSegments = splitSegments(pathname);\n\n if (patternSegments.length !== pathSegments.length) return undefined;\n\n const params: Record<string, string> = {};\n\n for (let index = 0; index < patternSegments.length; index++) {\n const patternSegment = patternSegments[index];\n const pathSegment = pathSegments[index];\n\n if (patternSegment.startsWith(\":\")) {\n params[patternSegment.slice(1)] = decodeURIComponent(pathSegment);\n continue;\n }\n\n if (patternSegment !== pathSegment) return undefined;\n }\n\n return params;\n}\n\nexport function matchRoute(\n pathname: string,\n routes: readonly PageRouteEntry[],\n): { entry: PageRouteEntry; params: Record<string, string> } | undefined {\n for (const entry of routes) {\n const params = matchPath(entry.path, pathname);\n\n if (params) return { entry, params };\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAS,cAAc,MAAwB;CAC7C,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAO,YAAW,QAAQ,SAAS,CAAC;AAC7D;AAEA,SAAgB,UACd,SACA,UACoC;CACpC,MAAM,kBAAkB,cAAc,OAAO;CAC7C,MAAM,eAAe,cAAc,QAAQ;CAE3C,IAAI,gBAAgB,WAAW,aAAa,QAAQ,OAAO;CAE3D,MAAM,SAAiC,CAAC;CAExC,KAAK,IAAI,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ,SAAS;EAC3D,MAAM,iBAAiB,gBAAgB;EACvC,MAAM,cAAc,aAAa;EAEjC,IAAI,eAAe,WAAW,GAAG,GAAG;GAClC,OAAO,eAAe,MAAM,CAAC,KAAK,mBAAmB,WAAW;GAChE;EACF;EAEA,IAAI,mBAAmB,aAAa,OAAO;CAC7C;CAEA,OAAO;AACT;AAEA,SAAgB,WACd,UACA,QACuE;CACvE,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,SAAS,UAAU,MAAM,MAAM,QAAQ;EAE7C,IAAI,QAAQ,OAAO;GAAE;GAAO;EAAO;CACrC;AAGF"}
1
+ {"version":3,"file":"match-page-route.mjs","names":[],"sources":["../../../../../../../web/src/server/match-page-route.ts"],"sourcesContent":["import type { PageRouteEntry } from \"./execute-page-request.types\";\r\n\r\n/**\r\n * Stage 1 — turn a URL into a route entry plus its params.\r\n *\r\n * This matches only URL-driven render requests that have no HTTP router result\r\n * to carry through. On the live HTTP path core has already selected the route\r\n * and decoded its params; `create-page-route-handler.ts` passes that match into\r\n * the pipeline rather than re-running this matcher.\r\n *\r\n * `match-page-route.parity.spec.ts` keeps the param contract gated, including\r\n * a multi-segment URL and the param-free page catch-all convention.\r\n */\r\n\r\nfunction splitSegments(path: string): string[] {\r\n return path.split(\"/\").filter((segment) => segment.length > 0);\r\n}\r\n\r\nexport function matchPath(pattern: string, pathname: string): Record<string, string> | undefined {\r\n const patternSegments = splitSegments(pattern);\r\n const pathSegments = splitSegments(pathname);\r\n\r\n if (patternSegments.length !== pathSegments.length) return undefined;\r\n\r\n const params: Record<string, string> = {};\r\n\r\n for (let index = 0; index < patternSegments.length; index++) {\r\n const patternSegment = patternSegments[index];\r\n const pathSegment = pathSegments[index];\r\n\r\n if (patternSegment.startsWith(\":\")) {\r\n params[patternSegment.slice(1)] = decodeURIComponent(pathSegment);\r\n continue;\r\n }\r\n\r\n if (patternSegment !== pathSegment) return undefined;\r\n }\r\n\r\n return params;\r\n}\r\n\r\nexport function matchRoute(\r\n pathname: string,\r\n routes: readonly PageRouteEntry[],\r\n): { entry: PageRouteEntry; params: Record<string, string> } | undefined {\r\n for (const entry of routes) {\r\n const params = matchPath(entry.path, pathname);\r\n\r\n if (params) return { entry, params };\r\n }\r\n\r\n return undefined;\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAcA,SAAS,cAAc,MAAwB;CAC7C,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAQ,YAAY,QAAQ,SAAS,CAAC;AAC/D;AAEA,SAAgB,UAAU,SAAiB,UAAsD;CAC/F,MAAM,kBAAkB,cAAc,OAAO;CAC7C,MAAM,eAAe,cAAc,QAAQ;CAE3C,IAAI,gBAAgB,WAAW,aAAa,QAAQ,OAAO;CAE3D,MAAM,SAAiC,CAAC;CAExC,KAAK,IAAI,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ,SAAS;EAC3D,MAAM,iBAAiB,gBAAgB;EACvC,MAAM,cAAc,aAAa;EAEjC,IAAI,eAAe,WAAW,GAAG,GAAG;GAClC,OAAO,eAAe,MAAM,CAAC,KAAK,mBAAmB,WAAW;GAChE;EACF;EAEA,IAAI,mBAAmB,aAAa,OAAO;CAC7C;CAEA,OAAO;AACT;AAEA,SAAgB,WACd,UACA,QACuE;CACvE,KAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,SAAS,UAAU,MAAM,MAAM,QAAQ;EAE7C,IAAI,QAAQ,OAAO;GAAE;GAAO;EAAO;CACrC;AAGF"}
@@ -1,4 +1,5 @@
1
1
  import { PageRouteHandler } from "./create-page-route-handler.mjs";
2
+ import { Router } from "@warlock.js/core";
2
3
 
3
4
  //#region ../web/src/server/not-found-page.d.ts
4
5
  /**
@@ -196,7 +196,14 @@ function createNotFoundRouteHandler(options) {
196
196
  return renderPage(context);
197
197
  };
198
198
  }
199
+ /** Registers the invariant catch-all route both page installers share. */
200
+ function registerNotFoundPageRoute(options) {
201
+ options.router.get("*", createNotFoundRouteHandler({ renderPage: options.renderPage }), {
202
+ name: NOT_FOUND_ROUTE_NAME,
203
+ isPage: true
204
+ });
205
+ }
199
206
 
200
207
  //#endregion
201
- export { DuplicateNotFoundPageError, NOT_FOUND_PAGE_FILENAME, NOT_FOUND_ROUTE_NAME, NOT_FOUND_ROUTE_PATH, NotFoundPageDeclaresRouteError, acceptsHtmlExplicitly, classifyUnmatchedRequest, createNotFoundRouteHandler, frameworkDefaultNotFoundDocument, isNotFoundPageFile };
208
+ export { DuplicateNotFoundPageError, NOT_FOUND_PAGE_FILENAME, NOT_FOUND_ROUTE_NAME, NOT_FOUND_ROUTE_PATH, NotFoundPageDeclaresRouteError, acceptsHtmlExplicitly, classifyUnmatchedRequest, createNotFoundRouteHandler, frameworkDefaultNotFoundDocument, isNotFoundPageFile, registerNotFoundPageRoute };
202
209
  //# sourceMappingURL=not-found-page.mjs.map