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