@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
@@ -20,6 +20,8 @@ import { recipe as v5_5_0 } from "./5.5.0.ts"
20
20
  import { recipe as v5_6_0 } from "./5.6.0.ts"
21
21
  import { recipe as v5_7_0 } from "./5.7.0.ts"
22
22
  import { recipe as v5_8_0 } from "./5.8.0.ts"
23
+ import { recipe as v5_9_0 } from "./5.9.0.ts"
24
+ import { recipe as v5_10_0 } from "./5.10.0.ts"
23
25
 
24
26
  /** A pin rule: every dependency whose name starts with `match` is set to version `to`. */
25
27
  export interface PinRule {
@@ -69,6 +71,11 @@ export interface UpgradeRecipe {
69
71
  readonly importMoves: readonly ImportMove[]
70
72
  readonly dependencyAdds?: readonly DependencyAdd[]
71
73
  readonly retiredMarkers?: readonly RetiredMarker[]
74
+ /**
75
+ * Syntax-tree rewrites (`../source-rewrites.ts`) by id, run on every source file after the import
76
+ * moves with the project's own TypeScript. An upgrade that needs one refuses to run without it.
77
+ */
78
+ readonly sourceRewrites?: readonly string[]
72
79
  /** Human notes printed after the plan - e.g. structural changes the runner deliberately can't do. */
73
80
  readonly notes?: readonly string[]
74
81
  /**
@@ -94,6 +101,8 @@ const RECIPES: Record<string, UpgradeRecipe> = {
94
101
  [v5_6_0.version]: v5_6_0,
95
102
  [v5_7_0.version]: v5_7_0,
96
103
  [v5_8_0.version]: v5_8_0,
104
+ [v5_9_0.version]: v5_9_0,
105
+ [v5_10_0.version]: v5_10_0,
97
106
  }
98
107
 
99
108
  export function getRecipe(version: string): UpgradeRecipe | undefined {
package/src/review.ts CHANGED
@@ -17,6 +17,8 @@ import type { CheckResult } from "./check.ts"
17
17
  import type { CommandCtx, CommandSpec } from "./command-catalog.ts"
18
18
  import type { Diagnostic } from "./diagnostics.ts"
19
19
  import { diagnosticCompatibilityOf, toSarifLog } from "./diagnostics.ts"
20
+ import { codeUnitOrder } from "./internal/code-unit-order.ts"
21
+ import { isRecord } from "./internal/record.ts"
20
22
  import { RULE_CODES } from "./rules/codes.ts"
21
23
  import { LEGACY_RULE_CODES } from "./rules/legacy.ts"
22
24
 
@@ -43,10 +45,6 @@ const REVIEW_INPUT_KEYS = new Set(["strict", "diff", "sarif", "fix", "dryRun", "
43
45
  const CODE_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
44
46
  const SAFE_GIT_REF = /^[A-Za-z0-9][A-Za-z0-9._/@+-]{0,255}$/
45
47
 
46
- function compareText(left: string, right: string): number {
47
- return left < right ? -1 : left > right ? 1 : 0
48
- }
49
-
50
48
  const CHECK_IDS: readonly ReviewCheckId[] = [
51
49
  "typecheck",
52
50
  "typed-client",
@@ -164,6 +162,9 @@ export const CHECK_CODES: Readonly<Record<string, ReviewCheckId>> = {
164
162
  "NF-C045": "typed-client",
165
163
  "NF-C054": "typed-client",
166
164
  "NF-C055": "route-boundary",
165
+ "NF-C056": "route-boundary",
166
+ "NF-C057": "typed-client",
167
+ "NF-C058": "typed-client",
167
168
  "NF-C046": "dependency",
168
169
  "NF-D001": "dependency",
169
170
  "NF-D002": "dependency",
@@ -199,10 +200,6 @@ const REVIEW_INPUT_SCHEMA = {
199
200
  additionalProperties: false,
200
201
  } as const
201
202
 
202
- function isRecord(value: unknown): value is Record<string, unknown> {
203
- return typeof value === "object" && value !== null && !Array.isArray(value)
204
- }
205
-
206
203
  function optionalBoolean(raw: Record<string, unknown>, key: string): boolean | undefined {
207
204
  const value = raw[key]
208
205
  if (value === undefined) return undefined
@@ -485,7 +482,7 @@ async function diffScope(cwd: string, ref: string): Promise<ReviewScope> {
485
482
  const untracked = await runGit(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])
486
483
  if (!changed.ok || !untracked.ok) throw new ReviewInputError("invalid git scope")
487
484
  const paths = [...new Set([...nulPaths(changed.stdout), ...nulPaths(untracked.stdout)])].sort(
488
- compareText,
485
+ codeUnitOrder,
489
486
  )
490
487
  if (
491
488
  paths.some(
@@ -630,14 +627,17 @@ async function composeCollectedReport(
630
627
  const leftLocation = normalizedLocation(cwd, left.diagnostic.file, left.diagnostic.line)
631
628
  const rightLocation = normalizedLocation(cwd, right.diagnostic.file, right.diagnostic.line)
632
629
  return (
633
- compareText(normalizedCode(left.diagnostic.code), normalizedCode(right.diagnostic.code)) ||
634
- compareText(
630
+ codeUnitOrder(
631
+ normalizedCode(left.diagnostic.code),
632
+ normalizedCode(right.diagnostic.code),
633
+ ) ||
634
+ codeUnitOrder(
635
635
  normalizedSeverity(left.diagnostic.severity),
636
636
  normalizedSeverity(right.diagnostic.severity),
637
637
  ) ||
638
- compareText(leftLocation?.path ?? "", rightLocation?.path ?? "") ||
638
+ codeUnitOrder(leftLocation?.path ?? "", rightLocation?.path ?? "") ||
639
639
  (leftLocation?.line ?? 0) - (rightLocation?.line ?? 0) ||
640
- compareText(left.diagnostic.fix?.recipe ?? "", right.diagnostic.fix?.recipe ?? "") ||
640
+ codeUnitOrder(left.diagnostic.fix?.recipe ?? "", right.diagnostic.fix?.recipe ?? "") ||
641
641
  left.index - right.index
642
642
  )
643
643
  })
@@ -773,7 +773,7 @@ async function composeCollectedReport(
773
773
  findings.flatMap((finding) => (finding.fix === undefined ? [] : [finding.fix.recipe])),
774
774
  ),
775
775
  ]
776
- .sort(compareText)
776
+ .sort(codeUnitOrder)
777
777
  .map((recipe): ReviewFixResult => ({ recipe, status: "planned" }))
778
778
  : undefined
779
779
  const draft: ReviewReportDraft = {
@@ -825,7 +825,7 @@ async function safeChangedPaths(cwd: string, paths: readonly string[]): Promise<
825
825
  if (relativePath.length > 0 && relativePath !== ".." && !relativePath.startsWith("../"))
826
826
  result.push(relativePath)
827
827
  }
828
- return [...new Set(result)].sort(compareText)
828
+ return [...new Set(result)].sort(codeUnitOrder)
829
829
  }
830
830
 
831
831
  async function applyRequestedFixes(
@@ -54,6 +54,9 @@ export const RULE_CODES = Object.freeze({
54
54
  "NF-C053": "Partially prerendered page reads the request",
55
55
  "NF-C054": "Route without a response schema in a published document",
56
56
  "NF-C055": "zod coerce.boolean() reads request text",
57
+ "NF-C056": "serverFunctions namespace differs from its module's filename",
58
+ "NF-C057": "Internal link to a path no page serves",
59
+ "NF-C058": "Internal link written as a path string",
57
60
  "NF-D001": "Doctor check",
58
61
  "NF-D002": "Mixed nifra versions",
59
62
  "NF-D003": "Stale file: dependencies in bun.lock",
@@ -8,12 +8,13 @@
8
8
  * A contract imported from a workspace package is read through that package's `exports`.
9
9
  * Re-exports on the way to a contract, and `...operations` spreads inside one, are followed.
10
10
  */
11
- import { existsSync, readFileSync, realpathSync } from "node:fs"
11
+ import { existsSync, readFileSync } from "node:fs"
12
12
  import { join, relative } from "node:path"
13
13
  import type * as TSApi from "typescript"
14
14
  import { BACKEND_APP_FILE } from "../app-files.ts"
15
15
  import { type Diagnostic, diagnostic } from "../diagnostics.ts"
16
16
  import { createSpecifierResolver, type SpecifierResolver } from "../internal/project-specifiers.ts"
17
+ import { realpathOrSelf } from "../internal/realpath-or-self.ts"
17
18
  import { scriptKindOf } from "../internal/script-kind.ts"
18
19
  import { createExportedFileResolver } from "../internal/workspace-packages.ts"
19
20
  import type { CheckRule } from "./index.ts"
@@ -233,13 +234,7 @@ export const contractVisibilityRule: CheckRule = {
233
234
  return undefined
234
235
  }
235
236
  // The resolver answers with real paths, so the root is read as one to name files project-relative.
236
- const realRoot = (() => {
237
- try {
238
- return realpathSync(ctx.root)
239
- } catch {
240
- return ctx.root
241
- }
242
- })()
237
+ const realRoot = realpathOrSelf(ctx.root)
243
238
  const parsedCache = new Map<string, Parsed | undefined>()
244
239
  /** A project file, by its project-relative name, parsed with its contract bindings. */
245
240
  const parse = (file: string, text: string | undefined): Parsed | undefined => {
@@ -8,18 +8,17 @@
8
8
  * refuses (an object, array, string, number or boolean) and a warning otherwise, since only running
9
9
  * the loader proves what an expression evaluates to.
10
10
  */
11
- import { realpathSync } from "node:fs"
12
11
  import { isAbsolute, join, relative } from "node:path"
13
12
  import { isSensitiveFieldName } from "@nifrajs/web/zones"
14
13
  import { codePositionMask } from "../check-scan.ts"
15
14
  import { type Diagnostic, diagnostic } from "../diagnostics.ts"
16
15
  import { codeUnitOrder } from "../internal/code-unit-order.ts"
16
+ import { lineAt } from "../internal/line-at.ts"
17
17
  import { createSpecifierResolver } from "../internal/project-specifiers.ts"
18
+ import { realpathOrSelf } from "../internal/realpath-or-self.ts"
18
19
  import type { CheckRule } from "./index.ts"
19
20
  import { zonedFiles } from "./zones.ts"
20
21
 
21
- const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
22
-
23
22
  const byPlace = (a: Diagnostic, b: Diagnostic): number =>
24
23
  codeUnitOrder(a.file ?? "", b.file ?? "") || (a.line ?? 0) - (b.line ?? 0)
25
24
 
@@ -453,13 +452,7 @@ export const sensitiveOutputRule: CheckRule = {
453
452
  async scan(ctx) {
454
453
  const findings: Diagnostic[] = []
455
454
  const resolve = createSpecifierResolver()
456
- const realRoot = (() => {
457
- try {
458
- return realpathSync(ctx.root)
459
- } catch {
460
- return ctx.root
461
- }
462
- })()
455
+ const realRoot = realpathOrSelf(ctx.root)
463
456
  const sources = new Map<string, SchemaSource | undefined>()
464
457
  const sourceOf = (file: string): SchemaSource | undefined => {
465
458
  if (!sources.has(file)) {
@@ -289,6 +289,21 @@ export const RULE_EXPLANATIONS: Readonly<Record<BuiltInCode, RuleExplanation>> =
289
289
  fix: "Use `z.stringbool()`, which reads `true`/`1`/`yes`/`on` as true, `false`/`0`/`no`/`off` as false, and refuses other text. A use kept on purpose takes `// nifra-expect NF-C055: <reason>` above the call.",
290
290
  docs: "/docs/api",
291
291
  },
292
+ "NF-C056": {
293
+ why: "The client build calls the namespace named by a `*.fn.ts` file (`todos.fn.ts` posts under `todos`). A `serverFunctions` mount under another word serves routes the stubs never reach, so every call 404s.",
294
+ fix: 'Pass the filename\'s namespace to `serverFunctions` (`serverFunctions("todos", todos)` for `todos.fn.ts`), or rename the file. A mount kept on purpose takes `// nifra-expect NF-C056: <reason>` above the call.',
295
+ docs: "/docs/server-functions",
296
+ },
297
+ "NF-C057": {
298
+ why: "An `<a href>` names a path that no page of the app, no backend route and no file in `public/` serves, so following it is a 404. Nothing fails at build time: a path string is invisible to the types, and a renamed or removed page leaves every link to it dead.",
299
+ fix: "Build the link with `href({ to, params })` (exported by `@nifrajs/web-<framework>/router`): `to` is a route of the app, so a route that does not exist is a compile error. A path some other server answers takes `rawHref(path)`; a link kept on purpose takes `// nifra-expect NF-C057: <reason>` above the attribute.",
300
+ docs: "/docs/routing",
301
+ },
302
+ "NF-C058": {
303
+ why: "An `<a href>` writes a page's path as a string. It works today, but renaming or removing the page leaves the link dead and nothing fails: `href()` checks a link against the app's routes, a path string is not checked.",
304
+ fix: "Build the link with `href({ to, params, search, hash })`, which `nifra check` and `tsc` hold to the app's routes. A path built elsewhere, such as a CMS link, takes `rawHref(path)`; a link kept on purpose takes `// nifra-expect NF-C058: <reason>` above the attribute. Silence the code for the project with `rules` in `nifra.config`.",
305
+ docs: "/docs/routing",
306
+ },
292
307
  "NF-D001": {
293
308
  why: "The doctor gate of `nifra assure` found an undeclared import or a package installed more than once.",
294
309
  fix: "Run `nifra doctor` for the details and the fix of each finding.",