@nifrajs/cli 5.8.0 → 5.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/dist/agent-files.d.ts +0 -22
  3. package/dist/agent-files.d.ts.map +1 -1
  4. package/dist/agent-files.js +3 -1
  5. package/dist/agent-files.js.map +1 -1
  6. package/dist/assure-hydration.d.ts.map +1 -1
  7. package/dist/assure-hydration.js +2 -10
  8. package/dist/assure-hydration.js.map +1 -1
  9. package/dist/assure.d.ts.map +1 -1
  10. package/dist/assure.js +3 -3
  11. package/dist/assure.js.map +1 -1
  12. package/dist/check-diagnostics.d.ts +1 -0
  13. package/dist/check-diagnostics.d.ts.map +1 -1
  14. package/dist/check-diagnostics.js +4 -0
  15. package/dist/check-diagnostics.js.map +1 -1
  16. package/dist/check-scan.d.ts +3 -0
  17. package/dist/check-scan.d.ts.map +1 -1
  18. package/dist/check-scan.js +62 -87
  19. package/dist/check-scan.js.map +1 -1
  20. package/dist/check.d.ts +3 -0
  21. package/dist/check.d.ts.map +1 -1
  22. package/dist/check.js +27 -25
  23. package/dist/check.js.map +1 -1
  24. package/dist/cli.d.ts +8 -0
  25. package/dist/cli.d.ts.map +1 -1
  26. package/dist/cli.js +53 -20
  27. package/dist/cli.js.map +1 -1
  28. package/dist/command-catalog.d.ts +1 -5
  29. package/dist/command-catalog.d.ts.map +1 -1
  30. package/dist/command-catalog.js +20 -49
  31. package/dist/command-catalog.js.map +1 -1
  32. package/dist/config-target.js +1 -1
  33. package/dist/config-target.js.map +1 -1
  34. package/dist/db-child.js +3 -10
  35. package/dist/db-child.js.map +1 -1
  36. package/dist/db-config.d.ts +2 -0
  37. package/dist/db-config.d.ts.map +1 -1
  38. package/dist/db-config.js +2 -0
  39. package/dist/db-config.js.map +1 -1
  40. package/dist/doctor.d.ts +14 -3
  41. package/dist/doctor.d.ts.map +1 -1
  42. package/dist/doctor.js +91 -6
  43. package/dist/doctor.js.map +1 -1
  44. package/dist/frontend-guidance.d.ts +19 -0
  45. package/dist/frontend-guidance.d.ts.map +1 -1
  46. package/dist/frontend-guidance.js +267 -23
  47. package/dist/frontend-guidance.js.map +1 -1
  48. package/dist/hand-built-manifest.d.ts.map +1 -1
  49. package/dist/hand-built-manifest.js +1 -1
  50. package/dist/hand-built-manifest.js.map +1 -1
  51. package/dist/internal/control-character.d.ts +3 -0
  52. package/dist/internal/control-character.d.ts.map +1 -0
  53. package/dist/internal/control-character.js +10 -0
  54. package/dist/internal/control-character.js.map +1 -0
  55. package/dist/internal/escape-regexp.d.ts +3 -0
  56. package/dist/internal/escape-regexp.d.ts.map +1 -0
  57. package/dist/internal/escape-regexp.js +5 -0
  58. package/dist/internal/escape-regexp.js.map +1 -0
  59. package/dist/internal/line-at.d.ts +3 -0
  60. package/dist/internal/line-at.d.ts.map +1 -0
  61. package/dist/internal/line-at.js +5 -0
  62. package/dist/internal/line-at.js.map +1 -0
  63. package/dist/internal/nifra-project.d.ts.map +1 -1
  64. package/dist/internal/nifra-project.js +35 -41
  65. package/dist/internal/nifra-project.js.map +1 -1
  66. package/dist/internal/posix-path.d.ts +3 -0
  67. package/dist/internal/posix-path.d.ts.map +1 -0
  68. package/dist/internal/posix-path.js +5 -0
  69. package/dist/internal/posix-path.js.map +1 -0
  70. package/dist/internal/project-specifiers.d.ts.map +1 -1
  71. package/dist/internal/project-specifiers.js +3 -10
  72. package/dist/internal/project-specifiers.js.map +1 -1
  73. package/dist/internal/realpath-or-self.d.ts +3 -0
  74. package/dist/internal/realpath-or-self.d.ts.map +1 -0
  75. package/dist/internal/realpath-or-self.js +11 -0
  76. package/dist/internal/realpath-or-self.js.map +1 -0
  77. package/dist/internal/record.d.ts +3 -0
  78. package/dist/internal/record.d.ts.map +1 -0
  79. package/dist/internal/record.js +5 -0
  80. package/dist/internal/record.js.map +1 -0
  81. package/dist/internal/source-facts.d.ts +30 -0
  82. package/dist/internal/source-facts.d.ts.map +1 -1
  83. package/dist/internal/source-facts.js +155 -25
  84. package/dist/internal/source-facts.js.map +1 -1
  85. package/dist/introspect.d.ts +0 -22
  86. package/dist/introspect.d.ts.map +1 -1
  87. package/dist/introspect.js +11 -151
  88. package/dist/introspect.js.map +1 -1
  89. package/dist/levels-tool.d.ts +2 -0
  90. package/dist/levels-tool.d.ts.map +1 -1
  91. package/dist/levels-tool.js +54 -64
  92. package/dist/levels-tool.js.map +1 -1
  93. package/dist/load.d.ts +8 -1
  94. package/dist/load.d.ts.map +1 -1
  95. package/dist/load.js +5 -0
  96. package/dist/load.js.map +1 -1
  97. package/dist/local-cli.d.ts +7 -0
  98. package/dist/local-cli.d.ts.map +1 -1
  99. package/dist/local-cli.js +13 -0
  100. package/dist/local-cli.js.map +1 -1
  101. package/dist/mcp-docs-tools.d.ts +1 -1
  102. package/dist/mcp-docs-tools.d.ts.map +1 -1
  103. package/dist/mcp-docs-tools.js +46 -3
  104. package/dist/mcp-docs-tools.js.map +1 -1
  105. package/dist/mcp-http.d.ts +1 -1
  106. package/dist/mcp-http.js +2 -2
  107. package/dist/mcp-http.js.map +1 -1
  108. package/dist/mcp-io.d.ts +16 -0
  109. package/dist/mcp-io.d.ts.map +1 -1
  110. package/dist/mcp-io.js +63 -0
  111. package/dist/mcp-io.js.map +1 -1
  112. package/dist/mcp-isolate.d.ts.map +1 -1
  113. package/dist/mcp-isolate.js +2 -1
  114. package/dist/mcp-isolate.js.map +1 -1
  115. package/dist/mcp-project-child.d.ts.map +1 -1
  116. package/dist/mcp-project-child.js +5 -12
  117. package/dist/mcp-project-child.js.map +1 -1
  118. package/dist/mcp-render.d.ts.map +1 -1
  119. package/dist/mcp-render.js +9 -51
  120. package/dist/mcp-render.js.map +1 -1
  121. package/dist/mcp-root.js +1 -1
  122. package/dist/mcp-root.js.map +1 -1
  123. package/dist/mcp-run.d.ts.map +1 -1
  124. package/dist/mcp-run.js +3 -46
  125. package/dist/mcp-run.js.map +1 -1
  126. package/dist/mcp-tool-meta.d.ts.map +1 -1
  127. package/dist/mcp-tool-meta.js +0 -1
  128. package/dist/mcp-tool-meta.js.map +1 -1
  129. package/dist/mcp-ws.d.ts.map +1 -1
  130. package/dist/mcp-ws.js +2 -18
  131. package/dist/mcp-ws.js.map +1 -1
  132. package/dist/migrate-layout.d.ts.map +1 -1
  133. package/dist/migrate-layout.js +36 -57
  134. package/dist/migrate-layout.js.map +1 -1
  135. package/dist/output-schemas.d.ts.map +1 -1
  136. package/dist/output-schemas.js +7 -7
  137. package/dist/output-schemas.js.map +1 -1
  138. package/dist/port.d.ts.map +1 -1
  139. package/dist/port.js +1 -2
  140. package/dist/port.js.map +1 -1
  141. package/dist/ppr-read-fix.js +2 -2
  142. package/dist/ppr-read-fix.js.map +1 -1
  143. package/dist/recipes/5.10.0.d.ts +12 -0
  144. package/dist/recipes/5.10.0.d.ts.map +1 -0
  145. package/dist/recipes/5.10.0.js +44 -0
  146. package/dist/recipes/5.10.0.js.map +1 -0
  147. package/dist/recipes/5.9.0.d.ts +10 -0
  148. package/dist/recipes/5.9.0.d.ts.map +1 -0
  149. package/dist/recipes/5.9.0.js +41 -0
  150. package/dist/recipes/5.9.0.js.map +1 -0
  151. package/dist/recipes/index.d.ts +5 -0
  152. package/dist/recipes/index.d.ts.map +1 -1
  153. package/dist/recipes/index.js +4 -0
  154. package/dist/recipes/index.js.map +1 -1
  155. package/dist/review.d.ts.map +1 -1
  156. package/dist/review.js +12 -13
  157. package/dist/review.js.map +1 -1
  158. package/dist/rules/codes.d.ts +3 -0
  159. package/dist/rules/codes.d.ts.map +1 -1
  160. package/dist/rules/codes.js +3 -0
  161. package/dist/rules/codes.js.map +1 -1
  162. package/dist/rules/contract-visibility.d.ts.map +1 -1
  163. package/dist/rules/contract-visibility.js +3 -9
  164. package/dist/rules/contract-visibility.js.map +1 -1
  165. package/dist/rules/data-guard.d.ts.map +1 -1
  166. package/dist/rules/data-guard.js +3 -10
  167. package/dist/rules/data-guard.js.map +1 -1
  168. package/dist/rules/explanations.d.ts.map +1 -1
  169. package/dist/rules/explanations.js +15 -0
  170. package/dist/rules/explanations.js.map +1 -1
  171. package/dist/rules/internal-links.d.ts +5 -0
  172. package/dist/rules/internal-links.d.ts.map +1 -0
  173. package/dist/rules/internal-links.js +418 -0
  174. package/dist/rules/internal-links.js.map +1 -0
  175. package/dist/rules/legacy.d.ts.map +1 -1
  176. package/dist/rules/legacy.js +20 -0
  177. package/dist/rules/legacy.js.map +1 -1
  178. package/dist/rules/pages.d.ts.map +1 -1
  179. package/dist/rules/pages.js +41 -58
  180. package/dist/rules/pages.js.map +1 -1
  181. package/dist/rules/routes.d.ts.map +1 -1
  182. package/dist/rules/routes.js +20 -27
  183. package/dist/rules/routes.js.map +1 -1
  184. package/dist/rules/security.d.ts.map +1 -1
  185. package/dist/rules/security.js +206 -313
  186. package/dist/rules/security.js.map +1 -1
  187. package/dist/rules/server-fn-namespace.d.ts +8 -0
  188. package/dist/rules/server-fn-namespace.d.ts.map +1 -0
  189. package/dist/rules/server-fn-namespace.js +43 -0
  190. package/dist/rules/server-fn-namespace.js.map +1 -0
  191. package/dist/rules/source-scan.d.ts +29 -0
  192. package/dist/rules/source-scan.d.ts.map +1 -0
  193. package/dist/rules/source-scan.js +38 -0
  194. package/dist/rules/source-scan.js.map +1 -0
  195. package/dist/rules/text-slot-boolean.d.ts.map +1 -1
  196. package/dist/rules/text-slot-boolean.js +21 -43
  197. package/dist/rules/text-slot-boolean.js.map +1 -1
  198. package/dist/rules/zones.d.ts.map +1 -1
  199. package/dist/rules/zones.js +3 -10
  200. package/dist/rules/zones.js.map +1 -1
  201. package/dist/runtime-differences.d.ts +62 -0
  202. package/dist/runtime-differences.d.ts.map +1 -0
  203. package/dist/runtime-differences.js +222 -0
  204. package/dist/runtime-differences.js.map +1 -0
  205. package/dist/sdk.d.ts.map +1 -1
  206. package/dist/sdk.js +43 -43
  207. package/dist/sdk.js.map +1 -1
  208. package/dist/smoke.d.ts.map +1 -1
  209. package/dist/smoke.js +4 -12
  210. package/dist/smoke.js.map +1 -1
  211. package/dist/source-rewrites.d.ts +27 -0
  212. package/dist/source-rewrites.d.ts.map +1 -0
  213. package/dist/source-rewrites.js +517 -0
  214. package/dist/source-rewrites.js.map +1 -0
  215. package/dist/stylex-migrate.d.ts.map +1 -1
  216. package/dist/stylex-migrate.js +1 -1
  217. package/dist/stylex-migrate.js.map +1 -1
  218. package/dist/symptom-search.d.ts +5 -0
  219. package/dist/symptom-search.d.ts.map +1 -0
  220. package/dist/symptom-search.js +21 -0
  221. package/dist/symptom-search.js.map +1 -0
  222. package/dist/typecheck-coverage.d.ts +9 -0
  223. package/dist/typecheck-coverage.d.ts.map +1 -1
  224. package/dist/typecheck-coverage.js +16 -0
  225. package/dist/typecheck-coverage.js.map +1 -1
  226. package/dist/upgrade.d.ts +28 -3
  227. package/dist/upgrade.d.ts.map +1 -1
  228. package/dist/upgrade.js +153 -64
  229. package/dist/upgrade.js.map +1 -1
  230. package/dist/verification-plan.d.ts.map +1 -1
  231. package/dist/verification-plan.js +5 -3
  232. package/dist/verification-plan.js.map +1 -1
  233. package/docs/examples.json +51 -9
  234. package/docs/llms-full.txt +1296 -287
  235. package/docs/types.json +854 -170
  236. package/package.json +11 -11
  237. package/src/agent-files.ts +4 -1
  238. package/src/assure-hydration.ts +2 -9
  239. package/src/assure.ts +3 -4
  240. package/src/check-diagnostics.ts +5 -0
  241. package/src/check-scan.ts +74 -83
  242. package/src/check.ts +40 -26
  243. package/src/cli.ts +76 -20
  244. package/src/command-catalog.ts +22 -56
  245. package/src/config-target.ts +1 -1
  246. package/src/db-child.ts +3 -10
  247. package/src/db-config.ts +4 -0
  248. package/src/doctor.ts +128 -12
  249. package/src/frontend-guidance.ts +344 -25
  250. package/src/hand-built-manifest.ts +1 -2
  251. package/src/internal/control-character.ts +8 -0
  252. package/src/internal/escape-regexp.ts +4 -0
  253. package/src/internal/line-at.ts +4 -0
  254. package/src/internal/nifra-project.ts +39 -35
  255. package/src/internal/posix-path.ts +4 -0
  256. package/src/internal/project-specifiers.ts +3 -10
  257. package/src/internal/realpath-or-self.ts +10 -0
  258. package/src/internal/record.ts +4 -0
  259. package/src/internal/source-facts.ts +194 -29
  260. package/src/introspect.ts +16 -156
  261. package/src/levels-tool.ts +71 -78
  262. package/src/load.ts +15 -1
  263. package/src/local-cli.ts +12 -0
  264. package/src/mcp-docs-tools.ts +51 -3
  265. package/src/mcp-http.ts +2 -2
  266. package/src/mcp-io.ts +77 -0
  267. package/src/mcp-isolate.ts +2 -3
  268. package/src/mcp-project-child.ts +5 -14
  269. package/src/mcp-render.ts +11 -59
  270. package/src/mcp-root.ts +1 -1
  271. package/src/mcp-run.ts +5 -54
  272. package/src/mcp-tool-meta.ts +0 -1
  273. package/src/mcp-ws.ts +2 -19
  274. package/src/migrate-layout.ts +52 -72
  275. package/src/output-schemas.ts +7 -8
  276. package/src/port.ts +1 -4
  277. package/src/ppr-read-fix.ts +2 -2
  278. package/src/recipes/5.10.0.ts +45 -0
  279. package/src/recipes/5.9.0.ts +42 -0
  280. package/src/recipes/index.ts +9 -0
  281. package/src/review.ts +15 -15
  282. package/src/rules/codes.ts +3 -0
  283. package/src/rules/contract-visibility.ts +3 -8
  284. package/src/rules/data-guard.ts +3 -10
  285. package/src/rules/explanations.ts +15 -0
  286. package/src/rules/internal-links.ts +490 -0
  287. package/src/rules/legacy.ts +21 -0
  288. package/src/rules/pages.ts +47 -58
  289. package/src/rules/routes.ts +21 -27
  290. package/src/rules/security.ts +224 -255
  291. package/src/rules/server-fn-namespace.ts +47 -0
  292. package/src/rules/source-scan.ts +66 -0
  293. package/src/rules/text-slot-boolean.ts +26 -42
  294. package/src/rules/zones.ts +3 -10
  295. package/src/runtime-differences.ts +302 -0
  296. package/src/sdk.ts +55 -58
  297. package/src/smoke.ts +4 -13
  298. package/src/source-rewrites.ts +592 -0
  299. package/src/stylex-migrate.ts +1 -3
  300. package/src/symptom-search.ts +27 -0
  301. package/src/typecheck-coverage.ts +23 -0
  302. package/src/upgrade.ts +194 -74
  303. package/src/verification-plan.ts +10 -4
  304. package/dist/sync-routes.d.ts +0 -29
  305. package/dist/sync-routes.d.ts.map +0 -1
  306. package/dist/sync-routes.js +0 -56
  307. package/dist/sync-routes.js.map +0 -1
  308. package/src/sync-routes.ts +0 -70
@@ -0,0 +1,490 @@
1
+ import { existsSync, readFileSync } from "node:fs"
2
+ import { join } from "node:path"
3
+ import { Glob } from "bun"
4
+ import { CONFIG_FILE, FRAMEWORK_FILE } from "../app-files.ts"
5
+ import { IGNORED, stripComments } from "../check-scan.ts"
6
+ import { type Diagnostic, diagnostic } from "../diagnostics.ts"
7
+ import { codeUnitOrder } from "../internal/code-unit-order.ts"
8
+ import { toPosix } from "../internal/posix-path.ts"
9
+ import { ANCHOR_HOLE } from "../internal/source-facts.ts"
10
+ import { buildRouteTable } from "../introspect.ts"
11
+ import { commentBlockExpectation } from "./comment-markers.ts"
12
+ import type { CheckRule, RuleContext } from "./index.ts"
13
+ import { readStaticApiPrefix } from "./pages.ts"
14
+ import { scanSources } from "./source-scan.ts"
15
+
16
+ /**
17
+ * NF-C057 and NF-C058 - an `<a href="/path">` written as a string. `href()` checks a link against the
18
+ * app's routes, so a renamed or removed page is a compile error; a path string is invisible to the types.
19
+ * The two codes split what the route table can tell apart, so each takes its own severity:
20
+ *
21
+ * - NF-C057 (warn): the path matches no page, no backend route and no file: the link is a 404.
22
+ * - NF-C058 (info): the path is a page of the app, so it works today but nothing keeps it working.
23
+ *
24
+ * A template literal (`/users/${id}`) is judged by its shape only, and never reported as dead: the
25
+ * route it builds may live outside the file routes.
26
+ */
27
+
28
+ const TEST_DIR = /(?:^|\/)(?:tests?|__tests__)\//
29
+ const FILE_EXTENSION = /\.[A-Za-z0-9]{1,8}$/
30
+ // One attribute of a tag, matched where the previous one ended (sticky), so a tag is read in one pass:
31
+ // `href="/x"`, `href='/x'`, `href={"/x"}` or `` href={`/x`} `` (Svelte), and Vue's `:href="'/x'"`. Any
32
+ // other `{...}` value is an expression and names no path.
33
+ const ATTRIBUTE =
34
+ /\s+([^\s=>/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|\{\s*(?:"([^"]*)"|'([^']*)'|`([^`]*)`)\s*\}|\{[^}]*\}))?/y
35
+ const BOUND_LITERAL = /^\s*(?:'([^']*)'|"([^"]*)"|`([^`$]*)`)\s*$/
36
+
37
+ interface Judged {
38
+ readonly pattern: string
39
+ readonly params: ReadonlyMap<string, string>
40
+ }
41
+
42
+ interface PageRoutes {
43
+ /** The page route an anchor path resolves to, most specific first. */
44
+ match(path: string): Judged | undefined
45
+ /** Whether something other than a page serves `path`: a backend route or a file in `public/`. */
46
+ servedElsewhere(path: string): boolean
47
+ /** The static page pattern closest to `path`, when it is a typo away. */
48
+ nearest(path: string): string | undefined
49
+ /** Whether a backend route path the scan could not read leaves the dead-link verdict open. */
50
+ readonly backendUnknown: boolean
51
+ }
52
+
53
+ const cache = new WeakMap<RuleContext, Promise<PageRoutes | undefined>>()
54
+
55
+ function distance(a: string, b: string): number {
56
+ let row = Array.from({ length: b.length + 1 }, (_, i) => i)
57
+ for (let i = 1; i <= a.length; i++) {
58
+ const next = [i]
59
+ for (let j = 1; j <= b.length; j++) {
60
+ next[j] = Math.min(
61
+ (row[j] ?? 0) + 1,
62
+ (next[j - 1] ?? 0) + 1,
63
+ (row[j - 1] ?? 0) + (a[i - 1] === b[j - 1] ? 0 : 1),
64
+ )
65
+ }
66
+ row = next
67
+ }
68
+ return row[b.length] ?? 0
69
+ }
70
+
71
+ /** Read only literal mount exports, never import/evaluate the app's config. An unreadable field
72
+ * leaves the dead-link verdict open, just like an unreadable backend registration. */
73
+ function backendMount(
74
+ ctx: RuleContext,
75
+ ): { readonly prefix: string | undefined; readonly strip: boolean } | undefined {
76
+ let prefix: string | undefined
77
+ let strip = false
78
+ let prefixUnknown = false
79
+ let stripUnknown = false
80
+ // nifra.config.ts overrides individual fields inherited from backend/framework.ts.
81
+ for (const file of [FRAMEWORK_FILE, CONFIG_FILE]) {
82
+ const path = join(ctx.root, file)
83
+ if (!existsSync(path)) continue
84
+ const source = stripComments(readFileSync(path, "utf8"))
85
+ const read = readStaticApiPrefix(source)
86
+ if (read.kind !== "default") {
87
+ prefixUnknown = read.kind === "unreadable"
88
+ if (read.kind === "literal") prefix = read.value
89
+ }
90
+ if (/\bapiStrip\b/.test(source)) {
91
+ const literal =
92
+ /\bexport\s+const\s+apiStrip\s*(?::\s*boolean\s*)?=\s*(true|false)\s*(?:as\s+const\s*)?(?:;|\r?\n|$)/.exec(
93
+ source,
94
+ )
95
+ stripUnknown = literal === null
96
+ if (literal !== null) strip = literal[1] === "true"
97
+ }
98
+ // A star re-export may supply either field; it cannot prove an absent/default mount.
99
+ if (/\bexport\s*\*/.test(source)) {
100
+ prefixUnknown = true
101
+ stripUnknown = true
102
+ }
103
+ }
104
+ return prefixUnknown || stripUnknown ? undefined : { prefix, strip }
105
+ }
106
+
107
+ function pageRoutes(ctx: RuleContext): Promise<PageRoutes | undefined> {
108
+ let loaded = cache.get(ctx)
109
+ if (loaded === undefined) {
110
+ loaded = loadPageRoutes(ctx)
111
+ cache.set(ctx, loaded)
112
+ }
113
+ return loaded
114
+ }
115
+
116
+ async function loadPageRoutes(ctx: RuleContext): Promise<PageRoutes | undefined> {
117
+ // The pages come from the file system, not the scanned sources: a `.vue`, `.svelte` or `.mdx` page is
118
+ // not in the source index, and a missed page would turn its links into false 404s.
119
+ const routesDir = join(ctx.root, "routes")
120
+ if (!existsSync(routesDir)) return undefined
121
+ const { discoverRoutes } = await import("@nifrajs/web/fs")
122
+ const { compileRoutePattern, matchRoutePattern, sortRoutesBySpecificity } = await import(
123
+ "@nifrajs/core/pattern"
124
+ )
125
+ let patterns: string[]
126
+ try {
127
+ patterns = discoverRoutes(routesDir).routes.map((route) => route.pattern)
128
+ } catch {
129
+ return undefined
130
+ }
131
+ if (patterns.length === 0) return undefined
132
+ // `sortRoutesBySpecificity` reads the compiled pattern from `pattern`, and carries the rest along.
133
+ const compile = (route: string) => {
134
+ try {
135
+ return [{ route, pattern: compileRoutePattern(route) }]
136
+ } catch {
137
+ return []
138
+ }
139
+ }
140
+ const pageEntries = sortRoutesBySpecificity(patterns.flatMap(compile))
141
+ const mount = backendMount(ctx)
142
+ const backendEntries = buildRouteTable({
143
+ pages: [],
144
+ api: ctx.project.routes,
145
+ apiPrefix: mount?.prefix ?? "",
146
+ apiStrip: mount?.strip ?? false,
147
+ })
148
+ // Without a configured mount, preserve the scan's allowance for independently served backends.
149
+ .filter((route) => mount?.prefix === undefined || route.autoMounted)
150
+ .flatMap((route) => compile(route.path))
151
+ // Code-unit order, so which of two equally close pages a diagnostic names does not depend on the
152
+ // directory order of the machine that ran the check.
153
+ const staticPatterns = patterns.filter((pattern) => !/[:*]/.test(pattern)).sort(codeUnitOrder)
154
+ return {
155
+ backendUnknown: mount === undefined || ctx.project.sourceFindings.routePaths.length > 0,
156
+ match(path) {
157
+ for (const entry of pageEntries) {
158
+ const found = matchRoutePattern(entry.pattern, path)
159
+ if (found.matched)
160
+ return {
161
+ pattern: entry.route,
162
+ params: new Map(Object.entries(found.params).map(([k, v]) => [k, String(v)])),
163
+ }
164
+ }
165
+ return undefined
166
+ },
167
+ servedElsewhere(path) {
168
+ if (backendEntries.some((entry) => matchRoutePattern(entry.pattern, path).matched))
169
+ return true
170
+ if (FILE_EXTENSION.test(path) || path.startsWith("/_")) return true
171
+ try {
172
+ return existsSync(join(ctx.root, "public", decodeURI(path)))
173
+ } catch {
174
+ return false
175
+ }
176
+ },
177
+ nearest(path) {
178
+ let best: { pattern: string; at: number } | undefined
179
+ for (const pattern of staticPatterns) {
180
+ const at = distance(path, pattern)
181
+ if (at <= 2 && (best === undefined || at < best.at)) best = { pattern, at }
182
+ }
183
+ return best?.pattern
184
+ },
185
+ }
186
+ }
187
+
188
+ interface Verdict {
189
+ readonly kind: "dead" | "unchecked"
190
+ readonly shown: string
191
+ readonly message: string
192
+ readonly evidence: readonly string[]
193
+ }
194
+
195
+ const spell = (path: string): string => path.replaceAll(ANCHOR_HOLE, `\${…}`)
196
+
197
+ /** Judge one anchor path (a hole stands for a `${...}`), or undefined when it is not this rule's business. */
198
+ function judge(routes: PageRoutes, written: string): Verdict | undefined {
199
+ const cut = written.search(/[?#]/)
200
+ const path = cut < 0 ? written : written.slice(0, cut)
201
+ const rest = cut < 0 ? "" : written.slice(cut)
202
+ const dynamic = path.includes(ANCHOR_HOLE)
203
+ const found = routes.match(path)
204
+ const shown = spell(written)
205
+ if (found !== undefined) {
206
+ const hash = rest.includes("#") ? rest.slice(rest.indexOf("#") + 1) : undefined
207
+ const query = rest.startsWith("?")
208
+ const entries = [...found.params]
209
+ const params =
210
+ entries.length === 0
211
+ ? ""
212
+ : `, params: { ${entries.map(([name, value]) => `${name}: ${dynamic ? "…" : JSON.stringify(value)}`).join(", ")} }`
213
+ const call = `href({ to: ${JSON.stringify(found.pattern)}${params}${query ? ", search: { … }" : ""}${hash !== undefined && hash !== "" && !hash.includes(ANCHOR_HOLE) ? `, hash: ${JSON.stringify(hash)}` : ""} })`
214
+ return {
215
+ kind: "unchecked",
216
+ shown,
217
+ message: `\`<a href="${shown}">\` writes a page's path by hand, so renaming or removing ${found.pattern} leaves it dead and nothing fails. Build it with \`${call}\` (\`href\` is exported by \`@nifrajs/web-<framework>/router\`), which checks the route and its params against the app.`,
218
+ evidence: [
219
+ `${shown} resolves to the page route ${found.pattern}`,
220
+ "a path built elsewhere, such as a CMS link, takes `rawHref(path)`",
221
+ ],
222
+ }
223
+ }
224
+ if (dynamic || routes.backendUnknown || routes.servedElsewhere(path)) return undefined
225
+ const near = routes.nearest(path)
226
+ return {
227
+ kind: "dead",
228
+ shown,
229
+ message: `\`<a href="${shown}">\` links to a path no page of this app serves, so following it is a 404.${near === undefined ? "" : ` Did you mean ${near}?`} Use \`href({ to })\` with a route of the app, which fails to compile for one that does not exist.`,
230
+ evidence: [
231
+ `${path} matches no page route, no backend route and no file in public/`,
232
+ "a path another server answers takes `rawHref(path)`",
233
+ ],
234
+ }
235
+ }
236
+
237
+ const adviceFor = (code: string, template: boolean): string =>
238
+ template
239
+ ? `a link kept as written, on purpose: \`<!-- nifra-expect ${code}: <reason> -->\` above the anchor`
240
+ : `a link kept as written, on purpose: \`// nifra-expect ${code}: <reason>\` above the attribute`
241
+
242
+ function report(
243
+ code: string,
244
+ severity: "warn" | "info",
245
+ file: string,
246
+ line: number,
247
+ verdict: Verdict,
248
+ note: string | undefined,
249
+ template = false,
250
+ ): Diagnostic {
251
+ return diagnostic({
252
+ code,
253
+ severity,
254
+ file,
255
+ line,
256
+ message: note === undefined ? verdict.message : `${verdict.message} ${note}`,
257
+ evidence: [...verdict.evidence, adviceFor(code, template)],
258
+ verify: "nifra check",
259
+ })
260
+ }
261
+
262
+ interface HtmlComment {
263
+ readonly start: number
264
+ /** Where the text after `<!--` stops: before the closing delimiter. */
265
+ readonly bodyEnd: number
266
+ readonly end: number
267
+ }
268
+
269
+ // A comment ends at `-->` or `--!>`.
270
+ const COMMENT_END = /--!?>/g
271
+
272
+ /** The comment opened at `start`, which HTML ends at `-->` or `--!>`; `<!-->` and `<!--->` are empty. */
273
+ function commentAt(text: string, start: number): HtmlComment {
274
+ const body = start + 4
275
+ if (text.startsWith(">", body)) return { start, bodyEnd: body, end: body + 1 }
276
+ if (text.startsWith("->", body)) return { start, bodyEnd: body, end: body + 2 }
277
+ COMMENT_END.lastIndex = body
278
+ const close = COMMENT_END.exec(text)
279
+ return close === null
280
+ ? { start, bodyEnd: text.length, end: text.length }
281
+ : { start, bodyEnd: close.index, end: close.index + close[0].length }
282
+ }
283
+
284
+ /** The end of a markup tag or `{expression}`, ignoring `>`/braces inside quoted values. */
285
+ function markupEnd(text: string, start: number, expression = false): number {
286
+ let quote: string | undefined
287
+ let braces = expression ? 1 : 0
288
+ for (let at = start; at < text.length; at++) {
289
+ const char = text[at]
290
+ if (quote !== undefined) {
291
+ if (braces > 0 && char === "\\") at++
292
+ else if (char === quote) quote = undefined
293
+ } else if (char === '"' || char === "'" || (braces > 0 && char === "`")) quote = char
294
+ else if (char === "{") braces++
295
+ else if (char === "}") {
296
+ braces--
297
+ if (expression && braces === 0) return at + 1
298
+ } else if (!expression && braces === 0 && char === ">") return at + 1
299
+ }
300
+ return text.length
301
+ }
302
+
303
+ /** Scan markup, not script strings, HTML comments or other tags' quoted attributes. The existing
304
+ * componentScripts scanner only extracts scripts and cannot distinguish these template regions. */
305
+ function templateHrefs(
306
+ text: string,
307
+ vue: boolean,
308
+ ): {
309
+ readonly hrefs: Array<{ readonly at: number; readonly tagAt: number; readonly value: string }>
310
+ readonly expectationLines: readonly string[]
311
+ } {
312
+ const hrefs: Array<{ at: number; tagAt: number; value: string }> = []
313
+ const comments: HtmlComment[] = []
314
+ let templateDepth = 0
315
+ for (let at = 0; at < text.length; ) {
316
+ if (text.startsWith("<!--", at)) {
317
+ const comment = commentAt(text, at)
318
+ comments.push(comment)
319
+ at = comment.end
320
+ continue
321
+ }
322
+ if (text[at] === "{" && (!vue || text.startsWith("{{", at))) {
323
+ at = markupEnd(text, at + 1, true)
324
+ continue
325
+ }
326
+ if (text[at] !== "<") {
327
+ at++
328
+ continue
329
+ }
330
+ const tag = /^<(\/?)([\w-]+)(?=[\s/>])/.exec(text.slice(at))
331
+ if (tag === null) {
332
+ at++
333
+ continue
334
+ }
335
+ const tagAt = at
336
+ const end = markupEnd(text, at + tag[0].length)
337
+ const name = tag[2]?.toLowerCase()
338
+ const closing = tag[1] === "/"
339
+ at = end
340
+ if (!closing && (name === "script" || name === "style")) {
341
+ const close = name === "script" ? /<\/script\s*>/gi : /<\/style\s*>/gi
342
+ close.lastIndex = end
343
+ const match = close.exec(text)
344
+ at = match === null ? text.length : close.lastIndex
345
+ continue
346
+ }
347
+ if (name === "template") templateDepth += closing ? -1 : 1
348
+ if (closing || name !== "a" || (vue && templateDepth <= 0)) continue
349
+ ATTRIBUTE.lastIndex = tagAt + tag[0].length
350
+ for (let match = ATTRIBUTE.exec(text); match !== null; match = ATTRIBUTE.exec(text)) {
351
+ const [whole, attribute, doubled, single, braceDouble, braceSingle, braceTemplate] = match
352
+ if (attribute !== "href" && attribute !== ":href" && attribute !== "v-bind:href") continue
353
+ const raw = doubled ?? single
354
+ const value =
355
+ attribute === "href"
356
+ ? (raw ?? braceDouble ?? braceSingle ?? braceTemplate)
357
+ : raw
358
+ ?.match(BOUND_LITERAL)
359
+ ?.slice(1)
360
+ .find((part) => part !== undefined)
361
+ if (value !== undefined)
362
+ hrefs.push({
363
+ at: ATTRIBUTE.lastIndex - whole.length + whole.indexOf(attribute),
364
+ tagAt,
365
+ value,
366
+ })
367
+ }
368
+ }
369
+ // Adapt only real HTML comments to the shared directive parser. Non-comment code stays a block
370
+ // boundary; quoted marker text cannot suppress anything. Line counts are unchanged.
371
+ const code = (part: string): string => part.replace(/[^\s]/g, "x")
372
+ let expectations = ""
373
+ let previous = 0
374
+ for (const comment of comments) {
375
+ expectations += code(text.slice(previous, comment.start))
376
+ expectations += text
377
+ .slice(comment.start + 4, comment.bodyEnd)
378
+ .split("\n")
379
+ .map((line) => `// ${line}`)
380
+ .join("\n")
381
+ previous = comment.end
382
+ }
383
+ expectations += code(text.slice(previous))
384
+ return { hrefs, expectationLines: expectations.split("\n") }
385
+ }
386
+
387
+ /** The 1-based line of an offset in `text`: a search over the line starts, so a file with thousands of links is not re-split for each. */
388
+ function lineLookup(text: string): (offset: number) => number {
389
+ const starts = [0]
390
+ for (let at = text.indexOf("\n"); at !== -1; at = text.indexOf("\n", at + 1)) starts.push(at + 1)
391
+ return (offset) => {
392
+ let low = 0
393
+ let high = starts.length - 1
394
+ while (low < high) {
395
+ const mid = (low + high + 1) >> 1
396
+ if ((starts[mid] ?? 0) <= offset) low = mid
397
+ else high = mid - 1
398
+ }
399
+ return low + 1
400
+ }
401
+ }
402
+
403
+ async function templateFindings(
404
+ ctx: RuleContext,
405
+ routes: PageRoutes,
406
+ kind: Verdict["kind"],
407
+ code: string,
408
+ severity: "warn" | "info",
409
+ ): Promise<Diagnostic[]> {
410
+ const findings: Diagnostic[] = []
411
+ const files: string[] = []
412
+ for await (const entry of new Glob("**/*.{vue,svelte}").scan({ cwd: ctx.root, dot: false })) {
413
+ // Bun yields `\` paths on Windows, which IGNORED and TEST_DIR (and the reported location) expect as `/`.
414
+ const file = toPosix(entry)
415
+ if (!IGNORED.test(file) && !TEST_DIR.test(file)) files.push(file)
416
+ }
417
+ for (const file of files.sort()) {
418
+ // The source index holds only a component's script blocks; the links are in its template.
419
+ const text = readFileSync(join(ctx.root, file), "utf8")
420
+ if (!text.includes("href")) continue
421
+ const { hrefs, expectationLines } = templateHrefs(text, file.endsWith(".vue"))
422
+ const lineOf = lineLookup(text)
423
+ for (const { at, tagAt, value } of hrefs) {
424
+ if (!value.startsWith("/") || value.startsWith("//")) continue
425
+ // A Svelte `{expression}` inside the value is a hole.
426
+ const verdict = judge(routes, value.replace(/\$?\{[^}]*\}/g, ANCHOR_HOLE))
427
+ if (verdict?.kind !== kind) continue
428
+ const line = lineOf(at)
429
+ const tagLine = lineOf(tagAt)
430
+ if (
431
+ commentBlockExpectation(expectationLines, tagLine, [code, "internal-link"]) !== undefined ||
432
+ commentBlockExpectation(expectationLines, line, [code, "internal-link"]) !== undefined
433
+ )
434
+ continue
435
+ findings.push(report(code, severity, file, line, verdict, undefined, true))
436
+ }
437
+ }
438
+ return findings
439
+ }
440
+
441
+ function internalLinkRule(
442
+ code: string,
443
+ title: string,
444
+ kind: Verdict["kind"],
445
+ severity: "warn" | "info",
446
+ ): CheckRule {
447
+ return {
448
+ code,
449
+ title,
450
+ async scan(ctx) {
451
+ const routes = await pageRoutes(ctx)
452
+ if (routes === undefined) return []
453
+ const scripts = await scanSources(ctx, {
454
+ expectation: [code, "internal-link"],
455
+ mayMatch: (text) => text.includes("<a") && text.includes("href"),
456
+ find: (facts, tree) =>
457
+ TEST_DIR.test(tree.fileName)
458
+ ? []
459
+ : facts.internalAnchors(tree).flatMap((anchor) => {
460
+ const verdict = judge(routes, anchor.path)
461
+ if (verdict?.kind !== kind) return []
462
+ return [
463
+ {
464
+ position: anchor.position,
465
+ report: (line: number, note?: string) =>
466
+ report(code, severity, tree.fileName, line, verdict, note),
467
+ },
468
+ ]
469
+ }),
470
+ })
471
+ return [...scripts, ...(await templateFindings(ctx, routes, kind, code, severity))]
472
+ },
473
+ }
474
+ }
475
+
476
+ export const deadInternalLinkRule = internalLinkRule(
477
+ "NF-C057",
478
+ "Internal link to a path no page serves",
479
+ "dead",
480
+ "warn",
481
+ )
482
+
483
+ export const uncheckedInternalLinkRule = internalLinkRule(
484
+ "NF-C058",
485
+ "Internal link written as a path string",
486
+ "unchecked",
487
+ "info",
488
+ )
489
+
490
+ export const internalLinkRules = Object.freeze([deadInternalLinkRule, uncheckedInternalLinkRule])
@@ -409,10 +409,31 @@ const typecheckRule: CheckRule = {
409
409
  }
410
410
  }
411
411
  findings.push(...outsideProgramFindings(tc.outsideProgram ?? []))
412
+ if (tc.routeTableOutsideProgram !== undefined)
413
+ findings.push(routeTableFinding(tc.routeTableOutsideProgram))
412
414
  return findings
413
415
  },
414
416
  }
415
417
 
418
+ /** The route table exists but no program loads it: every `to` and `search` stays loose, silently. */
419
+ function routeTableFinding(file: string): Diagnostic {
420
+ return legacyDiagnostic("typecheck", {
421
+ severity: "warning",
422
+ file,
423
+ message: `${file} is outside tsc's program, so navigate, redirect and Link accept any target and search: no route imports its ./+types module, and no tsconfig names the table`,
424
+ fix: `Add "${file}" to tsconfig.json "files" (a "files" entry is not filtered by "exclude"), or import a route's ./+types module from a file the program holds`,
425
+ suggestion: {
426
+ kind: "manual",
427
+ title: "Load the generated route table",
428
+ steps: [
429
+ `Add "${file}" to the "files" array in tsconfig.json, or in another tsconfig the typecheck runs.`,
430
+ 'List it under "files", not "include": an "exclude" that names ".nifra" would drop it from "include".',
431
+ "Run `nifra check` again; links and redirects are now checked against the app's routes.",
432
+ ],
433
+ },
434
+ })
435
+ }
436
+
416
437
  /** One finding per zone folder: the fix (tsconfig `include`) is per folder, not per file. */
417
438
  function outsideProgramFindings(files: readonly string[]): Diagnostic[] {
418
439
  const byFolder = new Map<string, { readonly first: string; readonly group: string[] }>()
@@ -48,6 +48,25 @@ export function readStaticApiPrefix(source: string): StaticApiPrefix {
48
48
 
49
49
  const CONFIG_FILES = [FRAMEWORK_FILE, CONFIG_FILE] as const
50
50
 
51
+ type RouteManifest = ReturnType<typeof discoverRoutes>
52
+
53
+ /** The routes/ manifest; `undefined` without the tree or for one it refuses, which dev and build report themselves. */
54
+ function routeManifest(routesDir: string): RouteManifest | undefined {
55
+ if (!existsSync(routesDir)) return undefined
56
+ try {
57
+ return discoverRoutes(routesDir)
58
+ } catch {
59
+ return undefined
60
+ }
61
+ }
62
+
63
+ /** The manifest's script layouts, in code-unit order of their files. */
64
+ function scriptLayouts(manifest: RouteManifest): RouteManifest["layouts"][string][] {
65
+ return Object.values(manifest.layouts)
66
+ .filter((layout) => SCRIPT_LAYOUT.test(layout.file))
67
+ .sort((a, b) => codeUnitOrder(a.file, b.file))
68
+ }
69
+
51
70
  export const shadowedPageRule: CheckRule = {
52
71
  code: "NF-C027",
53
72
  title: "Page route under the backend mount",
@@ -78,13 +97,8 @@ export const shadowedPageRule: CheckRule = {
78
97
  }
79
98
  if (apiPrefix === "") return []
80
99
 
81
- let manifest: ReturnType<typeof discoverRoutes>
82
- try {
83
- manifest = discoverRoutes(routesDir)
84
- } catch {
85
- // A routes/ tree the manifest refuses fails dev and build with its own error.
86
- return []
87
- }
100
+ const manifest = routeManifest(routesDir)
101
+ if (manifest === undefined) return []
88
102
  const findings: Diagnostic[] = []
89
103
  for (const page of shadowedPages(manifest, [apiPrefix])) {
90
104
  findings.push(
@@ -128,13 +142,8 @@ export const statusLayoutRule: CheckRule = {
128
142
  title: "Root status page wraps the root layout itself",
129
143
  async scan(ctx) {
130
144
  const routesDir = join(ctx.root, "routes")
131
- if (!existsSync(routesDir)) return []
132
- let manifest: ReturnType<typeof discoverRoutes>
133
- try {
134
- manifest = discoverRoutes(routesDir)
135
- } catch {
136
- return []
137
- }
145
+ const manifest = routeManifest(routesDir)
146
+ if (manifest === undefined) return []
138
147
  const layout = manifest.layouts._layout
139
148
  if (layout === undefined) return []
140
149
  const pages = [
@@ -240,6 +249,18 @@ function createWebAppCallee(
240
249
  callee.name.text === "createWebApp"
241
250
  }
242
251
 
252
+ /** The object literal a `createWebApp(...)` call takes as its options; `undefined` for any other node. */
253
+ function createWebAppOptions(
254
+ ts: typeof TSApi,
255
+ isCreateWebApp: (callee: TSApi.Expression) => boolean,
256
+ node: TSApi.Node,
257
+ ): TSApi.ObjectLiteralExpression | undefined {
258
+ if (!ts.isCallExpression(node) || !isCreateWebApp(node.expression)) return undefined
259
+ const arg = node.arguments[0]
260
+ const options = arg === undefined ? undefined : unwrapExpression(ts, arg)
261
+ return options !== undefined && ts.isObjectLiteralExpression(options) ? options : undefined
262
+ }
263
+
243
264
  const objectPropertyName = (
244
265
  ts: typeof TSApi,
245
266
  property: TSApi.ObjectLiteralElementLike,
@@ -318,15 +339,8 @@ export function entryApiMounts(
318
339
  }
319
340
  const mounts: EntryApiMount[] = []
320
341
  const visit = (node: TSApi.Node): void => {
321
- const arg = ts.isCallExpression(node) ? node.arguments[0] : undefined
322
- const options = arg === undefined ? undefined : unwrapExpression(ts, arg)
323
- if (
324
- ts.isCallExpression(node) &&
325
- isCreateWebApp(node.expression) &&
326
- options !== undefined &&
327
- ts.isObjectLiteralExpression(options) &&
328
- options.properties.some((property) => objectPropertyName(ts, property) === "api")
329
- ) {
342
+ const options = createWebAppOptions(ts, isCreateWebApp, node)
343
+ if (options?.properties.some((property) => objectPropertyName(ts, property) === "api")) {
330
344
  // The last of an `apiPrefix` property and a spread decides, as it does at runtime.
331
345
  let apiPrefix: EntryApiPrefix = { kind: "literal", value: "", unset: true }
332
346
  let prefixNode: TSApi.Node | undefined
@@ -501,14 +515,8 @@ export function entryCopyChunksGaps(
501
515
  manifest = statement.moduleSpecifier.text
502
516
  const gaps: EntryCopyChunksGap[] = []
503
517
  const visit = (node: TSApi.Node): void => {
504
- const arg = ts.isCallExpression(node) ? node.arguments[0] : undefined
505
- const options = arg === undefined ? undefined : unwrapExpression(ts, arg)
506
- if (
507
- ts.isCallExpression(node) &&
508
- isCreateWebApp(node.expression) &&
509
- options !== undefined &&
510
- ts.isObjectLiteralExpression(options)
511
- ) {
518
+ const options = createWebAppOptions(ts, isCreateWebApp, node)
519
+ if (options !== undefined) {
512
520
  const names = options.properties.map((property) =>
513
521
  ts.isSpreadAssignment(property) ? undefined : objectPropertyName(ts, property),
514
522
  )
@@ -688,16 +696,9 @@ export const layoutMetaDataRule: CheckRule = {
688
696
  title: "Layout meta reads data its layout never loads",
689
697
  async scan(ctx) {
690
698
  const routesDir = join(ctx.root, "routes")
691
- if (!existsSync(routesDir)) return []
692
- let manifest: ReturnType<typeof discoverRoutes>
693
- try {
694
- manifest = discoverRoutes(routesDir)
695
- } catch {
696
- return []
697
- }
698
- const layouts = Object.values(manifest.layouts)
699
- .filter((layout) => SCRIPT_LAYOUT.test(layout.file))
700
- .sort((a, b) => codeUnitOrder(a.file, b.file))
699
+ const manifest = routeManifest(routesDir)
700
+ if (manifest === undefined) return []
701
+ const layouts = scriptLayouts(manifest)
701
702
  if (layouts.length === 0) return []
702
703
  const loaded = await loadRuleTypeScript(ctx)
703
704
  const ts = loaded.compiler
@@ -784,16 +785,9 @@ export const ungatedLayoutRefusalRule: CheckRule = {
784
785
  title: "Layout loader refuses access without a gate",
785
786
  async scan(ctx) {
786
787
  const routesDir = join(ctx.root, "routes")
787
- if (!existsSync(routesDir)) return []
788
- let manifest: ReturnType<typeof discoverRoutes>
789
- try {
790
- manifest = discoverRoutes(routesDir)
791
- } catch {
792
- return []
793
- }
794
- const layouts = Object.values(manifest.layouts)
795
- .filter((layout) => SCRIPT_LAYOUT.test(layout.file))
796
- .sort((a, b) => codeUnitOrder(a.file, b.file))
788
+ const manifest = routeManifest(routesDir)
789
+ if (manifest === undefined) return []
790
+ const layouts = scriptLayouts(manifest)
797
791
  if (layouts.length === 0) return []
798
792
  const sources = layouts.map((layout) =>
799
793
  [layout.file, ...(layout.backend === undefined ? [] : [layout.backend])].map((file) => ({
@@ -890,13 +884,8 @@ export const frontendServerExportRule: CheckRule = {
890
884
  title: "Server-only export in a route frontend file",
891
885
  async scan(ctx) {
892
886
  const routesDir = join(ctx.root, "routes")
893
- if (!existsSync(routesDir)) return []
894
- let manifest: ReturnType<typeof discoverRoutes>
895
- try {
896
- manifest = discoverRoutes(routesDir)
897
- } catch {
898
- return []
899
- }
887
+ const manifest = routeManifest(routesDir)
888
+ if (manifest === undefined) return []
900
889
  const files = new Set<string>()
901
890
  for (const entry of [
902
891
  ...manifest.routes,