@nifrajs/cli 5.0.0 → 5.2.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 (296) hide show
  1. package/CHANGELOG.md +3211 -0
  2. package/README.md +10 -2
  3. package/dist/agent-files.d.ts +19 -11
  4. package/dist/agent-files.d.ts.map +1 -1
  5. package/dist/agent-files.js +26 -18
  6. package/dist/agent-files.js.map +1 -1
  7. package/dist/assure-hydration.d.ts.map +1 -1
  8. package/dist/assure-hydration.js +5 -2
  9. package/dist/assure-hydration.js.map +1 -1
  10. package/dist/assure.d.ts +12 -2
  11. package/dist/assure.d.ts.map +1 -1
  12. package/dist/assure.js +73 -9
  13. package/dist/assure.js.map +1 -1
  14. package/dist/capabilities-tool.d.ts.map +1 -1
  15. package/dist/capabilities-tool.js +152 -49
  16. package/dist/capabilities-tool.js.map +1 -1
  17. package/dist/check-diagnostics.d.ts +7 -0
  18. package/dist/check-diagnostics.d.ts.map +1 -1
  19. package/dist/check-diagnostics.js +3 -0
  20. package/dist/check-diagnostics.js.map +1 -1
  21. package/dist/check-scan.d.ts +8 -2
  22. package/dist/check-scan.d.ts.map +1 -1
  23. package/dist/check-scan.js +49 -13
  24. package/dist/check-scan.js.map +1 -1
  25. package/dist/check.d.ts.map +1 -1
  26. package/dist/check.js +91 -45
  27. package/dist/check.js.map +1 -1
  28. package/dist/cli.d.ts +2 -0
  29. package/dist/cli.d.ts.map +1 -1
  30. package/dist/cli.js +128 -59
  31. package/dist/cli.js.map +1 -1
  32. package/dist/client-module.d.ts +5 -3
  33. package/dist/client-module.d.ts.map +1 -1
  34. package/dist/client-module.js +34 -10
  35. package/dist/client-module.js.map +1 -1
  36. package/dist/command-catalog.d.ts +9 -1
  37. package/dist/command-catalog.d.ts.map +1 -1
  38. package/dist/command-catalog.js +75 -26
  39. package/dist/command-catalog.js.map +1 -1
  40. package/dist/dev-bun-config.d.ts +6 -3
  41. package/dist/dev-bun-config.d.ts.map +1 -1
  42. package/dist/dev-bun-config.js +13 -10
  43. package/dist/dev-bun-config.js.map +1 -1
  44. package/dist/dev-feed-tool.d.ts +19 -1
  45. package/dist/dev-feed-tool.d.ts.map +1 -1
  46. package/dist/dev-feed-tool.js +114 -0
  47. package/dist/dev-feed-tool.js.map +1 -1
  48. package/dist/doctor.d.ts +15 -1
  49. package/dist/doctor.d.ts.map +1 -1
  50. package/dist/doctor.js +79 -61
  51. package/dist/doctor.js.map +1 -1
  52. package/dist/fix-recipes.d.ts +2 -0
  53. package/dist/fix-recipes.d.ts.map +1 -1
  54. package/dist/fix-recipes.js +93 -12
  55. package/dist/fix-recipes.js.map +1 -1
  56. package/dist/i18n-check.d.ts +11 -1
  57. package/dist/i18n-check.d.ts.map +1 -1
  58. package/dist/i18n-check.js +170 -17
  59. package/dist/i18n-check.js.map +1 -1
  60. package/dist/init-agents.d.ts +60 -4
  61. package/dist/init-agents.d.ts.map +1 -1
  62. package/dist/init-agents.js +196 -33
  63. package/dist/init-agents.js.map +1 -1
  64. package/dist/internal/config-paths.d.ts +16 -0
  65. package/dist/internal/config-paths.d.ts.map +1 -0
  66. package/dist/internal/config-paths.js +124 -0
  67. package/dist/internal/config-paths.js.map +1 -0
  68. package/dist/internal/installed-package.d.ts +4 -0
  69. package/dist/internal/installed-package.d.ts.map +1 -0
  70. package/dist/internal/installed-package.js +17 -0
  71. package/dist/internal/installed-package.js.map +1 -0
  72. package/dist/internal/project-specifiers.d.ts +14 -1
  73. package/dist/internal/project-specifiers.d.ts.map +1 -1
  74. package/dist/internal/project-specifiers.js +63 -16
  75. package/dist/internal/project-specifiers.js.map +1 -1
  76. package/dist/internal/source-facts.d.ts +12 -1
  77. package/dist/internal/source-facts.d.ts.map +1 -1
  78. package/dist/internal/source-facts.js +117 -5
  79. package/dist/internal/source-facts.js.map +1 -1
  80. package/dist/internal/typescript-import.d.ts.map +1 -1
  81. package/dist/internal/typescript-import.js +5 -3
  82. package/dist/internal/typescript-import.js.map +1 -1
  83. package/dist/internal/workspace-packages.d.ts +22 -0
  84. package/dist/internal/workspace-packages.d.ts.map +1 -0
  85. package/dist/internal/workspace-packages.js +215 -0
  86. package/dist/internal/workspace-packages.js.map +1 -0
  87. package/dist/introspect.d.ts +9 -0
  88. package/dist/introspect.d.ts.map +1 -1
  89. package/dist/introspect.js +32 -1
  90. package/dist/introspect.js.map +1 -1
  91. package/dist/levels-tool.d.ts.map +1 -1
  92. package/dist/levels-tool.js +5 -8
  93. package/dist/levels-tool.js.map +1 -1
  94. package/dist/load.d.ts +9 -4
  95. package/dist/load.d.ts.map +1 -1
  96. package/dist/load.js +32 -3
  97. package/dist/load.js.map +1 -1
  98. package/dist/lock-links.d.ts +42 -0
  99. package/dist/lock-links.d.ts.map +1 -0
  100. package/dist/lock-links.js +144 -0
  101. package/dist/lock-links.js.map +1 -0
  102. package/dist/mcp-context.d.ts.map +1 -1
  103. package/dist/mcp-context.js +6 -21
  104. package/dist/mcp-context.js.map +1 -1
  105. package/dist/mcp-delegate.d.ts +2 -2
  106. package/dist/mcp-delegate.d.ts.map +1 -1
  107. package/dist/mcp-delegate.js +19 -7
  108. package/dist/mcp-delegate.js.map +1 -1
  109. package/dist/mcp-exec.d.ts +1 -0
  110. package/dist/mcp-exec.d.ts.map +1 -1
  111. package/dist/mcp-exec.js +13 -5
  112. package/dist/mcp-exec.js.map +1 -1
  113. package/dist/mcp-http.js +1 -1
  114. package/dist/mcp-io.d.ts +13 -0
  115. package/dist/mcp-io.d.ts.map +1 -1
  116. package/dist/mcp-io.js +23 -0
  117. package/dist/mcp-io.js.map +1 -1
  118. package/dist/mcp-path.d.ts +2 -1
  119. package/dist/mcp-path.d.ts.map +1 -1
  120. package/dist/mcp-path.js +9 -24
  121. package/dist/mcp-path.js.map +1 -1
  122. package/dist/mcp-root.d.ts +6 -4
  123. package/dist/mcp-root.d.ts.map +1 -1
  124. package/dist/mcp-root.js +12 -8
  125. package/dist/mcp-root.js.map +1 -1
  126. package/dist/mcp.d.ts.map +1 -1
  127. package/dist/mcp.js +40 -17
  128. package/dist/mcp.js.map +1 -1
  129. package/dist/migrate-layout.d.ts +41 -1
  130. package/dist/migrate-layout.d.ts.map +1 -1
  131. package/dist/migrate-layout.js +1729 -236
  132. package/dist/migrate-layout.js.map +1 -1
  133. package/dist/output-schemas.d.ts +34 -0
  134. package/dist/output-schemas.d.ts.map +1 -1
  135. package/dist/output-schemas.js +132 -21
  136. package/dist/output-schemas.js.map +1 -1
  137. package/dist/project-path.d.ts +6 -0
  138. package/dist/project-path.d.ts.map +1 -1
  139. package/dist/project-path.js +48 -14
  140. package/dist/project-path.js.map +1 -1
  141. package/dist/project-site.d.ts +7 -0
  142. package/dist/project-site.d.ts.map +1 -0
  143. package/dist/project-site.js +19 -0
  144. package/dist/project-site.js.map +1 -0
  145. package/dist/recipes/4.0.0.d.ts.map +1 -1
  146. package/dist/recipes/4.0.0.js +2 -0
  147. package/dist/recipes/4.0.0.js.map +1 -1
  148. package/dist/recipes/5.1.0.d.ts +9 -0
  149. package/dist/recipes/5.1.0.d.ts.map +1 -0
  150. package/dist/recipes/5.1.0.js +22 -0
  151. package/dist/recipes/5.1.0.js.map +1 -0
  152. package/dist/recipes/5.2.0.d.ts +10 -0
  153. package/dist/recipes/5.2.0.d.ts.map +1 -0
  154. package/dist/recipes/5.2.0.js +32 -0
  155. package/dist/recipes/5.2.0.js.map +1 -0
  156. package/dist/recipes/index.d.ts +3 -0
  157. package/dist/recipes/index.d.ts.map +1 -1
  158. package/dist/recipes/index.js +7 -0
  159. package/dist/recipes/index.js.map +1 -1
  160. package/dist/release-verification.d.ts +5 -0
  161. package/dist/release-verification.d.ts.map +1 -1
  162. package/dist/release-verification.js +14 -0
  163. package/dist/release-verification.js.map +1 -1
  164. package/dist/review.d.ts.map +1 -1
  165. package/dist/review.js +7 -0
  166. package/dist/review.js.map +1 -1
  167. package/dist/rule-explain.d.ts +26 -0
  168. package/dist/rule-explain.d.ts.map +1 -0
  169. package/dist/rule-explain.js +49 -0
  170. package/dist/rule-explain.js.map +1 -0
  171. package/dist/rules/codes.d.ts +5 -1
  172. package/dist/rules/codes.d.ts.map +1 -1
  173. package/dist/rules/codes.js +5 -1
  174. package/dist/rules/codes.js.map +1 -1
  175. package/dist/rules/contract-visibility.d.ts.map +1 -1
  176. package/dist/rules/contract-visibility.js +93 -21
  177. package/dist/rules/contract-visibility.js.map +1 -1
  178. package/dist/rules/data-guard.d.ts +6 -0
  179. package/dist/rules/data-guard.d.ts.map +1 -1
  180. package/dist/rules/data-guard.js +37 -0
  181. package/dist/rules/data-guard.js.map +1 -1
  182. package/dist/rules/explanations.d.ts +14 -0
  183. package/dist/rules/explanations.d.ts.map +1 -0
  184. package/dist/rules/explanations.js +316 -0
  185. package/dist/rules/explanations.js.map +1 -0
  186. package/dist/rules/legacy.d.ts.map +1 -1
  187. package/dist/rules/legacy.js +44 -2
  188. package/dist/rules/legacy.js.map +1 -1
  189. package/dist/rules/merge-auth.d.ts +12 -0
  190. package/dist/rules/merge-auth.d.ts.map +1 -0
  191. package/dist/rules/merge-auth.js +52 -0
  192. package/dist/rules/merge-auth.js.map +1 -0
  193. package/dist/rules/pages.d.ts +56 -3
  194. package/dist/rules/pages.d.ts.map +1 -1
  195. package/dist/rules/pages.js +412 -23
  196. package/dist/rules/pages.js.map +1 -1
  197. package/dist/rules/routes.d.ts +3 -2
  198. package/dist/rules/routes.d.ts.map +1 -1
  199. package/dist/rules/routes.js +4 -3
  200. package/dist/rules/routes.js.map +1 -1
  201. package/dist/rules/security.d.ts +3 -2
  202. package/dist/rules/security.d.ts.map +1 -1
  203. package/dist/rules/security.js +42 -11
  204. package/dist/rules/security.js.map +1 -1
  205. package/dist/rules/zones.d.ts.map +1 -1
  206. package/dist/rules/zones.js +34 -11
  207. package/dist/rules/zones.js.map +1 -1
  208. package/dist/stylex-migrate.d.ts.map +1 -1
  209. package/dist/stylex-migrate.js +127 -17
  210. package/dist/stylex-migrate.js.map +1 -1
  211. package/dist/test-tool.d.ts.map +1 -1
  212. package/dist/test-tool.js +3 -9
  213. package/dist/test-tool.js.map +1 -1
  214. package/dist/typecheck-coverage.d.ts +11 -0
  215. package/dist/typecheck-coverage.d.ts.map +1 -1
  216. package/dist/typecheck-coverage.js +50 -7
  217. package/dist/typecheck-coverage.js.map +1 -1
  218. package/dist/upgrade.d.ts +57 -6
  219. package/dist/upgrade.d.ts.map +1 -1
  220. package/dist/upgrade.js +247 -19
  221. package/dist/upgrade.js.map +1 -1
  222. package/dist/verification-plan.d.ts.map +1 -1
  223. package/dist/verification-plan.js +7 -2
  224. package/dist/verification-plan.js.map +1 -1
  225. package/dist/version-drift.d.ts.map +1 -1
  226. package/dist/version-drift.js +66 -3
  227. package/dist/version-drift.js.map +1 -1
  228. package/dist/web-app-options.d.ts +1 -1
  229. package/dist/web-app-options.d.ts.map +1 -1
  230. package/dist/web-app-options.js.map +1 -1
  231. package/docs/examples.json +21 -3
  232. package/docs/llms-full.txt +1083 -168
  233. package/docs/types.json +535 -112
  234. package/package.json +13 -12
  235. package/src/agent-files.ts +27 -17
  236. package/src/assure-hydration.ts +5 -1
  237. package/src/assure.ts +99 -11
  238. package/src/capabilities-tool.ts +188 -53
  239. package/src/check-diagnostics.ts +10 -0
  240. package/src/check-scan.ts +65 -12
  241. package/src/check.ts +122 -51
  242. package/src/cli.ts +127 -45
  243. package/src/client-module.ts +45 -9
  244. package/src/command-catalog.ts +92 -28
  245. package/src/dev-bun-config.ts +13 -9
  246. package/src/dev-feed-tool.ts +146 -1
  247. package/src/doctor.ts +102 -66
  248. package/src/fix-recipes.ts +101 -10
  249. package/src/i18n-check.ts +254 -18
  250. package/src/init-agents.ts +225 -44
  251. package/src/internal/config-paths.ts +154 -0
  252. package/src/internal/installed-package.ts +15 -0
  253. package/src/internal/project-specifiers.ts +78 -17
  254. package/src/internal/source-facts.ts +147 -5
  255. package/src/internal/typescript-import.ts +5 -3
  256. package/src/internal/workspace-packages.ts +218 -0
  257. package/src/introspect.ts +39 -1
  258. package/src/levels-tool.ts +7 -9
  259. package/src/load.ts +46 -4
  260. package/src/lock-links.ts +173 -0
  261. package/src/mcp-context.ts +5 -18
  262. package/src/mcp-delegate.ts +22 -10
  263. package/src/mcp-exec.ts +14 -4
  264. package/src/mcp-http.ts +1 -1
  265. package/src/mcp-io.ts +33 -0
  266. package/src/mcp-path.ts +8 -22
  267. package/src/mcp-root.ts +14 -8
  268. package/src/mcp.ts +48 -19
  269. package/src/migrate-layout.ts +1968 -245
  270. package/src/output-schemas.ts +179 -23
  271. package/src/project-path.ts +44 -13
  272. package/src/project-site.ts +18 -0
  273. package/src/recipes/4.0.0.ts +2 -0
  274. package/src/recipes/5.1.0.ts +23 -0
  275. package/src/recipes/5.2.0.ts +33 -0
  276. package/src/recipes/index.ts +7 -0
  277. package/src/release-verification.ts +20 -0
  278. package/src/review.ts +7 -0
  279. package/src/rule-explain.ts +75 -0
  280. package/src/rules/codes.ts +5 -1
  281. package/src/rules/contract-visibility.ts +118 -20
  282. package/src/rules/data-guard.ts +40 -0
  283. package/src/rules/explanations.ts +329 -0
  284. package/src/rules/legacy.ts +46 -2
  285. package/src/rules/merge-auth.ts +55 -0
  286. package/src/rules/pages.ts +486 -25
  287. package/src/rules/routes.ts +4 -3
  288. package/src/rules/security.ts +49 -11
  289. package/src/rules/zones.ts +33 -9
  290. package/src/stylex-migrate.ts +117 -17
  291. package/src/test-tool.ts +3 -9
  292. package/src/typecheck-coverage.ts +51 -6
  293. package/src/upgrade.ts +312 -19
  294. package/src/verification-plan.ts +15 -2
  295. package/src/version-drift.ts +68 -2
  296. package/src/web-app-options.ts +9 -1
package/src/cli.ts CHANGED
@@ -126,6 +126,11 @@ Usage:
126
126
  one left. Exits 1 while current-code errors are open.
127
127
  nifra logs [--since <n>] [--level <l>] [--grep <s>] The dev server's console, server and
128
128
  browser, each line tagged with its request.
129
+ nifra explain [<message>] [--stack <s>] [--name <n>] A structured diagnostic for an error: its
130
+ code, the frame in your source, and the cause and fix when
131
+ nifra knows them. No message: the dev server's latest error.
132
+ A rule code (NF-C007): what that check rule reports and how
133
+ to fix it.
129
134
  nifra cdn-check <url> Check a deployed page behind a CDN: served from cache, no
130
135
  internal or CDN-only headers reaching the visitor, and soft
131
136
  navigations get page data, not the cached document. Exits 1
@@ -177,12 +182,16 @@ Usage:
177
182
  structure" sections. No-clobber by default (skips a file you've
178
183
  customized); --force overwrites the owned files. AGENTS.md is
179
184
  only appended to, never overwritten.
180
- nifra init-agents --sync-mcp [--json] Re-pin an existing app's MCP launch to the nifra the project
185
+ nifra init-agents --sync-mcp [--json] Move an existing app's MCP launch to the nifra the project
181
186
  installs: rewrites only the @nifrajs/cli@x.y.z version in
182
187
  .mcp.json, .cursor/mcp.json, CLAUDE.md and AGENTS.md's MCP
183
- section - every other byte stays as it is. Creates nothing.
188
+ section - every other byte stays as it is - and drops it
189
+ when the project declares @nifrajs/cli, so the launch runs
190
+ that install from then on. Creates nothing.
184
191
  At a workspace root with one nifra member, the two registries'
185
- launch also names that member (\`mcp app\`).
192
+ launch also names that member (\`mcp app\`). Run in a member,
193
+ it also re-pins the files above it, up to the repository
194
+ root, whose every nifra launch serves that member.
186
195
  nifra mcp [dir] Start an MCP server (stdio) exposing this project to a coding
187
196
  agent. The project root is [dir] when given, else resolved from
188
197
  cwd (marker walk-up + the client's MCP roots); tools refuse
@@ -268,25 +277,30 @@ Usage:
268
277
  [--list] [--json] apply exact imports, pin every matching dependency (keeping
269
278
  [--exact] ^/~, or exact with --exact), then verify with nifra check.
270
279
  [--allow-downgrade] Dry-run by default; --write applies then verifies (--no-verify
271
- [--no-hooks] to skip), then prints how hook scope changed (--no-hooks to
272
- skip). --list shows available targets. A version newer than
273
- this CLI prints the command for that release's CLI. Fail-closed
274
- on an unknown version or a rollback (--allow-downgrade
275
- overrides). Deterministic + idempotent.
276
- nifra migrate layout [--write] [--json]
280
+ [--allow-linked-skew] to skip), then prints how hook scope changed (--no-hooks to
281
+ [--no-hooks] skip). --list shows the targets with each newer release's
282
+ notes. A version newer than this CLI prints the command for
283
+ that release's CLI. Fail-closed on an unknown version, a
284
+ rollback (--allow-downgrade overrides), or a linked repository
285
+ that loads its own nifra at another version
286
+ (--allow-linked-skew overrides). Deterministic + idempotent.
287
+ nifra migrate layout [--write] [--zones] [--json]
277
288
  Move an app onto the frontend/backend split: split each route
278
289
  into x.tsx + x.backend.ts, fold _middleware.ts into
279
290
  _layout.backend.ts, move backend.ts/framework.ts under backend/,
280
- and zone the other modules into frontend/, backend/ or shared/.
281
- Dry-run by default; --write applies.
291
+ and zone the other modules into frontend/, backend/ or shared/
292
+ (--zones keeps them in place and lists them in package.json
293
+ "nifra.zones"). Dry-run by default; --write applies.
282
294
  nifra types [--check] [--json] Generate each route's ./+types module under .nifra/types: its
283
295
  params, the data its output schemas let through, and api typed
284
296
  by backend/app.ts. dev, build and check refresh them too;
285
297
  --check fails when one is stale.
286
- nifra schemas [--write] [--json] Draft loaderOutput/actionOutput from each loader's and
298
+ nifra schemas [--write] [--check] [--json]
299
+ Draft loaderOutput/actionOutput from each loader's and
287
300
  action's return type for review; --write adds the missing
288
301
  ones (marked nifra:generated) and refreshes generated ones.
289
- Lists the returned fields a hand-written schema drops.
302
+ Lists the returned fields a hand-written schema drops;
303
+ --check fails on a missing, stale or any-typed one.
290
304
  nifra port [--target <t>] [--json] Portability linter: print a feature × deploy-target capability
291
305
  [--ci] [--strict] matrix (in-memory stores, in-process cron/WebSocket, Bun/Deno
292
306
  globals, node: builtins) with file:line evidence. --target auto-
@@ -297,8 +311,9 @@ Usage:
297
311
  [--json] [--strict] placeholder + tag parity, plural cases, script purity,
298
312
  untranslated messages. IMPORTS the entry (default: the first
299
313
  i18n.ts in ., lib/, src/, src/lib/, app/), which exports
300
- \`locales\` + \`catalogs\` (+ optional \`ignore\`). Exits 1 on
301
- errors; --strict also on warnings.
314
+ \`locales\` + \`catalogs\` (+ optional \`ignore\`), or a
315
+ \`copy\` from defineCopy(), whose tables it finds in the
316
+ source. Exits 1 on errors; --strict also on warnings.
302
317
 
303
318
  Reads nifra.config.ts (adapter + clientModule + plugins; or backend/framework.ts), backend/app.ts
304
319
  (optional), and routes/ from the current directory. Run from your project root.
@@ -315,7 +330,7 @@ set in the process environment is never overwritten by a file.
315
330
  ${renderCommandCatalogHelp()}`
316
331
 
317
332
  // Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
318
- const CLI_VERSION = "5.0.0"
333
+ const CLI_VERSION = "5.2.0"
319
334
 
320
335
  // A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
321
336
  const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
@@ -366,6 +381,14 @@ export function formatCliError(err: unknown): string {
366
381
  return String(err)
367
382
  }
368
383
 
384
+ /** A failed command's message on stderr and, for a `--json` caller parsing stdout, as JSON there. */
385
+ function reportFailure(err: unknown, argv: readonly string[]): void {
386
+ const message = formatCliError(err)
387
+ console.error(message)
388
+ if (argv.includes("--json") || argv.includes("--json=true"))
389
+ console.log(JSON.stringify({ ok: false, error: message }, null, 2))
390
+ }
391
+
369
392
  async function dev(app: LoadedApp, flags: Flags): Promise<void> {
370
393
  if (app.framework.componentPipeline !== undefined) {
371
394
  if (flags.bun)
@@ -430,6 +453,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
430
453
  app.cwd,
431
454
  app.configPath,
432
455
  app.framework.define,
456
+ app.framework.publicEnvPrefix,
433
457
  )
434
458
  // Bun 1.4 on Windows may discard the script-relative portion of argv when `--config` is
435
459
  // present. Keep a second, authenticated copy of the user vector in the child's environment so
@@ -922,6 +946,7 @@ async function buildPrerenderApp(
922
946
  ...(client.routes ? { routePreload: client.routes } : {}),
923
947
  ...(client.css ? { styles: client.css } : {}),
924
948
  ...(client.routeStyles ? { routeStyles: client.routeStyles } : {}),
949
+ ...(client.copyChunks ? { copyChunks: client.copyChunks } : {}),
925
950
  ...(client.cssLoading !== undefined ? { cssLoading: client.cssLoading } : {}),
926
951
  })
927
952
  }
@@ -931,6 +956,7 @@ interface BuiltManifest {
931
956
  readonly routes?: Readonly<Record<string, readonly string[]>>
932
957
  readonly css?: readonly string[]
933
958
  readonly routeStyles?: Readonly<Record<string, readonly string[]>>
959
+ readonly copyChunks?: Readonly<Record<string, string>>
934
960
  readonly cssLoading?: CssLoadingMode
935
961
  }
936
962
 
@@ -954,35 +980,73 @@ async function start(app: LoadedApp, flags: Flags): Promise<void> {
954
980
  await import(serverFile)
955
981
  }
956
982
 
983
+ const VALUE_FLAGS: Readonly<Record<string, "port" | "out" | "target">> = {
984
+ "--port": "port",
985
+ "-p": "port",
986
+ "--out": "out",
987
+ "--target": "target",
988
+ }
989
+
990
+ type SwitchField = "poll" | "report" | "vite" | "bun" | "allowDuplicateIdentity" | "noIndicator"
991
+
992
+ const SWITCH_FLAGS: Readonly<Record<string, SwitchField>> = {
993
+ "--poll": "poll",
994
+ "--report": "report",
995
+ "--vite": "vite",
996
+ "--bun": "bun",
997
+ "--allow-duplicate-identity": "allowDuplicateIdentity",
998
+ "--no-indicator": "noIndicator",
999
+ }
1000
+
1001
+ /** The flags of `nifra dev`, `build` and `start`, as `--flag value` or `--flag=value`. Anything else is
1002
+ * refused: an ignored `--target=vercel` would build the default target and exit 0. */
957
1003
  export function parseFlags(args: readonly string[]): Flags {
958
1004
  // Port precedence: `--port`/`-p` (most specific) > `PORT` env > the framework default. The default is
959
1005
  // the SAME uncommon port for `nifra dev` and `nifra start` (DEFAULT_DEV_PORT) so a project's URL is
960
1006
  // stable across commands and doesn't collide with the usual 3000/5173/8080 crowd.
961
1007
  let port = Number(Bun.env.PORT ?? DEFAULT_DEV_PORT)
962
1008
  let out: string | undefined
963
- let poll = Bun.env.CHOKIDAR_USEPOLLING === "1"
964
1009
  let target: string | undefined
965
- let report = false
966
- let vite = false
967
- let bun = false
968
- let allowDuplicateIdentity = false
969
- let noIndicator = false
1010
+ const switches: Record<SwitchField, boolean> = {
1011
+ poll: Bun.env.CHOKIDAR_USEPOLLING === "1",
1012
+ report: false,
1013
+ vite: false,
1014
+ bun: false,
1015
+ allowDuplicateIdentity: false,
1016
+ noIndicator: false,
1017
+ }
970
1018
  for (let i = 0; i < args.length; i++) {
971
- const a = args[i]
972
- if ((a === "--port" || a === "-p") && args[i + 1]) port = Number(args[++i])
973
- else if (a === "--out" && args[i + 1]) out = args[++i] as string
974
- else if (a === "--poll") poll = true
975
- else if (a === "--target" && args[i + 1]) target = args[++i] as string
976
- else if (a === "--report") report = true
977
- else if (a === "--vite") vite = true
978
- else if (a === "--bun") bun = true
979
- else if (a === "--allow-duplicate-identity") allowDuplicateIdentity = true
980
- else if (a === "--no-indicator") noIndicator = true
1019
+ const arg = args[i] as string
1020
+ const equals = arg.startsWith("--") ? arg.indexOf("=") : -1
1021
+ const name = equals === -1 ? arg : arg.slice(0, equals)
1022
+ const valueField = Object.hasOwn(VALUE_FLAGS, name) ? VALUE_FLAGS[name] : undefined
1023
+ if (valueField !== undefined) {
1024
+ const value = equals === -1 ? args[++i] : arg.slice(equals + 1)
1025
+ if (value === undefined || value === "" || (equals === -1 && value.startsWith("-")))
1026
+ throw new Error(`[nifra] ${name} needs a value`)
1027
+ if (valueField === "port") port = Number(value)
1028
+ else if (valueField === "out") out = value
1029
+ else target = value
1030
+ continue
1031
+ }
1032
+ const switchField = Object.hasOwn(SWITCH_FLAGS, name) ? SWITCH_FLAGS[name] : undefined
1033
+ if (switchField !== undefined) {
1034
+ const value = equals === -1 ? "true" : arg.slice(equals + 1)
1035
+ if (value !== "true" && value !== "false")
1036
+ throw new Error(`[nifra] ${name} takes no value (or =true / =false)`)
1037
+ switches[switchField] = value === "true"
1038
+ continue
1039
+ }
1040
+ throw new Error(
1041
+ arg.startsWith("-")
1042
+ ? `[nifra] unknown option: ${arg} - see \`nifra help\``
1043
+ : `[nifra] unexpected argument: ${arg} - see \`nifra help\``,
1044
+ )
981
1045
  }
982
1046
  if (!Number.isFinite(port) || port < 0 || port > 65535) {
983
1047
  throw new Error(`[nifra] invalid --port: ${port}`)
984
1048
  }
985
- return { port, out, poll, target, report, vite, bun, allowDuplicateIdentity, noIndicator }
1049
+ return { port, out, target, ...switches }
986
1050
  }
987
1051
 
988
1052
  /**
@@ -1190,7 +1254,7 @@ async function main(): Promise<void> {
1190
1254
  // A thrown error is nifra's own reporting path, not a silent abort: clear the sentinel so the
1191
1255
  // hint stays reserved for the case where the process died inside the app import.
1192
1256
  markReflecting(undefined)
1193
- console.error(formatCliError(err))
1257
+ reportFailure(err, argv)
1194
1258
  const candidate =
1195
1259
  typeof err === "object" && err !== null && "exitCode" in err
1196
1260
  ? (err as { readonly exitCode?: unknown }).exitCode
@@ -1253,6 +1317,7 @@ async function main(): Promise<void> {
1253
1317
  console.error(formatCliError(err))
1254
1318
  process.exitCode = 1
1255
1319
  }
1320
+ exitIfHeldOpen(command)
1256
1321
  return
1257
1322
  }
1258
1323
  // `upgrade` is a pure cwd file-transformer (package.json pins + import moves) driven by a per-release
@@ -1270,14 +1335,16 @@ async function main(): Promise<void> {
1270
1335
  verify: !argv.includes("--no-verify"),
1271
1336
  hooks: !argv.includes("--no-hooks"),
1272
1337
  allowDowngrade: argv.includes("--allow-downgrade"),
1338
+ allowLinkedSkew: argv.includes("--allow-linked-skew"),
1273
1339
  exact: argv.includes("--exact"),
1274
1340
  cliVersion: CLI_VERSION,
1275
1341
  })
1276
1342
  if (!ok) process.exitCode = 1
1277
1343
  } catch (err) {
1278
- console.error(formatCliError(err))
1344
+ reportFailure(err, argv)
1279
1345
  process.exitCode = 1
1280
1346
  }
1347
+ exitIfHeldOpen(command)
1281
1348
  return
1282
1349
  }
1283
1350
  // `port` is a pure cwd-based portability linter (scans source, doesn't run the app) - like `check`/
@@ -1288,17 +1355,32 @@ async function main(): Promise<void> {
1288
1355
  process.exitCode = 1
1289
1356
  return
1290
1357
  }
1358
+ if (argv.includes("--help") || argv.includes("-h")) {
1359
+ console.log(HELP)
1360
+ return
1361
+ }
1291
1362
  const flags = parseFlags(argv.slice(1))
1292
- const app = await loadApp(process.cwd(), flags.out)
1293
- if (command !== "start") {
1294
- const { refreshRouteTypes, watchRouteTypes } = await import("./route-types.ts")
1295
- refreshRouteTypes(app.cwd)
1296
- // A relaunched `nifra dev --bun` child runs beside its parent, which already watches.
1297
- if (command === "dev" && process.env.NIFRA_BUN_DEV_TOKEN === undefined) watchRouteTypes(app.cwd)
1363
+ try {
1364
+ const app = await loadApp(process.cwd(), flags.out)
1365
+ if (command !== "start" && process.env.NIFRA_BUN_DEV_TOKEN === undefined) {
1366
+ const { unservedRoutesWarning } = await import("./introspect.ts")
1367
+ const unserved = unservedRoutesWarning(app)
1368
+ if (unserved !== undefined) console.warn(unserved)
1369
+ }
1370
+ if (command !== "start") {
1371
+ const { refreshRouteTypes, watchRouteTypes } = await import("./route-types.ts")
1372
+ refreshRouteTypes(app.cwd)
1373
+ // A relaunched `nifra dev --bun` child runs beside its parent, which already watches.
1374
+ if (command === "dev" && process.env.NIFRA_BUN_DEV_TOKEN === undefined)
1375
+ watchRouteTypes(app.cwd)
1376
+ }
1377
+ if (command === "dev") await dev(app, flags)
1378
+ else if (command === "build") await buildForTarget(app, flags.target, flags)
1379
+ else await start(app, flags)
1380
+ } finally {
1381
+ // `dev` and `start` keep serving after they return; a build is over.
1382
+ if (command === "build") exitIfHeldOpen(command)
1298
1383
  }
1299
- if (command === "dev") await dev(app, flags)
1300
- else if (command === "build") await buildForTarget(app, flags.target, flags)
1301
- else await start(app, flags)
1302
1384
  }
1303
1385
 
1304
1386
  /**
@@ -1485,7 +1567,7 @@ if (isMainModule() || isBunDevReexecChild() || hasCliCommandToken()) {
1485
1567
  try {
1486
1568
  await main()
1487
1569
  } catch (err) {
1488
- console.error(formatCliError(err))
1570
+ reportFailure(err, cliArgv())
1489
1571
  process.exitCode = 1
1490
1572
  }
1491
1573
  }
@@ -4,8 +4,10 @@
4
4
  */
5
5
  import { existsSync, readFileSync } from "node:fs"
6
6
  import { join } from "node:path"
7
+ import type * as TS from "typescript"
7
8
  import { CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
8
9
  import { stripComments } from "./check-scan.ts"
10
+ import { configPathReader, exportedInitializer } from "./internal/config-paths.ts"
9
11
  import type { SpecifierResolver } from "./internal/project-specifiers.ts"
10
12
 
11
13
  const CLIENT_MODULE_EXPORT =
@@ -34,28 +36,62 @@ export function appDirs(files: readonly string[]): string[] {
34
36
 
35
37
  /**
36
38
  * The file `clientModule` names in `app`, read the way the loader reads it: from `nifra.config.ts`
37
- * when it exists, else `backend/framework.ts`, and a relative path against the app root. `undefined`
38
- * for a package specifier, a value that is not a string literal, or a path to no file.
39
+ * when it exists, else `backend/framework.ts`; a string against the app root, and, with `ts`, a
40
+ * `resolve`/`join` of the config's own folder against that folder. `undefined` for a package
41
+ * specifier, a value built any other way, or a path to no file.
39
42
  */
40
43
  export function clientModuleRoot(
41
44
  root: string,
42
45
  app: string,
43
46
  resolve: SpecifierResolver,
47
+ ts?: typeof TS,
44
48
  ): ClientModuleRoot | undefined {
45
49
  const config = existsSync(join(root, app, CONFIG_FILE)) ? CONFIG_FILE : FRAMEWORK_FILE
46
50
  const path = join(root, app, config)
47
51
  if (!existsSync(path)) return undefined
48
52
  const text = readFileSync(path, "utf8")
49
- // `stripComments` keeps offsets, so the match index is a position in `text`.
50
- const match = CLIENT_MODULE_EXPORT.exec(stripComments(text))
51
- if (match === null) return undefined
52
- const specifier = match[1] ?? match[2] ?? ""
53
- const file = resolve(join(root, app, CONFIG_FILE), specifier)
53
+ const found = ts === undefined ? literalClientModule(text) : staticClientModule(ts, path, text)
54
+ if (found === undefined) return undefined
55
+ const file =
56
+ found.base === "app"
57
+ ? resolve(join(root, app, CONFIG_FILE), found.specifier)
58
+ : resolve(path, found.specifier.startsWith("../") ? found.specifier : `./${found.specifier}`)
54
59
  if (file === undefined) return undefined
55
60
  return {
56
61
  config: app === "" ? config : `${app}/${config}`,
57
- line: text.slice(0, match.index).split("\n").length,
58
- specifier,
62
+ line: text.slice(0, found.index).split("\n").length,
63
+ specifier: found.specifier,
59
64
  file,
60
65
  }
61
66
  }
67
+
68
+ interface FoundClientModule {
69
+ readonly base: "app" | "config"
70
+ readonly specifier: string
71
+ readonly index: number
72
+ }
73
+
74
+ function literalClientModule(text: string): FoundClientModule | undefined {
75
+ // `stripComments` keeps offsets, so the match index is a position in `text`.
76
+ const match = CLIENT_MODULE_EXPORT.exec(stripComments(text))
77
+ if (match === null) return undefined
78
+ return { base: "app", specifier: match[1] ?? match[2] ?? "", index: match.index }
79
+ }
80
+
81
+ function staticClientModule(
82
+ ts: typeof TS,
83
+ path: string,
84
+ text: string,
85
+ ): FoundClientModule | undefined {
86
+ let sf: TS.SourceFile
87
+ try {
88
+ sf = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
89
+ } catch {
90
+ // TypeScript 7 parses only what its session preloaded; the literal form still reads.
91
+ return literalClientModule(text)
92
+ }
93
+ const initializer = exportedInitializer(ts, sf, "clientModule")
94
+ const found = configPathReader(ts, sf)(initializer)
95
+ if (initializer === undefined || found === undefined) return undefined
96
+ return { base: found.base, specifier: found.path, index: initializer.getStart(sf) }
97
+ }