@nifrajs/cli 5.12.1 → 5.14.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 (379) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +3 -1
  3. package/dist/agent-files.js +0 -74
  4. package/dist/agent-files.js.map +1 -1
  5. package/dist/app-files.js +0 -19
  6. package/dist/app-files.js.map +1 -1
  7. package/dist/assure-hydration.js +0 -23
  8. package/dist/assure-hydration.js.map +1 -1
  9. package/dist/assure.js +0 -14
  10. package/dist/assure.js.map +1 -1
  11. package/dist/capabilities-tool.js +0 -51
  12. package/dist/capabilities-tool.js.map +1 -1
  13. package/dist/cdn-check.js +0 -2
  14. package/dist/cdn-check.js.map +1 -1
  15. package/dist/check-diagnostics.js +0 -29
  16. package/dist/check-diagnostics.js.map +1 -1
  17. package/dist/check-scan.js +10 -621
  18. package/dist/check-scan.js.map +1 -1
  19. package/dist/check.js +0 -86
  20. package/dist/check.js.map +1 -1
  21. package/dist/cli.d.ts +9 -2
  22. package/dist/cli.d.ts.map +1 -1
  23. package/dist/cli.js +139 -351
  24. package/dist/cli.js.map +1 -1
  25. package/dist/client-module.js +0 -13
  26. package/dist/client-module.js.map +1 -1
  27. package/dist/command-catalog.d.ts +29 -1
  28. package/dist/command-catalog.d.ts.map +1 -1
  29. package/dist/command-catalog.js +100 -23
  30. package/dist/command-catalog.js.map +1 -1
  31. package/dist/component-check.js +1 -7
  32. package/dist/component-check.js.map +1 -1
  33. package/dist/config-target.js +0 -13
  34. package/dist/config-target.js.map +1 -1
  35. package/dist/contract-proof.js +0 -1
  36. package/dist/contract-proof.js.map +1 -1
  37. package/dist/contracts.js +0 -36
  38. package/dist/contracts.js.map +1 -1
  39. package/dist/db-audit.js +0 -15
  40. package/dist/db-audit.js.map +1 -1
  41. package/dist/db-child.js +0 -20
  42. package/dist/db-child.js.map +1 -1
  43. package/dist/db-config.js +0 -23
  44. package/dist/db-config.js.map +1 -1
  45. package/dist/db-tool.js +0 -24
  46. package/dist/db-tool.js.map +1 -1
  47. package/dist/deployment-adapters.d.ts +12 -0
  48. package/dist/deployment-adapters.d.ts.map +1 -0
  49. package/dist/deployment-adapters.js +86 -0
  50. package/dist/deployment-adapters.js.map +1 -0
  51. package/dist/dev-bun-config.d.ts +4 -3
  52. package/dist/dev-bun-config.d.ts.map +1 -1
  53. package/dist/dev-bun-config.js +9 -101
  54. package/dist/dev-bun-config.js.map +1 -1
  55. package/dist/dev-feed-tool.js +0 -32
  56. package/dist/dev-feed-tool.js.map +1 -1
  57. package/dist/dev-server-client.js +0 -16
  58. package/dist/dev-server-client.js.map +1 -1
  59. package/dist/diagnostics.js +0 -10
  60. package/dist/diagnostics.js.map +1 -1
  61. package/dist/diff-tool.js +0 -23
  62. package/dist/diff-tool.js.map +1 -1
  63. package/dist/docs-search.js +0 -35
  64. package/dist/docs-search.js.map +1 -1
  65. package/dist/doctor.js +3 -161
  66. package/dist/doctor.js.map +1 -1
  67. package/dist/env-file.js +0 -66
  68. package/dist/env-file.js.map +1 -1
  69. package/dist/examples.js +0 -16
  70. package/dist/examples.js.map +1 -1
  71. package/dist/fix-recipes.js +0 -20
  72. package/dist/fix-recipes.js.map +1 -1
  73. package/dist/frontend-guidance.js +0 -36
  74. package/dist/frontend-guidance.js.map +1 -1
  75. package/dist/hand-built-manifest.js +0 -17
  76. package/dist/hand-built-manifest.js.map +1 -1
  77. package/dist/hooks-report.js +0 -4
  78. package/dist/hooks-report.js.map +1 -1
  79. package/dist/i18n-check.js +0 -30
  80. package/dist/i18n-check.js.map +1 -1
  81. package/dist/init-agents.d.ts +5 -0
  82. package/dist/init-agents.d.ts.map +1 -1
  83. package/dist/init-agents.js +2 -134
  84. package/dist/init-agents.js.map +1 -1
  85. package/dist/internal/code-unit-order.js +0 -2
  86. package/dist/internal/code-unit-order.js.map +1 -1
  87. package/dist/internal/config-paths.js +0 -12
  88. package/dist/internal/config-paths.js.map +1 -1
  89. package/dist/internal/control-character.js +0 -1
  90. package/dist/internal/control-character.js.map +1 -1
  91. package/dist/internal/escape-regexp.d.ts +1 -2
  92. package/dist/internal/escape-regexp.d.ts.map +1 -1
  93. package/dist/internal/escape-regexp.js +1 -4
  94. package/dist/internal/escape-regexp.js.map +1 -1
  95. package/dist/internal/git-ignored.js +0 -11
  96. package/dist/internal/git-ignored.js.map +1 -1
  97. package/dist/internal/installed-package.js +0 -2
  98. package/dist/internal/installed-package.js.map +1 -1
  99. package/dist/internal/line-at.js +0 -1
  100. package/dist/internal/line-at.js.map +1 -1
  101. package/dist/internal/nifra-project.js +0 -31
  102. package/dist/internal/nifra-project.js.map +1 -1
  103. package/dist/internal/posix-path.js +0 -1
  104. package/dist/internal/posix-path.js.map +1 -1
  105. package/dist/internal/project-specifiers.js +0 -34
  106. package/dist/internal/project-specifiers.js.map +1 -1
  107. package/dist/internal/realpath-or-self.js +0 -1
  108. package/dist/internal/realpath-or-self.js.map +1 -1
  109. package/dist/internal/record.d.ts +1 -1
  110. package/dist/internal/record.d.ts.map +1 -1
  111. package/dist/internal/record.js +1 -4
  112. package/dist/internal/record.js.map +1 -1
  113. package/dist/internal/reserved-segment-codemod.js +0 -44
  114. package/dist/internal/reserved-segment-codemod.js.map +1 -1
  115. package/dist/internal/script-kind.js +0 -5
  116. package/dist/internal/script-kind.js.map +1 -1
  117. package/dist/internal/source-facts.js +3 -37
  118. package/dist/internal/source-facts.js.map +1 -1
  119. package/dist/internal/typescript-import.js +0 -49
  120. package/dist/internal/typescript-import.js.map +1 -1
  121. package/dist/internal/workspace-packages.js +0 -24
  122. package/dist/internal/workspace-packages.js.map +1 -1
  123. package/dist/introspect.js +1 -89
  124. package/dist/introspect.js.map +1 -1
  125. package/dist/learn.js +0 -16
  126. package/dist/learn.js.map +1 -1
  127. package/dist/levels-tool.js +0 -34
  128. package/dist/levels-tool.js.map +1 -1
  129. package/dist/load.d.ts +12 -3
  130. package/dist/load.d.ts.map +1 -1
  131. package/dist/load.js +19 -75
  132. package/dist/load.js.map +1 -1
  133. package/dist/local-cli.js +0 -23
  134. package/dist/local-cli.js.map +1 -1
  135. package/dist/lock-links.js +0 -20
  136. package/dist/lock-links.js.map +1 -1
  137. package/dist/manifest-tool.js +0 -5
  138. package/dist/manifest-tool.js.map +1 -1
  139. package/dist/mcp-app-tool.js +0 -9
  140. package/dist/mcp-app-tool.js.map +1 -1
  141. package/dist/mcp-context.js +0 -30
  142. package/dist/mcp-context.js.map +1 -1
  143. package/dist/mcp-delegate.js +0 -45
  144. package/dist/mcp-delegate.js.map +1 -1
  145. package/dist/mcp-docs-tools.js +0 -13
  146. package/dist/mcp-docs-tools.js.map +1 -1
  147. package/dist/mcp-exec.js +0 -71
  148. package/dist/mcp-exec.js.map +1 -1
  149. package/dist/mcp-http.js +1 -38
  150. package/dist/mcp-http.js.map +1 -1
  151. package/dist/mcp-io.d.ts +5 -1
  152. package/dist/mcp-io.d.ts.map +1 -1
  153. package/dist/mcp-io.js +3 -68
  154. package/dist/mcp-io.js.map +1 -1
  155. package/dist/mcp-isolate.js +0 -28
  156. package/dist/mcp-isolate.js.map +1 -1
  157. package/dist/mcp-path.js +0 -8
  158. package/dist/mcp-path.js.map +1 -1
  159. package/dist/mcp-project-child.js +0 -19
  160. package/dist/mcp-project-child.js.map +1 -1
  161. package/dist/mcp-protocol.js +0 -5
  162. package/dist/mcp-protocol.js.map +1 -1
  163. package/dist/mcp-reflect.js +0 -11
  164. package/dist/mcp-reflect.js.map +1 -1
  165. package/dist/mcp-relay.d.ts +4 -0
  166. package/dist/mcp-relay.d.ts.map +1 -1
  167. package/dist/mcp-relay.js +9 -20
  168. package/dist/mcp-relay.js.map +1 -1
  169. package/dist/mcp-render.js +1 -42
  170. package/dist/mcp-render.js.map +1 -1
  171. package/dist/mcp-root.d.ts.map +1 -1
  172. package/dist/mcp-root.js +18 -90
  173. package/dist/mcp-root.js.map +1 -1
  174. package/dist/mcp-run.js +1 -38
  175. package/dist/mcp-run.js.map +1 -1
  176. package/dist/mcp-tool-meta.js +3 -8
  177. package/dist/mcp-tool-meta.js.map +1 -1
  178. package/dist/mcp-ws.js +0 -16
  179. package/dist/mcp-ws.js.map +1 -1
  180. package/dist/mcp.js +0 -86
  181. package/dist/mcp.js.map +1 -1
  182. package/dist/migrate-layout.js +0 -313
  183. package/dist/migrate-layout.js.map +1 -1
  184. package/dist/openapi-tool.js +0 -18
  185. package/dist/openapi-tool.js.map +1 -1
  186. package/dist/openapi-types.js +0 -22
  187. package/dist/openapi-types.js.map +1 -1
  188. package/dist/output-schemas.js +0 -67
  189. package/dist/output-schemas.js.map +1 -1
  190. package/dist/pipeline-guard.js +0 -58
  191. package/dist/pipeline-guard.js.map +1 -1
  192. package/dist/pipeline-report.js +0 -71
  193. package/dist/pipeline-report.js.map +1 -1
  194. package/dist/port.d.ts +6 -3
  195. package/dist/port.d.ts.map +1 -1
  196. package/dist/port.js +16 -92
  197. package/dist/port.js.map +1 -1
  198. package/dist/ppr-read-fix.js +0 -29
  199. package/dist/ppr-read-fix.js.map +1 -1
  200. package/dist/project-facts.js +0 -5
  201. package/dist/project-facts.js.map +1 -1
  202. package/dist/project-path.js +0 -7
  203. package/dist/project-path.js.map +1 -1
  204. package/dist/project-site.js +0 -2
  205. package/dist/project-site.js.map +1 -1
  206. package/dist/recipes/1.8.0.js +0 -9
  207. package/dist/recipes/1.8.0.js.map +1 -1
  208. package/dist/recipes/2.0.0.js +0 -6
  209. package/dist/recipes/2.0.0.js.map +1 -1
  210. package/dist/recipes/3.0.0.js +0 -7
  211. package/dist/recipes/3.0.0.js.map +1 -1
  212. package/dist/recipes/4.0.0.js +0 -6
  213. package/dist/recipes/4.0.0.js.map +1 -1
  214. package/dist/recipes/5.0.0.js +0 -8
  215. package/dist/recipes/5.0.0.js.map +1 -1
  216. package/dist/recipes/5.1.0.js +0 -6
  217. package/dist/recipes/5.1.0.js.map +1 -1
  218. package/dist/recipes/5.10.0.js +0 -10
  219. package/dist/recipes/5.10.0.js.map +1 -1
  220. package/dist/recipes/5.11.0.js +0 -7
  221. package/dist/recipes/5.11.0.js.map +1 -1
  222. package/dist/recipes/5.12.0.js +0 -6
  223. package/dist/recipes/5.12.0.js.map +1 -1
  224. package/dist/recipes/5.13.0.d.ts +9 -0
  225. package/dist/recipes/5.13.0.d.ts.map +1 -0
  226. package/dist/recipes/5.13.0.js +34 -0
  227. package/dist/recipes/5.13.0.js.map +1 -0
  228. package/dist/recipes/5.14.0.d.ts +10 -0
  229. package/dist/recipes/5.14.0.d.ts.map +1 -0
  230. package/dist/recipes/5.14.0.js +26 -0
  231. package/dist/recipes/5.14.0.js.map +1 -0
  232. package/dist/recipes/5.2.0.js +0 -7
  233. package/dist/recipes/5.2.0.js.map +1 -1
  234. package/dist/recipes/5.3.0.js +0 -8
  235. package/dist/recipes/5.3.0.js.map +1 -1
  236. package/dist/recipes/5.4.0.js +0 -8
  237. package/dist/recipes/5.4.0.js.map +1 -1
  238. package/dist/recipes/5.5.0.js +0 -6
  239. package/dist/recipes/5.5.0.js.map +1 -1
  240. package/dist/recipes/5.6.0.js +0 -7
  241. package/dist/recipes/5.6.0.js.map +1 -1
  242. package/dist/recipes/5.7.0.js +0 -9
  243. package/dist/recipes/5.7.0.js.map +1 -1
  244. package/dist/recipes/5.8.0.js +0 -6
  245. package/dist/recipes/5.8.0.js.map +1 -1
  246. package/dist/recipes/5.9.0.js +0 -9
  247. package/dist/recipes/5.9.0.js.map +1 -1
  248. package/dist/recipes/index.d.ts.map +1 -1
  249. package/dist/recipes/index.js +4 -9
  250. package/dist/recipes/index.js.map +1 -1
  251. package/dist/release-verification.js +0 -14
  252. package/dist/release-verification.js.map +1 -1
  253. package/dist/replay.js +0 -3
  254. package/dist/replay.js.map +1 -1
  255. package/dist/review.js +0 -21
  256. package/dist/review.js.map +1 -1
  257. package/dist/route-types.js +0 -17
  258. package/dist/route-types.js.map +1 -1
  259. package/dist/rule-explain.js +0 -5
  260. package/dist/rule-explain.js.map +1 -1
  261. package/dist/rules/codes.js +0 -2
  262. package/dist/rules/codes.js.map +1 -1
  263. package/dist/rules/comment-markers.js +0 -25
  264. package/dist/rules/comment-markers.js.map +1 -1
  265. package/dist/rules/contract-visibility.js +0 -27
  266. package/dist/rules/contract-visibility.js.map +1 -1
  267. package/dist/rules/data-guard.js +1 -52
  268. package/dist/rules/data-guard.js.map +1 -1
  269. package/dist/rules/internal-links.js +0 -36
  270. package/dist/rules/internal-links.js.map +1 -1
  271. package/dist/rules/islands.js +2 -65
  272. package/dist/rules/islands.js.map +1 -1
  273. package/dist/rules/layout.js +0 -1
  274. package/dist/rules/layout.js.map +1 -1
  275. package/dist/rules/legacy.js +0 -31
  276. package/dist/rules/legacy.js.map +1 -1
  277. package/dist/rules/merge-auth.js +0 -9
  278. package/dist/rules/merge-auth.js.map +1 -1
  279. package/dist/rules/pages.js +0 -95
  280. package/dist/rules/pages.js.map +1 -1
  281. package/dist/rules/ppr.js +0 -8
  282. package/dist/rules/ppr.js.map +1 -1
  283. package/dist/rules/route-statement.js +0 -13
  284. package/dist/rules/route-statement.js.map +1 -1
  285. package/dist/rules/routes.js +1 -67
  286. package/dist/rules/routes.js.map +1 -1
  287. package/dist/rules/secrets.js +0 -15
  288. package/dist/rules/secrets.js.map +1 -1
  289. package/dist/rules/security.js +0 -113
  290. package/dist/rules/security.js.map +1 -1
  291. package/dist/rules/server-fn-namespace.js +0 -5
  292. package/dist/rules/server-fn-namespace.js.map +1 -1
  293. package/dist/rules/source-scan.js +0 -5
  294. package/dist/rules/source-scan.js.map +1 -1
  295. package/dist/rules/swap.js +0 -21
  296. package/dist/rules/swap.js.map +1 -1
  297. package/dist/rules/text-slot-boolean.js +0 -5
  298. package/dist/rules/text-slot-boolean.js.map +1 -1
  299. package/dist/rules/typescript.js +0 -5
  300. package/dist/rules/typescript.js.map +1 -1
  301. package/dist/rules/undeclared-response.js +0 -8
  302. package/dist/rules/undeclared-response.js.map +1 -1
  303. package/dist/rules/zones.js +0 -45
  304. package/dist/rules/zones.js.map +1 -1
  305. package/dist/runtime-differences.js +0 -20
  306. package/dist/runtime-differences.js.map +1 -1
  307. package/dist/scaffold-hole.js +1 -45
  308. package/dist/scaffold-hole.js.map +1 -1
  309. package/dist/scaffold.js +3 -60
  310. package/dist/scaffold.js.map +1 -1
  311. package/dist/sdk.js +1 -13
  312. package/dist/sdk.js.map +1 -1
  313. package/dist/search-terms.js +0 -12
  314. package/dist/search-terms.js.map +1 -1
  315. package/dist/shell-files.d.ts +44 -0
  316. package/dist/shell-files.d.ts.map +1 -0
  317. package/dist/shell-files.js +186 -0
  318. package/dist/shell-files.js.map +1 -0
  319. package/dist/shell-init.d.ts +33 -0
  320. package/dist/shell-init.d.ts.map +1 -0
  321. package/dist/shell-init.js +84 -0
  322. package/dist/shell-init.js.map +1 -0
  323. package/dist/smoke.js +0 -4
  324. package/dist/smoke.js.map +1 -1
  325. package/dist/source-rewrites.js +0 -43
  326. package/dist/source-rewrites.js.map +1 -1
  327. package/dist/stylex-migrate.js +0 -29
  328. package/dist/stylex-migrate.js.map +1 -1
  329. package/dist/symptom-search.js +0 -3
  330. package/dist/symptom-search.js.map +1 -1
  331. package/dist/sync-manifest.js +3 -33
  332. package/dist/sync-manifest.js.map +1 -1
  333. package/dist/test-tool.js +0 -10
  334. package/dist/test-tool.js.map +1 -1
  335. package/dist/typecheck-coverage.js +0 -36
  336. package/dist/typecheck-coverage.js.map +1 -1
  337. package/dist/types-search.js +0 -35
  338. package/dist/types-search.js.map +1 -1
  339. package/dist/upgrade.js +0 -214
  340. package/dist/upgrade.js.map +1 -1
  341. package/dist/verification-plan.js +0 -19
  342. package/dist/verification-plan.js.map +1 -1
  343. package/dist/verification.js +0 -23
  344. package/dist/verification.js.map +1 -1
  345. package/dist/version-drift.js +0 -8
  346. package/dist/version-drift.js.map +1 -1
  347. package/dist/web-app-options.js +0 -16
  348. package/dist/web-app-options.js.map +1 -1
  349. package/dist/work-graph.js +0 -21
  350. package/dist/work-graph.js.map +1 -1
  351. package/dist/workspace-link.js +0 -31
  352. package/dist/workspace-link.js.map +1 -1
  353. package/docs/examples.json +97 -1
  354. package/docs/llms-full.txt +1347 -59
  355. package/docs/types.json +756 -37
  356. package/package.json +12 -11
  357. package/src/assure-hydration.ts +3 -3
  358. package/src/cli.ts +189 -39
  359. package/src/command-catalog.ts +144 -7
  360. package/src/deployment-adapters.ts +107 -0
  361. package/src/dev-bun-config.ts +21 -2
  362. package/src/init-agents.ts +1 -1
  363. package/src/internal/escape-regexp.ts +1 -4
  364. package/src/internal/record.ts +1 -3
  365. package/src/internal/typescript-import.ts +1 -1
  366. package/src/load.ts +36 -3
  367. package/src/mcp-http.ts +1 -1
  368. package/src/mcp-io.ts +8 -5
  369. package/src/mcp-relay.ts +19 -7
  370. package/src/mcp-render.ts +1 -1
  371. package/src/mcp-root.ts +21 -3
  372. package/src/mcp-tool-meta.ts +3 -3
  373. package/src/port.ts +25 -8
  374. package/src/recipes/5.13.0.ts +41 -0
  375. package/src/recipes/5.14.0.ts +34 -0
  376. package/src/recipes/index.ts +4 -0
  377. package/src/rules/routes.ts +2 -2
  378. package/src/shell-files.ts +225 -0
  379. package/src/shell-init.ts +139 -0
package/dist/cli.js CHANGED
@@ -7,17 +7,6 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
7
7
  }
8
8
  return path;
9
9
  };
10
- /**
11
- * `nifra` - the zero-config CLI for a nifra app. Reads `backend/framework.ts` + `backend/app.ts` +
12
- * `routes/` from the project root (see {@link loadApp}) and wires the right `@nifrajs/web`
13
- * entrypoint:
14
- *
15
- * nifra dev true-HMR dev server (Bun native HMR + nifra SSR) - @nifrajs/web/dev
16
- * nifra build emit a complete target-specific deploy directory - @nifrajs/web/build
17
- * nifra start run the default Bun build - dist/server.js
18
- *
19
- * Bun-only (it runs the framework's TS + Bun plugins directly). The *output* runs anywhere.
20
- */
21
10
  import { existsSync, readFileSync, realpathSync } from "node:fs";
22
11
  import { resolve } from "node:path";
23
12
  import { fileURLToPath } from "node:url";
@@ -32,7 +21,6 @@ import { FRAMEWORK_WEB_OPTIONS, loadApp } from "./load.js";
32
21
  import { PROJECT_COMMANDS, runThroughLocalCli } from "./local-cli.js";
33
22
  import { chooseBuildPipeline, describePipeline } from "./pipeline-guard.js";
34
23
  import { frameworkMountPaths, frameworkOptionImports, frameworkWebAppOptions, } from "./web-app-options.js";
35
- /** Forward a re-exec'd Bun child's output without relying on Windows inheriting a pipe-of-a-pipe. */
36
24
  async function forwardChildOutput(stream, sink, observe) {
37
25
  const reader = stream.getReader();
38
26
  try {
@@ -48,7 +36,6 @@ async function forwardChildOutput(stream, sink, observe) {
48
36
  reader.releaseLock();
49
37
  }
50
38
  }
51
- /** The last `max` bytes of a stream, decoded: what a crashed child printed last. */
52
39
  function streamTail(max) {
53
40
  let chunks = [];
54
41
  let size = 0;
@@ -112,8 +99,12 @@ Usage:
112
99
  nifra db role Print the SQL for a read-only Postgres role. Runs nothing.
113
100
  nifra db audit [--limit <n>] What nifra db ran (.nifra/db-audit.jsonl), never the rows.
114
101
  nifra build [--out <dir>] [--report] Emit a complete deploy directory.
102
+ [--transport <module>] Reach the server through this module's fetch (a native shell).
103
+ [--prerender <paths>] With --target static: also prerender these pages (comma-separated,
104
+ such as /,/about) whether or not their route exports prerender.
115
105
  [--target <t>] Target a FULL deploy dir for <t>:
116
- bun | node | deno | cloudflare | vercel | static. Packages
106
+ bun | node | deno | cloudflare | vercel | static, or an installed
107
+ public adapter selected by deploymentAdapter in nifra.config.ts. Packages
117
108
  buildClient + buildServer (+ prerender for static, bun and
118
109
  node, whose server answers those pages from file) so an app
119
110
  no longer hand-writes build-<target>.ts + _worker.ts +
@@ -291,7 +282,8 @@ Usage:
291
282
  nifra port [--target <t>] [--json] Portability linter: print a feature × deploy-target capability
292
283
  [--ci] [--strict] matrix (in-memory stores, in-process cron/WebSocket, Bun/Deno
293
284
  globals, node: builtins) with file:line evidence. --target auto-
294
- detected from build/deploy scripts, wrangler.toml, or vercel config;
285
+ detected from build/deploy scripts, wrangler.toml, vercel config,
286
+ or installed adapter metadata (base runtime only);
295
287
  --ci (or any --target) exits nonzero when a used feature is
296
288
  unsupported on the target; --strict also fails on caveats.
297
289
  nifra i18n check [entry] Check i18n catalogs: coverage, missing + unused keys, ICU syntax,
@@ -315,26 +307,10 @@ set in the process environment is never overwritten by a file.
315
307
  e.g. \`nifra check --env-file .env.local\`
316
308
 
317
309
  ${renderCommandCatalogHelp()}`;
318
- // Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
319
- const CLI_VERSION = "5.12.1";
320
- // A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
310
+ const CLI_VERSION = "5.14.0";
321
311
  const asAdapter = (v) => v;
322
312
  const asBunPlugins = (v) => v;
323
- const asComponentPlugins = (value) =>
324
- // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Trusted config forwards the pinned Vite plugin ABI; this does not accept request data.
325
- value;
326
- /**
327
- * Render an error for the CLI, unwrapping the detail a bare `.message` drops.
328
- *
329
- * `Bun.build` reports a bundling failure as an `AggregateError` whose `.message` is a generic
330
- * "Bundle failed" and whose `.errors` hold the real causes - the unresolved import, the plugin that
331
- * threw, each with a file and line. `buildClient`/`buildServer` catch a RETURNED `{ success: false }`
332
- * and print `result.logs`, but a `Bun.build` that THROWS (a plugin `onLoad`/`onResolve` that throws, a
333
- * resolution failure) rejects before that check runs, so the AggregateError reaches the CLI whole and a
334
- * catch printing only `.message` throws the causes away. That is the difference between "Bundle failed"
335
- * and "Could not resolve ./db from routes/x.tsx". So unwrap an AggregateError - directly, or one carried
336
- * as a `.cause` - into a line per underlying error.
337
- */
313
+ const asComponentPlugins = (value) => value;
338
314
  export function formatCliError(err) {
339
315
  const aggregate = err instanceof AggregateError
340
316
  ? err
@@ -344,9 +320,6 @@ export function formatCliError(err) {
344
320
  if (aggregate !== undefined && aggregate.errors.length > 0) {
345
321
  const outer = err instanceof Error ? err.message : "";
346
322
  const head = outer !== "" && outer !== "Bundle failed" ? outer : "build failed";
347
- // `formatBuildLog`, not `String(e)`: a Bun BuildMessage/ResolveMessage keeps its file and line in
348
- // `position`, which `String` drops. Multi-line entries are indented to stay under the head.
349
- // Deduplicated because Bun can repeat one cause across `.errors`.
350
323
  const details = [...new Set(aggregate.errors.map((e) => formatBuildLog(e).trim()))].map((line) => ` - ${line.replace(/\n/g, "\n ")}`);
351
324
  return [head, ...details].join("\n");
352
325
  }
@@ -354,8 +327,6 @@ export function formatCliError(err) {
354
327
  return err.message;
355
328
  return String(err);
356
329
  }
357
- /** A failed command's message on stderr and, for a `--json` caller parsing stdout, as JSON there. */
358
- /** One catalog command's usage: its lines from {@link HELP} when it has them, else the catalog's. */
359
330
  export function commandHelp(spec) {
360
331
  const name = spec.name.replace(/^db-/, "db ");
361
332
  const lines = [];
@@ -364,7 +335,6 @@ export function commandHelp(spec) {
364
335
  if (line.startsWith(` nifra ${name} `) || line === ` nifra ${name}`)
365
336
  inside = true;
366
337
  else if (!inside || !/^ {3,}\S/.test(line)) {
367
- // The first block is the hand-written one; the catalog's one-line summary repeats it below.
368
338
  if (lines.length > 0)
369
339
  break;
370
340
  continue;
@@ -401,65 +371,26 @@ async function dev(app, flags) {
401
371
  if (flags.vite && flags.bun) {
402
372
  throw new Error("[nifra] `nifra dev` takes `--vite` or `--bun`, not both.");
403
373
  }
404
- // Default to Bun for the dev phase too. An app whose only transforms are Vite plugins stays on Vite so
405
- // its transform is never silently dropped; `--vite`/`--bun` make that choice explicit.
406
- // ONE rule for both phases - `chooseBuildPipeline` decides `dev` exactly as it decides `build`, so a
407
- // project cannot end up bundled by one toolchain in dev and the other in production. An earlier
408
- // version of this kept apps declaring `vitePlugins` on Vite for dev even when they also shipped Bun
409
- // equivalents, on the theory that the framework plugins were the safer HMR path. Measurement killed
410
- // it: Vue, Solid and Svelte all render correctly on the Bun pipeline, so the hedge bought nothing
411
- // and cost an app the guarantee that dev and production bundle the same way. (Svelte used to render
412
- // ONLY on Bun, which made the hedge actively harmful; it now renders on either - see the note at the
413
- // Vite branch for what the adapter had to be given to make that true.)
414
374
  const decision = chooseBuildPipeline(app.resolvedPlugins, flags.vite ? "vite" : flags.bun ? "bun" : undefined, "dev");
415
375
  if (decision.pipeline === "bun") {
416
- // Bun's dev-server bundler takes plugins only via bunfig `[serve.static]`, read at process
417
- // start - so the boundary plugins (zone guard, server-fn stubs) are delivered by
418
- // generating a config and re-execing this same command once with `--config=`. The child proves
419
- // it IS the configured child with a per-launch random token (matched against the file the
420
- // parent just wrote, consumed on first read). A fixed sentinel here would be a secret-leak
421
- // switch: any inherited environment could set it, skip the generation, and serve the app with
422
- // no boundary plugins at all. An unprovable token acts as a parent - fail closed.
423
376
  const { consumeLaunchToken, writeBunDevConfig } = await import("./dev-bun-config.js");
424
377
  if (!consumeLaunchToken(app.cwd, process.env.NIFRA_BUN_DEV_TOKEN)) {
425
- // Re-exec depth backstop: token verification makes recursion terminate (the direct child
426
- // always verifies), so hitting this means filesystem/env sabotage - refuse over fork-looping.
427
378
  const depth = Number(process.env.NIFRA_BUN_DEV_DEPTH ?? "0");
428
379
  if (depth >= 3) {
429
380
  throw new Error("[nifra] `nifra dev --bun` could not verify its generated dev config after several " +
430
381
  "relaunches. Something is rewriting `.nifra/dev-bun/` or the environment between " +
431
382
  "launches; refusing to serve without the client-boundary plugins.");
432
383
  }
433
- const { bunfigPath, launchToken } = await writeBunDevConfig(app.cwd, app.configPath, app.framework.define, app.framework.publicEnvPrefix);
434
- // Bun 1.4 on Windows may discard the script-relative portion of argv when `--config` is
435
- // present. Keep a second, authenticated copy of the user vector in the child's environment so
436
- // the configured process cannot silently fall back to `nifra`'s help and exit 0. The launch token
437
- // is still the proof boundary; these arguments are only a transport, never authorization.
384
+ const { publicEnvDefines } = await import("@nifrajs/web/build");
385
+ const { bunfigPath, launchToken } = await writeBunDevConfig(app.cwd, app.configPath, app.framework.define, app.framework.publicEnvPrefix, publicEnvDefines(app.framework.publicEnvPrefix ?? "PUBLIC_", process.env));
438
386
  const childCliArgv = [...cliArgv()];
439
387
  const child = Bun.spawn([
440
388
  process.execPath,
441
389
  `--config=${bunfigPath}`,
442
- // The app's `conditions` reach SSR here or nowhere: bunfig has no key for them (a top-level,
443
- // `[run]`, `[serve.static]` or `[bundle]` `conditions` is parsed and ignored), and the re-exec
444
- // is the only point where this process's resolver is still configurable. Without it a package
445
- // with an `exports` map resolves to a DIFFERENT file on the server than in the client bundle,
446
- // which is the two-toolchains-one-module failure the pipeline guard exists to prevent.
447
- //
448
- // One flag per condition. `--conditions=a,b` is accepted and matches nothing: Bun takes the
449
- // whole string as a single condition name, so the comma form fails silently.
450
390
  ...(app.framework.conditions ?? []).map((condition) => `--conditions=${condition}`),
451
- // Reuse the actual loaded module rather than trusting either runtime's reconstructed
452
- // `argv[1]` spelling. This also works when a package-bin shim launches the CLI. `cliArgv()`
453
- // is important here: Bun 1.4 on Windows can omit the script from Bun.argv, making the
454
- // command start at index 1 instead of index 2. Slicing at a fixed index would silently drop
455
- // `dev`, causing the child to load this module and exit successfully without starting it.
456
391
  fileURLToPath(import.meta.url),
457
392
  ...childCliArgv,
458
393
  ], {
459
- // On Windows, inheriting the parent's already-piped stdout/stderr can make a nested Bun
460
- // process exit successfully without exposing either its banner or its error. Use explicit
461
- // pipes and forward them from this process instead; the caller still observes one CLI stream,
462
- // while the child gets real handles it can write to on every platform.
463
394
  stdin: "inherit",
464
395
  stdout: "pipe",
465
396
  stderr: "pipe",
@@ -468,17 +399,9 @@ async function dev(app, flags) {
468
399
  NIFRA_BUN_DEV_TOKEN: launchToken,
469
400
  NIFRA_BUN_DEV_DEPTH: String(depth + 1),
470
401
  NIFRA_BUN_DEV_ARGS: JSON.stringify(childCliArgv),
471
- // The child is the process that renders, so it is the one that needs dev-shaped runtimes.
472
- // A library ships its dev build behind the `development` export condition with a `NODE_ENV`
473
- // fallback for resolvers that set no conditions - which is Bun's runtime, where SSR runs,
474
- // so on the server that fallback is the only signal there is. It has to be in place before
475
- // the app's config is read, because reading it imports the adapter and through it the
476
- // framework runtime; setting it inside the dev server would already be a step too late.
477
- // Preserved if the caller pinned one.
478
402
  NODE_ENV: process.env.NODE_ENV ?? "development",
479
403
  },
480
404
  });
481
- // The child's last words, kept so a crash leaves a record `nifra errors` can read after the fact.
482
405
  const stderrTail = streamTail(16 * 1024);
483
406
  const forwarded = Promise.all([
484
407
  forwardChildOutput(child.stdout, Bun.stdout),
@@ -500,7 +423,6 @@ async function dev(app, flags) {
500
423
  recordDevCrash(app.cwd, code, stderrTail.text());
501
424
  }
502
425
  catch {
503
- // The crash is already on the terminal; failing to persist it must not mask the exit code.
504
426
  }
505
427
  }
506
428
  }
@@ -510,34 +432,14 @@ async function dev(app, flags) {
510
432
  }
511
433
  return;
512
434
  }
513
- // The verified child no longer needs the transport or its launch proof. Remove both from the
514
- // long-lived dev process so command-line values (which may include an env-file path) are not
515
- // inherited by an app-spawned subprocess or exposed through its environment diagnostics.
516
435
  delete process.env.NIFRA_BUN_DEV_ARGS;
517
436
  delete process.env.NIFRA_BUN_DEV_TOKEN;
518
437
  delete process.env.NIFRA_BUN_DEV_DEPTH;
519
- // SSR runs in THIS process, on Bun's runtime - a different loader from the dev-server bundler the
520
- // bunfig above configures. Both halves have to agree, so the runtime gets the same transforms:
521
- //
522
- // - CSS Modules. The scoped name is a pure function of file path + class name, so the `"ssr"` form
523
- // produces the identical map the client bundle emits (and no stylesheet - that ships from the
524
- // client build). Without it `styles.box` is `undefined` on the server: the SSR markup carries no
525
- // class, the page paints unstyled, and hydration then reports a className mismatch.
526
- // - the app's `serverPlugins` - the SSR counterpart of the `clientPlugins` the generated bunfig
527
- // delivers, exactly as `nifra build`'s prerender pass registers them.
528
- //
529
- // Registered BEFORE `createDevServer`, because a Bun runtime plugin only affects modules loaded
530
- // after it - and `createApp` imports the route modules.
531
438
  const { plugin } = await import("bun");
532
439
  const { cssModulesBunPlugin } = await import("@nifrajs/web/plugins/css-modules");
533
440
  plugin(cssModulesBunPlugin("ssr"));
534
441
  for (const p of asBunPlugins(app.resolvedPlugins.serverPlugins))
535
442
  plugin(p);
536
- // "After" has one consequence an adapter has to respect. Reading the app's config is what PRODUCES
537
- // these plugins, so the config's import graph - which includes the adapter - is already loaded when
538
- // they register. An adapter must therefore not import an asset its own plugin compiles at module
539
- // scope; it has to defer to first render, which happens after this point. `@nifrajs/web-svelte`
540
- // loads its `Chain.svelte` that way for exactly this reason, and says so at the import.
541
443
  const { createDevServer } = await import("@nifrajs/web/dev");
542
444
  const { framework: fw, routesDir, outDir, backend } = app;
543
445
  const server = await createDevServer({
@@ -545,10 +447,6 @@ async function dev(app, flags) {
545
447
  outDir,
546
448
  clientModule: fw.clientModule,
547
449
  port: flags.port,
548
- // For the background client-leak guard, which re-runs `buildClient` on change - the SERVED client
549
- // bundle gets these same plugins through the generated bunfig, since Bun's dev-server bundler takes
550
- // plugins only as module paths. Never `vitePlugins`, which belong to the other pipeline;
551
- // `assertPipelineSeparation` already refuses a plugin sitting in the wrong slot.
552
450
  plugins: asBunPlugins(app.resolvedPlugins.clientPlugins),
553
451
  ...(fw.publicDir !== undefined ? { publicDir: fw.publicDir } : {}),
554
452
  ...(fw.conditions ? { conditions: fw.conditions } : {}),
@@ -556,6 +454,7 @@ async function dev(app, flags) {
556
454
  indicator: showsIndicator(flags, fw),
557
455
  allowedHosts: fw.dev?.allowedHosts ?? [],
558
456
  live: fw.live?.clientEntry,
457
+ ...transportOption(flags, fw, app.cwd),
559
458
  createApp: (clientEntry, importQuery, dev) => createWebApp({
560
459
  adapter: asAdapter(fw.adapter),
561
460
  manifest: discoverRoutes(routesDir, { importQuery }),
@@ -568,9 +467,6 @@ async function dev(app, flags) {
568
467
  console.log(` ${describePipeline(decision)}`);
569
468
  return;
570
469
  }
571
- // Preflight: the Vite fallback needs `vite` resolvable from the project. Run via `bunx @nifrajs/cli dev` the CLI
572
- // sits in an isolated install where the project's peer deps don't resolve, so the vite import below fails
573
- // with an opaque ERR_MODULE_NOT_FOUND. Surface the real fix instead.
574
470
  try {
575
471
  Bun.resolveSync("vite", app.cwd);
576
472
  }
@@ -580,26 +476,6 @@ async function dev(app, flags) {
580
476
  }
581
477
  const { createViteDevServer } = await import("@nifrajs/web/vite");
582
478
  const { framework: fw, routesDir, cwd, backend } = app;
583
- // No Bun SSR plugins here. `nifra dev` runs the VITE pipeline, and Vite now resolves and compiles
584
- // route modules for SSR too (via `ssrLoadModule`), so `.vue`/`.svelte`/Solid are handled by the
585
- // app's `vitePlugins` on both halves.
586
- //
587
- // Registering Bun's SFC plugins alongside was the structural intermix: two toolchains compiling the
588
- // same file in one process, with only one of them governed by Vite's `resolve.dedupe`. That is what
589
- // made an app's hand-written React alias fail to reach SSR, and it is the condition being removed -
590
- // not a redundancy worth keeping "just in case".
591
- //
592
- // Svelte is the case that proves the rule, and the discarded attempts are recorded so they are not
593
- // retried. The adapter package stays `ssr.external` (its context must be the ONE instance the
594
- // Bun-imported adapter provides), so BUN loads it - and `@nifrajs/web-svelte` renders through its own
595
- // `Chain.svelte`, which needs a compiler that this pipeline does not put in the runtime. Registering
596
- // the app's `serverPlugins` here, scoped to that package's directory, compiles it against a SECOND
597
- // Svelte runtime and the first `setContext` dies (`context.function` null); externalizing the
598
- // adapter's framework peer as well gets further and then dies on `context.function[FILENAME]`,
599
- // because `svelteBunPlugin` and `vite-plugin-svelte` do not emit the same dev-mode component shape.
600
- // Both attempts add a compiler. The fix removes one instead: `createViteDevServer` publishes its
601
- // `ssrLoadModule` via `setSsrModuleLoader`, and the adapter loads `Chain.svelte` AND `svelte/server`
602
- // through it - one toolchain, one runtime, context intact across the whole tree.
603
479
  const server = await createViteDevServer({
604
480
  root: cwd,
605
481
  routesDir,
@@ -612,11 +488,9 @@ async function dev(app, flags) {
612
488
  ...(flags.allowDuplicateIdentity ? { allowDuplicateIdentity: true } : {}),
613
489
  indicator: showsIndicator(flags, fw),
614
490
  live: fw.live?.clientEntry,
491
+ ...transportOption(flags, fw, cwd),
615
492
  ...(fw.conditions ? { conditions: fw.conditions } : {}),
616
493
  ...(fw.define ? { define: fw.define } : {}),
617
- // `load` resolves route modules through VITE, not through Bun. That is what makes the Vite
618
- // pipeline own the whole phase: the client and the server now agree on every specifier, so
619
- // `resolve.dedupe` finally governs SSR and the dual-React crash cannot occur.
620
494
  createApp: (clientEntry, load, dev) => createWebApp({
621
495
  adapter: asAdapter(fw.adapter),
622
496
  manifest: discoverRoutes(routesDir, { load }),
@@ -628,30 +502,6 @@ async function dev(app, flags) {
628
502
  console.log(`nifra dev (vite) → http://localhost:${server.port}`);
629
503
  console.log(` ${describePipeline(decision)}`);
630
504
  }
631
- /**
632
- * `nifra build --target <t>` - package the engine (buildClient + buildServer + prerender) into one
633
- * command that emits a full deploy dir, so an app no longer hand-writes build-bun.ts + _worker.ts +
634
- * _routes.json per target. The adapter is imported from `backend/framework.ts` (the edge-bundlable
635
- * file - never `nifra.config.ts`, which pulls in Vite plugins), and the backend from
636
- * `backend/app.ts` when present; `buildTarget` generates the per-target server entry from those +
637
- * the app's `routes/`.
638
- */
639
- /**
640
- * Refuse a `use` the generated server entry cannot import.
641
- *
642
- * `nifra build` emits `import { use } from <frameworkFile>` (backend/framework.ts, the
643
- * edge-bundlable file), but `loadApp` prefers `nifra.config.ts` - so an app with BOTH files whose
644
- * `use` lives only in `nifra.config.ts` makes `fw.use` defined while `backend/framework.ts` exports
645
- * nothing of that name, and the build dies later with an opaque bundler error pointing at generated
646
- * code. Refuse it here with the exact move instead, in the spirit of `assertPipelineSeparation`
647
- * (load.ts).
648
- *
649
- * Detected by importing `frameworkFile` and checking the named export, not by comparing paths
650
- * alone: a split app legitimately DEFINES `use` in backend/framework.ts and re-exports it from
651
- * nifra.config.ts (exactly how `adapter` reaches both readers), and a path compare would refuse
652
- * that correct layout. The import is cheap - backend/framework.ts is already in the loaded config's
653
- * module graph in that layout.
654
- */
655
505
  export async function assertUseIsEdgeExported(use, configPath, frameworkFile) {
656
506
  if (use === undefined || configPath === frameworkFile)
657
507
  return;
@@ -664,16 +514,6 @@ export async function assertUseIsEdgeExported(use, configPath, frameworkFile) {
664
514
  " - Define `use` in backend/framework.ts and re-export it from nifra.config.ts " +
665
515
  '(`export { use } from "./backend/framework.ts"`) so `nifra dev` sees it too.');
666
516
  }
667
- /**
668
- * Refuse a forwarded framework field (`apiPrefix`, `mounts`, `csp`, ...) the generated server entry
669
- * would not see, or would see with a different value.
670
- *
671
- * `nifra dev` reads these from the loaded config (`nifra.config.ts` when it exists) while the
672
- * server entry imports them from backend/framework.ts. A field set only in nifra.config.ts would be
673
- * missing from production, and one defined separately in each file could differ - dev mounting the
674
- * backend at one path while production mounts it at another. Identity is required, which a
675
- * re-export satisfies.
676
- */
677
517
  export async function assertFrameworkOptionsEdgeExported(fw, configPath, frameworkFile) {
678
518
  if (configPath === frameworkFile)
679
519
  return;
@@ -691,12 +531,6 @@ export async function assertFrameworkOptionsEdgeExported(fw, configPath, framewo
691
531
  ` - Define ${drifted.length === 1 ? "it" : "them"} in backend/framework.ts and re-export from nifra.config.ts ` +
692
532
  `(\`export { ${drifted.join(", ")} } from "./backend/framework.ts"\`).`);
693
533
  }
694
- /**
695
- * Refuse a build whose page routes sit under a mount: each would ship as a route that can never render.
696
- * Read from the config and `routes/` alone; the server also checks its own mount table at startup,
697
- * which covers a mount added inside `use`.
698
- */
699
- /** `nifra dev` shows the in-page issues badge unless `--no-indicator` or `dev.indicator: false` turns it off. */
700
534
  export function showsIndicator(flags, fw) {
701
535
  return !flags.noIndicator && fw.dev?.indicator !== false;
702
536
  }
@@ -709,14 +543,6 @@ export function assertNoShadowedPages(app) {
709
543
  return;
710
544
  throw new Error(`[nifra] build blocked: ${formatShadowedPages(shadowed)}`);
711
545
  }
712
- /**
713
- * A production build must not ship a workspace-linked package whose `default`-condition artifact is
714
- * missing or older than its source. The `"bun": "./src"` / `"default": "./dist"` split means Bun (this
715
- * build, the tests) reads live source while the deployed app and any node consumer read `dist/` - so a
716
- * green `nifra build` can bundle stale or absent dist and the drift never shows in a diff. The doctor
717
- * reports the same skew as an advisory during development; at build time it is a hard failure, because
718
- * this is the artifact that ships. No-op outside a workspace: tarball-installed deps cannot drift.
719
- */
720
546
  async function assertFreshWorkspaceDists(cwd) {
721
547
  const pkgPath = resolve(cwd, "package.json");
722
548
  if (!existsSync(pkgPath))
@@ -724,11 +550,9 @@ async function assertFreshWorkspaceDists(cwd) {
724
550
  let rootPackage;
725
551
  try {
726
552
  rootPackage = JSON.parse(readFileSync(pkgPath, "utf8"));
727
- // nifra-expect NF-S001: not a security gate. An unreadable/non-JSON package.json is a separate
728
- // build problem; returning here skips the freshness check rather than masking a denial.
729
553
  }
730
554
  catch {
731
- return; // an unreadable/!JSON package.json is a separate problem; don't mask it as a stale-dist failure
555
+ return;
732
556
  }
733
557
  const { collectStaleWorkspaceDists } = await import("./doctor.js");
734
558
  const stale = await collectStaleWorkspaceDists(cwd, rootPackage);
@@ -740,15 +564,39 @@ async function assertFreshWorkspaceDists(cwd) {
740
564
  throw new Error(`[nifra] build blocked: ${stale.length} workspace-linked package(s) ship a stale or missing dist artifact, so the deployed app would serve code this build did not produce:\n${lines.join("\n")}\nBuild the offending package(s) (\`bun run build\` in each) so every export target exists and is at least as new as its source, then rebuild.`);
741
565
  }
742
566
  async function buildForTarget(app, flag, flags) {
743
- const { parseBuildTarget, renderSizeReport, validateVercelRuntime } = await import("@nifrajs/web/build");
744
- const target = parseBuildTarget(flag ?? app.framework.target ?? "bun", flag === undefined ? "target in nifra.config.ts" : "--target");
567
+ const { buildWithDeploymentAdapter, isBuildTarget, parseBuildTarget, renderSizeReport, validateVercelRuntime, } = await import("@nifrajs/web/build");
568
+ const { framework: fw } = app;
569
+ const configuredAdapter = fw.deploymentAdapter;
570
+ const adapter = configuredAdapter?.adapter;
571
+ if (adapter !== undefined && flag === undefined && fw.target === undefined) {
572
+ throw new Error(`[nifra] deploymentAdapter "${adapter.id}" is configured; set target = "${adapter.id}" or pass --target ${adapter.id} to select it`);
573
+ }
574
+ const requestedTarget = flag ?? fw.target ?? "bun";
575
+ const adapterSelected = adapter !== undefined && requestedTarget === adapter.id;
576
+ if (!isBuildTarget(requestedTarget) && !adapterSelected) {
577
+ if (adapter === undefined) {
578
+ try {
579
+ parseBuildTarget(requestedTarget, flag === undefined ? "target in nifra.config.ts" : "--target");
580
+ }
581
+ catch (error) {
582
+ throw new Error(`${error instanceof Error ? error.message : String(error)} (no deploymentAdapter is configured in nifra.config.ts)`);
583
+ }
584
+ }
585
+ throw new Error(`[nifra] target "${requestedTarget}" does not match the configured deployment adapter "${adapter?.id}"`);
586
+ }
587
+ const target = adapterSelected
588
+ ? adapter.baseTarget
589
+ : parseBuildTarget(requestedTarget, flag === undefined ? "target in nifra.config.ts" : "--target");
590
+ if (adapterSelected && app.configPath === adapterFile(app.cwd)) {
591
+ throw new Error("[nifra] deploymentAdapter is build-time config, but this file is also the generated server's runtime import. " +
592
+ "Add backend/framework.ts for adapter and clientModule, keep deploymentAdapter in nifra.config.ts, and re-export the runtime fields there.");
593
+ }
745
594
  if (flags.vite && flags.bun) {
746
595
  throw new Error("[nifra] `nifra build` takes `--vite` or `--bun`, not both.");
747
596
  }
748
- const { framework: fw } = app;
749
597
  validateVercelRuntime(target, fw.vercelRuntime);
750
598
  if (fw.componentPipeline !== undefined) {
751
- // The component pipeline already owns its Vercel Node handler; this selector is ordinary SSR only.
599
+ const componentPipeline = fw.componentPipeline;
752
600
  if (fw.vercelRuntime !== undefined)
753
601
  throw new Error("[nifra/components] vercelRuntime selects ordinary SSR only; omit it for the component pipeline");
754
602
  if (flags.bun)
@@ -762,15 +610,45 @@ async function buildForTarget(app, flag, flags) {
762
610
  const outDir = target === "vercel" && flags.out === undefined
763
611
  ? resolve(app.cwd, ".vercel/output")
764
612
  : app.outDir;
765
- const result = await buildServerComponents({
766
- ...fw.componentPipeline,
613
+ const buildComponents = (output) => buildServerComponents({
614
+ ...componentPipeline,
767
615
  target,
768
616
  root: app.cwd,
769
- outDir,
617
+ outDir: output,
770
618
  plugins: asComponentPlugins(app.resolvedPlugins.vitePlugins),
771
619
  });
772
- await assertFreshWorkspaceDists(app.cwd);
773
- console.log(`[nifra/components] Built ${fw.componentPipeline.adapter} for ${target} (${result.build}) in ${outDir}`);
620
+ let result;
621
+ let adapterRun;
622
+ if (adapterSelected && adapter !== undefined) {
623
+ const packaged = await buildWithDeploymentAdapter({
624
+ adapter,
625
+ appRoot: app.cwd,
626
+ outDir,
627
+ options: configuredAdapter?.options,
628
+ secretExemptions: fw.secretExemptions,
629
+ componentPipeline: true,
630
+ protectedPaths: [
631
+ app.routesDir,
632
+ resolve(app.cwd, BACKEND_APP_FILE),
633
+ adapterFile(app.cwd),
634
+ ...(fw.publicDir === false ? [] : [resolve(fw.publicDir ?? resolve(app.cwd, "public"))]),
635
+ ],
636
+ build: async (stagingOutDir) => {
637
+ const built = await buildComponents(stagingOutDir);
638
+ await assertFreshWorkspaceDists(app.cwd);
639
+ return built;
640
+ },
641
+ });
642
+ result = packaged.result;
643
+ adapterRun = packaged.run;
644
+ }
645
+ else {
646
+ result = await buildComponents(outDir);
647
+ await assertFreshWorkspaceDists(app.cwd);
648
+ }
649
+ console.log(adapterRun === undefined
650
+ ? `[nifra/components] Built ${fw.componentPipeline.adapter} for ${target} (${result.build}) in ${outDir}`
651
+ : `[nifra/components] Built ${componentPipeline.adapter} for ${adapter.id} (base ${target}, ${result.build}) in ${outDir}\n from output directory: ${adapterRun}`);
774
652
  return;
775
653
  }
776
654
  const cssCodeSplitRequested = fw.cssCodeSplit === false;
@@ -784,13 +662,8 @@ async function buildForTarget(app, flag, flags) {
784
662
  "Bun client/server plugins. Use `--vite` with Vite equivalents, or remove the aggregate CSS setting; " +
785
663
  "switching pipelines would silently drop the Bun transforms.");
786
664
  }
787
- // Which bundler builds this app. Default is Bun; an app whose ONLY transforms are `vitePlugins` gets
788
- // Vite instead, because the Bun build cannot run them and would silently omit the work. `--vite`/`--bun`
789
- // force it, and the one forced combination that would drop transforms throws.
790
665
  let decision = chooseBuildPipeline(app.resolvedPlugins, flags.vite ? "vite" : flags.bun ? "bun" : undefined);
791
666
  if (cssCodeSplitRequested && decision.pipeline === "bun") {
792
- // With no Bun transforms, aggregate CSS is a Vite-only request that can be honored safely by
793
- // selecting the same pipeline the user would otherwise have to force explicitly.
794
667
  decision = {
795
668
  pipeline: "vite",
796
669
  why: "auto",
@@ -798,26 +671,16 @@ async function buildForTarget(app, flag, flags) {
798
671
  };
799
672
  }
800
673
  const useVite = decision.pipeline === "vite";
801
- // Same deploy-dir output - buildTargetVite delegates to the same orchestrator as buildTarget - so only
802
- // the bundler and the plugin FORMAT (Vite plugins, not Bun) differ.
803
674
  const buildTarget = useVite
804
675
  ? (await import("@nifrajs/web/build-vite")).buildTargetVite
805
676
  : (await import("@nifrajs/web/build")).buildTarget;
806
677
  const { routesDir, cwd, backend } = app;
807
- // `vercel deploy --prebuilt` uploads `.vercel/output` from the project root, so that is where a
808
- // Vercel build goes unless `--out` says otherwise.
809
678
  const outDir = target === "vercel" && flags.out === undefined ? resolve(cwd, ".vercel/output") : app.outDir;
810
- // The server entry must import the adapter from `backend/framework.ts` (edge-safe), not the
811
- // loaded config, so a multi-target app's Vite-plugin config never reaches the edge bundle
812
- // (load.ts header).
813
679
  const frameworkFile = adapterFile(cwd);
814
680
  const backendFile = resolve(cwd, BACKEND_APP_FILE);
815
681
  await assertUseIsEdgeExported(fw.use, app.configPath, frameworkFile);
816
682
  await assertFrameworkOptionsEdgeExported(fw, app.configPath, frameworkFile);
817
683
  assertNoShadowedPages(app);
818
- // Plugin FORMAT differs by pipeline: the Bun build takes Bun plugins (clientPlugins/serverPlugins); the
819
- // Vite build takes the app's Vite plugins (fw.vitePlugins) for BOTH halves. buildTargetWith forwards
820
- // whatever it's given straight to the chosen bundler, which casts to its own plugin type.
821
684
  const plugins = useVite
822
685
  ? {
823
686
  clientPlugins: app.resolvedPlugins.vitePlugins,
@@ -827,10 +690,10 @@ async function buildForTarget(app, flag, flags) {
827
690
  clientPlugins: asBunPlugins(app.resolvedPlugins.clientPlugins),
828
691
  serverPlugins: asBunPlugins(app.resolvedPlugins.serverPlugins),
829
692
  };
830
- const result = await buildTarget(target, {
693
+ const workDir = resolve(cwd, ".nifra-build");
694
+ const buildOptions = {
831
695
  routesDir,
832
- outDir,
833
- workDir: resolve(cwd, ".nifra-build"),
696
+ workDir,
834
697
  clientModule: fw.clientModule,
835
698
  adapterImport: frameworkFile,
836
699
  ...(fw.use ? { useImport: frameworkFile } : {}),
@@ -848,31 +711,48 @@ async function buildForTarget(app, flag, flags) {
848
711
  ...(fw.vercelRuntime !== undefined ? { vercelRuntime: fw.vercelRuntime } : {}),
849
712
  ...(fw.selfHost !== undefined ? { selfHost: fw.selfHost } : {}),
850
713
  live: fw.live?.clientEntry,
851
- // Prerendering drives a built app: the static target is made of its pages, and a bun or node server
852
- // answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
853
- // transforms the prerender pass (Bun's runtime) does not apply: those pages keep rendering on demand.
714
+ ...transportOption(flags, fw, cwd),
715
+ prerenderPaths: prerenderPaths(flags, target),
854
716
  ...(target === "static" || (!useVite && (target === "bun" || target === "node"))
855
717
  ? { prerenderApp: await buildPrerenderApp(app) }
856
718
  : {}),
857
- });
858
- // A production build must not certify itself green while a workspace-linked dependency ships a dist
859
- // artifact older than (or absent next to) its source: the `bun`->src condition let this compile read
860
- // live source, but the deployed app and every node consumer read `dist/`. Gate here, after the compile
861
- // proved the source is buildable, so the failure names the package to rebuild rather than a bundle error.
862
- await assertFreshWorkspaceDists(cwd);
863
- console.log(`nifra build (${target}, ${decision.pipeline}) → ${result.run}`);
864
- // The pipeline is stated on every build, not only the surprising ones - an auto-selected Vite build
865
- // must never look like the default, and a default Bun build must not leave the question open either.
719
+ };
720
+ let result;
721
+ let adapterRun;
722
+ if (adapterSelected && adapter !== undefined) {
723
+ const packaged = await buildWithDeploymentAdapter({
724
+ adapter,
725
+ appRoot: cwd,
726
+ outDir,
727
+ options: configuredAdapter?.options,
728
+ secretExemptions: fw.secretExemptions,
729
+ protectedPaths: [
730
+ routesDir,
731
+ workDir,
732
+ frameworkFile,
733
+ backendFile,
734
+ ...(fw.publicDir === false ? [] : [resolve(fw.publicDir ?? resolve(cwd, "public"))]),
735
+ ],
736
+ build: async (stagingOutDir) => {
737
+ const built = await buildTarget(target, { ...buildOptions, outDir: stagingOutDir });
738
+ await assertFreshWorkspaceDists(cwd);
739
+ return built;
740
+ },
741
+ });
742
+ result = packaged.result;
743
+ adapterRun = packaged.run;
744
+ }
745
+ else {
746
+ result = await buildTarget(target, { ...buildOptions, outDir });
747
+ await assertFreshWorkspaceDists(cwd);
748
+ }
749
+ console.log(adapterRun === undefined
750
+ ? `nifra build (${target}, ${decision.pipeline}) → ${result.run}`
751
+ : `nifra build (${adapter.id}, base ${target}, ${decision.pipeline}) → ${outDir}\n from output directory: ${adapterRun}`);
866
752
  console.log(` ${describePipeline(decision)}`);
867
753
  if (flags.report)
868
754
  console.log(`\n${renderSizeReport(result.size)}`);
869
755
  }
870
- /** Build the app FACTORY for the prerender pass of the `static`, `bun` and `node` targets. Registers the
871
- * framework's SSR Bun plugins (so `.vue`/`.svelte`/Solid routes import) once, then return a factory that
872
- * `createWebApp`s the app for the client build's manifest. The client entry MUST be the real content-hashed
873
- * bundle (`client.entry`) - it's the hydration `<script src>` the prerendered HTML emits, so a placeholder
874
- * would 404 and the pages would render but never hydrate (inert controls). Styles/route-preload are wired
875
- * from the same manifest so the static HTML matches the deployed app. */
876
756
  async function buildPrerenderApp(app) {
877
757
  const { plugin } = await import("bun");
878
758
  const { framework: fw, routesDir, backend } = app;
@@ -893,9 +773,6 @@ async function buildPrerenderApp(app) {
893
773
  async function start(app, flags) {
894
774
  const serverFile = resolve(app.outDir, "server.js");
895
775
  if (!existsSync(serverFile)) {
896
- // A Cloudflare Pages build emits `_worker.js` (a Workers bundle), not a self-hosting `server.js` - so
897
- // `nifra start` on a dir built for cloudflare would otherwise fail with a bare "no server.js". Name the
898
- // actual mismatch and the fix.
899
776
  if (existsSync(resolve(app.outDir, "_worker.js"))) {
900
777
  throw new Error(`[nifra] ${app.outDir} holds a Cloudflare Pages worker bundle (_worker.js), not a self-hosting ` +
901
778
  "server. Run `nifra build --target bun` then `nifra start`, or serve this dir with `wrangler pages`.");
@@ -910,6 +787,8 @@ const VALUE_FLAGS = {
910
787
  "-p": "port",
911
788
  "--out": "out",
912
789
  "--target": "target",
790
+ "--transport": "transport",
791
+ "--prerender": "prerender",
913
792
  };
914
793
  const SWITCH_FLAGS = {
915
794
  "--poll": "poll",
@@ -919,15 +798,27 @@ const SWITCH_FLAGS = {
919
798
  "--allow-duplicate-identity": "allowDuplicateIdentity",
920
799
  "--no-indicator": "noIndicator",
921
800
  };
922
- /** The flags of `nifra dev`, `build` and `start`, as `--flag value` or `--flag=value`. Anything else is
923
- * refused: an ignored `--target=vercel` would build the default target and exit 0. */
801
+ function transportOption(flags, fw, cwd) {
802
+ const module = flags.transport ?? fw.transport;
803
+ return module === undefined ? {} : { transport: resolve(cwd, module) };
804
+ }
805
+ function prerenderPaths(flags, target) {
806
+ if (flags.prerender === undefined)
807
+ return undefined;
808
+ if (target !== "static") {
809
+ throw new Error(`[nifra] --prerender applies to \`--target static\` (this build is ${target}): other targets prerender the routes that export \`prerender\``);
810
+ }
811
+ return flags.prerender
812
+ .split(",")
813
+ .map((path) => path.trim())
814
+ .filter((path) => path !== "");
815
+ }
924
816
  export function parseFlags(args) {
925
- // Port precedence: `--port`/`-p` (most specific) > `PORT` env > the framework default. The default is
926
- // the SAME uncommon port for `nifra dev` and `nifra start` (DEFAULT_DEV_PORT) so a project's URL is
927
- // stable across commands and doesn't collide with the usual 3000/5173/8080 crowd.
928
817
  let port = Number(Bun.env.PORT ?? DEFAULT_DEV_PORT);
929
818
  let out;
930
819
  let target;
820
+ let transport;
821
+ let prerender;
931
822
  const switches = {
932
823
  poll: Bun.env.CHOKIDAR_USEPOLLING === "1",
933
824
  report: false,
@@ -949,6 +840,10 @@ export function parseFlags(args) {
949
840
  port = Number(value);
950
841
  else if (valueField === "out")
951
842
  out = value;
843
+ else if (valueField === "transport")
844
+ transport = value;
845
+ else if (valueField === "prerender")
846
+ prerender = value;
952
847
  else
953
848
  target = value;
954
849
  continue;
@@ -968,14 +863,8 @@ export function parseFlags(args) {
968
863
  if (!Number.isFinite(port) || port < 0 || port > 65535) {
969
864
  throw new Error(`[nifra] invalid --port: ${port}`);
970
865
  }
971
- return { port, out, target, ...switches };
866
+ return { port, out, target, transport, prerender, ...switches };
972
867
  }
973
- /**
974
- * `assure` uses the structured-bundle lane only when explicitly asked. A bare `--json` is NOT a
975
- * request for the bundle - it keeps the legacy `{ ok, routes, findings }` report machine-readable, so a
976
- * pre-bundle consumer is never silently handed the `{ gates, verdict }` shape. `--bundle` (or a
977
- * bundle-only flag) opts in; `--bundle --json` still yields the bundle, which is always JSON.
978
- */
979
868
  export function assureBundleRequested(argv) {
980
869
  return (argv.includes("--bundle") ||
981
870
  argv.includes("--strict") ||
@@ -983,12 +872,6 @@ export function assureBundleRequested(argv) {
983
872
  argv.includes("--interact") ||
984
873
  argv.includes("--out"));
985
874
  }
986
- /**
987
- * A command that reflects the project imports it, and an app that validates its environment at module
988
- * scope calls `process.exit` from inside that import. Nothing is throwable at that point, so the whole
989
- * output is the app's own abort message with no hint that a nifra command triggered it. Name the cause
990
- * on the way out and point at the flag that supplies the environment.
991
- */
992
875
  function installReflectionExitHint() {
993
876
  let inFlight;
994
877
  process.on("exit", (code) => {
@@ -1003,8 +886,6 @@ function installReflectionExitHint() {
1003
886
  inFlight = command;
1004
887
  };
1005
888
  }
1006
- /** Commands that import the app only to read what it declares, never sending it a request, so the
1007
- * app may skip connecting to its services. `assure` qualifies without its bundle lane, which renders. */
1008
889
  const READ_ONLY_COMMANDS = new Set([
1009
890
  "capabilities",
1010
891
  "check",
@@ -1018,11 +899,6 @@ const READ_ONLY_COMMANDS = new Set([
1018
899
  "sync-manifest",
1019
900
  ]);
1020
901
  const HELD_OPEN_GRACE_MS = 2_000;
1021
- /**
1022
- * A command that imports the app for its answer has already answered when the app's own work - a
1023
- * database or Redis client reconnecting, an interval - would keep the process alive indefinitely.
1024
- * A process that exits on its own never reaches this unref'd timer; a held one is ended with a note.
1025
- */
1026
902
  function exitIfHeldOpen(command) {
1027
903
  setTimeout(() => {
1028
904
  process.stderr.write(`[nifra] \`nifra ${command}\` has finished, but something the app started when it was imported ` +
@@ -1033,9 +909,7 @@ function exitIfHeldOpen(command) {
1033
909
  process.exit(typeof process.exitCode === "number" ? process.exitCode : 0);
1034
910
  }, HELD_OPEN_GRACE_MS).unref();
1035
911
  }
1036
- /** Set on the copy of `nifra mcp` that serves without `.env` files, so it does not restart again. */
1037
912
  const MCP_WITHOUT_ENV_FILES = "NIFRA_MCP_WITHOUT_ENV_FILES";
1038
- /** Parse frontend positionals separately from flags so `--json` never becomes a symptom. */
1039
913
  export function frontendCommandInput(argv, parseAdapter) {
1040
914
  const unknown = argv.find((arg) => arg.startsWith("-") && arg !== "--json" && arg !== "--help" && arg !== "-h");
1041
915
  if (unknown !== undefined)
@@ -1051,16 +925,11 @@ export function frontendCommandInput(argv, parseAdapter) {
1051
925
  json: argv.includes("--json"),
1052
926
  };
1053
927
  }
1054
- /** Dispatch a CLI invocation, including project-independent agent and documentation commands. */
1055
928
  async function main() {
1056
929
  const { argv: rawArgv, files: envFiles } = takeEnvFileFlags(cliArgv());
1057
- // `nifra mcp` keeps none of the `.env` values Bun loaded at startup. Decided before the
1058
- // `--env-file`s below, which the caller names explicitly and which stay.
1059
930
  const forgotten = rawArgv[0] === "mcp" && process.env[MCP_WITHOUT_ENV_FILES] !== "1"
1060
931
  ? await forgetAutoLoadedEnv()
1061
932
  : [];
1062
- // Applied before any command runs: a reflecting command imports the app on its first await, and the
1063
- // app reads its environment at module scope, so the variables must already be in place by then.
1064
933
  if (envFiles.length > 0)
1065
934
  await applyEnvFiles(process.cwd(), envFiles);
1066
935
  const argv = rawArgv;
@@ -1091,11 +960,7 @@ async function main() {
1091
960
  return;
1092
961
  }
1093
962
  }
1094
- // `mcp` runs a long-lived stdio server and loads the project lazily per-tool - it must not go through
1095
- // the eager `loadApp` below (which would fail fast on a project that's API-only / not yet built).
1096
963
  if (command === "mcp") {
1097
- // Bun passes what it loaded to every subprocess whatever `process.env` says now, so the session
1098
- // moves to a copy of this process that never loads `.env` files.
1099
964
  if (forgotten.length > 0) {
1100
965
  const { handOffSession } = await import("./mcp-delegate.js");
1101
966
  const exitCode = await handOffSession([process.execPath, "--no-env-file", ...process.argv.slice(1)], { cwd: process.cwd(), env: { ...process.env, [MCP_WITHOUT_ENV_FILES]: "1" } });
@@ -1105,14 +970,10 @@ async function main() {
1105
970
  }
1106
971
  }
1107
972
  const { runMcpServer } = await import("./mcp.js");
1108
- // `nifra mcp [dir]` - an explicit project directory pins the root (for clients configured outside
1109
- // the project); otherwise the server resolves it from cwd + the client's MCP roots.
1110
973
  const dirArg = argv[1] !== undefined && !argv[1].startsWith("-") ? argv[1] : undefined;
1111
974
  await runMcpServer(process.cwd(), CLI_VERSION, dirArg);
1112
975
  return;
1113
976
  }
1114
- // `docs-mcp` runs the PUBLIC docs MCP over HTTP - project-independent (serves the bundled corpus), so
1115
- // it self-hosts anywhere Bun runs (a VPS behind a reverse proxy, a container). Long-lived; no loadApp.
1116
977
  if (command === "docs-mcp") {
1117
978
  const { handleMcpHttp } = await import("./mcp-http.js");
1118
979
  const portArg = argv[argv.indexOf("--port") + 1];
@@ -1124,17 +985,12 @@ async function main() {
1124
985
  console.log(`nifra docs MCP (HTTP) → ${server.url}`);
1125
986
  return;
1126
987
  }
1127
- // `learn` prints the guided build-an-app path (the human head of `nifra_learn`). Project-independent:
1128
- // the path is static, so no project needs to load. `nifra learn` for the index, `nifra learn 3` for a step.
1129
988
  if (command === "learn") {
1130
989
  const { renderLearnResult } = await import("./learn.js");
1131
990
  const stepArg = argv[1];
1132
991
  console.log(renderLearnResult(stepArg !== undefined && /^\d+$/.test(stepArg) ? Number(stepArg) : undefined));
1133
992
  return;
1134
993
  }
1135
- // `frontend` prints the client-side footgun catalog (the human head of `nifra_frontend`).
1136
- // Project-independent and static. `nifra frontend` for the index, `nifra frontend vue "lost reactivity"`
1137
- // to filter by adapter and/or symptom (either arg may be omitted; an adapter is recognized by name).
1138
994
  if (command === "frontend") {
1139
995
  const { selectFrontendGuidance, renderFrontendResult, parseAdapter } = await import("./frontend-guidance.js");
1140
996
  const input = frontendCommandInput(argv.slice(1), parseAdapter);
@@ -1143,9 +999,6 @@ async function main() {
1143
999
  : renderFrontendResult(input));
1144
1000
  return;
1145
1001
  }
1146
- // `runtime` prints the Bun/Node/Deno/Workers differences catalog (the human head of `nifra_runtime`).
1147
- // Project-independent and static. `nifra runtime` for the index, `nifra runtime deno "path guard"` to
1148
- // filter by runtime and/or symptom (either arg may be omitted; a runtime is recognized by name).
1149
1002
  if (command === "runtime") {
1150
1003
  const { selectRuntimeDifferences, renderRuntimeResult, parseRuntime } = await import("./runtime-differences.js");
1151
1004
  const input = frontendCommandInput(argv.slice(1), parseRuntime);
@@ -1155,7 +1008,6 @@ async function main() {
1155
1008
  : renderRuntimeResult(query));
1156
1009
  return;
1157
1010
  }
1158
- // `nifra db <sub>` is the catalog's `db-<sub>` command, projected to MCP as `nifra_db_<sub>`.
1159
1011
  const dbSub = command === "db" && argv[1] !== undefined && !argv[1].startsWith("-") ? argv[1] : undefined;
1160
1012
  if (command === "db" && (dbSub === undefined || findCommandSpec(`db-${dbSub}`) === undefined)) {
1161
1013
  throw new Error("[nifra] usage: nifra db schema|query|role|audit - see `nifra help`");
@@ -1200,8 +1052,6 @@ async function main() {
1200
1052
  }
1201
1053
  }
1202
1054
  catch (err) {
1203
- // A thrown error is nifra's own reporting path, not a silent abort: clear the sentinel so the
1204
- // hint stays reserved for the case where the process died inside the app import.
1205
1055
  markReflecting(undefined);
1206
1056
  reportFailure(err, argv);
1207
1057
  const candidate = typeof err === "object" && err !== null && "exitCode" in err
@@ -1228,9 +1078,6 @@ async function main() {
1228
1078
  process.exitCode = 1;
1229
1079
  return;
1230
1080
  }
1231
- // `init-agents` retrofits the agent files (.mcp.json, CLAUDE.md, AGENTS.md, …) into the cwd. It's a
1232
- // pure file-writing command independent of the app loading, so dispatch it before the eager `loadApp`
1233
- // (an existing app might be API-only or not yet built). It always succeeds unless a write throws.
1234
1081
  if (command === "init-agents") {
1235
1082
  const { runInitAgents } = await import("./init-agents.js");
1236
1083
  await runInitAgents(process.cwd(), {
@@ -1270,9 +1117,6 @@ async function main() {
1270
1117
  exitIfHeldOpen(command);
1271
1118
  return;
1272
1119
  }
1273
- // `upgrade` is a pure cwd file-transformer (package.json pins + import moves) driven by a per-release
1274
- // recipe, then verified with `nifra check`. Dispatch before the eager `loadApp` - it must run on any
1275
- // repo (API-only, not built, or mid-upgrade with edits that don't yet typecheck under dry-run).
1276
1120
  if (command === "upgrade") {
1277
1121
  if (argv.includes("--help") || argv.includes("-h")) {
1278
1122
  console.log(HELP);
@@ -1294,8 +1138,6 @@ async function main() {
1294
1138
  exitIfHeldOpen(command);
1295
1139
  return;
1296
1140
  }
1297
- // `port` is a pure cwd-based portability linter (scans source, doesn't run the app) - like `check`/
1298
- // `doctor`, dispatch before the eager `loadApp` so it runs on an API-only / not-yet-built project.
1299
1141
  if (command !== "dev" && command !== "build" && command !== "start") {
1300
1142
  console.error(`[nifra] unknown command: ${command}\n`);
1301
1143
  console.error(HELP);
@@ -1318,7 +1160,6 @@ async function main() {
1318
1160
  if (command !== "start") {
1319
1161
  const { refreshRouteTypes, watchRouteTypes } = await import("./route-types.js");
1320
1162
  refreshRouteTypes(app.cwd);
1321
- // A relaunched `nifra dev --bun` child runs beside its parent, which already watches.
1322
1163
  if (command === "dev" && process.env.NIFRA_BUN_DEV_TOKEN === undefined)
1323
1164
  watchRouteTypes(app.cwd);
1324
1165
  }
@@ -1330,29 +1171,14 @@ async function main() {
1330
1171
  await start(app, flags);
1331
1172
  }
1332
1173
  finally {
1333
- // `dev` and `start` keep serving after they return; a build is over.
1334
1174
  if (command === "build")
1335
1175
  exitIfHeldOpen(command);
1336
1176
  }
1337
1177
  }
1338
- /**
1339
- * Bun 1.4 on Windows can report `import.meta.main === false` for a module launched after a `--config`
1340
- * re-exec, even though that module is the process entry. Treat the runtime flag as authoritative when
1341
- * it is true, but recover from that false negative by comparing the runtime's entry path with this file.
1342
- * The comparison is deliberately realpath-based so a package-bin symlink is accepted while an imported
1343
- * copy of the CLI remains inert (tests import `parseFlags` from this module).
1344
- */
1345
1178
  function isMainModule() {
1346
1179
  if (import.meta.main)
1347
1180
  return true;
1348
1181
  const target = fileURLToPath(import.meta.url);
1349
- /**
1350
- * Bun's `--config`/`--conditions` flags can sit before the script in the child argv. `argv[1]` is
1351
- * therefore a runtime flag on Bun 1.4/Windows, not the entry module. `Bun.main` is the authoritative
1352
- * runtime answer when available; the bounded argv fallback covers Bun releases that do not expose it.
1353
- * Only non-flag entries are considered and every match must resolve to this exact file, so an
1354
- * unresolved or arbitrary flag can never turn an imported CLI module into a running CLI.
1355
- */
1356
1182
  const bunMain = Bun.main;
1357
1183
  const argvEntries = (argv) => {
1358
1184
  const entries = [];
@@ -1362,8 +1188,6 @@ function isMainModule() {
1362
1188
  if (value.startsWith("-"))
1363
1189
  continue;
1364
1190
  entries.push(value);
1365
- // The script is before the user's command/flags. A small bound keeps a caller's arbitrary
1366
- // arguments from becoming an entry-point probe while covering a config plus a few conditions.
1367
1191
  if (entries.length === 4)
1368
1192
  break;
1369
1193
  }
@@ -1394,7 +1218,6 @@ function isMainModule() {
1394
1218
  add(resolver(value));
1395
1219
  }
1396
1220
  catch {
1397
- // A virtual/synthetic argv entry has no realpath; it is not safe evidence of main-ness.
1398
1221
  }
1399
1222
  }
1400
1223
  return paths;
@@ -1406,12 +1229,6 @@ function isMainModule() {
1406
1229
  }
1407
1230
  return false;
1408
1231
  }
1409
- /**
1410
- * Bun 1.4 on Windows can omit the script path from both argv vectors when a TS file is launched by
1411
- * `Bun.spawn`. The command token is a safe last-resort discriminator: a test importing this module
1412
- * sees test-file paths and runner flags, not an exact Nifra command, while a direct CLI invocation
1413
- * has one of the manual or catalogued command names below.
1414
- */
1415
1232
  function isCliCommandToken(value) {
1416
1233
  return (value === "dev" ||
1417
1234
  value === "build" ||
@@ -1428,17 +1245,8 @@ function isCliCommandToken(value) {
1428
1245
  findCommandSpec(value) !== undefined);
1429
1246
  }
1430
1247
  function findCliCommand(values) {
1431
- // Most Bun/Node argv vectors reserve index 0 for the runtime and index 1 for the script. Bun 1.4
1432
- // on Windows can omit the script for a directly spawned TS entry, leaving the command at index 0.
1433
- // Accept that one exact-token shape while keeping arbitrary imported-module argv inert.
1434
1248
  return values.findIndex((value) => isCliCommandToken(value));
1435
1249
  }
1436
- /**
1437
- * The command vector from one runtime argv: the command, then its arguments. Arguments typed before
1438
- * the command (`nifra --json check`) follow the command's own, ahead of any `--`, rather than being
1439
- * dropped. Only when index 1 is the script: a runtime flag there means the leading entries are the
1440
- * runtime's own, not the caller's.
1441
- */
1442
1250
  export function commandArgv(values, commandIndex) {
1443
1251
  const command = values.slice(commandIndex);
1444
1252
  const script = values[1];
@@ -1461,12 +1269,6 @@ function cliArgv() {
1461
1269
  }
1462
1270
  return Bun.argv.slice(2);
1463
1271
  }
1464
- /**
1465
- * Recover the original command vector when Bun's Windows `--config` launch drops it from both public
1466
- * argv arrays. This is deliberately narrow: only a positive re-exec marker can enable the channel, the
1467
- * first item must be a real Nifra command, and malformed/oversized data is ignored so an inherited
1468
- * environment can never turn an imported CLI module into an arbitrary command runner.
1469
- */
1470
1272
  function reexecCliArgv() {
1471
1273
  if (!isBunDevReexecChild())
1472
1274
  return undefined;
@@ -1493,14 +1295,6 @@ function reexecCliArgv() {
1493
1295
  function hasCliCommandToken() {
1494
1296
  return findCliCommand(Bun.argv) >= 0 || findCliCommand(process.argv) >= 0;
1495
1297
  }
1496
- /**
1497
- * Bun 1.4/Windows can load the explicit script after a `--config` re-exec while reporting neither a
1498
- * usable `import.meta.main` nor the script in its public argv vectors. The child still carries the
1499
- * parent-generated launch proof and a positive depth; accepting that narrow marker lets it enter
1500
- * `main()`, where `consumeLaunchToken()` remains the fail-closed gate before the configured server can
1501
- * run. A forged marker only causes the normal token-mismatch relaunch/error path - it cannot bypass the
1502
- * boundary plugin proof.
1503
- */
1504
1298
  function isBunDevReexecChild() {
1505
1299
  const depth = Number(process.env.NIFRA_BUN_DEV_DEPTH);
1506
1300
  return (process.env.NIFRA_BUN_DEV_TOKEN !== undefined &&
@@ -1508,13 +1302,7 @@ function isBunDevReexecChild() {
1508
1302
  Number.isSafeInteger(depth) &&
1509
1303
  depth > 0);
1510
1304
  }
1511
- // Only run the CLI when invoked as the entry (`bun cli.ts …`), not when a test imports it for the
1512
- // exported `parseFlags`.
1513
1305
  if (isMainModule() || isBunDevReexecChild() || hasCliCommandToken()) {
1514
- // Keep the entry module alive until the async CLI has completed. Bun 1.4 on Windows can otherwise
1515
- // terminate a process created by Bun.spawn while its first dynamic import is pending, leaving an
1516
- // exit-0 child with no output. Imported test modules never enter this branch, so the CLI's top-level
1517
- // await cannot start a server merely because a test imports a helper from this file.
1518
1306
  try {
1519
1307
  await main();
1520
1308
  }