@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
package/src/mcp-run.ts CHANGED
@@ -21,9 +21,11 @@ import { BACKEND_APP_FILE } from "./app-files.ts"
21
21
  import {
22
22
  CHILD_INPUT_MAX_BYTES,
23
23
  CHILD_OUTPUT_MAX_BYTES,
24
- readBoundedLines,
25
24
  readBoundedStream,
25
+ redirectConsoleToStderr,
26
26
  serializeBoundedJson,
27
+ workerReplyWriter,
28
+ workerRequests,
27
29
  } from "./mcp-io.ts"
28
30
 
29
31
  const ENTRY_CANDIDATES = [BACKEND_APP_FILE, "app.ts", "src/app.ts"]
@@ -163,28 +165,6 @@ function withCapture(feed: DevFeed, requestId: string, result: RunResult): RunRe
163
165
  return { ...result, ...capture }
164
166
  }
165
167
 
166
- interface WorkerMessage {
167
- readonly id?: unknown
168
- readonly input?: { readonly requests?: unknown; readonly entry?: string }
169
- }
170
-
171
- function redirectConsoleToStderr(): void {
172
- const write = (level: string, args: unknown[]): void => {
173
- Bun.stderr.write(`[${level}] ${args.map((arg) => String(arg)).join(" ")}\n`)
174
- }
175
- console.debug = (...args: unknown[]) => write("debug", args)
176
- console.info = (...args: unknown[]) => write("info", args)
177
- console.log = (...args: unknown[]) => write("log", args)
178
- console.warn = (...args: unknown[]) => write("warn", args)
179
- console.error = (...args: unknown[]) => write("error", args)
180
- }
181
-
182
- function safeResponseId(value: unknown): number | string | null {
183
- if (typeof value === "number" && Number.isSafeInteger(value)) return value
184
- if (typeof value === "string" && value.length <= 128) return value
185
- return null
186
- }
187
-
188
168
  /**
189
169
  * Keep stdout for the protocol. The app's console and any direct `process.stdout.write` go to stderr,
190
170
  * or a stray `console.log` in a handler would corrupt the JSON the parent reads. Returns the writer
@@ -206,37 +186,8 @@ function reserveStdout(): (text: string) => void {
206
186
 
207
187
  async function runWorker(cwd: string, protocol: (text: string) => void): Promise<void> {
208
188
  const apps = new Map<string, Promise<{ app: AppLike } | { error: string }>>()
209
- const send = (id: unknown, output: unknown): void => {
210
- const responseId = safeResponseId(id)
211
- const encoded = serializeBoundedJson({ id: responseId, output }, CHILD_OUTPUT_MAX_BYTES - 1)
212
- protocol(
213
- `${encoded ?? JSON.stringify({ id: responseId, output: { error: "worker output exceeded the size limit" } })}\n`,
214
- )
215
- }
216
- for await (const item of readBoundedLines(Bun.stdin.stream(), CHILD_INPUT_MAX_BYTES)) {
217
- if (item.kind === "too-large") {
218
- send(null, { error: `worker input exceeded ${CHILD_INPUT_MAX_BYTES} bytes` })
219
- continue
220
- }
221
- const line = item.text.trim()
222
- if (line === "") continue
223
-
224
- let message: unknown
225
- try {
226
- message = JSON.parse(line) as unknown
227
- } catch {
228
- send(null, { error: "invalid worker input: expected JSON line" })
229
- continue
230
- }
231
- const record =
232
- message !== null && typeof message === "object" && !Array.isArray(message)
233
- ? (message as WorkerMessage)
234
- : undefined
235
- const input =
236
- record?.input !== null && typeof record?.input === "object" && !Array.isArray(record.input)
237
- ? record.input
238
- : undefined
239
- const id = record?.id
189
+ const send = workerReplyWriter(protocol)
190
+ for await (const { id, input } of workerRequests(send)) {
240
191
  const requests = input?.requests
241
192
  const entry = input?.entry
242
193
  if (!Array.isArray(requests)) {
@@ -177,7 +177,6 @@ export const PROJECT_TOOL_META: Readonly<Record<string, ToolMeta>> = {
177
177
  },
178
178
  },
179
179
  nifra_sync_manifest: { annotations: WRITE, fields: { json: JSON_RESULT, dir: DIR } },
180
- nifra_sync_routes: { annotations: WRITE, fields: { json: JSON_RESULT, dir: DIR } },
181
180
  nifra_prove: {
182
181
  annotations: EXECUTE,
183
182
  fields: {
package/src/mcp-ws.ts CHANGED
@@ -6,6 +6,8 @@
6
6
  * general-purpose network client.
7
7
  */
8
8
 
9
+ import { hasControlCharacter } from "./internal/control-character.ts"
10
+ import { redirectConsoleToStderr } from "./mcp-io.ts"
9
11
  import { loadBackend } from "./mcp-run.ts"
10
12
 
11
13
  const DEFAULT_TIMEOUT_MS = 3_000
@@ -53,14 +55,6 @@ export interface WebSocketVerificationResult {
53
55
  const errString = (err: unknown): string =>
54
56
  err instanceof Error ? `${err.name}: ${err.message}` : String(err)
55
57
 
56
- function hasControlCharacter(value: string): boolean {
57
- for (let i = 0; i < value.length; i++) {
58
- const code = value.charCodeAt(i)
59
- if (code < 0x20 || code === 0x7f) return true
60
- }
61
- return false
62
- }
63
-
64
58
  function fail(
65
59
  path: string,
66
60
  sent: readonly string[],
@@ -171,17 +165,6 @@ function closeInfo(event: CloseEvent): CloseInfo {
171
165
  return { code: event.code, reason: event.reason, wasClean: event.wasClean }
172
166
  }
173
167
 
174
- function redirectConsoleToStderr(): void {
175
- const write = (level: string, args: unknown[]): void => {
176
- Bun.stderr.write(`[${level}] ${args.map((arg) => String(arg)).join(" ")}\n`)
177
- }
178
- console.debug = (...args: unknown[]) => write("debug", args)
179
- console.info = (...args: unknown[]) => write("info", args)
180
- console.log = (...args: unknown[]) => write("log", args)
181
- console.warn = (...args: unknown[]) => write("warn", args)
182
- console.error = (...args: unknown[]) => write("error", args)
183
- }
184
-
185
168
  export async function runWebSocket(
186
169
  cwd: string,
187
170
  args: unknown,
@@ -30,7 +30,6 @@ import {
30
30
  mkdirSync,
31
31
  readdirSync,
32
32
  readFileSync,
33
- realpathSync,
34
33
  renameSync,
35
34
  rmdirSync,
36
35
  rmSync,
@@ -45,8 +44,11 @@ import type * as TS from "typescript"
45
44
  import { BACKEND_APP_FILE, CONFIG_FILE, FRAMEWORK_FILE, retiredRootFiles } from "./app-files.ts"
46
45
  import { codeUnitOrder } from "./internal/code-unit-order.ts"
47
46
  import { configPathReader, type StaticConfigPath } from "./internal/config-paths.ts"
47
+ import { escapeRegExp } from "./internal/escape-regexp.ts"
48
48
  import { createKindProbe, hasWebConfig } from "./internal/nifra-project.ts"
49
+ import { toPosix } from "./internal/posix-path.ts"
49
50
  import { createSpecifierResolver, isFile } from "./internal/project-specifiers.ts"
51
+ import { realpathOrSelf } from "./internal/realpath-or-self.ts"
50
52
  import { importTypeScript } from "./internal/typescript-import.ts"
51
53
  import { type OutputSchemaEntry, planOutputSchemas } from "./output-schemas.ts"
52
54
  import { missingOutputSchemas } from "./rules/data-guard.ts"
@@ -171,8 +173,6 @@ export interface LayoutMigrationOptions {
171
173
  /** A file's text, as the migration sees it before writing. */
172
174
  type Files = Map<string, string>
173
175
 
174
- const toPosix = (path: string): string => path.replaceAll("\\", "/")
175
-
176
176
  /** A specifier without its `?query` or `#hash`; a leading `#` names a package.json import. Cut by
177
177
  * index, since `/[?#].*$/` retries from every `#` and is quadratic on a long run of them. */
178
178
  const withoutQuery = (specifier: string): string => {
@@ -466,8 +466,6 @@ function filterExportList(
466
466
  return `${leading}export ${node.isTypeOnly ? "type " : ""}{ ${kept.join(", ")} }${from}${terminatorOf(sf, node)}`
467
467
  }
468
468
 
469
- const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
470
-
471
469
  const joinStatements = (texts: readonly string[]): string => {
472
470
  const body = texts.join("").replace(/^\s*\n/, "")
473
471
  return body.endsWith("\n") ? body : `${body}\n`
@@ -1044,6 +1042,21 @@ function scriptBlocks(
1044
1042
  return blocks
1045
1043
  }
1046
1044
 
1045
+ /** A replacement of the source between `start` and `end`. */
1046
+ interface TextEdit {
1047
+ start: number
1048
+ end: number
1049
+ text: string
1050
+ }
1051
+
1052
+ /** `text` with every edit made, last offset first so the ones before it still point where they did. */
1053
+ function applyEdits(text: string, edits: TextEdit[]): string {
1054
+ let out = text
1055
+ for (const edit of edits.sort((a, b) => b.start - a.start))
1056
+ out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
1057
+ return out
1058
+ }
1059
+
1047
1060
  // ---------------------------------------------------------------------------------------------------
1048
1061
  // Import graph + zoning
1049
1062
  // ---------------------------------------------------------------------------------------------------
@@ -1374,7 +1387,7 @@ function rebaseShellPaths(
1374
1387
  locate: (target: string) => string,
1375
1388
  ): { readonly text: string; readonly unfollowed: string | undefined } {
1376
1389
  let unfollowed: string | undefined
1377
- const edits: Array<{ start: number; end: number; text: string }> = []
1390
+ const edits: TextEdit[] = []
1378
1391
  for (const match of text.matchAll(SHELL_OWN_DIR)) {
1379
1392
  const start = match.index + match[0].length
1380
1393
  const trailing = /^\/([\w.@-]+(?:\/[\w.@-]+)*\/?)/.exec(text.slice(start))?.[1]
@@ -1457,7 +1470,7 @@ function rebaseOwnPaths(
1457
1470
  true,
1458
1471
  to.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
1459
1472
  )
1460
- const edits: Array<{ start: number; end: number; text: string }> = []
1473
+ const edits: TextEdit[] = []
1461
1474
  const followed: Array<readonly [number, number]> = []
1462
1475
  const aliases = ownDirAliases(ts, sf)
1463
1476
  const isOwnDir = (node: TS.Node | undefined): node is TS.Expression =>
@@ -1571,10 +1584,7 @@ function rebaseOwnPaths(
1571
1584
  const unfollowed = [...text.matchAll(new RegExp(SELF_LOCATION.source, "g"))].find(
1572
1585
  (match) => !followed.some(([start, end]) => start <= match.index && match.index < end),
1573
1586
  )?.[0]
1574
- let next = text
1575
- for (const edit of edits.sort((a, b) => b.start - a.start))
1576
- next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
1577
- return { text: next, unfollowed }
1587
+ return { text: applyEdits(text, edits), unfollowed }
1578
1588
  }
1579
1589
 
1580
1590
  /** Rewrite one relative specifier from `from`'s new location to `target`'s new location, keeping the
@@ -1660,7 +1670,7 @@ function redirectMovedImports(
1660
1670
  true,
1661
1671
  file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS,
1662
1672
  )
1663
- const edits: Array<{ start: number; end: number; text: string }> = []
1673
+ const edits: TextEdit[] = []
1664
1674
  const issues: string[] = []
1665
1675
  const mentioned = (split: SplitTarget, pattern: (name: string) => RegExp): string[] =>
1666
1676
  [...split.moved].filter((name) => pattern(escapeRegExp(name)).test(text)).sort()
@@ -1756,10 +1766,7 @@ function redirectMovedImports(
1756
1766
  ts.forEachChild(node, visit)
1757
1767
  }
1758
1768
  visit(sf)
1759
- let out = text
1760
- for (const edit of edits.sort((a, b) => b.start - a.start))
1761
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
1762
- return { text: out, issues, redirects }
1769
+ return { text: applyEdits(text, edits), issues, redirects }
1763
1770
  }
1764
1771
 
1765
1772
  /**
@@ -1822,7 +1829,7 @@ function dynamicReads(
1822
1829
  function workspacePattern(glob: string): RegExp {
1823
1830
  const source = glob
1824
1831
  .replace(/^\.\//, "")
1825
- .replace(/\/+$/, "")
1832
+ .replace(/(?<!\/)\/+$/, "")
1826
1833
  .split("/")
1827
1834
  .map((segment) =>
1828
1835
  segment === "**"
@@ -1989,12 +1996,7 @@ function rewriteImports(
1989
1996
  text: string,
1990
1997
  rewrite: (specifier: string) => string | undefined,
1991
1998
  ): string {
1992
- const replace = (
1993
- code: string,
1994
- offset: number,
1995
- out: Array<{ start: number; end: number; text: string }>,
1996
- kind: TS.ScriptKind,
1997
- ): void => {
1999
+ const replace = (code: string, offset: number, out: TextEdit[], kind: TS.ScriptKind): void => {
1998
2000
  const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, kind)
1999
2001
  const visit = (node: TS.Node): void => {
2000
2002
  let literal: TS.StringLiteralLike | undefined
@@ -2032,39 +2034,34 @@ function rewriteImports(
2032
2034
  }
2033
2035
  visit(sf)
2034
2036
  }
2035
- const edits: Array<{ start: number; end: number; text: string }> = []
2036
- if (/\.(?:svelte|vue)$/.test(file)) {
2037
- for (const block of scriptBlocks(text))
2038
- replace(text.slice(block.start, block.end), block.start, edits, ts.ScriptKind.TS)
2039
- } else if (file.endsWith(".css")) {
2040
- for (const match of text.matchAll(/(@import\s+(?:url\()?["'])([^"']+)["']/g)) {
2037
+ const edits: TextEdit[] = []
2038
+ // A match's group 2 is the specifier; group 1 is everything before it.
2039
+ const rewriteMatches = (pattern: RegExp): void => {
2040
+ for (const match of text.matchAll(pattern)) {
2041
2041
  const next = rewrite(match[2] ?? "")
2042
2042
  if (next !== undefined) {
2043
2043
  const start = (match.index ?? 0) + (match[1] ?? "").length
2044
2044
  edits.push({ start, end: start + (match[2] ?? "").length, text: next })
2045
2045
  }
2046
2046
  }
2047
+ }
2048
+ if (/\.(?:svelte|vue)$/.test(file)) {
2049
+ for (const block of scriptBlocks(text))
2050
+ replace(text.slice(block.start, block.end), block.start, edits, ts.ScriptKind.TS)
2051
+ } else if (file.endsWith(".css")) {
2052
+ rewriteMatches(/(@import\s+(?:url\()?["'])([^"']+)["']/g)
2047
2053
  } else if (file.endsWith(".mdx")) {
2048
- for (const match of text.matchAll(/^((?:import|export)\s[^\n]*?from\s+["'])([^"']+)["']/gm)) {
2049
- const next = rewrite(match[2] ?? "")
2050
- if (next !== undefined) {
2051
- const start = (match.index ?? 0) + (match[1] ?? "").length
2052
- edits.push({ start, end: start + (match[2] ?? "").length, text: next })
2053
- }
2054
- }
2054
+ rewriteMatches(/^((?:import|export)\s[^\n]*?from\s+["'])([^"']+)["']/gm)
2055
2055
  } else if (/\.[cm]?[jt]sx?$/.test(file)) {
2056
2056
  replace(text, 0, edits, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS)
2057
2057
  }
2058
- let out = text
2059
- for (const edit of edits.sort((a, b) => b.start - a.start))
2060
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
2061
- return out
2058
+ return applyEdits(text, edits)
2062
2059
  }
2063
2060
 
2064
2061
  /** `ServerOnly` imported from `@nifrajs/web` becomes `BackendOnly`, along with every use of it. */
2065
2062
  function renameRetiredTypes(ts: typeof TS, file: string, text: string): string {
2066
2063
  if (!text.includes("ServerOnly")) return text
2067
- const edits: Array<{ start: number; end: number; text: string }> = []
2064
+ const edits: TextEdit[] = []
2068
2065
  const scan = (code: string, offset: number, kind: TS.ScriptKind): void => {
2069
2066
  const sf = ts.createSourceFile(file, code, ts.ScriptTarget.Latest, true, kind)
2070
2067
  const rename = (node: TS.Node): void => {
@@ -2103,10 +2100,7 @@ function renameRetiredTypes(ts: typeof TS, file: string, text: string): string {
2103
2100
  } else if (/\.[cm]?[jt]sx?$/.test(file)) {
2104
2101
  scan(text, 0, file.endsWith("x") ? ts.ScriptKind.TSX : ts.ScriptKind.TS)
2105
2102
  }
2106
- let out = text
2107
- for (const edit of edits.sort((a, b) => b.start - a.start))
2108
- out = out.slice(0, edit.start) + edit.text + out.slice(edit.end)
2109
- return out
2103
+ return applyEdits(text, edits)
2110
2104
  }
2111
2105
 
2112
2106
  // ---------------------------------------------------------------------------------------------------
@@ -2363,13 +2357,7 @@ export async function migrateLayout(
2363
2357
  const resolver = createSpecifierResolver({
2364
2358
  moduleExists: (path) => knownPaths.has(path) || isFile(path),
2365
2359
  })
2366
- const realRoot = (() => {
2367
- try {
2368
- return realpathSync(root)
2369
- } catch {
2370
- return root
2371
- }
2372
- })()
2360
+ const realRoot = realpathOrSelf(root)
2373
2361
  /** An app file as the migration names it, from a path the resolver found (real, or as planned). */
2374
2362
  const appFile = (path: string | undefined): string | undefined => {
2375
2363
  if (path === undefined) return undefined
@@ -2821,7 +2809,7 @@ export async function migrateLayout(
2821
2809
  const at = newPath(file)
2822
2810
  const text = final.get(at)
2823
2811
  if (text === undefined) continue
2824
- const edits: Array<{ start: number; end: number; text: string }> = []
2812
+ const edits: TextEdit[] = []
2825
2813
  for (const call of globCalls(ts, at, text)) {
2826
2814
  if (!call.literal) continue
2827
2815
  const written = call.patterns.map((pattern) => pattern.text)
@@ -2848,10 +2836,7 @@ export async function migrateLayout(
2848
2836
  })
2849
2837
  }
2850
2838
  if (edits.length === 0) continue
2851
- let updated = text
2852
- for (const edit of edits.sort((a, b) => b.start - a.start))
2853
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
2854
- final.set(at, updated)
2839
+ final.set(at, applyEdits(text, edits))
2855
2840
  if (!moveMap.has(file) && !rewritten.includes(file)) rewritten.push(file)
2856
2841
  }
2857
2842
 
@@ -2861,7 +2846,7 @@ export async function migrateLayout(
2861
2846
  const at = newPath(configFile)
2862
2847
  const text = final.get(at)
2863
2848
  if (text === undefined || !next.has(configFile)) continue
2864
- const edits: Array<{ start: number; end: number; text: string }> = []
2849
+ const edits: TextEdit[] = []
2865
2850
  for (const entry of configEntries(ts, at, text)) {
2866
2851
  if (entry.span === undefined) continue
2867
2852
  const target = resolveAny("nifra.config.ts", entry.path)
@@ -2872,10 +2857,7 @@ export async function migrateLayout(
2872
2857
  if (value !== undefined) edits.push({ start: entry.span[0], end: entry.span[1], text: value })
2873
2858
  }
2874
2859
  if (edits.length === 0) continue
2875
- let updated = text
2876
- for (const edit of edits.sort((a, b) => b.start - a.start))
2877
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
2878
- final.set(at, updated)
2860
+ final.set(at, applyEdits(text, edits))
2879
2861
  if (!moveMap.has(configFile) && !rewritten.includes(configFile)) rewritten.push(configFile)
2880
2862
  }
2881
2863
 
@@ -3304,7 +3286,10 @@ const matchers = new Map<string, (file: string) => boolean>()
3304
3286
  function matches(pattern: string, file: string): boolean {
3305
3287
  let match = matchers.get(pattern)
3306
3288
  if (match === undefined) {
3307
- let spec = pattern.replaceAll("\\", "/").replace(/^\.\//, "").replace(/\/+$/, "")
3289
+ let spec = pattern
3290
+ .replaceAll("\\", "/")
3291
+ .replace(/^\.\//, "")
3292
+ .replace(/(?<!\/)\/+$/, "")
3308
3293
  if (spec === "" || spec === ".") match = () => true
3309
3294
  else if (!/[*?]/.test(spec)) {
3310
3295
  const folder = `${spec}/`
@@ -3398,7 +3383,7 @@ function followTsconfigs(
3398
3383
  const inherited = parent === undefined ? undefined : settled.get(parent)
3399
3384
  const extendsOther = base !== undefined && inherited === undefined
3400
3385
 
3401
- const edits: Array<{ start: number; end: number; text: string }> = []
3386
+ const edits: TextEdit[] = []
3402
3387
  const own = new Map<string, { before: string[]; after: string[] }>()
3403
3388
  let malformed: string | undefined
3404
3389
  for (const key of ["include", "exclude", "files"]) {
@@ -3427,9 +3412,7 @@ function followTsconfigs(
3427
3412
  }
3428
3413
  own.set(key, lists)
3429
3414
  }
3430
- let updated = text
3431
- for (const edit of edits.sort((a, b) => b.start - a.start))
3432
- updated = updated.slice(0, edit.start) + edit.text + updated.slice(edit.end)
3415
+ let updated = applyEdits(text, edits)
3433
3416
  const changes: string[] = []
3434
3417
  if (edits.length > 0) changes.push(`${edits.length} file path(s) follow their moved files`)
3435
3418
 
@@ -3780,7 +3763,7 @@ function rewritePackagePaths(
3780
3763
  `(?<![\\w.@/-])(\\./)?(${ordered.map(([from]) => escapeRegExp(from)).join("|")})(?![\\w/-]|\\.\\w)`,
3781
3764
  "g",
3782
3765
  )
3783
- const edits: Array<{ start: number; end: number; text: string }> = []
3766
+ const edits: TextEdit[] = []
3784
3767
  let count = 0
3785
3768
  const visit = (node: TS.Node, field: string): void => {
3786
3769
  if (ts.isStringLiteral(node)) {
@@ -3813,10 +3796,7 @@ function rewritePackagePaths(
3813
3796
  if (!ts.isPropertyAssignment(property) || !ts.isStringLiteral(property.name)) continue
3814
3797
  if (PACKAGE_PATH_FIELDS.has(property.name.text)) visit(property.initializer, property.name.text)
3815
3798
  }
3816
- let next = text
3817
- for (const edit of edits.sort((a, b) => b.start - a.start))
3818
- next = next.slice(0, edit.start) + edit.text + next.slice(edit.end)
3819
- return { text: next, count }
3799
+ return { text: applyEdits(text, edits), count }
3820
3800
  }
3821
3801
 
3822
3802
  /** Tailwind `content` globs that matched a moved file at its old path and match nothing at its new one. */
@@ -15,6 +15,8 @@ import { isSensitiveFieldName } from "@nifrajs/web/zones"
15
15
  import type * as TSApi from "typescript"
16
16
  import { codePositionMask } from "./check-scan.ts"
17
17
  import { codeUnitOrder } from "./internal/code-unit-order.ts"
18
+ import { lineAt } from "./internal/line-at.ts"
19
+ import { toPosix } from "./internal/posix-path.ts"
18
20
  import {
19
21
  loadProjectTypeScript,
20
22
  type TypeScriptApi,
@@ -480,7 +482,7 @@ function schemaTokens(text: string): string {
480
482
  i++
481
483
  }
482
484
  }
483
- return out.replace(/,(?=[}\])])/g, "").replace(/;+$/, "")
485
+ return out.replace(/,(?=[}\])])/g, "").replace(/(?<!;);+$/, "")
484
486
  }
485
487
 
486
488
  function declarationText(schema: OutputExport, fn: RouteFn, body: string): string {
@@ -506,8 +508,6 @@ interface ProbeResult {
506
508
  readonly warnings: readonly string[]
507
509
  }
508
510
 
509
- const posix = (path: string): string => path.replaceAll("\\", "/")
510
-
511
511
  const PROBE_HELPERS = [
512
512
  "type __NifraReturned<M, F extends string> = M extends { readonly [K in F]: (...args: any) => infer R } ? Awaited<R> : never",
513
513
  'type __NifraDeclared<M, N extends string> = M extends { readonly [K in N]: infer S } ? S extends { readonly "~standard": { readonly types?: infer T } } ? NonNullable<T> extends { readonly output: infer O } ? O : never : never : never',
@@ -520,7 +520,7 @@ function probeSource(routes: readonly ProbeRoute[]): {
520
520
  const lines = [...PROBE_HELPERS]
521
521
  const names = new Map<string, string>()
522
522
  routes.forEach((route, i) => {
523
- const rel = posix(route.file)
523
+ const rel = toPosix(route.file)
524
524
  lines.push(
525
525
  `import type * as __nifra_m${i} from ${JSON.stringify(rel.startsWith(".") ? rel : `./${rel}`)}`,
526
526
  )
@@ -701,7 +701,7 @@ async function readShapes(
701
701
  let close: (() => Promise<void>) | undefined
702
702
  try {
703
703
  await writeFile(probePath, probe, "utf8")
704
- const include = [...routes.map((route) => posix(route.file)), basename(probePath)]
704
+ const include = [...routes.map((route) => toPosix(route.file)), basename(probePath)]
705
705
  await writeFile(
706
706
  probeConfigPath,
707
707
  JSON.stringify(
@@ -810,7 +810,7 @@ function overlaidHost(
810
810
  contents: ReadonlyMap<string, string>,
811
811
  ): TSApi.CompilerHost {
812
812
  const host = ts.createCompilerHost(options, true)
813
- const key = (file: string): string => posix(ts.sys.resolvePath(file))
813
+ const key = (file: string): string => toPosix(ts.sys.resolvePath(file))
814
814
  const overlay = new Map([...contents].map(([file, text]) => [key(file), text]))
815
815
  const folders = new Set<string>()
816
816
  for (const file of overlay.keys())
@@ -893,7 +893,6 @@ interface Target {
893
893
  readonly declaration: SchemaDeclaration | null | undefined
894
894
  }
895
895
 
896
- const lineAt = (text: string, index: number): number => text.slice(0, index).split("\n").length
897
896
  const lineStart = (text: string, index: number): number => text.lastIndexOf("\n", index - 1) + 1
898
897
 
899
898
  /** The start of the comment block directly above the line at `start`, or `start`. */
@@ -1183,7 +1182,7 @@ function routeBackends(dir: string): string[] {
1183
1182
  const routes = join(dir, "routes")
1184
1183
  if (!existsSync(routes)) return []
1185
1184
  return readdirSync(routes, { recursive: true, encoding: "utf8" })
1186
- .map((file) => posix(join("routes", file)))
1185
+ .map((file) => toPosix(join("routes", file)))
1187
1186
  .filter((file) => ROUTE_BACKEND_TS.test(file) && !file.split("/").includes("node_modules"))
1188
1187
  .sort(codeUnitOrder)
1189
1188
  }
package/src/port.ts CHANGED
@@ -19,6 +19,7 @@ import { Glob } from "bun"
19
19
  import { stripComments } from "./check.ts"
20
20
  import { readConfigTarget } from "./config-target.ts"
21
21
  import { codeUnitOrder } from "./internal/code-unit-order.ts"
22
+ import { lineAt } from "./internal/line-at.ts"
22
23
 
23
24
  /** The five deploy targets a nifra `site` app can build for (mirrors create-nifra's DEPLOY presets). */
24
25
  export const TARGETS = ["bun", "node", "deno", "cloudflare", "vercel"] as const
@@ -211,10 +212,6 @@ export interface DetectedFeature {
211
212
  readonly verdicts: Readonly<Record<Target, Verdict>>
212
213
  }
213
214
 
214
- /** Line number (1-based) of a string index. */
215
- const lineAt = (content: string, index: number): number =>
216
- content.slice(0, index).split("\n").length
217
-
218
215
  // --- Detection signals (all matched against comment-stripped source so doc examples don't false-positive) ---
219
216
 
220
217
  // A non-type import (static, side-effect, dynamic, or re-export) from one of these `@nifrajs/*` packages.
@@ -143,9 +143,9 @@ function holeNameOf(local: string): string | undefined {
143
143
  .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
144
144
  .toLowerCase()
145
145
  .replace(/[^a-z0-9]+/g, "-")
146
- .replace(/^[^a-z]+|-+$/g, "")
146
+ .replace(/^[^a-z]+|(?<!-)-+$/g, "")
147
147
  .slice(0, 28)
148
- .replace(/-+$/, "")
148
+ .replace(/(?<!-)-+$/, "")
149
149
  return HOLE_NAME.test(name) ? name : undefined
150
150
  }
151
151
 
@@ -0,0 +1,45 @@
1
+ import type { UpgradeRecipe } from "./index.ts"
2
+
3
+ /**
4
+ * Upgrade recipe for Nifra 5.10.
5
+ *
6
+ * No import or dependency moves. Partial prerendering is stable, so `createWebApp` takes it as `ppr`
7
+ * and the `ppr-option` source rewrite moves `experimental: { ppr }`. In-app links are typed: `navigate`,
8
+ * `redirect` and React's `Link` take an `Href`, and the route table that types it replaces
9
+ * `RouteSearch`. The query cache sends nothing to the browser unless the app names the queries, and
10
+ * an identity change cancels a mutation still running; the notes say what an app sees differently.
11
+ */
12
+ export const recipe: UpgradeRecipe = {
13
+ version: "5.10.0",
14
+ pins: [
15
+ { match: "@nifrajs/", to: "5.10.0" },
16
+ { match: "create-nifra", to: "5.10.0" },
17
+ { match: "nifra", to: "5.10.0" },
18
+ ],
19
+ importMoves: [],
20
+ sourceRewrites: ["ppr-option"],
21
+ affects: [
22
+ "@nifrajs/core",
23
+ "@nifrajs/client",
24
+ "@nifrajs/testing",
25
+ "@nifrajs/web",
26
+ "@nifrajs/web-react",
27
+ "@nifrajs/web-preact",
28
+ "@nifrajs/web-vue",
29
+ "@nifrajs/web-svelte",
30
+ "@nifrajs/web-solid",
31
+ "@nifrajs/cli",
32
+ "nifra",
33
+ ],
34
+ notes: [
35
+ "Partial prerendering is stable: `createWebApp({ ppr: partialPrerendering(...) })` replaces `experimental: { ppr: partialPrerendering(...) }`, and the `experimental` option is removed. Passing it throws a `TypeError` that names `ppr`. The startup errors name `ppr.origin`, `ppr.deployment`, `ppr.store` and `ppr.storeSecret`. The `ppr-option` rewrite moves `experimental: { ppr }` in a `createWebApp` options literal; options with a spread, a second key under `experimental`, or an `experimental` built in another file are listed by line or left for you to check.",
36
+ '`navigate()`, `redirect()` and the React `Link`, `NavLink` and `Navigate` take an `Href`, built by `href({ to, params, search, hash })` from `@nifrajs/web` (or an adapter\'s `/router` entry), or by `rawHref(path)` for a same-origin path built elsewhere. A string path, a template literal and the `{ to, search }` form of `navigate` are compile errors, so `tsc` lists each call: `navigate("/users/7")` becomes `navigate(href({ to: "/users/:id", params: { id: "7" } }))`, `redirect("/login")` becomes `redirect(href({ to: "/login" }))`, `<Link to="/pricing">` becomes `<Link to={href({ to: "/pricing" })}>`, and `navigate({ to, search, replace: true })` becomes `navigate(href({ to, search }), { replace: true })`. `redirect(url, { external: true })` is unchanged. `resolveNavigate`, `NavigateTargetInput` and `NavigateSearchOf` are removed from `@nifrajs/web`. `Link` and `NavLink` render the anchor without an `href`, and log a `console.error`, when `to` is not a same-origin path; `rawHref` throws a `TypeError` for one. `tsc` cannot see plain anchors, so search for `href="/` and ``href={`/``.',
37
+ '`nifra dev`, `nifra build`, `nifra check` and `nifra types` write `.nifra/types/routes.d.ts`, which fills `RouteTable` with one `{ params, search }` entry per URL pattern, and `href()` reads it. A route file that imports no `./+types/...` module does not load it: `nifra check` warns when a source imports a navigation API and no program loads the table, and listing `.nifra/types/routes.d.ts` under `files` in tsconfig.json clears it. `RouteSearch`, `generateRouteSearchTypes`, `GenerateRouteSearchTypesOptions`, `nifra sync-routes` and the `nifra_sync_routes` MCP tool are removed: delete `nifra-routes.d.ts` and its tsconfig `include` entry, and move a hand-written `RouteSearch` entry to `RouteTable` as `"/path": { params: ...; search: ... }`. A route file whose name holds `#` or `?` is an error that names the file.',
38
+ "`dehydrate()` on a query client sends nothing unless `shouldDehydrateQuery` selects the queries, where a bare call sent every successful query, regular and infinite. Every dehydrated value is serialized into the page and readable by the visitor. Pass `shouldDehydrateQuery` naming the keys that are safe to send, or `() => true` when every successful query in that client is meant for the browser. Without it the browser starts with no cache for those queries and fetches them itself, so a component that rendered their data on the server can differ from it on the first client render.",
39
+ "A mutation still running when the visitor's identity changes, in this tab or another tab of the site, is cancelled: its `mutate` promise rejects with `MutationCancelledError`, and its `onSuccess`, `onError` and `onSettled` callbacks do not run. The mutation function takes a second argument, `{ signal }`, an `AbortSignal` that is aborted at that moment; pass it to `fetch` to stop the request. A call site that awaits `mutateAsync` across a sign-in or sign-out catches that error.",
40
+ '`nifra check` reports NF-C056 (error) for `serverFunctions("todo", todos)` where `todos` is a namespace import of `todos.fn.ts`: the client stubs call the namespace the file names, so a mount under another word answers 404 on every call. Rename the mount, or put `// nifra-expect NF-C056: <reason>` above a call kept on purpose.',
41
+ "Closing a modal route with Back shows the page kept under it as it was, and the route's loader is not called again for it, unless that page was loaded for a previous visitor or marked stale.",
42
+ '`nifra check` reports NF-C057 (warn) for an `<a href="/path">` that no page, backend route or file in `public/` serves, and NF-C058 (info) for one that is a page today, with the `href()` call that replaces it. Neither fails a check unless `--strict` is set for the warning. Raise, lower or silence either with `rules` in `nifra.config`, or keep one link as written with `rawHref(path)` or `// nifra-expect NF-C058: <reason>` above the attribute.',
43
+ "A path segment has one spelling in `getStaticPaths` output, the prerender report and written files, `enumerateStaticRoutes`, the typed client's path params and the requests `@nifrajs/testing` builds: characters outside `A-Za-z0-9 -._~!$&'()*+,:=@` are percent-encoded in upper-case hex, so `;`, `[`, `]` and `|` are escaped. A `getStaticPaths` entry that leaves out a param, or holds one no path can carry (`.`, `..`, a lone surrogate), is skipped, and the prerender report names the param. Adjacent route parameter values that the router would split differently are rejected, and translated pathnames refuse segments nested deeper than three percent-encodings.",
44
+ ],
45
+ }
@@ -0,0 +1,42 @@
1
+ import type { UpgradeRecipe } from "./index.ts"
2
+
3
+ /**
4
+ * Upgrade recipe for Nifra 5.9.
5
+ *
6
+ * One `serveStatic` with one set of options on every runtime: `@nifrajs/web`'s `servePublicDir` is
7
+ * removed, and `@nifrajs/node`'s `static` takes a function. The `serve-static` source rewrite moves
8
+ * each call, and `gracefulSignals` replaces `signals` on the Node and Deno adapters.
9
+ */
10
+ export const recipe: UpgradeRecipe = {
11
+ version: "5.9.0",
12
+ pins: [
13
+ { match: "@nifrajs/", to: "5.9.0" },
14
+ { match: "create-nifra", to: "5.9.0" },
15
+ { match: "nifra", to: "5.9.0" },
16
+ ],
17
+ importMoves: [],
18
+ sourceRewrites: ["serve-static"],
19
+ // A servePublicDir call on Bun becomes @nifrajs/core/serve-static's, which an app may have had only
20
+ // through @nifrajs/web.
21
+ dependencyAdds: [
22
+ { imports: ["@nifrajs/core/serve-static"], add: "@nifrajs/core", beside: ["@nifrajs/web"] },
23
+ ],
24
+ affects: [
25
+ "@nifrajs/core",
26
+ "@nifrajs/schema",
27
+ "@nifrajs/mcp-db",
28
+ "@nifrajs/web",
29
+ "@nifrajs/node",
30
+ "@nifrajs/deno",
31
+ ],
32
+ notes: [
33
+ '`servePublicDir` is removed from @nifrajs/web. Each call becomes `serveStatic({ dir, prefix: "/", fallthrough: true, hashedFiles, cacheControl: ONE_DAY })`, from @nifrajs/core/serve-static on Bun, and from @nifrajs/node or @nifrajs/deno in a file that serves on one of them: the same files, headers and misses as before. A `cache.hashed` other than the one-year immutable policy, or options built elsewhere, is listed to edit by hand. `serveStatic` answers `undefined` synchronously for a path no mount takes, so `handler(request).then(...)` needs `await` or `?.then`.',
34
+ "@nifrajs/node's `static` takes a function, as on Bun and Deno: mount objects passed to it are wrapped in `serveStatic(...)`, which keeps them on Node's own request. A mount object `static` names through a variable is listed; passing one throws a TypeError that names `serveStatic`.",
35
+ "`serve()` on @nifrajs/node and @nifrajs/deno takes `gracefulSignals` in place of `signals`, the name Bun's `server()` uses; `signals` throws a TypeError.",
36
+ "@nifrajs/deno exports `serveStatic`, which reads files with Deno's file API. The servers `nifra build` emits for bun, node and deno pass their runtime's `serveStatic` the same mounts, so a missing file under /assets/ or a listed public file answers `404 Not Found` on each.",
37
+ "Host validation is opt-in on Deno, as it is on Bun. Deno used to answer `400 invalid_host` for a malformed Host by default; it now routes the Host it received unless `server({ validateHost: true })` is set. Deno builds `Request.url` from the Host, so set it when Deno receives requests with an untrusted Host header.",
38
+ "Request targets are no longer normalized by default on Deno and Node. `/public/../admin` used to be routed as `/admin` on every runtime; Deno and Node now route the target as sent, as most frameworks do, and Bun still delivers a parsed URL. Set `server({ normalizeTarget: true })` on Deno or `serve(app, { normalizeTarget: true })` from @nifrajs/node when path guards, or a proxy that normalizes paths, sit in front of or inside the app.",
39
+ "The `date-time`, `date` and `time` string formats in @nifrajs/schema follow RFC 3339 in full: a day the calendar lacks (`2026-02-30`), an hour of `24` and an offset past `23:59` now fail validation. `t.date()` is a `Date` in code and an RFC 3339 string on the wire, in a request and a response alike.",
40
+ "@nifrajs/mcp-db/postgres checks the connected role's own privileges before every query and explain, and refuses a role that can read a masked column, an excluded table, a view over hidden data or a SECURITY DEFINER function with `NIFRA_DB_ROLE_GRANTS`. Run `nifra db role` for the grants a declaration needs, or name a function in `devDatabase.allowFunctions`.",
41
+ ],
42
+ }