@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/upgrade.js CHANGED
@@ -1,36 +1,3 @@
1
- /**
2
- * `nifra upgrade <version>` - an executable, per-release upgrade runner. Framework and shared-package
3
- * bumps otherwise spread the same mechanical edits across every consuming app by hand; a recipe turns
4
- * them into `detect → transform → verify`:
5
- *
6
- * 1. **pin sweep** - set every matching dependency to the target version across the workspace's
7
- * package.json files, preserving the caret/tilde/exact style and skipping `workspace:`/`link:` specs.
8
- * `overrides`, `resolutions` and `pnpm.overrides` are swept too, since they decide what installs.
9
- * The MCP launch pin in `.mcp.json`, `.cursor/mcp.json`, CLAUDE.md and AGENTS.md moves too, the
10
- * edit `nifra init-agents --sync-mcp` makes; a version pinned anywhere else (a Dockerfile, a CI
11
- * workflow, another lockfile) is listed only.
12
- * 2. **dependency moves** - replace removed packages with their supported successor without
13
- * reserializing package.json or leaving duplicate dependency keys.
14
- * 3. **import moves** - rewrite exact import specifiers to their updated module paths.
15
- * 4. **dependency adds** - add a package an imported entry needs to the manifest that imports it,
16
- * beside the package the entry belongs to, when that manifest lists it nowhere.
17
- * 5. **verify** - reuse the existing `nifra check` gate; no new verification surface. It reads the
18
- * installed packages, so while the edited pins are not installed yet it is skipped with the
19
- * install command to run first: a check then would judge the release being left.
20
- *
21
- * Upgrading across several releases runs every recipe between the installed version (the lowest
22
- * fixed-group version the workspace declares) and the target, oldest first, then pins the target. A
23
- * target newer than this CLI prints the newer CLI's command instead of guessing at recipes it does not
24
- * carry; nothing is downloaded or run on the user's behalf.
25
- *
26
- * Dry-run by default (prints the plan, writes nothing); `--write` applies. Fail-closed on an unknown
27
- * target version or a missing package.json, and deterministic (same repo + target → same edits).
28
- *
29
- * Transforms are string/specifier-level, except a recipe's `sourceRewrites`: syntax-tree edits made
30
- * with the project's own TypeScript (`source-rewrites.ts`), each rewriting only a shape it recognizes
31
- * whole and listing every other site to edit by hand. Without TypeScript such an upgrade refuses to
32
- * run rather than leave the rewrite undone: after its pins land, no later upgrade would run it.
33
- */
34
1
  import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync, } from "node:fs";
35
2
  import { basename, dirname, join, relative, resolve, sep } from "node:path";
36
3
  import { fileURLToPath } from "node:url";
@@ -52,18 +19,9 @@ const DEP_FIELDS = [
52
19
  "optionalDependencies",
53
20
  ];
54
21
  const PEER_FIELD = "peerDependencies";
55
- // Only a bare semver spec is rewritten. Anything else - workspace:*, link:/file:, npm: aliases, git
56
- // urls, "*", "latest", or a multi-part range - is intentionally left untouched (skipped, not guessed).
57
22
  const SEMVER_SPEC = /^([\^~]|>=|<=|>|<|=)?\s*(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
58
23
  const UPPER_BOUND = /^\s*<=?/;
59
- // A strict bound kept on the target would exclude it: `>5.2.0` → `>5.3.0` refuses 5.3.0.
60
24
  const INCLUSIVE_OPERATOR = { ">": ">=", "<": "<=" };
61
- /**
62
- * Rewrite a dependency version spec to `toVersion`, preserving the range operator (`^`, `~`, …;
63
- * a strict `>` or `<` becomes `>=` or `<=`, so the result admits the target), or dropping it when
64
- * `exact`. Returns null when the spec is not a plain semver spec (→ skip it) or already equals the
65
- * target.
66
- */
67
25
  export function rewriteVersionSpec(spec, toVersion, exact = false) {
68
26
  const match = SEMVER_SPEC.exec(spec.trim());
69
27
  if (!match)
@@ -73,16 +31,13 @@ export function rewriteVersionSpec(spec, toVersion, exact = false) {
73
31
  const next = `${operator}${toVersion}`;
74
32
  return next === spec ? null : next;
75
33
  }
76
- /** The version a plain semver spec names (`^2.4.1` → `2.4.1`), or null for any other spec. */
77
34
  export function specVersion(spec) {
78
35
  const match = SEMVER_SPEC.exec(spec.trim());
79
36
  if (!match)
80
37
  return null;
81
38
  return `${match[2]}.${match[3]}.${match[4]}${match[5] === undefined ? "" : `-${match[5]}`}`;
82
39
  }
83
- // A release target: a bare version, never a range, so it can be pinned and printed in a command.
84
40
  const RELEASE_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
85
- /** Numeric core (major, minor, patch) of a semver spec, ignoring the range operator + prerelease/build. */
86
41
  export function specVersionTuple(spec) {
87
42
  const match = SEMVER_SPEC.exec(spec.trim());
88
43
  if (!match)
@@ -101,11 +56,9 @@ function parseSpecVersion(spec) {
101
56
  : prerelease.map((part) => (/^\d+$/.test(part) ? Number(part) : part)),
102
57
  };
103
58
  }
104
- /** Compare two semver cores: <0 when a<b, 0 equal, >0 when a>b. */
105
59
  export function compareSemverCore(a, b) {
106
60
  return a[0] - b[0] || a[1] - b[1] || a[2] - b[2];
107
61
  }
108
- /** Compare full semver precedence, including prereleases (`2.3.0-beta` < `2.3.0`). */
109
62
  export function compareSemverSpec(a, b) {
110
63
  const left = parseSpecVersion(a);
111
64
  const right = parseSpecVersion(b);
@@ -140,11 +93,6 @@ export function compareSemverSpec(a, b) {
140
93
  }
141
94
  return 0;
142
95
  }
143
- /**
144
- * Whether a plain semver spec's range admits `version`, as npm reads it: `^` and `~` stop before the
145
- * next breaking release, and a prerelease satisfies only a spec naming a prerelease of its own core.
146
- * False for any other spec.
147
- */
148
96
  export function specIncludes(spec, version) {
149
97
  const match = SEMVER_SPEC.exec(spec.trim());
150
98
  const target = parseSpecVersion(version);
@@ -179,11 +127,6 @@ export function specIncludes(spec, version) {
179
127
  return order === 0;
180
128
  }
181
129
  }
182
- /**
183
- * Apply pin rules to one package.json's TEXT (format-preserving - targeted string replaces, never a
184
- * JSON re-serialize that would reorder keys or drop comments-as-formatting). Returns the new text and
185
- * the changes made.
186
- */
187
130
  export function pinSweepText(text, rules, allowDowngrade = false, exact = false) {
188
131
  let parsed;
189
132
  try {
@@ -200,21 +143,14 @@ export function pinSweepText(text, rules, allowDowngrade = false, exact = false)
200
143
  const rule = rules.find((r) => name === r.match || (r.match.endsWith("/") && name.startsWith(r.match)));
201
144
  if (!rule)
202
145
  continue;
203
- // A peer range states what a library accepts, not what installs: widening a floor that already
204
- // admits the target would drop every consumer still on an older release, and an exact peer pin
205
- // would admit one release only.
206
146
  const peer = field === PEER_FIELD;
207
147
  if (peer && specIncludes(rawSpec, rule.to))
208
148
  continue;
209
- // An upper bound has no floor to raise: one that admits the target (`<6.0.0`) stays as written,
210
- // in every field, and is never read as a rollback.
211
149
  if (UPPER_BOUND.test(rawSpec) && specIncludes(rawSpec, rule.to))
212
150
  continue;
213
151
  const next = rewriteVersionSpec(rawSpec, rule.to, exact && !peer);
214
152
  if (next === null)
215
153
  continue;
216
- // Refuse a rollback: `upgrade <version>` pins an exact target, so an OLD target on a newer install
217
- // walks dependencies backward (e.g. ^2.3.0 → ^2.0.0) and can break a shared-package peer range.
218
154
  const current = specVersionTuple(rawSpec);
219
155
  const target = specVersionTuple(rule.to);
220
156
  if (!allowDowngrade &&
@@ -224,8 +160,6 @@ export function pinSweepText(text, rules, allowDowngrade = false, exact = false)
224
160
  downgrades.push({ field, name: key, from: rawSpec, to: next });
225
161
  continue;
226
162
  }
227
- // Replace exactly `"key"<ws>:<ws>"spec"` inside the object holding this pin, preserving the
228
- // whitespace: npm's nested `{ ".": "5.2.0" }` under another package names that package.
229
163
  const range = objectRangeAt(out, holder);
230
164
  const at = range === undefined ? undefined : memberValueAt(out, range, key);
231
165
  const written = JSON.stringify(rawSpec);
@@ -236,17 +170,11 @@ export function pinSweepText(text, rules, allowDowngrade = false, exact = false)
236
170
  }
237
171
  return { text: out, changes, downgrades };
238
172
  }
239
- /** Where a package manager forces one version over every range: npm and Bun `overrides` (nested by
240
- * parent), Yarn and Bun `resolutions`, pnpm `pnpm.overrides`. */
241
173
  const OVERRIDE_FIELDS = [
242
174
  ["overrides"],
243
175
  ["resolutions"],
244
176
  ["pnpm", "overrides"],
245
177
  ];
246
- /**
247
- * The package an override key pins: `@nifrajs/core`, `parent/@nifrajs/core` and the same behind a `**`
248
- * glob (resolutions), `parent>@nifrajs/core` and `@nifrajs/core@<4` (pnpm).
249
- */
250
178
  function overrideTarget(key) {
251
179
  const last = key.slice(key.lastIndexOf(">") + 1);
252
180
  return /(?:^|\/)((?:@[^/@]+\/)?[^/@]+)(?:@[^/]*)?$/.exec(last)?.[1] ?? last;
@@ -265,7 +193,6 @@ function pinEntries(parsed) {
265
193
  let value = parsed;
266
194
  for (const key of path)
267
195
  value = typeof value === "object" && value !== null ? Reflect.get(value, key) : undefined;
268
- // npm nests an override under the package whose dependency it pins; `.` pins that package itself.
269
196
  const walk = (object, parent, holder) => {
270
197
  for (const [key, spec] of Object.entries(object)) {
271
198
  const target = key === "." ? parent : overrideTarget(key);
@@ -280,8 +207,6 @@ function pinEntries(parsed) {
280
207
  }
281
208
  return entries;
282
209
  }
283
- /** The body (between the braces) of the object at `path` in a JSON text: top-level key first, then
284
- * each nested one, never a same-named key deeper in the document. */
285
210
  function objectRangeAt(text, path) {
286
211
  const rootOpen = text.indexOf("{");
287
212
  if (rootOpen === -1)
@@ -297,7 +222,6 @@ function objectRangeAt(text, path) {
297
222
  }
298
223
  return range;
299
224
  }
300
- /** The index of the `"` that closes the string opening at `open`. */
301
225
  function stringEnd(text, open) {
302
226
  for (let index = open + 1; index < text.length; index++) {
303
227
  if (text[index] === "\\")
@@ -307,7 +231,6 @@ function stringEnd(text, open) {
307
231
  }
308
232
  return text.length;
309
233
  }
310
- /** The index of the brace that closes the one at `open`. */
311
234
  function closingBrace(text, open) {
312
235
  let depth = 0;
313
236
  for (let index = open; index < text.length; index++) {
@@ -321,14 +244,12 @@ function closingBrace(text, open) {
321
244
  }
322
245
  return text.length;
323
246
  }
324
- /** The body of `key`'s object value among the direct members of the object body `within`. */
325
247
  function memberObjectRange(text, within, key) {
326
248
  const at = memberValueAt(text, within, key);
327
249
  return at !== undefined && text[at] === "{"
328
250
  ? { start: at + 1, end: closingBrace(text, at) }
329
251
  : undefined;
330
252
  }
331
- /** Where `key`'s value starts among the direct members of the object body `within`. */
332
253
  function memberValueAt(text, within, key) {
333
254
  let depth = 0;
334
255
  for (let index = within.start; index < within.end; index++) {
@@ -391,7 +312,6 @@ function rewriteDependencyEntry(text, field, from, fromVersion, to, toVersion) {
391
312
  }
392
313
  return text.slice(0, range.start) + nextBody + text.slice(range.end);
393
314
  }
394
- /** Move removed package dependencies without reserializing or reordering package.json. */
395
315
  export function moveDependenciesText(text, moves, exact = false) {
396
316
  let out = text;
397
317
  const changes = [];
@@ -414,8 +334,6 @@ export function moveDependenciesText(text, moves, exact = false) {
414
334
  if (typeof fromVersion !== "string")
415
335
  continue;
416
336
  const movedVersion = rewriteVersionSpec(fromVersion, move.toVersion, exact) ?? fromVersion;
417
- // Dependency fields have different install semantics. A devDependency does not satisfy a runtime
418
- // dependency, so only deduplicate the successor inside the same field.
419
337
  const targetExists = Object.hasOwn(dependencyMap, move.to);
420
338
  const action = targetExists ? "removed" : "renamed";
421
339
  const next = rewriteDependencyEntry(out, field, move.from, fromVersion, targetExists ? undefined : move.to, targetExists ? undefined : movedVersion);
@@ -432,7 +350,6 @@ export function moveDependenciesText(text, moves, exact = false) {
432
350
  });
433
351
  }
434
352
  }
435
- // The edit is textual; a result that no longer parses is never written.
436
353
  try {
437
354
  JSON.parse(out);
438
355
  }
@@ -442,7 +359,6 @@ export function moveDependenciesText(text, moves, exact = false) {
442
359
  return { text: out, changes };
443
360
  }
444
361
  const IMPORT_SPEC = (from) => new RegExp(`(\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\brequire\\s*\\(\\s*|\\bimport\\s+)(['"])${escapeRegExp(from)}(['"])`, "g");
445
- /** Rewrite exact import/export/require/dynamic-import specifiers in one source file's text. */
446
362
  export function applyImportMoves(text, moves) {
447
363
  let out = text;
448
364
  const changes = [];
@@ -460,10 +376,8 @@ export function applyImportMoves(text, moves) {
460
376
  return { text: out, changes };
461
377
  }
462
378
  const SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}";
463
- // Svelte and Vue components import adapter entries too.
464
379
  const ADD_SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}";
465
380
  const IMPORTED_SPEC = (prefix) => new RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\brequire\\s*\\(\\s*|\\bimport\\s+)(['"])(${escapeRegExp(prefix)}(?:/[^'"]*)?)\\1`);
466
- /** The first specifier in `text` that names one of `imports` or a subpath of one. */
467
381
  export function importedSpecifier(text, imports) {
468
382
  for (const prefix of imports) {
469
383
  const match = IMPORTED_SPEC(prefix).exec(text);
@@ -477,11 +391,6 @@ const packageOf = (specifier) => specifier
477
391
  .slice(0, specifier.startsWith("@") ? 2 : 1)
478
392
  .join("/");
479
393
  const MEMBER = /("(?:[^"\\]|\\.)*")\s*:\s*"(?:[^"\\]|\\.)*"/g;
480
- /**
481
- * Add `"name": "version"` to the `field` object of a package.json text without reserializing it,
482
- * creating the field at the end of the root when absent. The entry goes before the first larger name
483
- * when the members are sorted, last otherwise.
484
- */
485
394
  function insertDependencyEntry(text, field, name, version) {
486
395
  const entry = `${JSON.stringify(name)}: ${JSON.stringify(version)}`;
487
396
  const unit = /\n([ \t]+)"/.exec(text)?.[1] ?? " ";
@@ -515,12 +424,6 @@ function insertDependencyEntry(text, field, name, version) {
515
424
  const insert = before === undefined ? `,${separator}${entry}` : `${entry},${separator}`;
516
425
  return text.slice(0, at) + insert + text.slice(at);
517
426
  }
518
- /**
519
- * Add `rule.add` to a package.json text beside the first anchor it lists - the imported entry's own
520
- * package, then each of `rule.beside` - in every field that anchor is in, with the anchor's range
521
- * style; in `dependencies` when no anchor is listed. Undefined when the manifest already lists the
522
- * package in any field, is that package, or the edit would not parse.
523
- */
524
427
  export function addDependencyText(text, rule, specifier, version, exact = false) {
525
428
  let parsed;
526
429
  try {
@@ -559,7 +462,6 @@ export function addDependencyText(text, rule, specifier, version, exact = false)
559
462
  let out = text;
560
463
  for (const change of placed)
561
464
  out = insertDependencyEntry(out, change.field, rule.add, change.version);
562
- // The edit is textual; a result that does not parse, or lacks an entry, is never written.
563
465
  let written;
564
466
  try {
565
467
  written = JSON.parse(out);
@@ -574,7 +476,6 @@ export function addDependencyText(text, rule, specifier, version, exact = false)
574
476
  return undefined;
575
477
  return { text: out, changes: placed };
576
478
  }
577
- /** The package.json nearest above `file`, both relative to `cwd`; undefined when none is under it. */
578
479
  function nearestManifest(cwd, file) {
579
480
  for (let dir = dirname(file);; dir = dirname(dir)) {
580
481
  const manifest = dir === "." ? "package.json" : `${dir}/package.json`;
@@ -585,8 +486,6 @@ function nearestManifest(cwd, file) {
585
486
  }
586
487
  }
587
488
  const IGNORED_DIRECTORIES = new Set(["node_modules", "dist", "build", ".git", "coverage", ".next"]);
588
- // Any directory on the path counts, the top-level one included (`dist/index.js`). Bun's glob yields
589
- // `dist\index.js` on Windows.
590
489
  const isIgnored = (path) => path
591
490
  .split(/[\\/]/)
592
491
  .slice(0, -1)
@@ -594,24 +493,19 @@ const isIgnored = (path) => path
594
493
  function scan(cwd, pattern, dot = false) {
595
494
  const glob = new Glob(pattern);
596
495
  const out = [];
597
- // The write boundary: a symlinked file or directory (a linked repository) is never yielded, so the
598
- // upgrade can only edit files that live under `cwd`.
599
496
  for (const path of glob.scanSync({ cwd, dot, followSymlinks: false })) {
600
497
  if (!isIgnored(path))
601
498
  out.push(path.replaceAll("\\", "/"));
602
499
  }
603
- // A gitignored copy (a backup, a generated app) is not the project: never edited, never reported.
604
500
  const ignored = gitIgnoredSync(cwd, out);
605
501
  return (ignored.size === 0 ? out : out.filter((path) => !ignored.has(path))).sort();
606
502
  }
607
- // The fixed version group: every package released together at one version.
608
503
  export const isFixedGroup = (name) => name.startsWith("@nifrajs/") || name === "nifra" || name === "create-nifra";
609
504
  const groupPins = (version) => [
610
505
  { match: "@nifrajs/", to: version },
611
506
  { match: "create-nifra", to: version },
612
507
  { match: "nifra", to: version },
613
508
  ];
614
- /** Every fixed-group package a package.json under `cwd` names, whatever its spec. */
615
509
  export function groupDeclaredNames(cwd) {
616
510
  const names = new Set();
617
511
  for (const rel of scan(cwd, "**/package.json")) {
@@ -622,12 +516,10 @@ export function groupDeclaredNames(cwd) {
622
516
  names.add(target);
623
517
  }
624
518
  catch {
625
- // Not JSON: it declares nothing.
626
519
  }
627
520
  }
628
521
  return names;
629
522
  }
630
- /** The fixed-group packages the package installed at `dir` depends on. */
631
523
  export function groupDependenciesAt(dir) {
632
524
  try {
633
525
  const manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
@@ -642,14 +534,7 @@ export function groupDependenciesAt(dir) {
642
534
  return [];
643
535
  }
644
536
  }
645
- // Tools: what they depend on is not loaded by the app, so a release that changes what one does
646
- // names the tool itself in `affects`.
647
537
  const GROUP_TOOLS = new Set(["@nifrajs/cli", "nifra", "create-nifra"]);
648
- /**
649
- * The fixed-group packages this project loads: every one a package.json under `cwd` names, and what
650
- * those depend on, followed through their installed manifests. `undefined` when a package to follow
651
- * is not installed at the root, since what it loads is then unknown.
652
- */
653
538
  export function groupSurface(cwd) {
654
539
  const surface = new Set(groupDeclaredNames(cwd));
655
540
  const queue = [...surface];
@@ -672,11 +557,6 @@ export function groupSurface(cwd) {
672
557
  }
673
558
  return surface;
674
559
  }
675
- /**
676
- * The `versions` whose recipe lists the packages its behaviour changes touch ({@link
677
- * UpgradeRecipe.affects}) and none is in `surface`. A recipe without the list, or an unknown surface,
678
- * is never reported unaffected.
679
- */
680
560
  export function unaffectedReleases(versions, surface) {
681
561
  if (surface === undefined)
682
562
  return [];
@@ -692,12 +572,6 @@ function unaffectedLine(release) {
692
572
  ? `${release.version} announces no behaviour change`
693
573
  : `${release.version} changes only ${release.affects.join(", ")}, which this project does not load: no announced behaviour change for it`;
694
574
  }
695
- /**
696
- * Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
697
- * with the files that declare it. An override counts: it decides what installs. A peer range does
698
- * not (`>=3.1.0` names a floor a library accepts, not a version anything loads), and `workspace:`,
699
- * `link:` and other non-semver specs are not versions.
700
- */
701
575
  export function groupPinVersions(cwd) {
702
576
  return groupSpecVersions(cwd, false);
703
577
  }
@@ -737,12 +611,6 @@ const STRAY_PIN_FILES = [
737
611
  ];
738
612
  const LOCKFILE = /(?:\.lock|package-lock\.json|pnpm-lock\.yaml)$/;
739
613
  const GROUP_PIN = /(?<![\w.@/-])(@nifrajs\/[a-z0-9._-]+|create-nifra|nifra)@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/g;
740
- /**
741
- * Fixed-group versions other than `version` pinned where `nifra upgrade` does not edit: MCP configs and
742
- * agent guidance beyond the launch pin it moves, container files, CI workflows, and lockfiles besides
743
- * the workspace's own (which install rewrites). `planned` holds a file's text after the upgrade's own
744
- * edits, so a dry run lists what `--write` would leave.
745
- */
746
614
  export function strayPins(cwd, version, planned = new Map()) {
747
615
  const found = [];
748
616
  const files = new Set(STRAY_PIN_FILES.flatMap((pattern) => scan(cwd, pattern, true)));
@@ -778,7 +646,6 @@ export function strayPins(cwd, version, planned = new Map()) {
778
646
  }
779
647
  return found;
780
648
  }
781
- /** Whether `rel` is a regular file under `cwd` reached through no symlink: the upgrade's write boundary. */
782
649
  function plainFileAt(cwd, rel) {
783
650
  let path = cwd;
784
651
  const parts = rel.split("/");
@@ -798,11 +665,6 @@ function plainFileAt(cwd, rel) {
798
665
  }
799
666
  return true;
800
667
  }
801
- /**
802
- * The MCP launch pin in each agent file at `cwd`, and in each file above it whose launches all serve
803
- * it ({@link ancestorPins}), moved to `version`: the files and the edit of `nifra init-agents
804
- * --sync-mcp`, so an agent launches the nifra the project installs once it does.
805
- */
806
668
  function agentPinEdits(cwd, version, above) {
807
669
  const target = declaresCli(cwd) ? null : version;
808
670
  const edits = [];
@@ -814,9 +676,7 @@ function agentPinEdits(cwd, version, above) {
814
676
  if (!plainFileAt(dir, file))
815
677
  continue;
816
678
  const abs = join(dir, file);
817
- // A launch above the project runs from that directory, which need not see the install: it stays pinned.
818
679
  const to = dir === cwd ? target : version;
819
- // latin1 is one char per byte, so every byte outside a pin is written back as it was.
820
680
  const scan = site.repin(readFileSync(abs, "latin1"), to);
821
681
  if (scan.stale.length === 0)
822
682
  continue;
@@ -838,13 +698,11 @@ const packageVersionAt = (dir) => {
838
698
  return undefined;
839
699
  }
840
700
  };
841
- /** The install a package belongs to: the folder above its last `node_modules`, or the package itself. */
842
701
  export const installRootOf = (path) => {
843
702
  const parts = path.split(sep);
844
703
  const last = parts.lastIndexOf("node_modules");
845
704
  return last <= 0 ? path : parts.slice(0, last).join(sep);
846
705
  };
847
- /** `name` as Node and Bun resolve it from `dir`: the first `node_modules/<name>` walking up to the root. */
848
706
  export function resolvePackageFrom(dir, name) {
849
707
  for (let at = dir;;) {
850
708
  if (basename(at) !== "node_modules") {
@@ -852,7 +710,6 @@ export function resolvePackageFrom(dir, name) {
852
710
  return realpathSync(join(at, "node_modules", name));
853
711
  }
854
712
  catch {
855
- // Not installed here: Node and Bun look in the parent's node_modules next.
856
713
  }
857
714
  }
858
715
  const parent = dirname(at);
@@ -862,12 +719,6 @@ export function resolvePackageFrom(dir, name) {
862
719
  }
863
720
  }
864
721
  const RUNTIME_FIELDS = ["dependencies", "peerDependencies", "optionalDependencies"];
865
- /**
866
- * Every fixed-group package the package at `dir` loads, each resolved from the real path of the package
867
- * that imports it: its own runtime dependencies, whatever its own `node_modules` holds, and the same
868
- * through each source package it depends on (a workspace sibling or another link, never a registry
869
- * install). A workspace member reads a hoisted copy from the workspace root, not its own folder.
870
- */
871
722
  function resolvedGroupPackages(dir) {
872
723
  const found = new Map();
873
724
  const visited = new Set();
@@ -910,12 +761,6 @@ function resolvedGroupPackages(dir) {
910
761
  visit(dir);
911
762
  return [...found.values()];
912
763
  }
913
- /**
914
- * Every `link:` or `file:` dependency whose installed folder resolves outside `cwd` and loads
915
- * fixed-group packages from outside it, with those copies ({@link resolvedGroupPackages}). Its imports
916
- * resolve from its real path, so it loads its own copy whatever this project installs. A copy that
917
- * resolves back inside `cwd` follows this project's install and is not counted.
918
- */
919
764
  export function linkedRepositories(cwd) {
920
765
  let root;
921
766
  try {
@@ -949,7 +794,6 @@ export function linkedRepositories(cwd) {
949
794
  break;
950
795
  }
951
796
  catch {
952
- // Not installed beside this manifest: try the root's node_modules.
953
797
  }
954
798
  }
955
799
  if (path === undefined || inside(path) || seen.has(path))
@@ -965,21 +809,12 @@ export function linkedRepositories(cwd) {
965
809
  }
966
810
  return found;
967
811
  }
968
- /**
969
- * The {@link linkedRepositories} that install a fixed-group package at a version other than `target`:
970
- * they keep loading that copy after this project upgrades, so a `server()` one builds can no longer be
971
- * merged here, and single-copy never redirects across versions.
972
- */
973
812
  export function linkedSkew(cwd, target) {
974
813
  return linkedRepositories(cwd).flatMap((repo) => {
975
814
  const installs = repo.installs.filter((entry) => entry.version !== target);
976
815
  return installs.length === 0 ? [] : [{ ...repo, installs }];
977
816
  });
978
817
  }
979
- /**
980
- * Every fixed-group package installed in `cwd/node_modules`, realpath-resolved so a linked repository
981
- * reports its own version. `inside` is false for one that resolves outside the workspace root.
982
- */
983
818
  export function installedGroupPackages(cwd) {
984
819
  const modules = join(cwd, "node_modules");
985
820
  const names = ["nifra", "create-nifra"].filter((name) => existsSync(join(modules, name)));
@@ -988,7 +823,6 @@ export function installedGroupPackages(cwd) {
988
823
  names.push(`@nifrajs/${name}`);
989
824
  }
990
825
  catch {
991
- // No scoped installs.
992
826
  }
993
827
  let root;
994
828
  try {
@@ -1018,12 +852,6 @@ export function installedGroupPackages(cwd) {
1018
852
  }
1019
853
  return found;
1020
854
  }
1021
- /**
1022
- * The version the workspace upgrades from: the lowest fixed-group version any package.json under
1023
- * `cwd` pins ({@link groupPinVersions}), since recipes newer than it still have edits to make
1024
- * somewhere. Without a pin, the lowest one installed inside the root, then the lowest peer floor;
1025
- * null when none names one.
1026
- */
1027
855
  export function installedGroupVersion(cwd) {
1028
856
  const lowest = (versions) => {
1029
857
  let found = null;
@@ -1038,11 +866,6 @@ export function installedGroupVersion(cwd) {
1038
866
  .map((entry) => entry.version)) ??
1039
867
  lowest(groupSpecVersions(cwd, true).keys()));
1040
868
  }
1041
- /**
1042
- * Chain the recipes after `installed` (exclusive) up to `target` (inclusive): their dependency and
1043
- * import moves in release order, their notes labeled by release, and the fixed group pinned to
1044
- * `target`. Without a known installed version only the target's own recipe applies.
1045
- */
1046
869
  export function chainRecipes(target, installed) {
1047
870
  const steps = installed === null
1048
871
  ? getRecipe(target) === undefined
@@ -1050,7 +873,6 @@ export function chainRecipes(target, installed) {
1050
873
  : [target]
1051
874
  : listRecipeVersions().filter((version) => compareSemverSpec(version, installed) > 0 && compareSemverSpec(version, target) <= 0);
1052
875
  const recipes = steps.flatMap((version) => getRecipe(version) ?? []);
1053
- // A later rule for the same match replaces an earlier one; the target's pins win last.
1054
876
  const pins = new Map();
1055
877
  for (const recipe of recipes)
1056
878
  for (const rule of recipe.pins)
@@ -1069,7 +891,6 @@ export function chainRecipes(target, installed) {
1069
891
  notes: recipes.flatMap((recipe) => (recipe.notes ?? []).map((note) => `${recipe.version}: ${note}`)),
1070
892
  };
1071
893
  }
1072
- /** Compute the plan (and, when `write`, apply it) for a target recipe against `cwd`. */
1073
894
  export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact = false, above = [], compiler) {
1074
895
  const pins = [];
1075
896
  const agentPins = [];
@@ -1101,7 +922,6 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
1101
922
  writeFileSync(abs, pinned.text);
1102
923
  }
1103
924
  }
1104
- // Read against the manifests as this upgrade leaves them.
1105
925
  const linkLocks = plainFileAt(cwd, BUN_LOCK) ? staleLinkLocks(resolve(cwd), manifests) : [];
1106
926
  for (const { change, text, abs } of agentPinEdits(cwd, recipe.version, above)) {
1107
927
  agentPins.push(change);
@@ -1124,7 +944,6 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
1124
944
  writeFileSync(abs, result.text);
1125
945
  }
1126
946
  }
1127
- // Each rewrite reads a source as the import moves (and the rewrites before it) leave it.
1128
947
  const sourceRewrites = [];
1129
948
  const manualRewrites = [];
1130
949
  const rewritesNeedTypeScript = [];
@@ -1155,7 +974,6 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
1155
974
  writeFileSync(join(cwd, rel), text);
1156
975
  }
1157
976
  }
1158
- // Read the sources as the import moves leave them, and each manifest as the pins left it.
1159
977
  const adds = recipe.dependencyAdds ?? [];
1160
978
  if (adds.length > 0) {
1161
979
  for (const rel of scan(cwd, ADD_SOURCE_GLOB)) {
@@ -1180,7 +998,6 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
1180
998
  }
1181
999
  }
1182
1000
  }
1183
- // Read after the import moves, so a listed line number is the one the file has after `--write`.
1184
1001
  const retired = recipe.retiredMarkers ?? [];
1185
1002
  if (retired.length > 0) {
1186
1003
  for (const rel of scan(cwd, SOURCE_GLOB)) {
@@ -1347,11 +1164,8 @@ function renderPlan(plan, write, from, steps) {
1347
1164
  lines.push("\nRe-run with --write to apply, then install and run nifra check.");
1348
1165
  return lines.join("\n").trimEnd();
1349
1166
  }
1350
- /** Explain a refused rollback: which pins would roll back, why it's blocked, and the escape hatch. */
1351
- /** The linked repositories to upgrade first, each with the commands that move it to `version`. */
1352
1167
  function renderLinkedSkew(version, skew, cwd, allowed) {
1353
1168
  const display = (path) => relative(cwd, path).split(sep).join("/") || ".";
1354
- // A hoisted workspace member loads the copy at its workspace root, so the upgrade runs there.
1355
1169
  const roots = [
1356
1170
  ...new Set(skew.flatMap((entry) => entry.installs.map((install) => installRootOf(install.path)))),
1357
1171
  ].sort(codeUnitOrder);
@@ -1385,10 +1199,6 @@ const INSTALL_COMMANDS = [
1385
1199
  ["yarn.lock", "yarn install"],
1386
1200
  ["package-lock.json", "npm install"],
1387
1201
  ];
1388
- /**
1389
- * Whether the project needs an install before a check can judge the target: `--write` changed what
1390
- * package.json declares, or node_modules holds a group package at another version. A link from outside the root is left out; installing here does not move it.
1391
- */
1392
1202
  export function pendingInstall(cwd, plan) {
1393
1203
  const installed = installedGroupPackages(cwd)
1394
1204
  .filter((entry) => entry.inside && entry.version !== plan.version)
@@ -1424,9 +1234,6 @@ async function hookReportBefore(cwd) {
1424
1234
  return { error: error instanceof Error ? error.message : String(error) };
1425
1235
  }
1426
1236
  }
1427
- /** The report after the edits, from a fresh process: the edited sources must not come from this one's
1428
- * module cache. Saves the pre-upgrade report for `nifra routes --hooks --since` after an install.
1429
- * While the edits are not installed, the old release would load in its place, so none is taken. */
1430
1237
  async function hookScopeAcross(cwd, before, installed) {
1431
1238
  if ("error" in before)
1432
1239
  return { error: before.error };
@@ -1479,15 +1286,12 @@ function renderHookScope(scope) {
1479
1286
  ...since(scope.saved),
1480
1287
  ].join("\n");
1481
1288
  }
1482
- /** The targets this CLI applies: each release recipe up to its own version, and that version. */
1483
1289
  export function upgradeTargets(cliVersion) {
1484
1290
  const versions = listRecipeVersions().filter((version) => compareSemverSpec(version, cliVersion) <= 0);
1485
1291
  if (!versions.includes(cliVersion))
1486
1292
  versions.push(cliVersion);
1487
1293
  return versions.sort(compareSemverSpec);
1488
1294
  }
1489
- /** Each target with the notes of every release after the installed one: what an app can observe
1490
- * changing on the way up. Older releases are listed by version only. */
1491
1295
  function renderUpgradeList(targets, installed, notes, unaffected = []) {
1492
1296
  const lines = [
1493
1297
  installed === null
@@ -1511,7 +1315,6 @@ function renderUpgradeList(targets, installed, notes, unaffected = []) {
1511
1315
  lines.push("", "A newer release upgrades with its own CLI: bunx @nifrajs/cli@<version> upgrade <version>");
1512
1316
  return lines.join("\n");
1513
1317
  }
1514
- /** The command that runs `version`'s own CLI with the same flags. `version` is a validated release. */
1515
1318
  function newerCliCommand(version, options) {
1516
1319
  const flags = [
1517
1320
  options.write === true ? "--write" : "",
@@ -1523,10 +1326,6 @@ function newerCliCommand(version, options) {
1523
1326
  ].filter((flag) => flag !== "");
1524
1327
  return ["bunx", `@nifrajs/cli@${version}`, "upgrade", version, ...flags].join(" ");
1525
1328
  }
1526
- /** CLI entry. Returns false (→ non-zero exit) on an unknown version, no project, or a failed verify. */
1527
- /** The contracts.lock.json routes that send a body but whose request side guards nothing. A release
1528
- * that reads a body schema the installed one could not has `nifra check` report each as newly
1529
- * covered. Read routes and response sides are left out: most declare no schema there. */
1530
1329
  async function uncoveredContracts(cwd) {
1531
1330
  const { blindLockEntries, DEFAULT_CONTRACTS_LOCK, parseContractsLock } = await import("./contracts.js");
1532
1331
  try {
@@ -1550,8 +1349,6 @@ const UPGRADE_SWITCHES = [
1550
1349
  "--no-verify",
1551
1350
  "--no-hooks",
1552
1351
  ];
1553
- /** The arguments of `nifra upgrade`. Anything else is refused: an ignored `--from` would plan the
1554
- * upgrade from the wrong version and still exit 0. */
1555
1352
  export function parseUpgradeArgs(args) {
1556
1353
  const on = new Set();
1557
1354
  let version;
@@ -1618,8 +1415,6 @@ export async function runUpgrade(cwd, options) {
1618
1415
  return false;
1619
1416
  }
1620
1417
  if (compareSemverSpec(version, cliVersion) > 0) {
1621
- // Recipes ship with the CLI: only the target release's CLI knows every recipe up to it. Print its
1622
- // command rather than downloading and running code on the user's behalf.
1623
1418
  const command = newerCliCommand(version, options);
1624
1419
  if (options.json) {
1625
1420
  console.log(JSON.stringify({ version, cliVersion, refused: "newer-than-cli", command }, null, 2));
@@ -1635,7 +1430,6 @@ export async function runUpgrade(cwd, options) {
1635
1430
  `For ${version} itself, run: ${newerCliCommand(version, options)}`);
1636
1431
  return false;
1637
1432
  }
1638
- // Detect: the cwd must be a project (or workspace) root.
1639
1433
  try {
1640
1434
  readFileSync(join(cwd, "package.json"), "utf8");
1641
1435
  }
@@ -1648,7 +1442,6 @@ export async function runUpgrade(cwd, options) {
1648
1442
  const exact = options.exact === true;
1649
1443
  const from = options.from ?? installedGroupVersion(cwd);
1650
1444
  const recipe = chainRecipes(version, from);
1651
- // Fail-closed on rollback: a dry pass writes nothing, so we can refuse before any package.json is touched.
1652
1445
  const above = (await ancestorPins(cwd)).owned;
1653
1446
  const loaded = (recipe.sourceRewrites?.length ?? 0) > 0
1654
1447
  ? await (await import("./internal/typescript-import.js")).loadProjectTypeScript(cwd, options.loadTypeScript)
@@ -1661,7 +1454,6 @@ export async function runUpgrade(cwd, options) {
1661
1454
  }
1662
1455
  async function upgradeWith(compiler) {
1663
1456
  const preview = computeUpgrade(cwd, recipe, false, allowDowngrade, exact, above, compiler);
1664
- // Refused before anything is written: once the pins land, no later upgrade runs this rewrite.
1665
1457
  if (preview.rewritesNeedTypeScript.length > 0) {
1666
1458
  if (options.json) {
1667
1459
  console.log(JSON.stringify({ ...preview, from, steps: recipe.steps, write: false, refused: "needs-typescript" }, null, 2));
@@ -1680,7 +1472,6 @@ export async function runUpgrade(cwd, options) {
1680
1472
  }
1681
1473
  return false;
1682
1474
  }
1683
- // Refused before anything is written: the linked repository fails at the first merge(), not here.
1684
1475
  if (preview.linkedSkew.length > 0 && options.allowLinkedSkew !== true) {
1685
1476
  if (options.json) {
1686
1477
  console.log(JSON.stringify({ ...preview, from, steps: recipe.steps, write: false, refused: "linked-skew" }, null, 2));
@@ -1693,8 +1484,6 @@ export async function runUpgrade(cwd, options) {
1693
1484
  return false;
1694
1485
  }
1695
1486
  const captureHooks = write && options.hooks !== false;
1696
- // A server() the project's copy builds is not one this CLI's copy can reflect, which is the normal
1697
- // state of an upgrade run from the new release before it is installed.
1698
1487
  const otherCore = captureHooks && otherProjectCore(cwd) !== undefined;
1699
1488
  const before = captureHooks && !otherCore ? await hookReportBefore(cwd) : undefined;
1700
1489
  const plan = write
@@ -1706,12 +1495,9 @@ export async function runUpgrade(cwd, options) {
1706
1495
  : before === undefined
1707
1496
  ? undefined
1708
1497
  : await hookScopeAcross(cwd, before, pending === undefined);
1709
- // Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
1710
- // with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
1711
1498
  const verify = write && options.verify !== false && pending === undefined;
1712
1499
  const uncovered = await uncoveredContracts(cwd);
1713
1500
  if (options.json) {
1714
- // The check result rides inside the one JSON document; its human report would break the stream.
1715
1501
  const report = { ...plan, from, steps: recipe.steps, write };
1716
1502
  if (uncovered.length > 0)
1717
1503
  report.contractsUncovered = uncovered;