@warlock.js/web 5.2.0 → 5.2.2

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 (201) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/esm/build/contribution.d.mts +1 -1
  3. package/esm/build/contribution.mjs +1 -1
  4. package/esm/build/contribution.mjs.map +1 -1
  5. package/esm/build/discover-pages.mjs +1 -1
  6. package/esm/build/discover-pages.mjs.map +1 -1
  7. package/esm/build/generate-client-registry.mjs +1 -1
  8. package/esm/build/generate-client-registry.mjs.map +1 -1
  9. package/esm/build/generate-pages-barrel.mjs +1 -1
  10. package/esm/build/generate-pages-barrel.mjs.map +1 -1
  11. package/esm/build/page-default-export.mjs +1 -1
  12. package/esm/build/page-default-export.mjs.map +1 -1
  13. package/esm/build/page-routes-manifest.mjs +1 -1
  14. package/esm/build/page-routes-manifest.mjs.map +1 -1
  15. package/esm/build/public-files.mjs +1 -1
  16. package/esm/build/public-files.mjs.map +1 -1
  17. package/esm/build/read-route-exports.mjs +1 -1
  18. package/esm/build/read-route-exports.mjs.map +1 -1
  19. package/esm/client/build-hydrated-tree.mjs +1 -1
  20. package/esm/client/build-hydrated-tree.mjs.map +1 -1
  21. package/esm/client/hydrate-page.mjs +1 -1
  22. package/esm/client/hydrate-page.mjs.map +1 -1
  23. package/esm/client/navigation/current-route.d.mts +1 -1
  24. package/esm/client/navigation/current-route.mjs +1 -1
  25. package/esm/client/navigation/current-route.mjs.map +1 -1
  26. package/esm/client/navigation/fetch-page-data.mjs +1 -1
  27. package/esm/client/navigation/fetch-page-data.mjs.map +1 -1
  28. package/esm/client/navigation/navigation-root.mjs +1 -1
  29. package/esm/client/navigation/navigation-root.mjs.map +1 -1
  30. package/esm/client/navigation/prefetch.mjs +1 -1
  31. package/esm/client/navigation/prefetch.mjs.map +1 -1
  32. package/esm/client/navigation/refresh.d.mts +1 -1
  33. package/esm/client/navigation/refresh.mjs +1 -1
  34. package/esm/client/navigation/refresh.mjs.map +1 -1
  35. package/esm/client/navigation/scroll-to-fragment.mjs +1 -1
  36. package/esm/client/navigation/scroll-to-fragment.mjs.map +1 -1
  37. package/esm/client/navigation/verbs.d.mts +1 -1
  38. package/esm/client/navigation/verbs.mjs +1 -1
  39. package/esm/client/navigation/verbs.mjs.map +1 -1
  40. package/esm/client/runtime/manifest.d.mts +1 -1
  41. package/esm/client/runtime/manifest.mjs +1 -1
  42. package/esm/client/runtime/manifest.mjs.map +1 -1
  43. package/esm/client/runtime/matcher.d.mts +1 -1
  44. package/esm/client/runtime/matcher.mjs +1 -1
  45. package/esm/client/runtime/matcher.mjs.map +1 -1
  46. package/esm/client/runtime/types.d.mts +1 -1
  47. package/esm/components/default-app.mjs +1 -1
  48. package/esm/components/default-app.mjs.map +1 -1
  49. package/esm/components/document-context.d.mts +1 -1
  50. package/esm/components/document-context.mjs +1 -1
  51. package/esm/components/document-context.mjs.map +1 -1
  52. package/esm/components/head.d.mts +1 -1
  53. package/esm/components/head.mjs +1 -1
  54. package/esm/components/head.mjs.map +1 -1
  55. package/esm/components/link.d.mts +1 -1
  56. package/esm/components/link.mjs +1 -1
  57. package/esm/components/link.mjs.map +1 -1
  58. package/esm/components/scripts.d.mts +1 -1
  59. package/esm/components/scripts.mjs +1 -1
  60. package/esm/components/scripts.mjs.map +1 -1
  61. package/esm/context.d.mts +1 -1
  62. package/esm/hydration/index.mjs +1 -1
  63. package/esm/hydration/index.mjs.map +1 -1
  64. package/esm/hydration-payload.mjs +1 -1
  65. package/esm/hydration-payload.mjs.map +1 -1
  66. package/esm/index.d.mts +1 -1
  67. package/esm/loaders.d.mts +1 -1
  68. package/esm/metadata.d.mts +1 -1
  69. package/esm/metadata.mjs +1 -1
  70. package/esm/metadata.mjs.map +1 -1
  71. package/esm/props.d.mts +1 -1
  72. package/esm/route.d.mts +1 -1
  73. package/esm/routing/compose-route-path.d.mts +1 -1
  74. package/esm/routing/compose-route-path.mjs +1 -1
  75. package/esm/routing/compose-route-path.mjs.map +1 -1
  76. package/esm/routing/data-request.mjs +1 -1
  77. package/esm/routing/data-request.mjs.map +1 -1
  78. package/esm/routing/filesystem-route.mjs +1 -1
  79. package/esm/routing/filesystem-route.mjs.map +1 -1
  80. package/esm/routing/layout-policy.mjs +1 -1
  81. package/esm/routing/layout-policy.mjs.map +1 -1
  82. package/esm/routing/navigator.mjs +1 -1
  83. package/esm/routing/navigator.mjs.map +1 -1
  84. package/esm/routing/query-string.d.mts +1 -1
  85. package/esm/routing/query-string.mjs +1 -1
  86. package/esm/routing/query-string.mjs.map +1 -1
  87. package/esm/routing/route-identity.mjs +1 -1
  88. package/esm/routing/route-identity.mjs.map +1 -1
  89. package/esm/routing/route-table.d.mts +1 -1
  90. package/esm/routing/route-table.mjs +1 -1
  91. package/esm/routing/route-table.mjs.map +1 -1
  92. package/esm/routing/router-events.d.mts +1 -1
  93. package/esm/routing/router-events.mjs +1 -1
  94. package/esm/routing/router-events.mjs.map +1 -1
  95. package/esm/routing/url-fragment.mjs +1 -1
  96. package/esm/routing/url-fragment.mjs.map +1 -1
  97. package/esm/runtime/register-modules.d.mts +1 -1
  98. package/esm/runtime/register-modules.mjs +1 -1
  99. package/esm/runtime/register-modules.mjs.map +1 -1
  100. package/esm/server/build-hydration-payload.mjs +1 -1
  101. package/esm/server/build-hydration-payload.mjs.map +1 -1
  102. package/esm/server/client-asset-url-prefix.d.mts +1 -1
  103. package/esm/server/client-asset-url-prefix.mjs +1 -1
  104. package/esm/server/client-asset-url-prefix.mjs.map +1 -1
  105. package/esm/server/create-page-module-loader.d.mts +1 -1
  106. package/esm/server/create-page-module-loader.mjs +1 -1
  107. package/esm/server/create-page-module-loader.mjs.map +1 -1
  108. package/esm/server/create-page-route-handler.d.mts +1 -1
  109. package/esm/server/create-page-route-handler.mjs +1 -1
  110. package/esm/server/create-page-route-handler.mjs.map +1 -1
  111. package/esm/server/dev-server.mjs +1 -1
  112. package/esm/server/dev-server.mjs.map +1 -1
  113. package/esm/server/error-page.d.mts +1 -1
  114. package/esm/server/error-page.mjs +1 -1
  115. package/esm/server/error-page.mjs.map +1 -1
  116. package/esm/server/execute-page-request.d.mts +1 -1
  117. package/esm/server/execute-page-request.mjs +1 -1
  118. package/esm/server/execute-page-request.mjs.map +1 -1
  119. package/esm/server/execute-page-request.types.d.mts +1 -1
  120. package/esm/server/hydration-client-url.d.mts +1 -1
  121. package/esm/server/hydration-client-url.mjs +1 -1
  122. package/esm/server/hydration-client-url.mjs.map +1 -1
  123. package/esm/server/install-page-routes-from-manifest.d.mts +1 -1
  124. package/esm/server/install-page-routes-from-manifest.mjs +1 -1
  125. package/esm/server/install-page-routes-from-manifest.mjs.map +1 -1
  126. package/esm/server/install-page-routes.d.mts +1 -1
  127. package/esm/server/install-page-routes.mjs +1 -1
  128. package/esm/server/install-page-routes.mjs.map +1 -1
  129. package/esm/server/install-production-page-routes.mjs +1 -1
  130. package/esm/server/install-production-page-routes.mjs.map +1 -1
  131. package/esm/server/match-page-route.mjs +1 -1
  132. package/esm/server/match-page-route.mjs.map +1 -1
  133. package/esm/server/not-found-page.d.mts +1 -1
  134. package/esm/server/not-found-page.mjs +1 -1
  135. package/esm/server/not-found-page.mjs.map +1 -1
  136. package/esm/server/page-context.d.mts +1 -1
  137. package/esm/server/page-context.mjs +1 -1
  138. package/esm/server/page-context.mjs.map +1 -1
  139. package/esm/server/page-file-change.mjs +1 -1
  140. package/esm/server/page-file-change.mjs.map +1 -1
  141. package/esm/server/page-manifest.d.mts +1 -1
  142. package/esm/server/page-manifest.mjs +1 -1
  143. package/esm/server/page-manifest.mjs.map +1 -1
  144. package/esm/server/page-render-bundle.mjs +1 -1
  145. package/esm/server/page-render-bundle.mjs.map +1 -1
  146. package/esm/server/page-route-reload.mjs +1 -1
  147. package/esm/server/page-route-reload.mjs.map +1 -1
  148. package/esm/server/register-production-public-files.mjs +1 -1
  149. package/esm/server/register-production-public-files.mjs.map +1 -1
  150. package/esm/server/render-page.d.mts +1 -1
  151. package/esm/server/render-page.mjs +1 -1
  152. package/esm/server/render-page.mjs.map +1 -1
  153. package/esm/server/resolve-page-metadata.mjs +1 -1
  154. package/esm/server/resolve-page-metadata.mjs.map +1 -1
  155. package/esm/server/resolve-validation-data.mjs +1 -1
  156. package/esm/server/resolve-validation-data.mjs.map +1 -1
  157. package/esm/server/settle-page-response.d.mts +1 -1
  158. package/esm/server/settle-page-response.mjs +1 -1
  159. package/esm/server/settle-page-response.mjs.map +1 -1
  160. package/esm/server/stylesheet-urls.d.mts +1 -1
  161. package/esm/server/stylesheet-urls.mjs +1 -1
  162. package/esm/server/stylesheet-urls.mjs.map +1 -1
  163. package/esm/server/unregistered-pages.mjs +1 -1
  164. package/esm/server/unregistered-pages.mjs.map +1 -1
  165. package/esm/server/web-connector-factory.d.mts +1 -1
  166. package/esm/server/web-connector-factory.mjs +1 -1
  167. package/esm/server/web-connector-factory.mjs.map +1 -1
  168. package/esm/server/web-connector.d.mts +1 -1
  169. package/esm/server/web-connector.mjs +1 -1
  170. package/esm/server/web-connector.mjs.map +1 -1
  171. package/esm/shared.d.mts +1 -1
  172. package/esm/shared.mjs +1 -1
  173. package/esm/shared.mjs.map +1 -1
  174. package/esm/validation.d.mts +1 -1
  175. package/esm/vite/app-convention-aliases.mjs +1 -1
  176. package/esm/vite/app-convention-aliases.mjs.map +1 -1
  177. package/esm/vite/build-client.d.mts +1 -1
  178. package/esm/vite/build-client.mjs +1 -1
  179. package/esm/vite/build-client.mjs.map +1 -1
  180. package/esm/vite/gate-a-resolve.d.mts +1 -1
  181. package/esm/vite/gate-a-resolve.mjs +1 -1
  182. package/esm/vite/gate-a-resolve.mjs.map +1 -1
  183. package/esm/vite/gate-b-secrets.d.mts +1 -1
  184. package/esm/vite/gate-b-secrets.mjs +1 -1
  185. package/esm/vite/gate-b-secrets.mjs.map +1 -1
  186. package/esm/vite/gate-c-verify.d.mts +1 -1
  187. package/esm/vite/gate-c-verify.mjs +1 -1
  188. package/esm/vite/gate-c-verify.mjs.map +1 -1
  189. package/esm/vite/hydration-entries.d.mts +1 -1
  190. package/esm/vite/hydration-entries.mjs +1 -1
  191. package/esm/vite/hydration-entries.mjs.map +1 -1
  192. package/esm/vite/index.d.mts +1 -1
  193. package/esm/vite/index.mjs +1 -1
  194. package/esm/vite/index.mjs.map +1 -1
  195. package/esm/vite/page-registry-plugin.d.mts +1 -1
  196. package/esm/vite/page-registry-plugin.mjs +1 -1
  197. package/esm/vite/page-registry-plugin.mjs.map +1 -1
  198. package/esm/vite/projection.d.mts +1 -1
  199. package/esm/vite/projection.mjs +1 -1
  200. package/esm/vite/projection.mjs.map +1 -1
  201. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -2,6 +2,21 @@
2
2
 
3
3
  All notable changes to `@warlock.js/web` are documented here.
4
4
 
5
+ ## 5.2.2
6
+
7
+ ### Fixed
8
+
9
+ - Restored exact Core and Seal peer pins at the family's shared 5.2.2 version.
10
+ The partial 5.2.1 release could not satisfy reciprocal family peer pins.
11
+
12
+ ## 5.2.1
13
+
14
+ ### Fixed
15
+
16
+ - Tightened the Core and Seal peer ranges to `^5.2.0`. Web 5.2 production
17
+ code imports Core APIs that were not available in Core 5.0, while the former
18
+ Seal `*` range promised compatibility across unrelated major versions.
19
+
5
20
  ## 5.2.0
6
21
 
7
22
  ### Added
@@ -1,7 +1,7 @@
1
1
  import { ConnectorBuildContribution } from "@warlock.js/core";
2
2
  import { PluginOption } from "vite";
3
3
 
4
- //#region web/src/build/contribution.d.ts
4
+ //#region ../web/src/build/contribution.d.ts
5
5
  type WebBuildOptions = {
6
6
  /** Source directory name under the app root. Default: `"src"`. */srcDir?: string;
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
 
4
- //#region web/src/build/contribution.ts
4
+ //#region ../web/src/build/contribution.ts
5
5
  /**
6
6
  * Web's build-time half — the object a `WebConnector` hands to
7
7
  * `warlock build` as its `build` contribution.
@@ -1 +1 @@
1
- {"version":3,"file":"contribution.mjs","names":[],"sources":["C:/Work/Warlock.js/web/src/build/contribution.ts"],"sourcesContent":["/**\r\n * Web's build-time half — the object a `WebConnector` hands to\r\n * `warlock build` as its `build` contribution.\r\n *\r\n * KEPT DELIBERATELY LIGHT: everything this\r\n * module imports statically is a type or `node:path`. The heavy halves — the\r\n * filesystem discovery/barrel generator, and the Vite client build — are\r\n * `await import(...)`ed INSIDE the hooks, so a config file that merely\r\n * constructs the connector never drags Vite, React or the page graph into its\r\n * static import graph.\r\n *\r\n * {@link WebBuildOptions} carries JSON-SERIALIZABLE VALUES ONLY (constraint\r\n * B): no plugin instances, no functions, no class instances. Anything heavy is\r\n * constructed inside a hook after that hook's dynamic import.\r\n */\r\nimport { readFileSync } from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport type {\r\n ConnectorBuildContext,\r\n ConnectorBuildContribution,\r\n ConnectorBuildGenerateResult,\r\n} from \"@warlock.js/core\";\r\nimport type { PluginOption } from \"vite\";\r\n\r\nexport type WebBuildOptions = {\r\n /** Source directory name under the app root. Default: `\"src\"`. */\r\n srcDir?: string;\r\n /**\r\n * Absolute path to the `@warlock.js/web` package root, which holds the\r\n * hydration entry (packaged as `esm/hydration/index.mjs`, with a source\r\n * fallback at `src/hydration/index.ts` for this checkout).\r\n *\r\n * Defaults to this module's own package root, derived from `import.meta.url`\r\n * at emit time. Set it explicitly when the build process loads this module\r\n * through a transform that rewrites `import.meta` (e.g. a CJS config\r\n * pipeline) — the derivation is the only thing here that depends on it.\r\n *\r\n * Derived or configured, the root is VERIFIED at emit time against\r\n * `<root>/package.json`'s `name`; a root that is not `@warlock.js/web`\r\n * throws {@link WebPackageRootResolutionError} rather than being guessed at.\r\n */\r\n webRoot?: string;\r\n /**\r\n * NOT SUPPORTED. The client bundle always lands at `<build.outdir>/client`,\r\n * the layout the runtime half reads (`resolveHydrationClientUrl`) — the\r\n * runtime does not yet consult a relocated path. Setting this option throws\r\n * {@link ClientOutDirNotSupportedError}.\r\n */\r\n clientOutDir?: string;\r\n /** Client-build resolve aliases: specifier -> absolute path. */\r\n aliases?: Record<string, string>;\r\n /** Extra package names to keep external to the client bundle. */\r\n external?: string[];\r\n};\r\n\r\nfunction resolveClientOutDir(context: ConnectorBuildContext): string {\r\n return path.resolve(context.appRoot, context.options.outdir, \"client\");\r\n}\r\n\r\n/**\r\n * `build.clientOutDir` was set.\r\n *\r\n * The production runtime hardcodes where it reads the client bundle from\r\n * (`<outdir>/client`, via `resolveHydrationClientUrl`) — it does not yet\r\n * consult the build config for a relocated path. A build that honored a\r\n * custom `clientOutDir` would therefore produce an artifact the runtime\r\n * cannot find, silently. Rejected at build start, before any work happens,\r\n * rather than left to surface later as a missing-bundle failure in\r\n * production.\r\n */\r\nexport class ClientOutDirNotSupportedError extends Error {\r\n public constructor() {\r\n super(\r\n '\"build.clientOutDir\" is not supported: the production server reads the client bundle ' +\r\n \"from its default location and does not consult this option, so a build honoring it \" +\r\n \"would produce an artifact production cannot serve correctly. Remove \" +\r\n '\"build.clientOutDir\" from the build config.',\r\n );\r\n this.name = \"ClientOutDirNotSupportedError\";\r\n }\r\n}\r\n\r\n/** The package name every candidate web root must declare to be one. */\r\nconst WEB_PACKAGE_NAME = \"@warlock.js/web\";\r\n\r\n/**\r\n * The resolved `@warlock.js/web` root is not that package.\r\n *\r\n * Same posture as the manifest resolver's three named errors: a root that\r\n * cannot be proven is REJECTED, never quietly\r\n * repaired by walking upwards or falling back to `process.cwd()`. A wrong root\r\n * would otherwise surface much later as an unintelligible Vite entry failure.\r\n */\r\nexport class WebPackageRootResolutionError extends Error {\r\n public constructor(webRoot: string, reason: string, cause?: unknown) {\r\n super(\r\n `Cannot resolve the \"${WEB_PACKAGE_NAME}\" package root: \"${webRoot}\" ${reason}. ` +\r\n \"Pass `webRoot` explicitly in the web build options to point at the package root \" +\r\n `whose package.json declares \"name\": \"${WEB_PACKAGE_NAME}\".`,\r\n { cause },\r\n );\r\n this.name = \"WebPackageRootResolutionError\";\r\n }\r\n}\r\n\r\n/**\r\n * Proves that `webRoot` really is the `@warlock.js/web` package root by reading\r\n * `<webRoot>/package.json` and matching its `name`. Returns the path unchanged.\r\n */\r\nexport function assertWebPackageRoot(webRoot: string): string {\r\n const manifestPath = path.join(webRoot, \"package.json\");\r\n\r\n let raw: string;\r\n\r\n try {\r\n raw = readFileSync(manifestPath, \"utf-8\");\r\n } catch (error) {\r\n throw new WebPackageRootResolutionError(webRoot, \"has no readable package.json\", error);\r\n }\r\n\r\n let parsed: unknown;\r\n\r\n try {\r\n parsed = JSON.parse(raw);\r\n } catch (error) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n \"has a package.json that is not valid JSON\",\r\n error,\r\n );\r\n }\r\n\r\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n \"has a package.json whose root is not a JSON object\",\r\n );\r\n }\r\n\r\n const name = (parsed as { name?: unknown }).name;\r\n\r\n if (name !== WEB_PACKAGE_NAME) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n `declares package name ${JSON.stringify(name)}, not \"${WEB_PACKAGE_NAME}\"`,\r\n );\r\n }\r\n\r\n return webRoot;\r\n}\r\n\r\nexport async function resolveWebPackageRoot(configured: string | undefined): Promise<string> {\r\n if (configured !== undefined) {\r\n return assertWebPackageRoot(path.resolve(configured));\r\n }\r\n\r\n const { fileURLToPath } = await import(\"node:url\");\r\n\r\n // `web/src/build/contribution.ts` published as `web/esm/build/contribution.js`\r\n // — two levels up is the package root under both layouts.\r\n return assertWebPackageRoot(\r\n path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\"),\r\n );\r\n}\r\n\r\n/**\r\n * Builds web's `ConnectorBuildContribution`.\r\n *\r\n * `generate` writes the page barrel into `ctx.productionDir` and patches\r\n * esbuild; `emit` produces the client bundle esbuild cannot. The two share one\r\n * closure facts — how many pages exist, the discovered route table, and the\n * exact app-public file list. A build with zero pages skips the hydration\n * bundle but still copies public files when present. `generate` itself does\n * NOT skip: the barrel and its entry import are emitted either way, so the\n * runtime can tell a page-free web build from a build without web.\n *\r\n * Connector plugins are a separate argument rather than a `WebBuildOptions`\r\n * field: the app constructs them once, the factory snapshots that array for\r\n * both dev and build, and this module keeps Vite as a type-only import until\r\n * `emit` dynamically loads the real client builder.\r\n */\r\nexport function createWebBuildContribution(\r\n options: WebBuildOptions = {},\r\n connectorPlugins: readonly PluginOption[] = [],\r\n): ConnectorBuildContribution {\r\n if (options.clientOutDir !== undefined) {\r\n throw new ClientOutDirNotSupportedError();\r\n }\r\n\r\n let pageCount = 0;\r\n let pageRoutes: import(\"./generate-pages-barrel\").PageRoutesManifest = {\n version: 1,\n routes: [],\n };\n let publicFiles: string[] = [];\n\r\n return {\r\n async generate(context: ConnectorBuildContext): Promise<ConnectorBuildGenerateResult | void> {\r\n const { generatePagesBarrel, WEB_ENTRY_IMPORT, WEB_ESBUILD_PATCH } =\n await import(\"./generate-pages-barrel\");\n const { collectPublicFiles } = await import(\"./public-files\");\n\n publicFiles = await collectPublicFiles(path.join(context.appRoot, \"public\"));\n\n const result = await generatePagesBarrel({\n appRoot: context.appRoot,\r\n productionDir: context.productionDir,\r\n srcDir: options.srcDir,\r\n // Derived from `resolveClientOutDir` — the SAME function `emit` passes\r\n // to the Vite build below — so the path baked into the manifest and\r\n // the path the bundle is written to are one expression, not two that\r\n // happen to agree today.\r\n // POSIX-normalised inline rather than via the generator's `toPosix`:\r\n // this module's static graph is `node:path` and types only, and the\r\n // generator is reached by `await import` precisely to keep it that way.\r\n clientDir: path\r\n .relative(context.appRoot, resolveClientOutDir(context))\r\n .split(path.sep)\n .join(\"/\"),\n publicFiles,\n });\n\r\n pageCount = result.pageCount;\r\n pageRoutes = result.pageRoutes;\r\n\r\n // Contributed unconditionally, zero pages included: the barrel is always\r\n // written, and the entry has to IMPORT it for the empty table to reach\r\n // the runtime. Withholding this line on zero pages would leave the\r\n // manifest absent, which is the runtime's signal for \"never built with\r\n // web\" — the exact confusion the always-written barrel removes.\r\n return { entryImports: [WEB_ENTRY_IMPORT], esbuild: WEB_ESBUILD_PATCH };\r\n },\r\n\r\n async emit(context: ConnectorBuildContext): Promise<void> {\r\n if (pageCount > 0) {\n const { buildWarlockHydrationClient } = await import(\"../vite\");\r\n const { appConventionAliases } = await import(\"../vite/app-convention-aliases\");\r\n\r\n // The app-tree convention (`web/*`, `app/*`) the dev server installs must\r\n // also reach the production build, from the SAME definition — see\r\n // `app-convention-aliases.ts`. Caller-supplied aliases come first so a\r\n // caller can win a conflict, matching the dev server's ordering.\r\n const callerAliases = Object.entries(options.aliases ?? {}).map(([find, replacement]) => ({\r\n find,\r\n replacement,\r\n }));\r\n\r\n await buildWarlockHydrationClient({\r\n appRoot: context.appRoot,\r\n webRoot: await resolveWebPackageRoot(options.webRoot),\r\n outDir: resolveClientOutDir(context),\r\n resolveAliases: [\r\n ...callerAliases,\r\n ...appConventionAliases(path.join(context.appRoot, options.srcDir ?? \"src\")),\r\n ],\r\n external: options.external,\r\n plugins: connectorPlugins,\r\n });\n }\n\n if (publicFiles.length > 0) {\n const { copyPublicFiles } = await import(\"./public-files\");\n await copyPublicFiles(\n path.join(context.appRoot, \"public\"),\n path.join(resolveClientOutDir(context), \"public\"),\n publicFiles,\n );\n }\n\n const { writePageRoutesManifest } = await import(\"./page-routes-manifest\");\n await writePageRoutesManifest(\r\n path.resolve(context.appRoot, context.options.outdir),\r\n pageRoutes,\r\n );\r\n },\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAS,oBAAoB,SAAwC;CACnE,OAAO,KAAK,QAAQ,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,QAAQ;AACvE;;;;;;;;;;;;AAaA,IAAa,gCAAb,cAAmD,MAAM;CACvD,AAAO,cAAc;EACnB,MACE,6RAIF;EACA,KAAK,OAAO;CACd;AACF;;AAGA,MAAM,mBAAmB;;;;;;;;;AAUzB,IAAa,gCAAb,cAAmD,MAAM;C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AAQ,QAAQ,MAAM,GACpD,UACF;EACF;CACF;AACF"}
1
+ {"version":3,"file":"contribution.mjs","names":[],"sources":["../../../../../../../web/src/build/contribution.ts"],"sourcesContent":["/**\r\n * Web's build-time half — the object a `WebConnector` hands to\r\n * `warlock build` as its `build` contribution.\r\n *\r\n * KEPT DELIBERATELY LIGHT: everything this\r\n * module imports statically is a type or `node:path`. The heavy halves — the\r\n * filesystem discovery/barrel generator, and the Vite client build — are\r\n * `await import(...)`ed INSIDE the hooks, so a config file that merely\r\n * constructs the connector never drags Vite, React or the page graph into its\r\n * static import graph.\r\n *\r\n * {@link WebBuildOptions} carries JSON-SERIALIZABLE VALUES ONLY (constraint\r\n * B): no plugin instances, no functions, no class instances. Anything heavy is\r\n * constructed inside a hook after that hook's dynamic import.\r\n */\r\nimport { readFileSync } from \"node:fs\";\r\nimport path from \"node:path\";\r\nimport type {\r\n ConnectorBuildContext,\r\n ConnectorBuildContribution,\r\n ConnectorBuildGenerateResult,\r\n} from \"@warlock.js/core\";\r\nimport type { PluginOption } from \"vite\";\r\n\r\nexport type WebBuildOptions = {\r\n /** Source directory name under the app root. Default: `\"src\"`. */\r\n srcDir?: string;\r\n /**\r\n * Absolute path to the `@warlock.js/web` package root, which holds the\r\n * hydration entry (packaged as `esm/hydration/index.mjs`, with a source\r\n * fallback at `src/hydration/index.ts` for this checkout).\r\n *\r\n * Defaults to this module's own package root, derived from `import.meta.url`\r\n * at emit time. Set it explicitly when the build process loads this module\r\n * through a transform that rewrites `import.meta` (e.g. a CJS config\r\n * pipeline) — the derivation is the only thing here that depends on it.\r\n *\r\n * Derived or configured, the root is VERIFIED at emit time against\r\n * `<root>/package.json`'s `name`; a root that is not `@warlock.js/web`\r\n * throws {@link WebPackageRootResolutionError} rather than being guessed at.\r\n */\r\n webRoot?: string;\r\n /**\r\n * NOT SUPPORTED. The client bundle always lands at `<build.outdir>/client`,\r\n * the layout the runtime half reads (`resolveHydrationClientUrl`) — the\r\n * runtime does not yet consult a relocated path. Setting this option throws\r\n * {@link ClientOutDirNotSupportedError}.\r\n */\r\n clientOutDir?: string;\r\n /** Client-build resolve aliases: specifier -> absolute path. */\r\n aliases?: Record<string, string>;\r\n /** Extra package names to keep external to the client bundle. */\r\n external?: string[];\r\n};\r\n\r\nfunction resolveClientOutDir(context: ConnectorBuildContext): string {\r\n return path.resolve(context.appRoot, context.options.outdir, \"client\");\r\n}\r\n\r\n/**\r\n * `build.clientOutDir` was set.\r\n *\r\n * The production runtime hardcodes where it reads the client bundle from\r\n * (`<outdir>/client`, via `resolveHydrationClientUrl`) — it does not yet\r\n * consult the build config for a relocated path. A build that honored a\r\n * custom `clientOutDir` would therefore produce an artifact the runtime\r\n * cannot find, silently. Rejected at build start, before any work happens,\r\n * rather than left to surface later as a missing-bundle failure in\r\n * production.\r\n */\r\nexport class ClientOutDirNotSupportedError extends Error {\r\n public constructor() {\r\n super(\r\n '\"build.clientOutDir\" is not supported: the production server reads the client bundle ' +\r\n \"from its default location and does not consult this option, so a build honoring it \" +\r\n \"would produce an artifact production cannot serve correctly. Remove \" +\r\n '\"build.clientOutDir\" from the build config.',\r\n );\r\n this.name = \"ClientOutDirNotSupportedError\";\r\n }\r\n}\r\n\r\n/** The package name every candidate web root must declare to be one. */\r\nconst WEB_PACKAGE_NAME = \"@warlock.js/web\";\r\n\r\n/**\r\n * The resolved `@warlock.js/web` root is not that package.\r\n *\r\n * Same posture as the manifest resolver's three named errors: a root that\r\n * cannot be proven is REJECTED, never quietly\r\n * repaired by walking upwards or falling back to `process.cwd()`. A wrong root\r\n * would otherwise surface much later as an unintelligible Vite entry failure.\r\n */\r\nexport class WebPackageRootResolutionError extends Error {\r\n public constructor(webRoot: string, reason: string, cause?: unknown) {\r\n super(\r\n `Cannot resolve the \"${WEB_PACKAGE_NAME}\" package root: \"${webRoot}\" ${reason}. ` +\r\n \"Pass `webRoot` explicitly in the web build options to point at the package root \" +\r\n `whose package.json declares \"name\": \"${WEB_PACKAGE_NAME}\".`,\r\n { cause },\r\n );\r\n this.name = \"WebPackageRootResolutionError\";\r\n }\r\n}\r\n\r\n/**\r\n * Proves that `webRoot` really is the `@warlock.js/web` package root by reading\r\n * `<webRoot>/package.json` and matching its `name`. Returns the path unchanged.\r\n */\r\nexport function assertWebPackageRoot(webRoot: string): string {\r\n const manifestPath = path.join(webRoot, \"package.json\");\r\n\r\n let raw: string;\r\n\r\n try {\r\n raw = readFileSync(manifestPath, \"utf-8\");\r\n } catch (error) {\r\n throw new WebPackageRootResolutionError(webRoot, \"has no readable package.json\", error);\r\n }\r\n\r\n let parsed: unknown;\r\n\r\n try {\r\n parsed = JSON.parse(raw);\r\n } catch (error) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n \"has a package.json that is not valid JSON\",\r\n error,\r\n );\r\n }\r\n\r\n if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n \"has a package.json whose root is not a JSON object\",\r\n );\r\n }\r\n\r\n const name = (parsed as { name?: unknown }).name;\r\n\r\n if (name !== WEB_PACKAGE_NAME) {\r\n throw new WebPackageRootResolutionError(\r\n webRoot,\r\n `declares package name ${JSON.stringify(name)}, not \"${WEB_PACKAGE_NAME}\"`,\r\n );\r\n }\r\n\r\n return webRoot;\r\n}\r\n\r\nexport async function resolveWebPackageRoot(configured: string | undefined): Promise<string> {\r\n if (configured !== undefined) {\r\n return assertWebPackageRoot(path.resolve(configured));\r\n }\r\n\r\n const { fileURLToPath } = await import(\"node:url\");\r\n\r\n // `web/src/build/contribution.ts` published as `web/esm/build/contribution.js`\r\n // — two levels up is the package root under both layouts.\r\n return assertWebPackageRoot(\r\n path.resolve(path.dirname(fileURLToPath(import.meta.url)), \"..\", \"..\"),\r\n );\r\n}\r\n\r\n/**\r\n * Builds web's `ConnectorBuildContribution`.\r\n *\r\n * `generate` writes the page barrel into `ctx.productionDir` and patches\r\n * esbuild; `emit` produces the client bundle esbuild cannot. The two share one\r\n * closure facts — how many pages exist, the discovered route table, and the\n * exact app-public file list. A build with zero pages skips the hydration\n * bundle but still copies public files when present. `generate` itself does\n * NOT skip: the barrel and its entry import are emitted either way, so the\n * runtime can tell a page-free web build from a build without web.\n *\r\n * Connector plugins are a separate argument rather than a `WebBuildOptions`\r\n * field: the app constructs them once, the factory snapshots that array for\r\n * both dev and build, and this module keeps Vite as a type-only import until\r\n * `emit` dynamically loads the real client builder.\r\n */\r\nexport function createWebBuildContribution(\r\n options: WebBuildOptions = {},\r\n connectorPlugins: readonly PluginOption[] = [],\r\n): ConnectorBuildContribution {\r\n if (options.clientOutDir !== undefined) {\r\n throw new ClientOutDirNotSupportedError();\r\n }\r\n\r\n let pageCount = 0;\r\n let pageRoutes: import(\"./generate-pages-barrel\").PageRoutesManifest = {\n version: 1,\n routes: [],\n };\n let publicFiles: string[] = [];\n\r\n return {\r\n async generate(context: ConnectorBuildContext): Promise<ConnectorBuildGenerateResult | void> {\r\n const { generatePagesBarrel, WEB_ENTRY_IMPORT, WEB_ESBUILD_PATCH } =\n await import(\"./generate-pages-barrel\");\n const { collectPublicFiles } = await import(\"./public-files\");\n\n publicFiles = await collectPublicFiles(path.join(context.appRoot, \"public\"));\n\n const result = await generatePagesBarrel({\n appRoot: context.appRoot,\r\n productionDir: context.productionDir,\r\n srcDir: options.srcDir,\r\n // Derived from `resolveClientOutDir` — the SAME function `emit` passes\r\n // to the Vite build below — so the path baked into the manifest and\r\n // the path the bundle is written to are one expression, not two that\r\n // happen to agree today.\r\n // POSIX-normalised inline rather than via the generator's `toPosix`:\r\n // this module's static graph is `node:path` and types only, and the\r\n // generator is reached by `await import` precisely to keep it that way.\r\n clientDir: path\r\n .relative(context.appRoot, resolveClientOutDir(context))\r\n .split(path.sep)\n .join(\"/\"),\n publicFiles,\n });\n\r\n pageCount = result.pageCount;\r\n pageRoutes = result.pageRoutes;\r\n\r\n // Contributed unconditionally, zero pages included: the barrel is always\r\n // written, and the entry has to IMPORT it for the empty table to reach\r\n // the runtime. Withholding this line on zero pages would leave the\r\n // manifest absent, which is the runtime's signal for \"never built with\r\n // web\" — the exact confusion the always-written barrel removes.\r\n return { entryImports: [WEB_ENTRY_IMPORT], esbuild: WEB_ESBUILD_PATCH };\r\n },\r\n\r\n async emit(context: ConnectorBuildContext): Promise<void> {\r\n if (pageCount > 0) {\n const { buildWarlockHydrationClient } = await import(\"../vite\");\r\n const { appConventionAliases } = await import(\"../vite/app-convention-aliases\");\r\n\r\n // The app-tree convention (`web/*`, `app/*`) the dev server installs must\r\n // also reach the production build, from the SAME definition — see\r\n // `app-convention-aliases.ts`. Caller-supplied aliases come first so a\r\n // caller can win a conflict, matching the dev server's ordering.\r\n const callerAliases = Object.entries(options.aliases ?? {}).map(([find, replacement]) => ({\r\n find,\r\n replacement,\r\n }));\r\n\r\n await buildWarlockHydrationClient({\r\n appRoot: context.appRoot,\r\n webRoot: await resolveWebPackageRoot(options.webRoot),\r\n outDir: resolveClientOutDir(context),\r\n resolveAliases: [\r\n ...callerAliases,\r\n ...appConventionAliases(path.join(context.appRoot, options.srcDir ?? \"src\")),\r\n ],\r\n external: options.external,\r\n plugins: connectorPlugins,\r\n });\n }\n\n if (publicFiles.length > 0) {\n const { copyPublicFiles } = await import(\"./public-files\");\n await copyPublicFiles(\n path.join(context.appRoot, \"public\"),\n path.join(resolveClientOutDir(context), \"public\"),\n publicFiles,\n );\n }\n\n const { writePageRoutesManifest } = await import(\"./page-routes-manifest\");\n await writePageRoutesManifest(\r\n path.resolve(context.appRoot, context.options.outdir),\r\n pageRoutes,\r\n );\r\n },\r\n };\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuDA,SAAS,oBAAoB,SAAwC;CACnE,OAAO,KAAK,QAAQ,QAAQ,SAAS,QAAQ,QAAQ,QAAQ,QAAQ;AACvE;;;;;;;;;;;;AAaA,IAAa,gCAAb,cAAmD,MAAM;CACvD,AAAO,cAAc;EACnB,MACE,6RAIF;EACA,KAAK,OAAO;CACd;AACF;;AAGA,M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AAM,OAAO;GACjD,MAAM,wBACJ,KAAK,QAAQ,QAAQ,SAAS,QAAQ,QAAQ,MAAM,GACpD,UACF;EACF;CACF;AACF"}
@@ -10,7 +10,7 @@ import fs from "node:fs";
10
10
  import path from "node:path";
11
11
  import { parse } from "@babel/parser";
12
12
 
13
- //#region web/src/build/discover-pages.ts
13
+ //#region ../web/src/build/discover-pages.ts
14
14
  /**
15
15
  * Static discovery of the application's page graph — the ONE scan every
16
16
  * provider shares.
@@ -1 +1 @@
1
- {"version":3,"file":"discover-pages.mjs","names":[],"sources":["C:/Work/Warlock.js/web/src/build/discover-pages.ts"],"sourcesContent":["/**\n * Static discovery of the application's page graph — the ONE scan every\n * provider shares.\n *\n * This module has a single responsibility: look at the filesystem and produce\n * the recipe. It writes nothing, knows nothing about the generated barrel, and\n * imports neither Vite nor a single application module. Everything that turns\n * the recipe into an artefact (the production barrel, the dev plugin, the\n * generated client entry) lives with that artefact and consumes\n * {@link discoverPages}.\n *\n * The reason it is one module rather than one function per consumer: two\n * scanners that agree today drift tomorrow, and a page that exists for the\n * server but not the client is the silent failure that costs a day to find.\n * Sharing the scan makes that disagreement impossible by construction instead\n * of catchable by test.\n *\n * \"Static\" means WITHOUT RUNNING THE APPLICATION — this module globs\n * `*.page.tsx`, `layout.tsx` and `root.tsx`, and reads each page's declared\n * `route` and each layout's declared `prefix` by PARSING the source\n * ({@link readRouteExports}). It still imports no application module.\n *\n * An explicit `route` export wins. Otherwise the URL is derived from the page's\n * path beneath `src/web`: directories contribute segments, `(groups)` do not,\n * `index.page.tsx` claims its directory, and `[id]` becomes `:id`. A layout\n * `prefix` replaces its own directory segment. The same recipe is emitted to\n * every provider so build and boot cannot drift.\n *\n * Discovery also CLASSIFIES each layout — does its module have a default\n * export, does it export `middleware` — because the layout policy\n * ({@link \"../routing/layout-policy.ts\"}) owns the rule but may not touch a\n * filesystem to learn the facts the rule needs. That classification is another\n * parse, never an import: a layout is read exactly the way a page's `route` is.\n *\n * And it CHECKS the page's `metadata` keys ({@link UnknownMetadataKeyError}) —\n * see that error and {@link readMetadataKeys} for why a type alone does not\n * close that hole.\n */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { parse } from \"@babel/parser\";\nimport { composeRoutePath } from \"../routing/compose-route-path\";\n// `../server/not-found-page` is imported for its CONSTANTS and its filename\n// predicate only — that module has no runtime imports of its own, precisely so\n// this edge cannot drag the render pipeline into the build. What a not-found\n// page is, and what identity it carries, is decided in one place for discovery\n// and both installers.\nimport {\n isNotFoundPageFile,\n NotFoundPageDeclaresRouteError,\n NOT_FOUND_ROUTE_NAME,\n NOT_FOUND_ROUTE_PATH,\n} from \"../server/not-found-page\";\n// The metadata key set, as VALUES. `../metadata` is a types-plus-constants\n// module with no runtime imports of its own (both its imports are `import\n// type`), so this costs the build nothing and buys the one thing a parse cannot\n// get from a type: the list of keys a page is allowed to write.\nimport { METADATA_KEYS, OPEN_GRAPH_KEYS, TWITTER_KEYS } from \"../metadata\";\nimport { NestedLayoutsNotSupportedError, selectPageLayout } from \"../routing/layout-policy\";\nimport {\n deriveFilesystemRouteName,\n deriveFilesystemRoutePath,\n} from \"../routing/filesystem-route\";\nimport { deriveFallbackRouteName } from \"../routing/route-identity\";\nimport { assertPageHasDefaultExport } from \"./page-default-export\";\nimport type { RouteExportsReadResult } from \"./read-route-exports\";\nimport { NonLiteralRouteExportError, readRouteExports } from \"./read-route-exports\";\n\nexport type DiscoverPagesOptions = {\n /** Absolute path to the application root (where `package.json` lives). */\n appRoot: string;\n /** Source directory name under `appRoot`; defaults to `\"src\"`. */\n srcDir?: string;\n};\n\nexport type DiscoveredRoutablePage = {\n /** A browsable page. Error pages are deliberately a different discovery kind. */\n type: \"page\";\n /**\n * The page's route name: the `name` its `route` export declares, or its\n * filesystem identity as dotted segments, with groups omitted.\n *\n * Unique across the whole graph — {@link discoverPages} refuses to return a\n * result where it is not.\n */\n routeName: string;\n /**\n * The page's effective route path. Explicit routes retain their existing\n * layout-prefix composition. Derived routes use filesystem segments, with\n * each declared layout prefix replacing that layout directory's segment.\n * Always `/`-prefixed.\n */\n routePath: string;\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root this page was found under — the root its layout chain climbs to. */\n webRoot: string;\n /** Absolute paths of every `layout.tsx` from the web root down to the page's own directory, OUTERMOST FIRST. */\n layouts: string[];\n /**\n * The page's middleware chain: the subset of {@link layouts} whose modules\n * export `middleware`, OUTERMOST FIRST — the order they must run in.\n *\n * Source files rather than the middleware values themselves, because\n * discovery never runs application code: this says WHICH layouts contribute a\n * guard, and the consumer that already loads those modules reads the values\n * off them.\n *\n * Empty when no layout on the path declares middleware, which is the common\n * case; a page with no layouts always has an empty chain.\n */\n middlewareLayouts: string[];\n /** Absolute path to the global `root.tsx` every page renders inside, when it exists. */\n appFile?: string;\n};\n\n/** The one application error boundary. It deliberately has no route identity. */\nexport type DiscoveredErrorPage = {\n type: \"error\";\n /** Absolute path to the sole `error.page.tsx` beneath `src/web`. */\n pageFile: string;\n webRoot: string;\n appFile?: string;\n};\n\n/** The complete static web graph: routable leaves plus the optional error boundary. */\nexport type DiscoveredPage = DiscoveredRoutablePage | DiscoveredErrorPage;\n\nexport function isDiscoveredRoutablePage(page: DiscoveredPage): page is DiscoveredRoutablePage {\n return page.type === \"page\";\n}\n\nexport function isErrorPageFile(file: string): boolean {\n return path.basename(file) === \"error.page.tsx\";\n}\n\nexport class DuplicateErrorPageError extends Error {\n public constructor(firstFile: string, secondFile: string) {\n super(\n `Two error pages were found: \"${firstFile}\" and \"${secondFile}\". An application may own exactly one \\`error.page.tsx\\` anywhere beneath src/web.`,\n );\n this.name = \"DuplicateErrorPageError\";\n }\n}\n\nexport class ErrorPageDeclaresRouteError extends Error {\n public constructor(pageFile: string) {\n super(\n `The error page \"${pageFile}\" exports \\`route\\`. error.page.tsx is an error boundary, not a browsable page; remove the route export.`,\n );\n this.name = \"ErrorPageDeclaresRouteError\";\n }\n}\n\n/** Raised when two pages claim one route name. */\nexport class DuplicatePageRouteNameError extends Error {\n public constructor(\n public readonly routeName: string,\n public readonly firstFile: string,\n public readonly secondFile: string,\n ) {\n super(\n `Two pages resolve to the same route name \"${routeName}\": \"${firstFile}\" and ` +\n `\"${secondFile}\". A route name identifies exactly one page, so the second ` +\n \"page would be unreachable. To fix: rename one of the files, or move it so \" +\n \"its directory gives it a different route name.\",\n );\n this.name = \"DuplicatePageRouteNameError\";\n }\n}\n\n/** Raised when two different page files resolve to one effective URL. */\nexport class DuplicatePageRoutePathError extends Error {\n public constructor(\n public readonly routePath: string,\n public readonly firstFile: string,\n public readonly secondFile: string,\n ) {\n super(\n `Two pages resolve to the same route path \"${routePath}\": \"${firstFile}\" and ` +\n `\"${secondFile}\". Each URL may identify exactly one page. Rename or move one file, ` +\n \"or give one page an explicit route with a different path.\",\n );\n this.name = \"DuplicatePageRoutePathError\";\n }\n}\n\nexport function toPosix(value: string): string {\n return value.replace(/\\\\/g, \"/\");\n}\n\nfunction isDirectory(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isDirectory();\n } catch {\n return false;\n }\n}\n\nexport function isFile(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * The page root. It is optional; a project without it has zero pages, which is\n * a legal empty state.\n */\nexport function discoverWebRoots(srcRoot: string): string[] {\n const webRoot = path.join(srcRoot, \"web\");\n\n return isDirectory(webRoot) ? [webRoot] : [];\n}\n\nfunction byName(left: { name: string }, right: { name: string }): number {\n return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;\n}\n\nexport type DiscoveredPageFile = {\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root ({@link discoverWebRoots}) this page was found under. */\n webRoot: string;\n};\n\n/**\n * The subject list: every `*.page.tsx` under the page root, one call for the\n * whole graph.\n *\n * Unlike {@link discoverPages}, this reads no `route` or `prefix` export and\n * throws on nothing — it answers only \"which page files exist\", so a provider\n * that still resolves a page's route by its own means (dev's\n * `ssrLoadModule`-driven installer, chiefly) can share the walk without\n * inheriting the static-parsing refusals that answering \"what route is this\"\n * requires.\n */\nexport function discoverPageFiles(srcRoot: string): DiscoveredPageFile[] {\n const found: DiscoveredPageFile[] = [];\n\n for (const webRoot of discoverWebRoots(srcRoot)) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n found.push({ pageFile, webRoot });\n }\n }\n\n return found;\n}\n\n/** Every file under `dir` (recursive) whose name matches `predicate`. */\nexport function walkFiles(dir: string, predicate: (fileName: string) => boolean): string[] {\n const found: string[] = [];\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort(byName)) {\n const full = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n found.push(...walkFiles(full, predicate));\n } else if (entry.isFile() && predicate(entry.name)) {\n found.push(full);\n }\n }\n\n return found;\n}\n\n/**\n * A page's layout chain: every `layout.tsx` in the directories from its web\n * root down to its own directory, OUTERMOST FIRST.\n *\n * Dev's installer reads only the nearest layout today, because its page module\n * triple holds a single layout; the recipe carries the whole chain so the\n * runtime side can compose\n * nested layouts without a second discovery pass. The nearest layout is always\n * the LAST element, so a consumer that still wants dev's one-layout behaviour\n * reads `layouts.at(-1)`.\n */\nexport function layoutChainFor(pageFile: string, webRoot: string): string[] {\n const chain: string[] = [];\n const relativeDir = path.relative(webRoot, path.dirname(pageFile));\n const segments = relativeDir === \"\" ? [] : relativeDir.split(path.sep);\n\n let current = webRoot;\n\n for (let index = 0; index <= segments.length; index++) {\n if (index > 0) {\n current = path.join(current, segments[index - 1]);\n }\n\n const candidate = path.join(current, \"layout.tsx\");\n\n if (isFile(candidate)) {\n chain.push(candidate);\n }\n }\n\n return chain;\n}\n\nfunction compareStrings(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\n/**\n * The total order every consumer sees, and the reason discovery returns an\n * array rather than a set: the page's SOURCE FILE PATH, lexicographic, POSIX.\n *\n * Serialization order only; matching precedence is a property of the route\n * grammar, not of this array.\n *\n * The file path rather than the route path, now that the route is the declared\n * one: a page's route can be rewritten by editing one line, which would reorder\n * an artefact that has not otherwise changed, while the file it lives in is the\n * stable identity the artefact is built from. It also carries no suggestion of\n * precedence — nobody reads \"sorted by file name\" as \"most specific first\",\n * which is the misreading a route-path order invites.\n *\n * Lexicographic because it is byte-comparable output across every provider,\n * which keeps diffs stable and keeps filesystem enumeration order out of the\n * artefact: two machines that list a directory differently must still produce\n * byte-identical output, or a build is only reproducible by luck.\n */\nfunction comparePages(left: DiscoveredPage, right: DiscoveredPage): number {\n return compareStrings(toPosix(left.pageFile), toPosix(right.pageFile));\n}\n\nfunction assertUniqueRouteNames(pages: readonly DiscoveredRoutablePage[], appRoot: string): void {\n const fileByRouteName = new Map<string, string>();\n\n for (const page of pages) {\n const existing = fileByRouteName.get(page.routeName);\n const relative = toPosix(path.relative(appRoot, page.pageFile));\n\n if (existing !== undefined) {\n throw new DuplicatePageRouteNameError(page.routeName, existing, relative);\n }\n\n fileByRouteName.set(page.routeName, relative);\n }\n}\n\n/**\n * A page's declared `route.path` is a choice its author made deliberately, so\n * two pages that both declare the same path are the author's call, not an\n * accident — {@link assertUniqueRouteNames} is what keeps each of them\n * reachable by name. What this refuses is a COLLISION NOBODY CHOSE: at least\n * one side's path is filesystem-derived, which is exactly the case a rename\n * or a new file can produce without anyone noticing two pages now answer the\n * same URL. The reserved not-found path (`\"*\"`) is never a candidate here\n * either way — it identifies no browsable URL, and {@link assertUniqueRouteNames}\n * already refuses a second `404.page.tsx` by its own reserved name.\n */\nfunction assertUniqueRoutePaths(\n pages: readonly DiscoveredRoutablePage[],\n appRoot: string,\n explicitFiles: ReadonlySet<string>,\n): void {\n const fileByRoutePath = new Map<string, string>();\n\n for (const page of pages) {\n if (page.routePath === NOT_FOUND_ROUTE_PATH) continue;\n\n const existing = fileByRoutePath.get(page.routePath);\n const relative = toPosix(path.relative(appRoot, page.pageFile));\n\n if (existing !== undefined && !(explicitFiles.has(existing) && explicitFiles.has(relative))) {\n throw new DuplicatePageRoutePathError(page.routePath, existing, relative);\n }\n\n if (existing === undefined) fileByRoutePath.set(page.routePath, relative);\n }\n}\n\n/** One key a page's `metadata` declares that nothing reads, and where it is written. */\nexport type UnknownMetadataKey = {\n /** The object it was declared in: `metadata`, `metadata.openGraph`, `metadata.twitter`. */\n container: string;\n /** The key exactly as the page wrote it. */\n key: string;\n /** 1-based line in the page file, so the message points at the character that is wrong. */\n line: number;\n /** The known key it is within two edits of, when there is one. Usually the whole answer. */\n suggestion?: string;\n};\n\n/**\n * Raised when a page's `metadata` export declares a key nothing reads.\n *\n * THE POINT OF THIS ERROR IS THE UNANNOTATED CASE. A page that writes\n * `export const metadata: PageMetadata = { tittle: \"x\" }` is already refused by\n * TypeScript, and if that were the whole story this class would not need to\n * exist. But the annotation is optional, nobody writes it, and\n * `export const metadata = { tittle: \"x\" }` is a perfectly well-typed program:\n * the compiler infers `{ tittle: string }`, has nothing to check it against, and\n * says nothing. The page is then served with no `<title>` — not a wrong title, a\n * missing one — and no error is raised anywhere, at build or at runtime, ever.\n *\n * So the check lives HERE instead, at the gate every page already passes\n * through: a page that silently omits requested metadata is worse than a build\n * that stops and says which line to fix.\n *\n * The alternative considered and rejected was a `defineMetadata({...})` wrapper,\n * which would infer the type for free. It also puts framework ceremony in every\n * page, and a page is meant to be two lines of framework surface (canon\n * `6ea0662f`). The gate gets the same safety without spending that.\n */\nexport class UnknownMetadataKeyError extends Error {\n public constructor(\n public readonly pageFile: string,\n public readonly unknownKeys: readonly UnknownMetadataKey[],\n ) {\n const findings = unknownKeys\n .map(({ container, key, line, suggestion }) => {\n const where = `line ${line}: \\`${container}.${key}\\` — no such key.`;\n\n return suggestion === undefined ? where : `${where} Did you mean \\`${suggestion}\\`?`;\n })\n .join(\"\\n \");\n\n super(\n `The \\`metadata\\` export of \"${pageFile}\" declares a key nothing reads:\\n ${findings}\\n` +\n \"Nothing writes an unknown key to `<head>`, so the tag it was meant to produce would \" +\n \"simply be absent from every response, with no error at build time or at runtime. The \" +\n \"build refuses it here instead.\\n\" +\n ` Known keys: ${METADATA_KEYS.join(\", \")}.\\n` +\n ` Inside \\`openGraph\\`: ${OPEN_GRAPH_KEYS.join(\", \")}.\\n` +\n ` Inside \\`twitter\\`: ${TWITTER_KEYS.join(\", \")}.\\n` +\n \"Annotating the export — `export const metadata: PageMetadata = { … }` — gets you the \" +\n \"same list as autocomplete in the editor, before the build runs.\",\n );\n this.name = \"UnknownMetadataKeyError\";\n }\n}\n\n/**\n * The AST types, derived from `parse`'s own return type rather than imported\n * from `@babel/types`, for the reason `read-route-exports.ts` gives: the parser\n * resolves its own copy of that package and nodes from one copy are not\n * assignable to the identical types from the other.\n */\ntype PageStatement = ReturnType<typeof parse>[\"program\"][\"body\"][number];\ntype PageExpression = Extract<PageStatement, { type: \"ExpressionStatement\" }>[\"expression\"];\ntype PageObjectExpression = Extract<PageExpression, { type: \"ObjectExpression\" }>;\ntype PageObjectProperty = Extract<\n PageObjectExpression[\"properties\"][number],\n { type: \"ObjectProperty\" }\n>;\ntype PageValueNode = PageObjectProperty[\"value\"];\n\n/** `as const`, `satisfies`, `!` and parentheses wrap a value without changing it. */\nfunction unwrapValue(node: PageValueNode): PageValueNode {\n switch (node.type) {\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n case \"TSNonNullExpression\":\n case \"TypeCastExpression\":\n case \"ParenthesizedExpression\":\n return unwrapValue(node.expression);\n default:\n return node;\n }\n}\n\n/** Levenshtein distance — small strings, so the plain two-row table is the whole cost. */\nfunction editDistance(left: string, right: string): number {\n let previous = Array.from({ length: right.length + 1 }, (_, index) => index);\n\n for (let row = 1; row <= left.length; row++) {\n const current = [row];\n\n for (let column = 1; column <= right.length; column++) {\n const substitution = previous[column - 1] + (left[row - 1] === right[column - 1] ? 0 : 1);\n current[column] = Math.min(substitution, previous[column] + 1, current[column - 1] + 1);\n }\n\n previous = current;\n }\n\n return previous[right.length];\n}\n\n/**\n * The known key the written one was probably meant to be.\n *\n * Two edits, because that covers the typos this exists for — `tittle`,\n * `descriptoin`, `keywrods` — without reaching so far that `image` gets\n * suggested for `alt`. Case is ignored first, so `Title` resolves exactly.\n */\nfunction suggestKey(written: string, known: readonly string[]): string | undefined {\n const lowered = written.toLowerCase();\n const sameLetters = known.find((candidate) => candidate.toLowerCase() === lowered);\n\n if (sameLetters !== undefined) return sameLetters;\n\n let best: string | undefined;\n let bestDistance = Number.POSITIVE_INFINITY;\n\n for (const candidate of known) {\n const distance = editDistance(lowered, candidate.toLowerCase());\n\n if (distance < bestDistance) {\n best = candidate;\n bestDistance = distance;\n }\n }\n\n return bestDistance <= 2 ? best : undefined;\n}\n\n/** The name an object key denotes, or `undefined` when knowing it needs evaluation. */\nfunction propertyKeyName(property: PageObjectProperty): string | undefined {\n if (property.computed) return undefined;\n\n const { key } = property;\n\n if (key.type === \"Identifier\") return key.name;\n if (key.type === \"StringLiteral\") return key.value;\n\n return undefined;\n}\n\n/** The nested objects that carry a key set of their own. */\nconst NESTED_METADATA_KEYS: Record<string, readonly string[]> = {\n openGraph: OPEN_GRAPH_KEYS,\n twitter: TWITTER_KEYS,\n};\n\n/**\n * Every unknown key in one metadata object literal, and in the `openGraph` /\n * `twitter` literals inside it.\n *\n * A SPREAD does not suppress the check, unlike the route reader's rule: a\n * spread can only ADD keys, and no value it contributes can make a key written\n * out beside it correct. A COMPUTED key is skipped — its name is not knowable\n * without running the page, and refusing what cannot be read would fail builds\n * that are fine. Both are silence in the narrow places where the parse genuinely\n * does not know, and the annotation is the second net there.\n */\nfunction collectUnknownKeys(\n object: PageObjectExpression,\n allowed: readonly string[],\n container: string,\n into: UnknownMetadataKey[],\n): void {\n for (const property of object.properties) {\n if (property.type === \"SpreadElement\") continue;\n\n const key = propertyKeyName(property as PageObjectProperty);\n\n if (key === undefined) continue;\n\n if (!allowed.includes(key)) {\n const suggestion = suggestKey(key, allowed);\n\n into.push({\n container,\n key,\n line: property.loc?.start.line ?? 0,\n ...(suggestion === undefined ? {} : { suggestion }),\n });\n\n continue;\n }\n\n const nested = container === \"metadata\" ? NESTED_METADATA_KEYS[key] : undefined;\n\n if (nested === undefined || property.type !== \"ObjectProperty\") continue;\n\n const value = unwrapValue(property.value);\n\n if (value.type === \"ObjectExpression\") {\n collectUnknownKeys(value, nested, `${container}.${key}`, into);\n }\n }\n}\n\n/**\n * Every object literal a function form RETURNS, without descending into\n * functions nested inside it — a callback's return value is not the metadata.\n *\n * A generic walk rather than a statement-by-statement one because a `return` is\n * legal anywhere a statement is: inside an `if`, a `switch`, a `try`. Enumerating\n * the statement types that may contain one is a list that is wrong the moment\n * the language grows.\n */\nfunction collectReturnedObjects(node: unknown, into: PageObjectExpression[]): void {\n if (node === null || typeof node !== \"object\") return;\n\n if (Array.isArray(node)) {\n for (const item of node) collectReturnedObjects(item, into);\n\n return;\n }\n\n const candidate = node as { type?: string; argument?: unknown };\n\n if (\n candidate.type === \"FunctionDeclaration\" ||\n candidate.type === \"FunctionExpression\" ||\n candidate.type === \"ArrowFunctionExpression\" ||\n candidate.type === \"ObjectMethod\" ||\n candidate.type === \"ClassMethod\"\n ) {\n return;\n }\n\n if (candidate.type === \"ReturnStatement\") {\n if (candidate.argument === null || candidate.argument === undefined) return;\n\n const returned = unwrapValue(candidate.argument as PageValueNode);\n\n if (returned.type === \"ObjectExpression\") into.push(returned);\n\n // Not descending into the returned value: a `return` inside it belongs to a\n // function this walk is deliberately not entering.\n return;\n }\n\n for (const value of Object.values(node as Record<string, unknown>)) {\n collectReturnedObjects(value, into);\n }\n}\n\n/** The metadata object literals one `metadata` export declares, if any can be seen at all. */\nfunction metadataObjectsOf(init: PageValueNode): PageObjectExpression[] {\n const value = unwrapValue(init);\n\n if (value.type === \"ObjectExpression\") return [value];\n\n if (value.type === \"ArrowFunctionExpression\" || value.type === \"FunctionExpression\") {\n const body = unwrapValue(value.body as PageValueNode);\n\n // The concise arrow body — `({ data }) => ({ title: data.name })`, which is\n // how every function-form metadata export in the reference app is written.\n if (body.type === \"ObjectExpression\") return [body];\n\n const returned: PageObjectExpression[] = [];\n\n collectReturnedObjects(value.body, returned);\n\n return returned;\n }\n\n // `export const metadata = buildMetadata()`, or a bare identifier: the keys\n // are not in this file. Silent by design — see `collectUnknownKeys`.\n return [];\n}\n\n/**\n * The unknown keys a page's `metadata` export declares, read by PARSING — the\n * same rule the rest of this module lives by, and the reason this check can run\n * before anything is built.\n *\n * Empty for a page with no `metadata` export, for one whose metadata is a value\n * this file cannot see into, and for a correct one.\n */\nexport function readMetadataKeys(pageFile: string, source: string): UnknownMetadataKey[] {\n let program: ReturnType<typeof parse>[\"program\"];\n\n try {\n program = parse(source, {\n sourceType: \"module\",\n plugins: [\"typescript\", \"jsx\"],\n errorRecovery: false,\n }).program;\n } catch (error) {\n throw new Error(\n `Cannot read the \\`metadata\\` export of \"${pageFile}\": the file could not be parsed ` +\n `(${(error as Error).message}). Fix the syntax error and the build will continue.`,\n );\n }\n\n const unknownKeys: UnknownMetadataKey[] = [];\n\n for (const statement of program.body) {\n if (statement.type !== \"ExportNamedDeclaration\" || statement.exportKind === \"type\") continue;\n\n const { declaration } = statement;\n\n if (declaration?.type !== \"VariableDeclaration\") continue;\n\n for (const declarator of declaration.declarations) {\n if (declarator.id.type !== \"Identifier\" || declarator.id.name !== \"metadata\") continue;\n if (declarator.init === null || declarator.init === undefined) continue;\n\n for (const object of metadataObjectsOf(declarator.init)) {\n collectUnknownKeys(object, METADATA_KEYS, \"metadata\", unknownKeys);\n }\n }\n }\n\n return unknownKeys;\n}\n\n/**\n * The declared exports of one file, or a thrown\n * {@link NonLiteralRouteExportError} when they cannot be read without running\n * the application. Layouts are read once per run and remembered: a layout is\n * the nearest one for every page beside it, and parsing it once per page would\n * be the same answer bought repeatedly.\n *\n * `source` is the file's text when the caller already holds it — the page loop\n * reads each page once and spends that read on both the route declarations and\n * the metadata check, rather than opening the same file twice.\n */\nfunction readDeclarations(\n sourceFile: string,\n cache: Map<string, RouteExportsReadResult>,\n source?: string,\n) {\n let result = cache.get(sourceFile);\n\n if (result === undefined) {\n result = readRouteExports(sourceFile, source);\n cache.set(sourceFile, result);\n }\n\n if (!result.ok) {\n throw new NonLiteralRouteExportError(result.rejection);\n }\n\n return result;\n}\n\n/**\n * What a layout DOES, read by parsing it — the facts the layout policy's rule\n * needs and, being a pure module, cannot go and find for itself.\n */\ntype LayoutShape = {\n /**\n * Whether the module has a default export — the export that puts an element\n * in the document, and therefore the one thing that makes a layout count\n * against the single-rendering-layout rule.\n */\n renders: boolean;\n /** Whether the module exports `middleware`, or might via a re-export this cannot see through. */\n hasMiddleware: boolean;\n};\n\n/**\n * Parses one layout and reports its shape. Remembered per run for the same\n * reason declarations are: a layout is on the path of every page beneath it.\n */\nfunction readLayoutShape(layoutFile: string, cache: Map<string, LayoutShape>): LayoutShape {\n const cached = cache.get(layoutFile);\n\n if (cached !== undefined) return cached;\n\n const source = fs.readFileSync(layoutFile, \"utf-8\");\n let program: ReturnType<typeof parse>[\"program\"];\n\n try {\n program = parse(source, {\n sourceType: \"module\",\n // Every file this reads is a layout, i.e. `.tsx`.\n plugins: [\"typescript\", \"jsx\"],\n errorRecovery: false,\n }).program;\n } catch (error) {\n throw new Error(\n `Cannot read the exports of \"${layoutFile}\": the file could not be parsed ` +\n `(${(error as Error).message}). Fix the syntax error and the build will continue.`,\n );\n }\n\n const shape: LayoutShape = { renders: false, hasMiddleware: false };\n\n for (const statement of program.body) {\n if (statement.type === \"ExportDefaultDeclaration\") {\n shape.renders = true;\n continue;\n }\n\n // `export * from \"./guard\"` cannot re-export a default — the language\n // excludes it — but it CAN contribute `middleware`, and no parse can see\n // through it without resolving and reading another module. Reading it as\n // \"no middleware here\" is exactly the silent unguarding this slice exists\n // to prevent, so it is read as \"possibly\" and fails loudly downstream.\n if (statement.type === \"ExportAllDeclaration\") {\n shape.hasMiddleware = true;\n continue;\n }\n\n if (statement.type !== \"ExportNamedDeclaration\" || statement.exportKind === \"type\") continue;\n\n for (const specifier of statement.specifiers) {\n if (specifier.type !== \"ExportSpecifier\" || specifier.exportKind === \"type\") continue;\n\n const exported =\n specifier.exported.type === \"Identifier\"\n ? specifier.exported.name\n : specifier.exported.value;\n\n if (exported === \"default\") shape.renders = true;\n if (exported === \"middleware\") shape.hasMiddleware = true;\n }\n\n const { declaration } = statement;\n\n if (declaration === null || declaration === undefined) continue;\n\n if (declaration.type === \"VariableDeclaration\") {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === \"Identifier\" && declarator.id.name === \"middleware\") {\n shape.hasMiddleware = true;\n }\n }\n\n continue;\n }\n\n if (\n (declaration.type === \"FunctionDeclaration\" || declaration.type === \"ClassDeclaration\") &&\n declaration.id?.name === \"middleware\"\n ) {\n shape.hasMiddleware = true;\n }\n }\n\n cache.set(layoutFile, shape);\n\n return shape;\n}\n\n/**\n * Scans the page root and returns the pages in a defined total order.\n *\n * Zero pages is a legal result, not an error: a project may be configured\n * with web and have nothing to serve yet. What is an error is a `*.page.tsx`\n * with a route or metadata export that cannot be read statically; two pages\n * claiming one effective path or route name, which this refuses\n * to return at all — the alternative is an artefact in which one of them is\n * silently unreachable; a `route` or `prefix` that cannot be read without\n * running the application, which is refused before any page is reported at\n * all; a `metadata` export declaring a key nothing reads, which no compiler\n * catches unless the page opted into the type and which otherwise serves a page\n * with a silently missing tag; and a page whose layout chain holds more than one RENDERING layout, which\n * the production installer would refuse anyway — discovery refuses it first so\n * that artefact is never produced.\n */\nexport function discoverPages(options: DiscoverPagesOptions): DiscoveredPage[] {\n const { appRoot } = options;\n const srcRoot = path.join(appRoot, options.srcDir ?? \"src\");\n const webRoots = discoverWebRoots(srcRoot);\n const appFile = path.join(srcRoot, \"web\", \"root.tsx\");\n const hasAppFile = isFile(appFile);\n const declarations = new Map<string, RouteExportsReadResult>();\n const layoutShapes = new Map<string, LayoutShape>();\n const relativeToApp = (file: string) => toPosix(path.relative(appRoot, file));\n\n const pages: DiscoveredPage[] = [];\n const explicitRouteFiles = new Set<string>();\n let errorPage: DiscoveredErrorPage | undefined;\n\n for (const webRoot of webRoots) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n const pageSource = fs.readFileSync(pageFile, \"utf-8\");\n assertPageHasDefaultExport(relativeToApp(pageFile), pageSource);\n const { route } = readDeclarations(pageFile, declarations, pageSource);\n if (isErrorPageFile(pageFile)) {\n if (route !== undefined) throw new ErrorPageDeclaresRouteError(relativeToApp(pageFile));\n\n if (errorPage !== undefined) {\n throw new DuplicateErrorPageError(relativeToApp(errorPage.pageFile), relativeToApp(pageFile));\n }\n\n errorPage = { type: \"error\", pageFile, webRoot, ...(hasAppFile ? { appFile } : {}) };\n continue;\n }\n const isNotFoundPage = isNotFoundPageFile(pageFile);\n\n // THE NOT-FOUND PAGE IS THE ONE PAGE WITH NO URL, in both directions.\n //\n // Every ordinary page may derive its URL from the filesystem.\n // `404.page.tsx` is reached by NOT matching, so the opposite remains the\n // error: a `route` export here reads as a promise that some path is\n // browsable, which the installers never keep.\n //\n // Discovery still reports it, with the SAME reserved identity both\n // installers register it under, so the emitted artefacts agree with the\n // server about which entry is the not-found page — and so the client\n // registry carries the module the SSR'd document has to hydrate against.\n if (isNotFoundPage && route !== undefined) {\n throw new NotFoundPageDeclaresRouteError(relativeToApp(pageFile));\n }\n\n // The page contract is not only `route`. `metadata` is the other export\n // every page may declare, and it is the one with no compiler behind it\n // unless the author opted in to a type annotation — so it is checked\n // here, by name, exactly like the route above.\n //\n // AFTER the reserved-404 route check on purpose: an impossible 404 route\n // contract is more fundamental than a malformed `<head>` declaration.\n const unknownMetadataKeys = readMetadataKeys(relativeToApp(pageFile), pageSource);\n\n if (unknownMetadataKeys.length > 0) {\n throw new UnknownMetadataKeyError(relativeToApp(pageFile), unknownMetadataKeys);\n }\n\n // The policy decides which layout the page RENDERS INSIDE, from the FULL\n // enumerated chain: a layout anywhere on the ancestry path counts, not\n // just one in the page's own directory. Discovery supplies the one fact\n // the rule needs and the pure policy cannot learn — whether each layout\n // renders anything at all.\n const layouts = layoutChainFor(pageFile, webRoot);\n const shapes = layouts.map((layoutFile) => readLayoutShape(layoutFile, layoutShapes));\n const selection = selectPageLayout(\n layouts.map((layout, index) => ({ layout, renders: shapes[index].renders })),\n );\n\n if (selection.type === \"rejected\") {\n throw new NestedLayoutsNotSupportedError(\n relativeToApp(pageFile),\n selection.layouts.map(relativeToApp),\n );\n }\n\n // Every layout that declares a guard, outermost first. Both installers\n // now CONCATENATE the whole chain into the pipeline's single layout slot\n // (`../server/install-page-routes.ts`, `../server/install-page-routes-from-manifest.ts`),\n // so a guard anywhere on the path runs, in this order — which is why the\n // temporary refusal that used to stand here is gone rather than relaxed.\n const middlewareLayouts = layouts.filter((_, index) => shapes[index].hasMiddleware);\n\n // EVERY prefix on the path, outermost first: a `prefix`-only layout is\n // still a segment of the URL, and composing only the rendering layout's\n // would serve the subtree from a path nobody declared.\n const layoutPrefix = layouts.reduce(\n (composed, layoutFile) =>\n composeRoutePath(composed, readDeclarations(layoutFile, declarations).prefix ?? \"/\"),\n \"/\",\n );\n\n const relativePageFile = toPosix(path.relative(webRoot, pageFile));\n const layoutPrefixes = Object.fromEntries(\n layouts.flatMap((layoutFile) => {\n const prefix = readDeclarations(layoutFile, declarations).prefix;\n if (prefix === undefined) return [];\n\n const directory = toPosix(path.relative(webRoot, path.dirname(layoutFile)));\n return [[directory, prefix]];\n }),\n );\n const effectiveRoutePath = isNotFoundPage\n ? NOT_FOUND_ROUTE_PATH\n : route\n ? composeRoutePath(layoutPrefix, route.path)\n : deriveFilesystemRoutePath({ pageFile: relativePageFile, layoutPrefixes });\n\n if (!isNotFoundPage && route !== undefined) {\n explicitRouteFiles.add(relativeToApp(pageFile));\n }\n\n pages.push({\n type: \"page\",\n routeName: isNotFoundPage\n ? NOT_FOUND_ROUTE_NAME\n : (route?.name ??\n (route\n ? deriveFallbackRouteName({\n routePath: route.path,\n sourceFile: relativeToApp(pageFile),\n })\n : deriveFilesystemRouteName(relativePageFile))),\n // The catch-all, which the client route matcher already understands as\n // a terminal `catch-all` token sorted LAST by specificity\n // (`../client/runtime/matcher.ts`) — so the browser resolves the\n // not-found page for a URL that matched nothing, exactly as the server\n // did, and never in preference to a real page.\n routePath: effectiveRoutePath,\n pageFile,\n webRoot,\n // THE NOT-FOUND PAGE RENDERS INSIDE THE APPLICATION ROOT AND NOTHING\n // ELSE — an EMPTY chain, not the one enumerated above.\n //\n // Both installers render it with `layoutFile: undefined`, deliberately\n // and independently (`../server/install-page-routes.ts`,\n // `../server/install-page-routes-from-manifest.ts`), for the same\n // reason the 404 page takes no loader: a path whose entire job is to\n // handle failure must not depend on chrome that can itself throw,\n // redirect, or need data. Reporting layouts here anyway put them in the\n // client registry and therefore in HYDRATION, so the server rendered\n // `App(Page)` while the browser rebuilt `App(Layout(Page))` — a\n // guaranteed mismatch on the one route nobody is watching, invisible to\n // any application that happens to have no layouts.\n //\n // Aligned by REMOVING them from the client, never by giving them to the\n // server: layouts on the not-found route would make it the most fragile\n // route in the application.\n //\n // The chain above is still enumerated and still validated, so a nested\n // layout on this page's path is refused at build time exactly as it is\n // everywhere else — what changes is only what the page renders inside.\n layouts: isNotFoundPage ? [] : layouts,\n middlewareLayouts: isNotFoundPage ? [] : middlewareLayouts,\n ...(hasAppFile ? { appFile } : {}),\n });\n }\n }\n\n // The error page is captured separately above so a second one can be\n // compared against the first before either is trusted — it joins the\n // returned graph here, once discovery knows there is exactly one.\n if (errorPage !== undefined) pages.push(errorPage);\n\n pages.sort(comparePages);\n\n const routablePages = pages.filter(isDiscoveredRoutablePage);\n assertUniqueRoutePaths(routablePages, appRoot, explicitRouteFiles);\n assertUniqueRouteNames(routablePages, appRoot);\n\n return pages;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,SAAgB,yBAAyB,MAAsD;CAC7F,OAAO,KAAK,SAAS;AACvB;AAEA,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,KAAK,SAAS,IAAI,MAAM;AACjC;AAE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,CAAC,IACD,0BAA0B,gBAAgB;GAMpD,WAAW;GACX;GACA;GAsBA,SAAS,iBAAiB,CAAC,IAAI;GAC/B,mBAAmB,iBAAiB,CAAC,IAAI;GACzC,GAAI,aAAa,EAAE,QAAQ,IAAI,CAAC;EAClC,CAAC;CACH;CAMF,IAAI,cAAc,QAAW,MAAM,KAAK,SAAS;CAEjD,MAAM,KAAK,YAAY;CAEvB,MAAM,gBAAgB,MAAM,OAAO,wBAAwB;CAC3D,uBAAuB,eAAe,SAAS,kBAAkB;CACjE,uBAAuB,eAAe,OAAO;CAE7C,OAAO;AACT"}
1
+ {"version":3,"file":"discover-pages.mjs","names":[],"sources":["../../../../../../../web/src/build/discover-pages.ts"],"sourcesContent":["/**\n * Static discovery of the application's page graph — the ONE scan every\n * provider shares.\n *\n * This module has a single responsibility: look at the filesystem and produce\n * the recipe. It writes nothing, knows nothing about the generated barrel, and\n * imports neither Vite nor a single application module. Everything that turns\n * the recipe into an artefact (the production barrel, the dev plugin, the\n * generated client entry) lives with that artefact and consumes\n * {@link discoverPages}.\n *\n * The reason it is one module rather than one function per consumer: two\n * scanners that agree today drift tomorrow, and a page that exists for the\n * server but not the client is the silent failure that costs a day to find.\n * Sharing the scan makes that disagreement impossible by construction instead\n * of catchable by test.\n *\n * \"Static\" means WITHOUT RUNNING THE APPLICATION — this module globs\n * `*.page.tsx`, `layout.tsx` and `root.tsx`, and reads each page's declared\n * `route` and each layout's declared `prefix` by PARSING the source\n * ({@link readRouteExports}). It still imports no application module.\n *\n * An explicit `route` export wins. Otherwise the URL is derived from the page's\n * path beneath `src/web`: directories contribute segments, `(groups)` do not,\n * `index.page.tsx` claims its directory, and `[id]` becomes `:id`. A layout\n * `prefix` replaces its own directory segment. The same recipe is emitted to\n * every provider so build and boot cannot drift.\n *\n * Discovery also CLASSIFIES each layout — does its module have a default\n * export, does it export `middleware` — because the layout policy\n * ({@link \"../routing/layout-policy.ts\"}) owns the rule but may not touch a\n * filesystem to learn the facts the rule needs. That classification is another\n * parse, never an import: a layout is read exactly the way a page's `route` is.\n *\n * And it CHECKS the page's `metadata` keys ({@link UnknownMetadataKeyError}) —\n * see that error and {@link readMetadataKeys} for why a type alone does not\n * close that hole.\n */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { parse } from \"@babel/parser\";\nimport { composeRoutePath } from \"../routing/compose-route-path\";\n// `../server/not-found-page` is imported for its CONSTANTS and its filename\n// predicate only — that module has no runtime imports of its own, precisely so\n// this edge cannot drag the render pipeline into the build. What a not-found\n// page is, and what identity it carries, is decided in one place for discovery\n// and both installers.\nimport {\n isNotFoundPageFile,\n NotFoundPageDeclaresRouteError,\n NOT_FOUND_ROUTE_NAME,\n NOT_FOUND_ROUTE_PATH,\n} from \"../server/not-found-page\";\n// The metadata key set, as VALUES. `../metadata` is a types-plus-constants\n// module with no runtime imports of its own (both its imports are `import\n// type`), so this costs the build nothing and buys the one thing a parse cannot\n// get from a type: the list of keys a page is allowed to write.\nimport { METADATA_KEYS, OPEN_GRAPH_KEYS, TWITTER_KEYS } from \"../metadata\";\nimport { NestedLayoutsNotSupportedError, selectPageLayout } from \"../routing/layout-policy\";\nimport {\n deriveFilesystemRouteName,\n deriveFilesystemRoutePath,\n} from \"../routing/filesystem-route\";\nimport { deriveFallbackRouteName } from \"../routing/route-identity\";\nimport { assertPageHasDefaultExport } from \"./page-default-export\";\nimport type { RouteExportsReadResult } from \"./read-route-exports\";\nimport { NonLiteralRouteExportError, readRouteExports } from \"./read-route-exports\";\n\nexport type DiscoverPagesOptions = {\n /** Absolute path to the application root (where `package.json` lives). */\n appRoot: string;\n /** Source directory name under `appRoot`; defaults to `\"src\"`. */\n srcDir?: string;\n};\n\nexport type DiscoveredRoutablePage = {\n /** A browsable page. Error pages are deliberately a different discovery kind. */\n type: \"page\";\n /**\n * The page's route name: the `name` its `route` export declares, or its\n * filesystem identity as dotted segments, with groups omitted.\n *\n * Unique across the whole graph — {@link discoverPages} refuses to return a\n * result where it is not.\n */\n routeName: string;\n /**\n * The page's effective route path. Explicit routes retain their existing\n * layout-prefix composition. Derived routes use filesystem segments, with\n * each declared layout prefix replacing that layout directory's segment.\n * Always `/`-prefixed.\n */\n routePath: string;\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root this page was found under — the root its layout chain climbs to. */\n webRoot: string;\n /** Absolute paths of every `layout.tsx` from the web root down to the page's own directory, OUTERMOST FIRST. */\n layouts: string[];\n /**\n * The page's middleware chain: the subset of {@link layouts} whose modules\n * export `middleware`, OUTERMOST FIRST — the order they must run in.\n *\n * Source files rather than the middleware values themselves, because\n * discovery never runs application code: this says WHICH layouts contribute a\n * guard, and the consumer that already loads those modules reads the values\n * off them.\n *\n * Empty when no layout on the path declares middleware, which is the common\n * case; a page with no layouts always has an empty chain.\n */\n middlewareLayouts: string[];\n /** Absolute path to the global `root.tsx` every page renders inside, when it exists. */\n appFile?: string;\n};\n\n/** The one application error boundary. It deliberately has no route identity. */\nexport type DiscoveredErrorPage = {\n type: \"error\";\n /** Absolute path to the sole `error.page.tsx` beneath `src/web`. */\n pageFile: string;\n webRoot: string;\n appFile?: string;\n};\n\n/** The complete static web graph: routable leaves plus the optional error boundary. */\nexport type DiscoveredPage = DiscoveredRoutablePage | DiscoveredErrorPage;\n\nexport function isDiscoveredRoutablePage(page: DiscoveredPage): page is DiscoveredRoutablePage {\n return page.type === \"page\";\n}\n\nexport function isErrorPageFile(file: string): boolean {\n return path.basename(file) === \"error.page.tsx\";\n}\n\nexport class DuplicateErrorPageError extends Error {\n public constructor(firstFile: string, secondFile: string) {\n super(\n `Two error pages were found: \"${firstFile}\" and \"${secondFile}\". An application may own exactly one \\`error.page.tsx\\` anywhere beneath src/web.`,\n );\n this.name = \"DuplicateErrorPageError\";\n }\n}\n\nexport class ErrorPageDeclaresRouteError extends Error {\n public constructor(pageFile: string) {\n super(\n `The error page \"${pageFile}\" exports \\`route\\`. error.page.tsx is an error boundary, not a browsable page; remove the route export.`,\n );\n this.name = \"ErrorPageDeclaresRouteError\";\n }\n}\n\n/** Raised when two pages claim one route name. */\nexport class DuplicatePageRouteNameError extends Error {\n public constructor(\n public readonly routeName: string,\n public readonly firstFile: string,\n public readonly secondFile: string,\n ) {\n super(\n `Two pages resolve to the same route name \"${routeName}\": \"${firstFile}\" and ` +\n `\"${secondFile}\". A route name identifies exactly one page, so the second ` +\n \"page would be unreachable. To fix: rename one of the files, or move it so \" +\n \"its directory gives it a different route name.\",\n );\n this.name = \"DuplicatePageRouteNameError\";\n }\n}\n\n/** Raised when two different page files resolve to one effective URL. */\nexport class DuplicatePageRoutePathError extends Error {\n public constructor(\n public readonly routePath: string,\n public readonly firstFile: string,\n public readonly secondFile: string,\n ) {\n super(\n `Two pages resolve to the same route path \"${routePath}\": \"${firstFile}\" and ` +\n `\"${secondFile}\". Each URL may identify exactly one page. Rename or move one file, ` +\n \"or give one page an explicit route with a different path.\",\n );\n this.name = \"DuplicatePageRoutePathError\";\n }\n}\n\nexport function toPosix(value: string): string {\n return value.replace(/\\\\/g, \"/\");\n}\n\nfunction isDirectory(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isDirectory();\n } catch {\n return false;\n }\n}\n\nexport function isFile(candidate: string): boolean {\n try {\n return fs.statSync(candidate).isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * The page root. It is optional; a project without it has zero pages, which is\n * a legal empty state.\n */\nexport function discoverWebRoots(srcRoot: string): string[] {\n const webRoot = path.join(srcRoot, \"web\");\n\n return isDirectory(webRoot) ? [webRoot] : [];\n}\n\nfunction byName(left: { name: string }, right: { name: string }): number {\n return left.name < right.name ? -1 : left.name > right.name ? 1 : 0;\n}\n\nexport type DiscoveredPageFile = {\n /** Absolute path to the `*.page.tsx` file. */\n pageFile: string;\n /** The web root ({@link discoverWebRoots}) this page was found under. */\n webRoot: string;\n};\n\n/**\n * The subject list: every `*.page.tsx` under the page root, one call for the\n * whole graph.\n *\n * Unlike {@link discoverPages}, this reads no `route` or `prefix` export and\n * throws on nothing — it answers only \"which page files exist\", so a provider\n * that still resolves a page's route by its own means (dev's\n * `ssrLoadModule`-driven installer, chiefly) can share the walk without\n * inheriting the static-parsing refusals that answering \"what route is this\"\n * requires.\n */\nexport function discoverPageFiles(srcRoot: string): DiscoveredPageFile[] {\n const found: DiscoveredPageFile[] = [];\n\n for (const webRoot of discoverWebRoots(srcRoot)) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n found.push({ pageFile, webRoot });\n }\n }\n\n return found;\n}\n\n/** Every file under `dir` (recursive) whose name matches `predicate`. */\nexport function walkFiles(dir: string, predicate: (fileName: string) => boolean): string[] {\n const found: string[] = [];\n\n for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort(byName)) {\n const full = path.join(dir, entry.name);\n\n if (entry.isDirectory()) {\n found.push(...walkFiles(full, predicate));\n } else if (entry.isFile() && predicate(entry.name)) {\n found.push(full);\n }\n }\n\n return found;\n}\n\n/**\n * A page's layout chain: every `layout.tsx` in the directories from its web\n * root down to its own directory, OUTERMOST FIRST.\n *\n * Dev's installer reads only the nearest layout today, because its page module\n * triple holds a single layout; the recipe carries the whole chain so the\n * runtime side can compose\n * nested layouts without a second discovery pass. The nearest layout is always\n * the LAST element, so a consumer that still wants dev's one-layout behaviour\n * reads `layouts.at(-1)`.\n */\nexport function layoutChainFor(pageFile: string, webRoot: string): string[] {\n const chain: string[] = [];\n const relativeDir = path.relative(webRoot, path.dirname(pageFile));\n const segments = relativeDir === \"\" ? [] : relativeDir.split(path.sep);\n\n let current = webRoot;\n\n for (let index = 0; index <= segments.length; index++) {\n if (index > 0) {\n current = path.join(current, segments[index - 1]);\n }\n\n const candidate = path.join(current, \"layout.tsx\");\n\n if (isFile(candidate)) {\n chain.push(candidate);\n }\n }\n\n return chain;\n}\n\nfunction compareStrings(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\n/**\n * The total order every consumer sees, and the reason discovery returns an\n * array rather than a set: the page's SOURCE FILE PATH, lexicographic, POSIX.\n *\n * Serialization order only; matching precedence is a property of the route\n * grammar, not of this array.\n *\n * The file path rather than the route path, now that the route is the declared\n * one: a page's route can be rewritten by editing one line, which would reorder\n * an artefact that has not otherwise changed, while the file it lives in is the\n * stable identity the artefact is built from. It also carries no suggestion of\n * precedence — nobody reads \"sorted by file name\" as \"most specific first\",\n * which is the misreading a route-path order invites.\n *\n * Lexicographic because it is byte-comparable output across every provider,\n * which keeps diffs stable and keeps filesystem enumeration order out of the\n * artefact: two machines that list a directory differently must still produce\n * byte-identical output, or a build is only reproducible by luck.\n */\nfunction comparePages(left: DiscoveredPage, right: DiscoveredPage): number {\n return compareStrings(toPosix(left.pageFile), toPosix(right.pageFile));\n}\n\nfunction assertUniqueRouteNames(pages: readonly DiscoveredRoutablePage[], appRoot: string): void {\n const fileByRouteName = new Map<string, string>();\n\n for (const page of pages) {\n const existing = fileByRouteName.get(page.routeName);\n const relative = toPosix(path.relative(appRoot, page.pageFile));\n\n if (existing !== undefined) {\n throw new DuplicatePageRouteNameError(page.routeName, existing, relative);\n }\n\n fileByRouteName.set(page.routeName, relative);\n }\n}\n\n/**\n * A page's declared `route.path` is a choice its author made deliberately, so\n * two pages that both declare the same path are the author's call, not an\n * accident — {@link assertUniqueRouteNames} is what keeps each of them\n * reachable by name. What this refuses is a COLLISION NOBODY CHOSE: at least\n * one side's path is filesystem-derived, which is exactly the case a rename\n * or a new file can produce without anyone noticing two pages now answer the\n * same URL. The reserved not-found path (`\"*\"`) is never a candidate here\n * either way — it identifies no browsable URL, and {@link assertUniqueRouteNames}\n * already refuses a second `404.page.tsx` by its own reserved name.\n */\nfunction assertUniqueRoutePaths(\n pages: readonly DiscoveredRoutablePage[],\n appRoot: string,\n explicitFiles: ReadonlySet<string>,\n): void {\n const fileByRoutePath = new Map<string, string>();\n\n for (const page of pages) {\n if (page.routePath === NOT_FOUND_ROUTE_PATH) continue;\n\n const existing = fileByRoutePath.get(page.routePath);\n const relative = toPosix(path.relative(appRoot, page.pageFile));\n\n if (existing !== undefined && !(explicitFiles.has(existing) && explicitFiles.has(relative))) {\n throw new DuplicatePageRoutePathError(page.routePath, existing, relative);\n }\n\n if (existing === undefined) fileByRoutePath.set(page.routePath, relative);\n }\n}\n\n/** One key a page's `metadata` declares that nothing reads, and where it is written. */\nexport type UnknownMetadataKey = {\n /** The object it was declared in: `metadata`, `metadata.openGraph`, `metadata.twitter`. */\n container: string;\n /** The key exactly as the page wrote it. */\n key: string;\n /** 1-based line in the page file, so the message points at the character that is wrong. */\n line: number;\n /** The known key it is within two edits of, when there is one. Usually the whole answer. */\n suggestion?: string;\n};\n\n/**\n * Raised when a page's `metadata` export declares a key nothing reads.\n *\n * THE POINT OF THIS ERROR IS THE UNANNOTATED CASE. A page that writes\n * `export const metadata: PageMetadata = { tittle: \"x\" }` is already refused by\n * TypeScript, and if that were the whole story this class would not need to\n * exist. But the annotation is optional, nobody writes it, and\n * `export const metadata = { tittle: \"x\" }` is a perfectly well-typed program:\n * the compiler infers `{ tittle: string }`, has nothing to check it against, and\n * says nothing. The page is then served with no `<title>` — not a wrong title, a\n * missing one — and no error is raised anywhere, at build or at runtime, ever.\n *\n * So the check lives HERE instead, at the gate every page already passes\n * through: a page that silently omits requested metadata is worse than a build\n * that stops and says which line to fix.\n *\n * The alternative considered and rejected was a `defineMetadata({...})` wrapper,\n * which would infer the type for free. It also puts framework ceremony in every\n * page, and a page is meant to be two lines of framework surface (canon\n * `6ea0662f`). The gate gets the same safety without spending that.\n */\nexport class UnknownMetadataKeyError extends Error {\n public constructor(\n public readonly pageFile: string,\n public readonly unknownKeys: readonly UnknownMetadataKey[],\n ) {\n const findings = unknownKeys\n .map(({ container, key, line, suggestion }) => {\n const where = `line ${line}: \\`${container}.${key}\\` — no such key.`;\n\n return suggestion === undefined ? where : `${where} Did you mean \\`${suggestion}\\`?`;\n })\n .join(\"\\n \");\n\n super(\n `The \\`metadata\\` export of \"${pageFile}\" declares a key nothing reads:\\n ${findings}\\n` +\n \"Nothing writes an unknown key to `<head>`, so the tag it was meant to produce would \" +\n \"simply be absent from every response, with no error at build time or at runtime. The \" +\n \"build refuses it here instead.\\n\" +\n ` Known keys: ${METADATA_KEYS.join(\", \")}.\\n` +\n ` Inside \\`openGraph\\`: ${OPEN_GRAPH_KEYS.join(\", \")}.\\n` +\n ` Inside \\`twitter\\`: ${TWITTER_KEYS.join(\", \")}.\\n` +\n \"Annotating the export — `export const metadata: PageMetadata = { … }` — gets you the \" +\n \"same list as autocomplete in the editor, before the build runs.\",\n );\n this.name = \"UnknownMetadataKeyError\";\n }\n}\n\n/**\n * The AST types, derived from `parse`'s own return type rather than imported\n * from `@babel/types`, for the reason `read-route-exports.ts` gives: the parser\n * resolves its own copy of that package and nodes from one copy are not\n * assignable to the identical types from the other.\n */\ntype PageStatement = ReturnType<typeof parse>[\"program\"][\"body\"][number];\ntype PageExpression = Extract<PageStatement, { type: \"ExpressionStatement\" }>[\"expression\"];\ntype PageObjectExpression = Extract<PageExpression, { type: \"ObjectExpression\" }>;\ntype PageObjectProperty = Extract<\n PageObjectExpression[\"properties\"][number],\n { type: \"ObjectProperty\" }\n>;\ntype PageValueNode = PageObjectProperty[\"value\"];\n\n/** `as const`, `satisfies`, `!` and parentheses wrap a value without changing it. */\nfunction unwrapValue(node: PageValueNode): PageValueNode {\n switch (node.type) {\n case \"TSAsExpression\":\n case \"TSSatisfiesExpression\":\n case \"TSNonNullExpression\":\n case \"TypeCastExpression\":\n case \"ParenthesizedExpression\":\n return unwrapValue(node.expression);\n default:\n return node;\n }\n}\n\n/** Levenshtein distance — small strings, so the plain two-row table is the whole cost. */\nfunction editDistance(left: string, right: string): number {\n let previous = Array.from({ length: right.length + 1 }, (_, index) => index);\n\n for (let row = 1; row <= left.length; row++) {\n const current = [row];\n\n for (let column = 1; column <= right.length; column++) {\n const substitution = previous[column - 1] + (left[row - 1] === right[column - 1] ? 0 : 1);\n current[column] = Math.min(substitution, previous[column] + 1, current[column - 1] + 1);\n }\n\n previous = current;\n }\n\n return previous[right.length];\n}\n\n/**\n * The known key the written one was probably meant to be.\n *\n * Two edits, because that covers the typos this exists for — `tittle`,\n * `descriptoin`, `keywrods` — without reaching so far that `image` gets\n * suggested for `alt`. Case is ignored first, so `Title` resolves exactly.\n */\nfunction suggestKey(written: string, known: readonly string[]): string | undefined {\n const lowered = written.toLowerCase();\n const sameLetters = known.find((candidate) => candidate.toLowerCase() === lowered);\n\n if (sameLetters !== undefined) return sameLetters;\n\n let best: string | undefined;\n let bestDistance = Number.POSITIVE_INFINITY;\n\n for (const candidate of known) {\n const distance = editDistance(lowered, candidate.toLowerCase());\n\n if (distance < bestDistance) {\n best = candidate;\n bestDistance = distance;\n }\n }\n\n return bestDistance <= 2 ? best : undefined;\n}\n\n/** The name an object key denotes, or `undefined` when knowing it needs evaluation. */\nfunction propertyKeyName(property: PageObjectProperty): string | undefined {\n if (property.computed) return undefined;\n\n const { key } = property;\n\n if (key.type === \"Identifier\") return key.name;\n if (key.type === \"StringLiteral\") return key.value;\n\n return undefined;\n}\n\n/** The nested objects that carry a key set of their own. */\nconst NESTED_METADATA_KEYS: Record<string, readonly string[]> = {\n openGraph: OPEN_GRAPH_KEYS,\n twitter: TWITTER_KEYS,\n};\n\n/**\n * Every unknown key in one metadata object literal, and in the `openGraph` /\n * `twitter` literals inside it.\n *\n * A SPREAD does not suppress the check, unlike the route reader's rule: a\n * spread can only ADD keys, and no value it contributes can make a key written\n * out beside it correct. A COMPUTED key is skipped — its name is not knowable\n * without running the page, and refusing what cannot be read would fail builds\n * that are fine. Both are silence in the narrow places where the parse genuinely\n * does not know, and the annotation is the second net there.\n */\nfunction collectUnknownKeys(\n object: PageObjectExpression,\n allowed: readonly string[],\n container: string,\n into: UnknownMetadataKey[],\n): void {\n for (const property of object.properties) {\n if (property.type === \"SpreadElement\") continue;\n\n const key = propertyKeyName(property as PageObjectProperty);\n\n if (key === undefined) continue;\n\n if (!allowed.includes(key)) {\n const suggestion = suggestKey(key, allowed);\n\n into.push({\n container,\n key,\n line: property.loc?.start.line ?? 0,\n ...(suggestion === undefined ? {} : { suggestion }),\n });\n\n continue;\n }\n\n const nested = container === \"metadata\" ? NESTED_METADATA_KEYS[key] : undefined;\n\n if (nested === undefined || property.type !== \"ObjectProperty\") continue;\n\n const value = unwrapValue(property.value);\n\n if (value.type === \"ObjectExpression\") {\n collectUnknownKeys(value, nested, `${container}.${key}`, into);\n }\n }\n}\n\n/**\n * Every object literal a function form RETURNS, without descending into\n * functions nested inside it — a callback's return value is not the metadata.\n *\n * A generic walk rather than a statement-by-statement one because a `return` is\n * legal anywhere a statement is: inside an `if`, a `switch`, a `try`. Enumerating\n * the statement types that may contain one is a list that is wrong the moment\n * the language grows.\n */\nfunction collectReturnedObjects(node: unknown, into: PageObjectExpression[]): void {\n if (node === null || typeof node !== \"object\") return;\n\n if (Array.isArray(node)) {\n for (const item of node) collectReturnedObjects(item, into);\n\n return;\n }\n\n const candidate = node as { type?: string; argument?: unknown };\n\n if (\n candidate.type === \"FunctionDeclaration\" ||\n candidate.type === \"FunctionExpression\" ||\n candidate.type === \"ArrowFunctionExpression\" ||\n candidate.type === \"ObjectMethod\" ||\n candidate.type === \"ClassMethod\"\n ) {\n return;\n }\n\n if (candidate.type === \"ReturnStatement\") {\n if (candidate.argument === null || candidate.argument === undefined) return;\n\n const returned = unwrapValue(candidate.argument as PageValueNode);\n\n if (returned.type === \"ObjectExpression\") into.push(returned);\n\n // Not descending into the returned value: a `return` inside it belongs to a\n // function this walk is deliberately not entering.\n return;\n }\n\n for (const value of Object.values(node as Record<string, unknown>)) {\n collectReturnedObjects(value, into);\n }\n}\n\n/** The metadata object literals one `metadata` export declares, if any can be seen at all. */\nfunction metadataObjectsOf(init: PageValueNode): PageObjectExpression[] {\n const value = unwrapValue(init);\n\n if (value.type === \"ObjectExpression\") return [value];\n\n if (value.type === \"ArrowFunctionExpression\" || value.type === \"FunctionExpression\") {\n const body = unwrapValue(value.body as PageValueNode);\n\n // The concise arrow body — `({ data }) => ({ title: data.name })`, which is\n // how every function-form metadata export in the reference app is written.\n if (body.type === \"ObjectExpression\") return [body];\n\n const returned: PageObjectExpression[] = [];\n\n collectReturnedObjects(value.body, returned);\n\n return returned;\n }\n\n // `export const metadata = buildMetadata()`, or a bare identifier: the keys\n // are not in this file. Silent by design — see `collectUnknownKeys`.\n return [];\n}\n\n/**\n * The unknown keys a page's `metadata` export declares, read by PARSING — the\n * same rule the rest of this module lives by, and the reason this check can run\n * before anything is built.\n *\n * Empty for a page with no `metadata` export, for one whose metadata is a value\n * this file cannot see into, and for a correct one.\n */\nexport function readMetadataKeys(pageFile: string, source: string): UnknownMetadataKey[] {\n let program: ReturnType<typeof parse>[\"program\"];\n\n try {\n program = parse(source, {\n sourceType: \"module\",\n plugins: [\"typescript\", \"jsx\"],\n errorRecovery: false,\n }).program;\n } catch (error) {\n throw new Error(\n `Cannot read the \\`metadata\\` export of \"${pageFile}\": the file could not be parsed ` +\n `(${(error as Error).message}). Fix the syntax error and the build will continue.`,\n );\n }\n\n const unknownKeys: UnknownMetadataKey[] = [];\n\n for (const statement of program.body) {\n if (statement.type !== \"ExportNamedDeclaration\" || statement.exportKind === \"type\") continue;\n\n const { declaration } = statement;\n\n if (declaration?.type !== \"VariableDeclaration\") continue;\n\n for (const declarator of declaration.declarations) {\n if (declarator.id.type !== \"Identifier\" || declarator.id.name !== \"metadata\") continue;\n if (declarator.init === null || declarator.init === undefined) continue;\n\n for (const object of metadataObjectsOf(declarator.init)) {\n collectUnknownKeys(object, METADATA_KEYS, \"metadata\", unknownKeys);\n }\n }\n }\n\n return unknownKeys;\n}\n\n/**\n * The declared exports of one file, or a thrown\n * {@link NonLiteralRouteExportError} when they cannot be read without running\n * the application. Layouts are read once per run and remembered: a layout is\n * the nearest one for every page beside it, and parsing it once per page would\n * be the same answer bought repeatedly.\n *\n * `source` is the file's text when the caller already holds it — the page loop\n * reads each page once and spends that read on both the route declarations and\n * the metadata check, rather than opening the same file twice.\n */\nfunction readDeclarations(\n sourceFile: string,\n cache: Map<string, RouteExportsReadResult>,\n source?: string,\n) {\n let result = cache.get(sourceFile);\n\n if (result === undefined) {\n result = readRouteExports(sourceFile, source);\n cache.set(sourceFile, result);\n }\n\n if (!result.ok) {\n throw new NonLiteralRouteExportError(result.rejection);\n }\n\n return result;\n}\n\n/**\n * What a layout DOES, read by parsing it — the facts the layout policy's rule\n * needs and, being a pure module, cannot go and find for itself.\n */\ntype LayoutShape = {\n /**\n * Whether the module has a default export — the export that puts an element\n * in the document, and therefore the one thing that makes a layout count\n * against the single-rendering-layout rule.\n */\n renders: boolean;\n /** Whether the module exports `middleware`, or might via a re-export this cannot see through. */\n hasMiddleware: boolean;\n};\n\n/**\n * Parses one layout and reports its shape. Remembered per run for the same\n * reason declarations are: a layout is on the path of every page beneath it.\n */\nfunction readLayoutShape(layoutFile: string, cache: Map<string, LayoutShape>): LayoutShape {\n const cached = cache.get(layoutFile);\n\n if (cached !== undefined) return cached;\n\n const source = fs.readFileSync(layoutFile, \"utf-8\");\n let program: ReturnType<typeof parse>[\"program\"];\n\n try {\n program = parse(source, {\n sourceType: \"module\",\n // Every file this reads is a layout, i.e. `.tsx`.\n plugins: [\"typescript\", \"jsx\"],\n errorRecovery: false,\n }).program;\n } catch (error) {\n throw new Error(\n `Cannot read the exports of \"${layoutFile}\": the file could not be parsed ` +\n `(${(error as Error).message}). Fix the syntax error and the build will continue.`,\n );\n }\n\n const shape: LayoutShape = { renders: false, hasMiddleware: false };\n\n for (const statement of program.body) {\n if (statement.type === \"ExportDefaultDeclaration\") {\n shape.renders = true;\n continue;\n }\n\n // `export * from \"./guard\"` cannot re-export a default — the language\n // excludes it — but it CAN contribute `middleware`, and no parse can see\n // through it without resolving and reading another module. Reading it as\n // \"no middleware here\" is exactly the silent unguarding this slice exists\n // to prevent, so it is read as \"possibly\" and fails loudly downstream.\n if (statement.type === \"ExportAllDeclaration\") {\n shape.hasMiddleware = true;\n continue;\n }\n\n if (statement.type !== \"ExportNamedDeclaration\" || statement.exportKind === \"type\") continue;\n\n for (const specifier of statement.specifiers) {\n if (specifier.type !== \"ExportSpecifier\" || specifier.exportKind === \"type\") continue;\n\n const exported =\n specifier.exported.type === \"Identifier\"\n ? specifier.exported.name\n : specifier.exported.value;\n\n if (exported === \"default\") shape.renders = true;\n if (exported === \"middleware\") shape.hasMiddleware = true;\n }\n\n const { declaration } = statement;\n\n if (declaration === null || declaration === undefined) continue;\n\n if (declaration.type === \"VariableDeclaration\") {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === \"Identifier\" && declarator.id.name === \"middleware\") {\n shape.hasMiddleware = true;\n }\n }\n\n continue;\n }\n\n if (\n (declaration.type === \"FunctionDeclaration\" || declaration.type === \"ClassDeclaration\") &&\n declaration.id?.name === \"middleware\"\n ) {\n shape.hasMiddleware = true;\n }\n }\n\n cache.set(layoutFile, shape);\n\n return shape;\n}\n\n/**\n * Scans the page root and returns the pages in a defined total order.\n *\n * Zero pages is a legal result, not an error: a project may be configured\n * with web and have nothing to serve yet. What is an error is a `*.page.tsx`\n * with a route or metadata export that cannot be read statically; two pages\n * claiming one effective path or route name, which this refuses\n * to return at all — the alternative is an artefact in which one of them is\n * silently unreachable; a `route` or `prefix` that cannot be read without\n * running the application, which is refused before any page is reported at\n * all; a `metadata` export declaring a key nothing reads, which no compiler\n * catches unless the page opted into the type and which otherwise serves a page\n * with a silently missing tag; and a page whose layout chain holds more than one RENDERING layout, which\n * the production installer would refuse anyway — discovery refuses it first so\n * that artefact is never produced.\n */\nexport function discoverPages(options: DiscoverPagesOptions): DiscoveredPage[] {\n const { appRoot } = options;\n const srcRoot = path.join(appRoot, options.srcDir ?? \"src\");\n const webRoots = discoverWebRoots(srcRoot);\n const appFile = path.join(srcRoot, \"web\", \"root.tsx\");\n const hasAppFile = isFile(appFile);\n const declarations = new Map<string, RouteExportsReadResult>();\n const layoutShapes = new Map<string, LayoutShape>();\n const relativeToApp = (file: string) => toPosix(path.relative(appRoot, file));\n\n const pages: DiscoveredPage[] = [];\n const explicitRouteFiles = new Set<string>();\n let errorPage: DiscoveredErrorPage | undefined;\n\n for (const webRoot of webRoots) {\n for (const pageFile of walkFiles(webRoot, (fileName) => fileName.endsWith(\".page.tsx\"))) {\n const pageSource = fs.readFileSync(pageFile, \"utf-8\");\n assertPageHasDefaultExport(relativeToApp(pageFile), pageSource);\n const { route } = readDeclarations(pageFile, declarations, pageSource);\n if (isErrorPageFile(pageFile)) {\n if (route !== undefined) throw new ErrorPageDeclaresRouteError(relativeToApp(pageFile));\n\n if (errorPage !== undefined) {\n throw new DuplicateErrorPageError(relativeToApp(errorPage.pageFile), relativeToApp(pageFile));\n }\n\n errorPage = { type: \"error\", pageFile, webRoot, ...(hasAppFile ? { appFile } : {}) };\n continue;\n }\n const isNotFoundPage = isNotFoundPageFile(pageFile);\n\n // THE NOT-FOUND PAGE IS THE ONE PAGE WITH NO URL, in both directions.\n //\n // Every ordinary page may derive its URL from the filesystem.\n // `404.page.tsx` is reached by NOT matching, so the opposite remains the\n // error: a `route` export here reads as a promise that some path is\n // browsable, which the installers never keep.\n //\n // Discovery still reports it, with the SAME reserved identity both\n // installers register it under, so the emitted artefacts agree with the\n // server about which entry is the not-found page — and so the client\n // registry carries the module the SSR'd document has to hydrate against.\n if (isNotFoundPage && route !== undefined) {\n throw new NotFoundPageDeclaresRouteError(relativeToApp(pageFile));\n }\n\n // The page contract is not only `route`. `metadata` is the other export\n // every page may declare, and it is the one with no compiler behind it\n // unless the author opted in to a type annotation — so it is checked\n // here, by name, exactly like the route above.\n //\n // AFTER the reserved-404 route check on purpose: an impossible 404 route\n // contract is more fundamental than a malformed `<head>` declaration.\n const unknownMetadataKeys = readMetadataKeys(relativeToApp(pageFile), pageSource);\n\n if (unknownMetadataKeys.length > 0) {\n throw new UnknownMetadataKeyError(relativeToApp(pageFile), unknownMetadataKeys);\n }\n\n // The policy decides which layout the page RENDERS INSIDE, from the FULL\n // enumerated chain: a layout anywhere on the ancestry path counts, not\n // just one in the page's own directory. Discovery supplies the one fact\n // the rule needs and the pure policy cannot learn — whether each layout\n // renders anything at all.\n const layouts = layoutChainFor(pageFile, webRoot);\n const shapes = layouts.map((layoutFile) => readLayoutShape(layoutFile, layoutShapes));\n const selection = selectPageLayout(\n layouts.map((layout, index) => ({ layout, renders: shapes[index].renders })),\n );\n\n if (selection.type === \"rejected\") {\n throw new NestedLayoutsNotSupportedError(\n relativeToApp(pageFile),\n selection.layouts.map(relativeToApp),\n );\n }\n\n // Every layout that declares a guard, outermost first. Both installers\n // now CONCATENATE the whole chain into the pipeline's single layout slot\n // (`../server/install-page-routes.ts`, `../server/install-page-routes-from-manifest.ts`),\n // so a guard anywhere on the path runs, in this order — which is why the\n // temporary refusal that used to stand here is gone rather than relaxed.\n const middlewareLayouts = layouts.filter((_, index) => shapes[index].hasMiddleware);\n\n // EVERY prefix on the path, outermost first: a `prefix`-only layout is\n // still a segment of the URL, and composing only the rendering layout's\n // would serve the subtree from a path nobody declared.\n const layoutPrefix = layouts.reduce(\n (composed, layoutFile) =>\n composeRoutePath(composed, readDeclarations(layoutFile, declarations).prefix ?? \"/\"),\n \"/\",\n );\n\n const relativePageFile = toPosix(path.relative(webRoot, pageFile));\n const layoutPrefixes = Object.fromEntries(\n layouts.flatMap((layoutFile) => {\n const prefix = readDeclarations(layoutFile, declarations).prefix;\n if (prefix === undefined) return [];\n\n const directory = toPosix(path.relative(webRoot, path.dirname(layoutFile)));\n return [[directory, prefix]];\n }),\n );\n const effectiveRoutePath = isNotFoundPage\n ? NOT_FOUND_ROUTE_PATH\n : route\n ? composeRoutePath(layoutPrefix, route.path)\n : deriveFilesystemRoutePath({ pageFile: relativePageFile, layoutPrefixes });\n\n if (!isNotFoundPage && route !== undefined) {\n explicitRouteFiles.add(relativeToApp(pageFile));\n }\n\n pages.push({\n type: \"page\",\n routeName: isNotFoundPage\n ? NOT_FOUND_ROUTE_NAME\n : (route?.name ??\n (route\n ? deriveFallbackRouteName({\n routePath: route.path,\n sourceFile: relativeToApp(pageFile),\n })\n : deriveFilesystemRouteName(relativePageFile))),\n // The catch-all, which the client route matcher already understands as\n // a terminal `catch-all` token sorted LAST by specificity\n // (`../client/runtime/matcher.ts`) — so the browser resolves the\n // not-found page for a URL that matched nothing, exactly as the server\n // did, and never in preference to a real page.\n routePath: effectiveRoutePath,\n pageFile,\n webRoot,\n // THE NOT-FOUND PAGE RENDERS INSIDE THE APPLICATION ROOT AND NOTHING\n // ELSE — an EMPTY chain, not the one enumerated above.\n //\n // Both installers render it with `layoutFile: undefined`, deliberately\n // and independently (`../server/install-page-routes.ts`,\n // `../server/install-page-routes-from-manifest.ts`), for the same\n // reason the 404 page takes no loader: a path whose entire job is to\n // handle failure must not depend on chrome that can itself throw,\n // redirect, or need data. Reporting layouts here anyway put them in the\n // client registry and therefore in HYDRATION, so the server rendered\n // `App(Page)` while the browser rebuilt `App(Layout(Page))` — a\n // guaranteed mismatch on the one route nobody is watching, invisible to\n // any application that happens to have no layouts.\n //\n // Aligned by REMOVING them from the client, never by giving them to the\n // server: layouts on the not-found route would make it the most fragile\n // route in the application.\n //\n // The chain above is still enumerated and still validated, so a nested\n // layout on this page's path is refused at build time exactly as it is\n // everywhere else — what changes is only what the page renders inside.\n layouts: isNotFoundPage ? [] : layouts,\n middlewareLayouts: isNotFoundPage ? [] : middlewareLayouts,\n ...(hasAppFile ? { appFile } : {}),\n });\n }\n }\n\n // The error page is captured separately above so a second one can be\n // compared against the first before either is trusted — it joins the\n // returned graph here, once discovery knows there is exactly one.\n if (errorPage !== undefined) pages.push(errorPage);\n\n pages.sort(comparePages);\n\n const routablePages = pages.filter(isDiscoveredRoutablePage);\n assertUniqueRoutePaths(routablePages, appRoot, explicitRouteFiles);\n assertUniqueRouteNames(routablePages, appRoot);\n\n return pages;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIA,SAAgB,yBAAyB,MAAsD;CAC7F,OAAO,KAAK,SAAS;AACvB;AAEA,SAAgB,gBA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,wBAAwB;IACtB,WAAW,MAAM;IACjB,YAAY,cAAc,QAAQ;GACpC,CAAC,IACD,0BAA0B,gBAAgB;GAMpD,WAAW;GACX;GACA;GAsBA,SAAS,iBAAiB,CAAC,IAAI;GAC/B,mBAAmB,iBAAiB,CAAC,IAAI;GACzC,GAAI,aAAa,EAAE,QAAQ,IAAI,CAAC;EAClC,CAAC;CACH;CAMF,IAAI,cAAc,QAAW,MAAM,KAAK,SAAS;CAEjD,MAAM,KAAK,YAAY;CAEvB,MAAM,gBAAgB,MAAM,OAAO,wBAAwB;CAC3D,uBAAuB,eAAe,SAAS,kBAAkB;CACjE,uBAAuB,eAAe,OAAO;CAE7C,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { isDiscoveredRoutablePage } from "./discover-pages.mjs";
2
2
 
3
- //#region web/src/build/generate-client-registry.ts
3
+ //#region ../web/src/build/generate-client-registry.ts
4
4
  /**
5
5
  * The CLIENT half of the build→runtime handoff: the source of a generated
6
6
  * module that carries the page graph into the BROWSER.
@@ -1 +1 @@
1
- {"version":3,"file":"generate-client-registry.mjs","names":[],"sources":["C:/Work/Warlock.js/web/src/build/generate-client-registry.ts"],"sourcesContent":["/**\r\n * The CLIENT half of the build→runtime handoff: the source of a generated\r\n * module that carries the page graph into the BROWSER.\r\n *\r\n * `generate-pages-barrel.ts` is the server half. The two are deliberately not\r\n * one function, because they want opposite things from the same recipe: the\r\n * server barrel emits STATIC `import * as` so every page lands in the one\r\n * server bundle and its route can be read off the module at boot, while the\r\n * browser must never download page B to render page A — so every module\r\n * reference here is a dynamic `import()`, and `name`/`path` are baked in as\r\n * DATA so the client runtime can match a route before loading anything.\r\n *\r\n * This function is PURE. It reads no filesystem, writes no file, and does not\r\n * call {@link discoverPages} — the caller passes the already-discovered graph\r\n * in. That is what keeps the \"one discovery run, one graph\" invariant: names\r\n * and paths agree with the server's because there is only ever one scan, not\r\n * because two scanners were written to match.\r\n *\r\n * Module RESOLUTION is the one thing that legitimately differs between the dev\r\n * provider and the production provider, so it is injected as\r\n * {@link GenerateClientRegistryOptions.toImportSpecifier} rather than computed\r\n * here. No provider-specific data — no Vite ids, no `/@fs/` prefixes, no\r\n * hashed chunk urls, no HMR metadata — reaches the emitted entry, and every\r\n * other property stays testable with a trivial mapper.\r\n */\r\nimport {\r\n isDiscoveredRoutablePage,\r\n type DiscoveredPage,\r\n type DiscoveredRoutablePage,\r\n} from \"./discover-pages\";\r\n\r\nexport type GenerateClientRegistryOptions = {\r\n /**\r\n * The discovered page graph, IN THE ORDER DISCOVERY GAVE IT.\r\n *\r\n * `discoverPages` already sorts by POSIX source-file path\r\n * (`discover-pages.ts:368`, comparator at `discover-pages.ts:248-250`), so\r\n * this emitter preserves that order rather than imposing a second one: two\r\n * orderings of one graph is exactly the drift the shared scan exists to\r\n * prevent. Serialization stability only — nothing emitted here implies\r\n * matching precedence, which is a property of the route grammar.\r\n */\r\n pages: readonly DiscoveredPage[];\r\n /** Maps an absolute source file path to the specifier the emitted module will import. */\r\n toImportSpecifier: (absoluteFilePath: string) => string;\r\n};\r\n\r\n/** The name of the array the generated module exports. */\r\nexport const CLIENT_REGISTRY_EXPORT_NAME = \"pages\";\r\n\r\n/** The specifier the generated module imports its entry type from. */\r\nconst CLIENT_RUNTIME_SPECIFIER = \"@warlock.js/web/client/runtime\";\r\n\r\n/**\r\n * Raised when two pages claim one route name.\r\n *\r\n * `discoverPages` promises uniqueness already (`discover-pages.ts:370`). This\r\n * asserts it anyway: the alternative is trusting an upstream promise and\r\n * emitting a registry in which one page is silently unreachable, which costs\r\n * far more to diagnose than the check costs to run.\r\n */\r\nexport class DuplicateClientPageNameError extends Error {\r\n public constructor(\r\n public readonly routeName: string,\r\n public readonly firstPageFile: string,\r\n public readonly secondPageFile: string,\r\n ) {\r\n super(\r\n `Two pages claim the client route name \"${routeName}\": \"${firstPageFile}\" and ` +\r\n `\"${secondPageFile}\". A route name identifies exactly one page, so the second ` +\r\n \"page would be unreachable in the browser. To fix: rename one page's `route` \" +\r\n \"export, or move the file so its directory gives it a different route name.\",\r\n );\r\n this.name = \"DuplicateClientPageNameError\";\r\n }\r\n}\r\n\r\n/**\r\n * Every literal the generator emits goes through here, without exception.\r\n * Windows separators, quotes and backslashes are all in scope, and a\r\n * hand-quoted literal that gets one of them wrong fails at bundle time with a\r\n * parse error no user can act on.\r\n */\r\nfunction quote(value: string): string {\r\n return JSON.stringify(value);\r\n}\r\n\r\nconst HEADER = [\r\n \"// AUTO-GENERATED by @warlock.js/web — do not edit.\",\r\n \"// The page graph, compiled into the CLIENT bundle.\",\r\n \"//\",\r\n \"// `name` and `path` are baked in as data so the client runtime can match a\",\r\n \"// route before loading anything; every module reference is a dynamic\",\r\n \"// `import()` so a page's code is downloaded only when that page is rendered.\",\r\n `import type { ClientPageEntry } from ${quote(CLIENT_RUNTIME_SPECIFIER)};`,\r\n];\r\n\r\nfunction assertUniqueNames(pages: readonly DiscoveredRoutablePage[]): void {\r\n const pageFileByName = new Map<string, string>();\r\n\r\n for (const page of pages) {\r\n const existing = pageFileByName.get(page.routeName);\r\n\r\n if (existing !== undefined) {\r\n throw new DuplicateClientPageNameError(page.routeName, existing, page.pageFile);\r\n }\r\n\r\n pageFileByName.set(page.routeName, page.pageFile);\r\n }\r\n}\r\n\r\n/**\r\n * One entry's `load`.\r\n *\r\n * It memoises NOTHING and holds no one-shot state: the runtime calls it again\r\n * on re-navigation to the same route, and a loader that works once and returns\r\n * undefined the second time is a silent blank page. Dynamic `import()` is\r\n * already module-cached by the bundler, so the correct implementation is to\r\n * let the cache do the caching.\r\n */\r\nfunction loadSource(\r\n page: DiscoveredRoutablePage,\r\n errorPageFile: string | undefined,\r\n toImportSpecifier: (file: string) => string,\r\n): string[] {\r\n // These bindings deliberately retain the REAL module namespace objects\r\n // returned by import(). The client lifecycle registers exports on those\r\n // namespaces before the tree builder extracts their default components.\r\n const bindings = [\"PageModule\"];\r\n const specifiers = [toImportSpecifier(page.pageFile)];\r\n\r\n // Outermost first, exactly as discovery enumerated the chain — the order IS\r\n // the nesting, so reordering it would silently reparent the page.\r\n //\r\n // Emitted VERBATIM, including the empty chain discovery reports for the\r\n // not-found page (`./discover-pages.ts`), which is what keeps hydration\r\n // rendering the same `App(Page)` the installers SSR'd. The not-found case is\r\n // NOT re-detected here: a second rule about which page gets layouts is a\r\n // second convention waiting to disagree with the server's, which is the same\r\n // reason `routePath` below is not re-composed either.\r\n const layoutBindings = page.layouts.map((layoutFile, index) => {\r\n bindings.push(`layoutModule${index}`);\r\n specifiers.push(toImportSpecifier(layoutFile));\r\n\r\n return `layoutModule${index}`;\r\n });\r\n\r\n if (page.appFile !== undefined) {\r\n bindings.push(\"AppModule\");\r\n specifiers.push(toImportSpecifier(page.appFile));\r\n }\r\n\r\n if (errorPageFile !== undefined) {\r\n bindings.push(\"ErrorPageModule\");\r\n specifiers.push(toImportSpecifier(errorPageFile));\r\n }\r\n\r\n // `App` is OMITTED, never emitted as `App: undefined`: the runtime validator\r\n // reads an own `App` key as a promise that a module namespace is behind it.\r\n const app = page.appFile === undefined ? \"\" : \", App: AppModule\";\r\n const errorPage = errorPageFile === undefined ? \"\" : \", ErrorPage: ErrorPageModule\";\r\n\r\n return [\r\n \" load: async () => {\",\r\n ` const [${bindings.join(\", \")}] = await Promise.all([`,\r\n ...specifiers.map((specifier) => ` import(${quote(specifier)}),`),\r\n \" ]);\",\r\n \"\",\r\n ` return { Page: PageModule, layouts: [${layoutBindings.join(\", \")}]${app}${errorPage} };`,\r\n \" },\",\r\n ];\r\n}\r\n\r\nfunction entrySource(\r\n page: DiscoveredRoutablePage,\r\n errorPageFile: string | undefined,\r\n toImportSpecifier: (file: string) => string,\r\n): string[] {\r\n return [\r\n \" {\",\r\n ' type: \"page\",',\r\n // Verbatim from discovery, both of them. `routePath` in particular is NOT\r\n // re-derived or re-normalised here: discovery already composed the layout\r\n // prefix with the declared route, and a second composition is a second\r\n // convention waiting to disagree with the server's.\r\n ` name: ${quote(page.routeName)},`,\r\n ` path: ${quote(page.routePath)},`,\r\n ...loadSource(page, errorPageFile, toImportSpecifier),\r\n \" },\",\r\n ];\r\n}\r\n\r\n/**\r\n * Returns the SOURCE of the client page registry module. Writes nothing.\r\n *\r\n * Zero pages is a legal result, not an error, and it is emitted as an explicit\r\n * empty registry: \"built with web, no pages\" must reach the runtime as a fact\r\n * rather than as a missing module.\r\n */\r\nexport function generateClientRegistry(options: GenerateClientRegistryOptions): string {\r\n const { pages, toImportSpecifier } = options;\r\n const routablePages = pages.filter(isDiscoveredRoutablePage);\r\n const errorPageFile = pages.find((page) => page.type === \"error\")?.pageFile;\r\n\r\n assertUniqueNames(routablePages);\r\n\r\n const declaration = `export const ${CLIENT_REGISTRY_EXPORT_NAME}: readonly ClientPageEntry[] =`;\r\n\r\n if (routablePages.length === 0) {\r\n return [...HEADER, \"\", `${declaration} [];`, \"\"].join(\"\\n\");\r\n }\r\n\r\n return [\r\n ...HEADER,\r\n \"\",\r\n `${declaration} [`,\r\n ...routablePages.flatMap((page) => entrySource(page, errorPageFile, toImportSpecifier)),\r\n \"];\",\r\n \"\",\r\n ].join(\"\\n\");\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,8BAA8B;;AAG3C,MAAM,2BAA2B;;;;;;;;;AAUjC,IAAa,+BAAb,cAAkD,MAAM;CAEpC;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,WAChB,AAAgB,eAChB,AAAgB,gBAChB;EACA,MACE,0CAA0C,UAAU,MAAM,cAAc,SAClE,eAAe,oNAGvB;EATgB;EACA;EACA;EAQhB,KAAK,OAAO;CACd;AACF;;;;;;;AAQA,SAAS,MAAM,OAAuB;CACpC,OAAO,KAAK,UAAU,KAAK;AAC7B;AAEA,MAAM,SAAS;CACb;CACA;CACA;CACA;CACA;CACA;CACA,wCAAwC,MAAM,wBAAwB,EAAE;AAC1E;AAEA,SAAS,kBAAkB,OAAgD;CACzE,MAAM,iCAAiB,IAAI,IAAoB;CAE/C,KAAK,MA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AO,wBAAwB;CAC3D,MAAM,gBAAgB,MAAM,MAAM,SAAS,KAAK,SAAS,OAAO,GAAG;CAEnE,kBAAkB,aAAa;CAE/B,MAAM,cAAc,gBAAgB,4BAA4B;CAEhE,IAAI,cAAc,WAAW,GAC3B,OAAO;EAAC,GAAG;EAAQ;EAAI,GAAG,YAAY;EAAO;CAAE,EAAE,KAAK,IAAI;CAG5D,OAAO;EACL,GAAG;EACH;EACA,GAAG,YAAY;EACf,GAAG,cAAc,SAAS,SAAS,YAAY,MAAM,eAAe,iBAAiB,CAAC;EACtF;EACA;CACF,EAAE,KAAK,IAAI;AACb"}
1
+ {"version":3,"file":"generate-client-registry.mjs","names":[],"sources":["../../../../../../../web/src/build/generate-client-registry.ts"],"sourcesContent":["/**\r\n * The CLIENT half of the build→runtime handoff: the source of a generated\r\n * module that carries the page graph into the BROWSER.\r\n *\r\n * `generate-pages-barrel.ts` is the server half. The two are deliberately not\r\n * one function, because they want opposite things from the same recipe: the\r\n * server barrel emits STATIC `import * as` so every page lands in the one\r\n * server bundle and its route can be read off the module at boot, while the\r\n * browser must never download page B to render page A — so every module\r\n * reference here is a dynamic `import()`, and `name`/`path` are baked in as\r\n * DATA so the client runtime can match a route before loading anything.\r\n *\r\n * This function is PURE. It reads no filesystem, writes no file, and does not\r\n * call {@link discoverPages} — the caller passes the already-discovered graph\r\n * in. That is what keeps the \"one discovery run, one graph\" invariant: names\r\n * and paths agree with the server's because there is only ever one scan, not\r\n * because two scanners were written to match.\r\n *\r\n * Module RESOLUTION is the one thing that legitimately differs between the dev\r\n * provider and the production provider, so it is injected as\r\n * {@link GenerateClientRegistryOptions.toImportSpecifier} rather than computed\r\n * here. No provider-specific data — no Vite ids, no `/@fs/` prefixes, no\r\n * hashed chunk urls, no HMR metadata — reaches the emitted entry, and every\r\n * other property stays testable with a trivial mapper.\r\n */\r\nimport {\r\n isDiscoveredRoutablePage,\r\n type DiscoveredPage,\r\n type DiscoveredRoutablePage,\r\n} from \"./discover-pages\";\r\n\r\nexport type GenerateClientRegistryOptions = {\r\n /**\r\n * The discovered page graph, IN THE ORDER DISCOVERY GAVE IT.\r\n *\r\n * `discoverPages` already sorts by POSIX source-file path\r\n * (`discover-pages.ts:368`, comparator at `discover-pages.ts:248-250`), so\r\n * this emitter preserves that order rather than imposing a second one: two\r\n * orderings of one graph is exactly the drift the shared scan exists to\r\n * prevent. Serialization stability only — nothing emitted here implies\r\n * matching precedence, which is a property of the route grammar.\r\n */\r\n pages: readonly DiscoveredPage[];\r\n /** Maps an absolute source file path to the specifier the emitted module will import. */\r\n toImportSpecifier: (absoluteFilePath: string) => string;\r\n};\r\n\r\n/** The name of the array the generated module exports. */\r\nexport const CLIENT_REGISTRY_EXPORT_NAME = \"pages\";\r\n\r\n/** The specifier the generated module imports its entry type from. */\r\nconst CLIENT_RUNTIME_SPECIFIER = \"@warlock.js/web/client/runtime\";\r\n\r\n/**\r\n * Raised when two pages claim one route name.\r\n *\r\n * `discoverPages` promises uniqueness already (`discover-pages.ts:370`). This\r\n * asserts it anyway: the alternative is trusting an upstream promise and\r\n * emitting a registry in which one page is silently unreachable, which costs\r\n * far more to diagnose than the check costs to run.\r\n */\r\nexport class DuplicateClientPageNameError extends Error {\r\n public constructor(\r\n public readonly routeName: string,\r\n public readonly firstPageFile: string,\r\n public readonly secondPageFile: string,\r\n ) {\r\n super(\r\n `Two pages claim the client route name \"${routeName}\": \"${firstPageFile}\" and ` +\r\n `\"${secondPageFile}\". A route name identifies exactly one page, so the second ` +\r\n \"page would be unreachable in the browser. To fix: rename one page's `route` \" +\r\n \"export, or move the file so its directory gives it a different route name.\",\r\n );\r\n this.name = \"DuplicateClientPageNameError\";\r\n }\r\n}\r\n\r\n/**\r\n * Every literal the generator emits goes through here, without exception.\r\n * Windows separators, quotes and backslashes are all in scope, and a\r\n * hand-quoted literal that gets one of them wrong fails at bundle time with a\r\n * parse error no user can act on.\r\n */\r\nfunction quote(value: string): string {\r\n return JSON.stringify(value);\r\n}\r\n\r\nconst HEADER = [\r\n \"// AUTO-GENERATED by @warlock.js/web — do not edit.\",\r\n \"// The page graph, compiled into the CLIENT bundle.\",\r\n \"//\",\r\n \"// `name` and `path` are baked in as data so the client runtime can match a\",\r\n \"// route before loading anything; every module reference is a dynamic\",\r\n \"// `import()` so a page's code is downloaded only when that page is rendered.\",\r\n `import type { ClientPageEntry } from ${quote(CLIENT_RUNTIME_SPECIFIER)};`,\r\n];\r\n\r\nfunction assertUniqueNames(pages: readonly DiscoveredRoutablePage[]): void {\r\n const pageFileByName = new Map<string, string>();\r\n\r\n for (const page of pages) {\r\n const existing = pageFileByName.get(page.routeName);\r\n\r\n if (existing !== undefined) {\r\n throw new DuplicateClientPageNameError(page.routeName, existing, page.pageFile);\r\n }\r\n\r\n pageFileByName.set(page.routeName, page.pageFile);\r\n }\r\n}\r\n\r\n/**\r\n * One entry's `load`.\r\n *\r\n * It memoises NOTHING and holds no one-shot state: the runtime calls it again\r\n * on re-navigation to the same route, and a loader that works once and returns\r\n * undefined the second time is a silent blank page. Dynamic `import()` is\r\n * already module-cached by the bundler, so the correct implementation is to\r\n * let the cache do the caching.\r\n */\r\nfunction loadSource(\r\n page: DiscoveredRoutablePage,\r\n errorPageFile: string | undefined,\r\n toImportSpecifier: (file: string) => string,\r\n): string[] {\r\n // These bindings deliberately retain the REAL module namespace objects\r\n // returned by import(). The client lifecycle registers exports on those\r\n // namespaces before the tree builder extracts their default components.\r\n const bindings = [\"PageModule\"];\r\n const specifiers = [toImportSpecifier(page.pageFile)];\r\n\r\n // Outermost first, exactly as discovery enumerated the chain — the order IS\r\n // the nesting, so reordering it would silently reparent the page.\r\n //\r\n // Emitted VERBATIM, including the empty chain discovery reports for the\r\n // not-found page (`./discover-pages.ts`), which is what keeps hydration\r\n // rendering the same `App(Page)` the installers SSR'd. The not-found case is\r\n // NOT re-detected here: a second rule about which page gets layouts is a\r\n // second convention waiting to disagree with the server's, which is the same\r\n // reason `routePath` below is not re-composed either.\r\n const layoutBindings = page.layouts.map((layoutFile, index) => {\r\n bindings.push(`layoutModule${index}`);\r\n specifiers.push(toImportSpecifier(layoutFile));\r\n\r\n return `layoutModule${index}`;\r\n });\r\n\r\n if (page.appFile !== undefined) {\r\n bindings.push(\"AppModule\");\r\n specifiers.push(toImportSpecifier(page.appFile));\r\n }\r\n\r\n if (errorPageFile !== undefined) {\r\n bindings.push(\"ErrorPageModule\");\r\n specifiers.push(toImportSpecifier(errorPageFile));\r\n }\r\n\r\n // `App` is OMITTED, never emitted as `App: undefined`: the runtime validator\r\n // reads an own `App` key as a promise that a module namespace is behind it.\r\n const app = page.appFile === undefined ? \"\" : \", App: AppModule\";\r\n const errorPage = errorPageFile === undefined ? \"\" : \", ErrorPage: ErrorPageModule\";\r\n\r\n return [\r\n \" load: async () => {\",\r\n ` const [${bindings.join(\", \")}] = await Promise.all([`,\r\n ...specifiers.map((specifier) => ` import(${quote(specifier)}),`),\r\n \" ]);\",\r\n \"\",\r\n ` return { Page: PageModule, layouts: [${layoutBindings.join(\", \")}]${app}${errorPage} };`,\r\n \" },\",\r\n ];\r\n}\r\n\r\nfunction entrySource(\r\n page: DiscoveredRoutablePage,\r\n errorPageFile: string | undefined,\r\n toImportSpecifier: (file: string) => string,\r\n): string[] {\r\n return [\r\n \" {\",\r\n ' type: \"page\",',\r\n // Verbatim from discovery, both of them. `routePath` in particular is NOT\r\n // re-derived or re-normalised here: discovery already composed the layout\r\n // prefix with the declared route, and a second composition is a second\r\n // convention waiting to disagree with the server's.\r\n ` name: ${quote(page.routeName)},`,\r\n ` path: ${quote(page.routePath)},`,\r\n ...loadSource(page, errorPageFile, toImportSpecifier),\r\n \" },\",\r\n ];\r\n}\r\n\r\n/**\r\n * Returns the SOURCE of the client page registry module. Writes nothing.\r\n *\r\n * Zero pages is a legal result, not an error, and it is emitted as an explicit\r\n * empty registry: \"built with web, no pages\" must reach the runtime as a fact\r\n * rather than as a missing module.\r\n */\r\nexport function generateClientRegistry(options: GenerateClientRegistryOptions): string {\r\n const { pages, toImportSpecifier } = options;\r\n const routablePages = pages.filter(isDiscoveredRoutablePage);\r\n const errorPageFile = pages.find((page) => page.type === \"error\")?.pageFile;\r\n\r\n assertUniqueNames(routablePages);\r\n\r\n const declaration = `export const ${CLIENT_REGISTRY_EXPORT_NAME}: readonly ClientPageEntry[] =`;\r\n\r\n if (routablePages.length === 0) {\r\n return [...HEADER, \"\", `${declaration} [];`, \"\"].join(\"\\n\");\r\n }\r\n\r\n return [\r\n ...HEADER,\r\n \"\",\r\n `${declaration} [`,\r\n ...routablePages.flatMap((page) => entrySource(page, errorPageFile, toImportSpecifier)),\r\n \"];\",\r\n \"\",\r\n ].join(\"\\n\");\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,8BAA8B;;AAG3C,MAAM,2BAA2B;;;;;;;;;AAUjC,IAAa,+BAAb,cAAkD,MAAM;CAEpC;CACA;CACA;CAHlB,AAAO,YACL,AAAgB,WAChB,AAAgB,eAChB,AAAgB,gBAChB;EACA,MACE,0CAA0C,UAAU,MAAM,cAAc,SAClE,eAAe,oNAGvB;EATgB;EACA;EACA;EAQhB,KAAK,OAAO;CACd;AACF;;;;;;;AAQA,SAAS,MAAM,OAAuB;CACpC,OAAO,KAAK,UAAU,KAAK;AAC7B;AAEA,MAAM,SAAS;CACb;CACA;CACA;CACA;CACA;CACA;CACA,wCAAwC,MAAM,wBAAwB,EAAE;AAC1E;AAEA,SAAS,kBAAkB,OAAgD;CACzE,MAAM,iCAAiB,IAAI,IAAoB;CAE/C,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,WAAW,eAAe,IAAI,KAAK,SAAS;EAElD,IAAI,aAAa,QACf,MAAM,IAAI,6BAA6B,KAAK,WAAW,UAAU,KAAK,QAAQ;EAGhF,eAAe,IAAI,KAAK,WAAW,KAAK,QAAQ;CAClD;AACF;;;;;;;;;;AAWA,SAAS,WACP,MACA,eACA,mBACU;CAIV,MAAM,WAAW,CAAC,YAAY;CAC9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;EACA,GAAG,YAAY;EACf,GAAG,cAAc,SAAS,SAAS,YAAY,MAAM,eAAe,iBAAiB,CAAC;EACtF;EACA;CACF,EAAE,KAAK,IAAI;AACb"}
@@ -6,7 +6,7 @@ import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { parse } from "@babel/parser";
8
8
 
9
- //#region web/src/build/generate-pages-barrel.ts
9
+ //#region ../web/src/build/generate-pages-barrel.ts
10
10
  /**
11
11
  * The server half of the build→runtime handoff: the generated
12
12
  * `<productionDir>/pages.ts` barrel that carries the page graph into the