@akanjs/devkit 3.2.0-rc.9 → 3.2.1-rc.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 (353) hide show
  1. package/CHANGELOG.md +0 -529
  2. package/DEV_RUNTIME_KNOBS.md +4 -3
  3. package/README.ko.md +3 -2
  4. package/README.md +4 -2
  5. package/akanApp/BackendImportGraph.test.ts +1 -1
  6. package/akanApp/akanApp.host.test.ts +152 -6
  7. package/akanApp/akanApp.host.ts +187 -1220
  8. package/akanApp/akanApp.host.wiring.test.ts +931 -0
  9. package/akanApp/builderGap.ts +68 -0
  10. package/akanApp/builderRequestRelay.test.ts +93 -0
  11. package/akanApp/builderRequestRelay.ts +100 -0
  12. package/akanApp/builderRssRecycler.ts +182 -0
  13. package/akanApp/devBackend.ts +394 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +200 -0
  16. package/akanApp/devIdleSuspend.test.ts +221 -0
  17. package/akanApp/devIdleSuspend.ts +192 -0
  18. package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
  19. package/akanApp/devRecycler.test.ts +66 -0
  20. package/akanApp/devRecycler.ts +305 -0
  21. package/akanApp/devStartTimeline.test.ts +115 -0
  22. package/akanApp/devStartTimeline.ts +69 -0
  23. package/akanApp/processRss.ts +61 -0
  24. package/akanConfig/akanConfig.test.ts +45 -17
  25. package/akanConfig/akanConfig.ts +10 -10
  26. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  27. package/akanConfig/productionLockfile.ts +1 -1
  28. package/apiReport/apiReport.test.ts +34 -3
  29. package/apiReport/apiReportDiff.ts +35 -1
  30. package/apiReport/apiReportPolicy.ts +3 -2
  31. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
  32. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
  33. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
  34. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  35. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
  36. package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
  37. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  38. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  39. package/artifact/implicitRootLayout.test.ts +71 -3
  40. package/artifact/implicitRootLayout.ts +9 -3
  41. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  42. package/biome.base.json +2 -1
  43. package/cloud/cloudApi.test.ts +1 -1
  44. package/cloud/configLock.test.ts +1 -1
  45. package/cloud/globalConfig.test.ts +1 -1
  46. package/cloud/globalConfig.ts +1 -1
  47. package/cloud/updatePackUpload.test.ts +1 -1
  48. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  49. package/codeAgent/agent/AkanCodeServices.ts +23 -0
  50. package/codeAgent/agent/akanCodePaths.ts +1 -1
  51. package/codeAgent/agent/akanCodeServices.test.ts +54 -0
  52. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  53. package/codeAgent/agent/codeAgent.test.ts +1 -1
  54. package/codeAgent/skills/akan-debug/SKILL.md +8 -5
  55. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  56. package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
  57. package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
  58. package/codeAgent/skills/akan-validate/SKILL.md +3 -3
  59. package/codeAgent/tools/AkanCli.ts +1 -1
  60. package/codeAgent/tools/AkanToolPack.ts +2 -2
  61. package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
  62. package/commandDecorators/command.ts +35 -6
  63. package/commandDecorators/commandBuilder.ts +1 -1
  64. package/commandDecorators/commandDecorators.test.ts +107 -6
  65. package/commandDecorators/targetMeta.ts +2 -0
  66. package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
  67. package/commandDecorators/workspaceVersionCheck.ts +64 -14
  68. package/context/akanContext.ts +576 -0
  69. package/context/akanContextInspection.ts +296 -0
  70. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  71. package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
  72. package/context/doctor/agentGuideCheck.ts +81 -0
  73. package/context/doctor/configLeftoverCheck.ts +35 -0
  74. package/context/doctor/doctorFindings.ts +70 -0
  75. package/context/doctor/generatedFreshness.ts +56 -0
  76. package/context/doctor/moduleShapeCheck.ts +88 -0
  77. package/context/doctor/recipeDuplicateCheck.ts +42 -0
  78. package/context/doctor/recipeIndexCheck.ts +87 -0
  79. package/context/doctor/rootShapeCheck.ts +55 -0
  80. package/context/doctor/workflowScope.ts +97 -0
  81. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  82. package/context/safeRead.ts +9 -0
  83. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  84. package/devkitUtils.test.ts +39 -5
  85. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  86. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  87. package/docs/errorCodeReference.test.ts +282 -0
  88. package/docs/errorCodeReference.ts +71 -0
  89. package/docs/errorCodeScan.ts +551 -0
  90. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  91. package/executors/appExecutor.ts +463 -0
  92. package/executors/commandExecutionError.ts +53 -0
  93. package/executors/executor.ts +527 -0
  94. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  95. package/{executors.test.ts → executors/executors.test.ts} +106 -18
  96. package/executors/index.ts +8 -0
  97. package/executors/libExecutor.ts +23 -0
  98. package/executors/moduleExecutor.ts +18 -0
  99. package/executors/pkgExecutor.ts +129 -0
  100. package/executors/sysExecutor.ts +301 -0
  101. package/executors/workspaceExecutor.ts +277 -0
  102. package/frontendBuild/allRoutesBuilder.test.ts +1 -1
  103. package/frontendBuild/autoImportSync.test.ts +1 -1
  104. package/frontendBuild/autoImportSync.ts +1 -1
  105. package/frontendBuild/buildCacheStamp.test.ts +42 -0
  106. package/frontendBuild/buildCacheStamp.ts +23 -0
  107. package/frontendBuild/buildRouteClient.test.ts +1 -1
  108. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  109. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  110. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  111. package/frontendBuild/cssCandidateCache.test.ts +70 -1
  112. package/frontendBuild/cssCandidateCache.ts +17 -10
  113. package/frontendBuild/cssCompiler.test.ts +3 -2
  114. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  115. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  116. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  117. package/frontendBuild/fontOptimizer.test.ts +145 -4
  118. package/frontendBuild/fontOptimizer.ts +103 -18
  119. package/frontendBuild/fontPruner.test.ts +1 -1
  120. package/frontendBuild/frontendBuild.test.ts +3 -3
  121. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  122. package/frontendBuild/hmrWatcher.test.ts +1 -1
  123. package/frontendBuild/hmrWatcher.ts +22 -1
  124. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  125. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  126. package/frontendBuild/nativeCore.test.ts +1 -1
  127. package/frontendBuild/optionalPeers.test.ts +36 -8
  128. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  129. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  130. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  131. package/frontendBuild/precompressArtifacts.ts +19 -6
  132. package/frontendBuild/serverGraphFile.ts +1 -1
  133. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  134. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
  135. package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
  136. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  137. package/frontendBuild/vendorImportScanner.test.ts +1 -1
  138. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  139. package/frontendBuild/watchRootResolver.test.ts +1 -1
  140. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  141. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  142. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  143. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  144. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  145. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  146. package/{prompter.ts → guideline/prompter.ts} +2 -3
  147. package/incrementalBuilder/buildBatch.proc.ts +16 -5
  148. package/incrementalBuilder/buildBatchProtocol.ts +3 -0
  149. package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
  150. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  151. package/incrementalBuilder/builderBoot.ts +113 -0
  152. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  153. package/incrementalBuilder/builderChannel.test.ts +1 -1
  154. package/incrementalBuilder/builderChannel.ts +19 -2
  155. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  156. package/incrementalBuilder/builderLanes.ts +157 -0
  157. package/incrementalBuilder/builderWatch.ts +213 -0
  158. package/incrementalBuilder/csrRegistry.ts +234 -0
  159. package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
  160. package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
  161. package/incrementalBuilder/incrementalBuilder.proc.test.ts +142 -7
  162. package/incrementalBuilder/incrementalBuilder.proc.ts +82 -823
  163. package/incrementalBuilder/ssrRegistry.ts +282 -0
  164. package/index.ts +22 -22
  165. package/integration/devStability.integration.test.ts +62 -56
  166. package/integration/devStabilityHarness.test.ts +1 -1
  167. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  168. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  169. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  170. package/lint/gritRules.test.ts +1 -1
  171. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  172. package/lint/no-import-common-err.grit +31 -0
  173. package/lint/no-init-fetch-in-client.grit +1 -1
  174. package/mobile/desktopBin.test.ts +1 -1
  175. package/mobile/desktopRelease.test.ts +1 -1
  176. package/mobile/desktopServerStage.test.ts +2 -2
  177. package/mobile/desktopServerStage.ts +1 -1
  178. package/mobile/nativeApi.test.ts +1 -1
  179. package/mobile/nativeApp.test.ts +1 -1
  180. package/mobile/nativeConfig.test.ts +1 -1
  181. package/mobile/nativePluginFolders.test.ts +1 -1
  182. package/mobile/nativePublicEnv.test.ts +1 -1
  183. package/mobile/nativePublicEnv.ts +2 -1
  184. package/mobile/nativeWebDir.test.ts +1 -1
  185. package/mobile/serverBundleSecrets.test.ts +1 -1
  186. package/mobile/tarWriter.test.ts +1 -1
  187. package/mobile/updatePackFolder.test.ts +1 -1
  188. package/package.json +173 -9
  189. package/packageExports.test.ts +20 -2
  190. package/piDependencyPins.test.ts +1 -1
  191. package/pipeline/PipelineDefinition.ts +1 -1
  192. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  193. package/platformTest/LinuxDockerTarget.ts +1 -1
  194. package/platformTest/PlatformTestRun.test.ts +1 -1
  195. package/platformTest/TestSnapshot.test.ts +1 -1
  196. package/platformTest/WindowsSshTarget.ts +1 -1
  197. package/preview/previewView.test.ts +23 -1
  198. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  199. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  200. package/quality/bareErrorScanner.ts +126 -0
  201. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  202. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  203. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  204. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  205. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  206. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  207. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  208. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  209. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
  210. package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
  211. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  212. package/quality/workspaceSourceFiles.ts +82 -0
  213. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  214. package/{subspace.ts → subspace/subspace.ts} +5 -5
  215. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  216. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  217. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  218. package/transforms/barrelAnalyzer.ts +31 -10
  219. package/transforms/browserDirnamePlugin.test.ts +1 -1
  220. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  221. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  222. package/transforms/pureLazyMarker.test.ts +1 -1
  223. package/transforms/serverEnvPlugin.test.ts +1 -1
  224. package/transforms/serverEnvProfile.test.ts +1 -1
  225. package/transforms/sideEffectImportOrder.test.ts +1 -1
  226. package/transforms/transforms.test.ts +52 -2
  227. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  228. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  229. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  230. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  231. package/typecheck/projectTypecheck.test.ts +23 -1
  232. package/typecheck/projectTypecheck.ts +10 -2
  233. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  234. package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
  235. package/typecheck/typecheck.proc.ts +6 -2
  236. package/typecheck/typecheckFailure.ts +1 -1
  237. package/util/errorReport.ts +66 -0
  238. package/{fileSys.test.ts → util/fileSys.test.ts} +13 -0
  239. package/{fileSys.ts → util/fileSys.ts} +2 -2
  240. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  241. package/workflow/constantSource.ts +187 -0
  242. package/workflow/dictionarySource.ts +184 -0
  243. package/workflow/executor.ts +6 -9
  244. package/workflow/fieldExpression.ts +153 -0
  245. package/workflow/fieldLabel.ts +61 -0
  246. package/workflow/fieldOrder.ts +117 -0
  247. package/workflow/fieldType.ts +2 -1
  248. package/workflow/guardCatalog.test.ts +1 -1
  249. package/workflow/keyRename.ts +1 -1
  250. package/workflow/moduleIndex.test.ts +2 -2
  251. package/workflow/moduleIndex.ts +2 -2
  252. package/workflow/modulePaths.ts +27 -0
  253. package/workflow/mutationScaffold.ts +7 -15
  254. package/workflow/mutationSource.ts +2 -1
  255. package/workflow/plan.ts +2 -1
  256. package/workflow/primitiveReport.ts +78 -0
  257. package/workflow/rolloutGate.test.ts +1 -1
  258. package/workflow/rolloutGate.ts +1 -1
  259. package/workflow/serviceSource.ts +33 -0
  260. package/workflow/signalSource.ts +96 -0
  261. package/workflow/source.ts +50 -1100
  262. package/workflow/sourceAst.ts +30 -0
  263. package/workflow/sourceImports.ts +105 -0
  264. package/workflow/sourceText.ts +13 -0
  265. package/workflow/templateSource.ts +30 -0
  266. package/workflow/testSource.ts +31 -0
  267. package/workflow/types.ts +1 -1
  268. package/workflow/uiPolicy.ts +1 -1
  269. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  270. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  271. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  272. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  273. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  274. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  275. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  276. package/{libSource.ts → workspace/libSource.ts} +1 -1
  277. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  278. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  279. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  280. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  281. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  282. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  283. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  284. package/akanContext.ts +0 -1083
  285. package/executors.ts +0 -1749
  286. /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
  287. /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
  288. /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
  289. /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
  290. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  291. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  292. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  293. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  294. /package/{linter.ts → lint/linter.ts} +0 -0
  295. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  296. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  297. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  298. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  299. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  300. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  301. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  302. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  303. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  304. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  305. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  306. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  307. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  308. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  309. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  310. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  311. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  312. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  313. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  314. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  315. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  316. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  317. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  318. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  319. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  320. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  321. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  322. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  323. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  324. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  325. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  326. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  327. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  328. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  329. /package/{writePath.ts → quality/writePath.ts} +0 -0
  330. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  331. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  332. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  333. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  334. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  335. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  336. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  337. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  338. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  339. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  340. /package/{semver.ts → util/semver.ts} +0 -0
  341. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  342. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  343. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  344. /package/{spinner.ts → util/spinner.ts} +0 -0
  345. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  346. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  347. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  348. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  349. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  350. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  351. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  352. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  353. /package/{types.ts → workspace/types.ts} +0 -0
@@ -8,7 +8,6 @@ import type {
8
8
  import { Logger } from "akanjs/common";
9
9
  import chalk from "chalk";
10
10
  import { type Command, type CommanderError, program } from "commander";
11
- import { AppSelectionMemory } from "../appSelectionMemory";
12
11
  import {
13
12
  AppExecutor,
14
13
  Executor,
@@ -18,9 +17,11 @@ import {
18
17
  type SysExecutor,
19
18
  WorkspaceExecutor,
20
19
  } from "../executors";
20
+ import { ErrorReport } from "../util/errorReport";
21
21
  // Never the root barrel: it drags ink, ssh2 and the cloud stack into every command process.
22
- import { FileSys, getDirname } from "../fileSys";
23
- import type { PackageJson } from "../types";
22
+ import { FileSys, getDirname } from "../util/fileSys";
23
+ import { AppSelectionMemory } from "../workspace/appSelectionMemory";
24
+ import type { PackageJson } from "../workspace/types";
24
25
  import {
25
26
  type ArgMeta,
26
27
  type CommandContext,
@@ -57,7 +58,7 @@ const printCliError = (error: unknown, stream: "log" | "error" = "log") => {
57
58
  if (loggedCliErrorObjects.has(error)) return;
58
59
  loggedCliErrorObjects.add(error);
59
60
  }
60
- const message = CliError.messageOf(error);
61
+ const message = error instanceof Error ? ErrorReport.format(error) || error.name : CliError.messageOf(error);
61
62
  if (loggedCliErrorMessages.has(message)) return;
62
63
  loggedCliErrorMessages.add(message);
63
64
  Logger.rawLog(`\n${chalk.red(message)}`, undefined, stream);
@@ -142,6 +143,32 @@ const givenOptionsOf = (argMetas: (ArgMeta | InternalArgMeta)[], opt: Record<str
142
143
  return given;
143
144
  };
144
145
 
146
+ const argValuesOf = (argMetas: (ArgMeta | InternalArgMeta)[], cmdArgs: unknown[], opt: Record<string, unknown>) => {
147
+ const values = givenOptionsOf(argMetas, opt);
148
+ for (const argMeta of argMetas) {
149
+ if (argMeta.type === "Argument") values[argMeta.name] = cmdArgs[argMeta.idx] ?? argMeta.argsOption.default;
150
+ else if (argMeta.type === "Option") values[argMeta.name] ??= argMeta.argsOption.default;
151
+ }
152
+ return values;
153
+ };
154
+
155
+ const resolvedValuesOf = (argMetas: (ArgMeta | InternalArgMeta)[], commandArgs: unknown[]) =>
156
+ Object.fromEntries(
157
+ argMetas.flatMap((argMeta) =>
158
+ argMeta.type === "Option" || argMeta.type === "Argument" ? [[argMeta.name, commandArgs[argMeta.idx]]] : [],
159
+ ),
160
+ );
161
+
162
+ const versionGateOf = (cliVersion: string | undefined) => {
163
+ let warning = WorkspaceVersionCheck.warning(cliVersion, process.argv, process.cwd());
164
+ const refusal = WorkspaceVersionCheck.refusal(cliVersion, process.argv, process.cwd());
165
+ return (targetOption: TargetOption, values: { [name: string]: unknown }) => {
166
+ if (refusal && !WorkspaceVersionCheck.readsOnly(targetOption, values)) throw new CliError("refused", refusal);
167
+ if (warning) Logger.rawLog(chalk.yellow(`\n${warning}`), undefined, "error");
168
+ warning = null;
169
+ };
170
+ };
171
+
145
172
  const normalizeEnumChoices = (enumChoices: EnumChoices) =>
146
173
  enumChoices.map((choice: EnumChoice) =>
147
174
  typeof choice === "object"
@@ -508,8 +535,7 @@ export const runCommands = async (...commands: CommandCls[]) => {
508
535
  program.version(process.env.AKAN_VERSION).description("Akan CLI").configureHelp({
509
536
  helpWidth: 100,
510
537
  });
511
- const versionWarning = WorkspaceVersionCheck.warning(cliPackageJson?.version, process.argv, process.cwd());
512
- if (versionWarning) Logger.rawLog(chalk.yellow(`\n${versionWarning}`), undefined, "error");
538
+ const checkVersion = versionGateOf(cliPackageJson?.version);
513
539
 
514
540
  for (const command of commands) {
515
541
  const targetMetas = getTargetMetas(command);
@@ -568,6 +594,7 @@ export const runCommands = async (...commands: CommandCls[]) => {
568
594
  usage: false,
569
595
  given: givenOptionsOf(allArgMetas, opt),
570
596
  });
597
+ checkVersion(targetMeta.targetOption, argValuesOf(allArgMetas, cmdArgs, opt));
571
598
  const commandArgs = [] as unknown[];
572
599
  if (targetMeta.targetOption.runsOnWorkspaceRoot) {
573
600
  await assertCurrentDirectoryIsWorkspaceRoot();
@@ -605,6 +632,8 @@ export const runCommands = async (...commands: CommandCls[]) => {
605
632
  assignCommandContext(commandContext, argMeta, commandArgs[argMeta.idx]);
606
633
  if ((opt as { verbose?: boolean }).verbose) Executor.setVerbose(true);
607
634
  }
635
+ //? Again on the answers: a left-out argument reads as read-only above, then may be answered `apply`.
636
+ checkVersion(targetMeta.targetOption, resolvedValuesOf(allArgMetas, commandArgs));
608
637
  const cmd = CommandContainer.get(command);
609
638
 
610
639
  try {
@@ -137,7 +137,7 @@ class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknow
137
137
  }
138
138
 
139
139
  type TargetDefinition = ReturnType<TargetBuilder<readonly DependencyCls[], unknown[]>["exec"]>;
140
- type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
140
+ export type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
141
141
  public: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
142
142
  cloud: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
143
143
  dev: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
@@ -1,7 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
2
  import path from "node:path";
3
3
  import { AppExecutor, LibExecutor, ModuleExecutor, PkgExecutor, WorkspaceExecutor } from "../executors";
4
- import { makeCliTempWorkspace, tempRoots, writeText } from "../testHelpers";
4
+ import { makeCliTempWorkspace, tempRoots, writeText } from "../test/testHelpers";
5
5
  import {
6
6
  App,
7
7
  type ArgMeta,
@@ -440,7 +440,6 @@ describe("enum arg type inference", () => {
440
440
 
441
441
  describe("a Sys that defaults to the only app", () => {
442
442
  const ownIsTTY = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
443
- const ownCwd = process.cwd();
444
443
  const asked: unknown[] = [];
445
444
  let answer = "";
446
445
  const setTTY = (isTTY: boolean | undefined) =>
@@ -456,7 +455,6 @@ describe("a Sys that defaults to the only app", () => {
456
455
  });
457
456
  afterEach(() => {
458
457
  CommandContainer.clear();
459
- process.chdir(ownCwd);
460
458
  if (ownIsTTY) Object.defineProperty(process.stdin, "isTTY", ownIsTTY);
461
459
  else Reflect.deleteProperty(process.stdin, "isTTY");
462
460
  });
@@ -479,10 +477,8 @@ describe("a Sys that defaults to the only app", () => {
479
477
  return meta;
480
478
  };
481
479
  const track = tempRoots();
482
- //? From the workspace root, as the CLI runs: getDirInModule stats its entries relative to the process directory.
483
480
  const moduleWorkspace = async () => {
484
481
  const { root, workspace } = track(await makeCliTempWorkspace());
485
- process.chdir(root);
486
482
  for (const [sys, name] of [
487
483
  ["apps/web", "card"],
488
484
  ["libs/util", "photo"],
@@ -767,6 +763,83 @@ describe("a target left out where no terminal can ask for it", () => {
767
763
  }, 30_000);
768
764
  });
769
765
 
766
+ describe("a CLI of another major.minor than the workspace's akanjs", () => {
767
+ const track = tempRoots();
768
+ const run = async (args: string[], env: { [name: string]: string } = {}) => {
769
+ const { root } = track(await makeCliTempWorkspace());
770
+ await writeText(path.join(root, "package.json"), '{ "name": "repo", "version": "1.0.0" }\n');
771
+ await writeText(path.join(root, "tsconfig.json"), "{}\n");
772
+ await writeText(path.join(root, "node_modules/akanjs/package.json"), '{ "name": "akanjs", "version": "1.0.0" }\n');
773
+ const entry = path.join(root, "cli.ts");
774
+ await writeText(
775
+ entry,
776
+ [
777
+ `import { command, runCommands } from ${JSON.stringify(path.join(import.meta.dir, "index.ts"))};`,
778
+ 'class ThingCommand extends command("thing", ({ public: target }) => ({',
779
+ ' makeThing: target({ desc: "writes a thing" }).exec(async function () {',
780
+ ' process.stdout.write("made\\n");',
781
+ " }),",
782
+ ' showThing: target({ desc: "reads a thing", readOnly: true }).exec(async function () {',
783
+ ' process.stdout.write("shown\\n");',
784
+ " }),",
785
+ ' fixThing: target({ desc: "fixes a thing", readOnly: ({ fix }) => fix === false })',
786
+ ' .option("fix", Boolean, { default: true })',
787
+ " .exec(async function (fix) {",
788
+ ' process.stdout.write("fix " + fix + "\\n");',
789
+ " }),",
790
+ ' actThing: target({ desc: "acts on a thing", readOnly: ({ action }) => action !== "apply" })',
791
+ ' .option("action", String, { enum: () => ["apply"] })',
792
+ " .exec(async function (action) {",
793
+ ' process.stdout.write("acted " + action + "\\n");',
794
+ " }),",
795
+ "})) {}",
796
+ "await runCommands(ThingCommand);",
797
+ "",
798
+ ].join("\n"),
799
+ );
800
+ const proc = Bun.spawn(["bun", entry, ...args], {
801
+ cwd: root,
802
+ env: { ...process.env, AKAN_ALLOW_VERSION_MISMATCH: "", ...env },
803
+ stdin: "ignore",
804
+ stdout: "pipe",
805
+ stderr: "pipe",
806
+ });
807
+ const [stdout, stderr, code] = await Promise.all([
808
+ new Response(proc.stdout).text(),
809
+ new Response(proc.stderr).text(),
810
+ proc.exited,
811
+ ]);
812
+ return { stdout, stderr, code };
813
+ };
814
+
815
+ test("refuses a command that writes, before it runs, naming akan update and the override", async () => {
816
+ const refused = await run(["make-thing"]);
817
+ expect(refused.code).toBe(2);
818
+ expect(refused.stdout).toContain("but this workspace has akanjs 1.0.0, another major.minor");
819
+ expect(refused.stdout).toContain("akan update");
820
+ expect(refused.stdout).toContain("AKAN_ALLOW_VERSION_MISMATCH=1");
821
+ expect(refused.stdout).not.toContain("made");
822
+ expect((await run(["fix-thing"])).code).toBe(2);
823
+ }, 30_000);
824
+
825
+ test("decides on the values the left-out arguments resolve to, so one answered later cannot slip through", async () => {
826
+ const acted = await run(["act-thing"]);
827
+ expect(acted.code).toBe(2);
828
+ expect(acted.stdout).toContain("AKAN_ALLOW_VERSION_MISMATCH=1");
829
+ expect(acted.stdout).not.toContain("acted");
830
+ expect((await run(["act-thing"], { AKAN_ALLOW_VERSION_MISMATCH: "1" })).stdout).toContain("acted apply\n");
831
+ }, 30_000);
832
+
833
+ test("only warns for a read-only command, and runs a writing one with the override set", async () => {
834
+ const shown = await run(["show-thing"]);
835
+ expect([shown.code, shown.stdout.trim()]).toEqual([0, "shown"]);
836
+ expect(shown.stderr).toContain("but this workspace has akanjs 1.0.0");
837
+ expect((await run(["fix-thing", "--fix", "false"])).stdout).toContain("fix false\n");
838
+ const overridden = await run(["make-thing"], { AKAN_ALLOW_VERSION_MISMATCH: "1" });
839
+ expect([overridden.code, overridden.stdout.trim()]).toEqual([0, "made"]);
840
+ }, 30_000);
841
+ });
842
+
770
843
  describe("the exit code of a command that failed", () => {
771
844
  const track = tempRoots();
772
845
  const run = async (
@@ -926,6 +999,34 @@ describe("the exit code of a command that failed", () => {
926
999
  expect(rejected.code).toBe(2);
927
1000
  }, 60_000);
928
1001
 
1002
+ test("ends with each reason an aggregate holds, where a bundler log names its file and line", async () => {
1003
+ const graphFailure = [
1004
+ "await (async () => {",
1005
+ ' await Bun.write("graph/server.ts", \'import { env } from "./env.server.debug";\\nexport default env;\\n\');',
1006
+ ' const result = await Bun.build({ entrypoints: ["graph/server.ts"], target: "bun", throw: false });',
1007
+ ' return new AggregateError(result.logs, "[licenseNotices] server graph failed");',
1008
+ "})()",
1009
+ ].join("\n");
1010
+ const reason = ' Could not resolve: "./env.server.debug" (graph/server.ts:1:21)';
1011
+ const json = ' }).option("json", Boolean, { default: false';
1012
+ const [text, asJson] = await Promise.all([
1013
+ run(graphFailure),
1014
+ run(graphFailure, { option: json, args: ["--json"] }),
1015
+ ]);
1016
+ expect(text.code).toBe(1);
1017
+ expect(stripAnsi(text.stdout).trimEnd().split("\n").slice(-2)).toEqual([
1018
+ "[licenseNotices] server graph failed",
1019
+ reason,
1020
+ ]);
1021
+ expect(asJson.code).toBe(1);
1022
+ expect(JSON.parse(asJson.stdout)).toEqual({
1023
+ ok: false,
1024
+ error: "[licenseNotices] server graph failed",
1025
+ code: "failed",
1026
+ });
1027
+ expect(stripAnsi(asJson.stderr).trimEnd().split("\n").at(-1)).toBe(reason);
1028
+ }, 30_000);
1029
+
929
1030
  test("prints nothing more for an error the command marked as printed", async () => {
930
1031
  const marked = await run(
931
1032
  '(() => { const error = new Error("printed already"); markCliErrorPrinted(error); return error; })()',
@@ -1031,7 +1132,7 @@ describe("a workspace whose akanjs is not the CLI's version", () => {
1031
1132
  'class PlanRunner extends runner("plan") {}',
1032
1133
  'class PlanScript extends script("plan", [PlanRunner]) {}',
1033
1134
  'class PlanCommand extends command("plan", [PlanScript], ({ public: target }) => ({',
1034
- ' plan: target({ desc: "plans", stdio: true }).exec(async function () {',
1135
+ ' plan: target({ desc: "plans", stdio: true, readOnly: true }).exec(async function () {',
1035
1136
  " process.stdout.write(JSON.stringify({ phases: 1 }));",
1036
1137
  " }),",
1037
1138
  "})) {}",
@@ -48,6 +48,8 @@ export interface TargetOption {
48
48
  usageExitCode?: number;
49
49
  /** It deletes files in its app, lib, pkg or module, so one left out or unknown is refused, never picked or asked. */
50
50
  destructive?: boolean;
51
+ /** Writes nothing akanjs's version shapes, so another major.minor CLI only warns; left out, it is refused. */
52
+ readOnly?: boolean | ((values: { [name: string]: unknown }) => boolean);
51
53
  /** Runs after the CLI printed a failure and before it exits, so what it writes ends the output. */
52
54
  onFailure?: (error: unknown, failure: TargetFailure) => void | Promise<void>;
53
55
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { mkdir, symlink } from "node:fs/promises";
3
3
  import path from "node:path";
4
- import { tempDirs, writeJson } from "../testHelpers";
4
+ import { tempDirs, writeJson } from "../test/testHelpers";
5
5
  import { WorkspaceVersionCheck } from "./workspaceVersionCheck";
6
6
 
7
7
  const makeRoot = tempDirs("akan-version-check-");
@@ -77,4 +77,73 @@ describe("WorkspaceVersionCheck", () => {
77
77
  expect(WorkspaceVersionCheck.installedAkanVersion(root)).toBeNull();
78
78
  expect(WorkspaceVersionCheck.warning("3.1.0", argv("sync", "demo"), root)).toBeNull();
79
79
  });
80
+
81
+ describe("refusal", () => {
82
+ test("refuses another major.minor, naming both versions, akan update and the variable that overrides it", async () => {
83
+ const root = await makeWorkspace({ akanjs: "3.1.4" });
84
+
85
+ const refusal = WorkspaceVersionCheck.refusal("3.2.0", argv("sync", "demo"), root, {});
86
+
87
+ expect(refusal).toContain("@akanjs/cli 3.2.0, but this workspace has akanjs 3.1.4, another major.minor");
88
+ expect(refusal).toContain("`akan sync` is refused");
89
+ expect(refusal).toContain("Move the workspace and this CLI to one release together: akan update\n");
90
+ expect(refusal).toContain("Or run the matching CLI once: bunx -p @akanjs/cli@3.1.4 akan sync demo");
91
+ expect(refusal).toEndWith("Or set AKAN_ALLOW_VERSION_MISMATCH=1 to run it anyway.");
92
+ expect(WorkspaceVersionCheck.refusal("4.0.0-rc.1", argv("sync"), root, {})).toContain("akan update --tag rc");
93
+ });
94
+
95
+ test("tells a CLI older than the workspace to install the matching one, not to run akan update", async () => {
96
+ const refusal = WorkspaceVersionCheck.refusal(
97
+ "3.1.4",
98
+ argv("sync", "demo"),
99
+ await makeWorkspace({ akanjs: "3.2.0" }),
100
+ {},
101
+ );
102
+
103
+ expect(refusal).toContain("Install the CLI this workspace was moved to: bun add -g @akanjs/cli@3.2.0");
104
+ expect(refusal).not.toContain("akan update");
105
+ });
106
+
107
+ test("passes the same major.minor, prereleases of it included, leaving the warning", async () => {
108
+ for (const [cli, akanjs] of [
109
+ ["3.2.0-rc.5", "3.2.0-rc.3"],
110
+ ["3.2.1", "3.2.0"],
111
+ ["3.2.0", "3.2.0-rc.9"],
112
+ ] as const) {
113
+ const root = await makeWorkspace({ akanjs });
114
+ expect(WorkspaceVersionCheck.refusal(cli, argv("sync"), root, {})).toBeNull();
115
+ expect(WorkspaceVersionCheck.warning(cli, argv("sync"), root)).toContain(`akanjs ${akanjs}`);
116
+ }
117
+ });
118
+
119
+ test("never refuses update, create-workspace, help or version, nor with the override set", async () => {
120
+ const root = await makeWorkspace({ akanjs: "3.1.4" });
121
+ for (const args of [["update"], ["create-workspace", "next"], ["--version"], ["sync", "--help"]])
122
+ expect(WorkspaceVersionCheck.refusal("3.2.0", argv(...args), root, {})).toBeNull();
123
+ for (const value of ["1", "true"])
124
+ expect(
125
+ WorkspaceVersionCheck.refusal("3.2.0", argv("sync"), root, { AKAN_ALLOW_VERSION_MISMATCH: value }),
126
+ ).toBeNull();
127
+ expect(
128
+ WorkspaceVersionCheck.refusal("3.2.0", argv("sync"), root, { AKAN_ALLOW_VERSION_MISMATCH: "0" }),
129
+ ).not.toBeNull();
130
+ });
131
+
132
+ test("never refuses a workspace that links akanjs from its own source", async () => {
133
+ const root = await makeWorkspace({});
134
+ await writeJson(path.join(root, "pkgs/akanjs/package.json"), { name: "akanjs", version: "2.0.0" });
135
+ await mkdir(path.join(root, "node_modules"), { recursive: true });
136
+ await symlink(path.join(root, "pkgs/akanjs"), path.join(root, "node_modules/akanjs"), "dir");
137
+
138
+ expect(WorkspaceVersionCheck.refusal("3.2.0", argv("sync", "demo"), root, {})).toBeNull();
139
+ });
140
+
141
+ test("counts a command as writing unless it is marked read-only, for the values it was given", () => {
142
+ expect(WorkspaceVersionCheck.readsOnly({ type: "public" }, {})).toBe(false);
143
+ expect(WorkspaceVersionCheck.readsOnly({ type: "public", readOnly: true }, {})).toBe(true);
144
+ const lint = { type: "public", readOnly: ({ fix }: { [name: string]: unknown }) => fix === false } as const;
145
+ expect(WorkspaceVersionCheck.readsOnly(lint, { fix: true })).toBe(false);
146
+ expect(WorkspaceVersionCheck.readsOnly(lint, { fix: false })).toBe(true);
147
+ });
148
+ });
80
149
  });
@@ -1,35 +1,66 @@
1
1
  import { existsSync, readFileSync, realpathSync } from "node:fs";
2
2
  import path from "node:path";
3
- import type { PackageJson } from "../types";
3
+ import type { PackageJson } from "../workspace/types";
4
+ import type { TargetOption } from "./targetMeta";
5
+
6
+ interface Mismatch {
7
+ args: string[];
8
+ cliVersion: string;
9
+ installed: string;
10
+ pinnedCli: string | null;
11
+ rerun: string;
12
+ update: string;
13
+ }
4
14
 
5
15
  export class WorkspaceVersionCheck {
16
+ static readonly overrideEnv = "AKAN_ALLOW_VERSION_MISMATCH";
6
17
  static readonly #exemptCommands = new Set(["update", "create-workspace"]);
7
18
  static readonly #infoFlags = new Set(["--help", "-h", "--version", "-V"]);
8
19
  static readonly #updateTags = new Set(["dev", "canary", "beta", "rc", "alpha"]);
9
20
 
10
21
  static warning(cliVersion: string | undefined, argv: string[], workspaceRoot: string) {
11
- const args = argv.slice(2);
12
- if (!cliVersion || WorkspaceVersionCheck.#exemptCommands.has(args[0] ?? "")) return null;
13
- if (args.some((arg) => WorkspaceVersionCheck.#infoFlags.has(arg))) return null;
14
- const installed = WorkspaceVersionCheck.installedAkanVersion(workspaceRoot);
15
- if (!installed || installed === cliVersion) return null;
16
- const pinnedCli = WorkspaceVersionCheck.#versionAt(path.join(workspaceRoot, "node_modules/@akanjs/cli"));
17
- const runner = pinnedCli === installed ? ["bunx"] : ["bunx", "-p", `@akanjs/cli@${installed}`];
18
- const rerun = [...runner, "akan", ...args].map(WorkspaceVersionCheck.#quote).join(" ");
19
- const [, prerelease = ""] = cliVersion.split("-");
20
- const tag = prerelease.split(".")[0];
21
- const update = `akan update${WorkspaceVersionCheck.#updateTags.has(tag) ? ` --tag ${tag}` : ""}`;
22
+ const mismatch = WorkspaceVersionCheck.#mismatchOf(cliVersion, argv, workspaceRoot);
23
+ if (!mismatch) return null;
24
+ const { cliVersion: cli, installed, pinnedCli, rerun, update } = mismatch;
22
25
  const lines = [
23
- `This akan is @akanjs/cli ${cliVersion}, but this workspace has akanjs ${installed}: what it generates may not match the installed framework.`,
26
+ `This akan is @akanjs/cli ${cli}, but this workspace has akanjs ${installed}: what it generates may not match the installed framework.`,
24
27
  `Run the matching CLI: ${rerun}`,
25
28
  ];
26
- if (Bun.semver.order(cliVersion, installed) > 0)
29
+ if (Bun.semver.order(cli, installed) > 0)
27
30
  lines.push(`Or move the workspace and this CLI to the newest release of the line together: ${update}`);
28
31
  else if (pinnedCli !== installed)
29
32
  lines.push(`Pin it so \`bunx akan\` runs it: bun add -d @akanjs/cli@${installed}`);
30
33
  return lines.join("\n");
31
34
  }
32
35
 
36
+ static refusal(
37
+ cliVersion: string | undefined,
38
+ argv: string[],
39
+ workspaceRoot: string,
40
+ env: { [name: string]: string | undefined } = process.env,
41
+ ) {
42
+ const mismatch = WorkspaceVersionCheck.#mismatchOf(cliVersion, argv, workspaceRoot);
43
+ if (!mismatch || ["1", "true"].includes(env[WorkspaceVersionCheck.overrideEnv] ?? "")) return null;
44
+ const { args, cliVersion: cli, installed, rerun, update } = mismatch;
45
+ if (WorkspaceVersionCheck.#lineOf(cli) === WorkspaceVersionCheck.#lineOf(installed)) return null;
46
+ //? An older CLI is not told `akan update`: it resolves the tag this CLI came from and could move akanjs back.
47
+ const realign =
48
+ Bun.semver.order(cli, installed) > 0
49
+ ? `Move the workspace and this CLI to one release together: ${update}`
50
+ : `Install the CLI this workspace was moved to: bun add -g @akanjs/cli@${installed}`;
51
+ return [
52
+ `This akan is @akanjs/cli ${cli}, but this workspace has akanjs ${installed}, another major.minor, so \`akan ${args[0]}\` is refused: it writes to the workspace, and what it writes would not match the installed framework.`,
53
+ realign,
54
+ `Or run the matching CLI once: ${rerun}`,
55
+ `Or set ${WorkspaceVersionCheck.overrideEnv}=1 to run it anyway.`,
56
+ ].join("\n");
57
+ }
58
+
59
+ static readsOnly(targetOption: TargetOption, values: { [name: string]: unknown }) {
60
+ const { readOnly = false } = targetOption;
61
+ return typeof readOnly === "function" ? readOnly(values) : readOnly;
62
+ }
63
+
33
64
  static installedAkanVersion(workspaceRoot: string) {
34
65
  const packageDir = path.join(workspaceRoot, "node_modules", "akanjs");
35
66
  if (!existsSync(packageDir)) return null;
@@ -38,6 +69,25 @@ export class WorkspaceVersionCheck {
38
69
  return WorkspaceVersionCheck.#versionAt(packageDir);
39
70
  }
40
71
 
72
+ static #mismatchOf(cliVersion: string | undefined, argv: string[], workspaceRoot: string): Mismatch | null {
73
+ const args = argv.slice(2);
74
+ if (!cliVersion || WorkspaceVersionCheck.#exemptCommands.has(args[0] ?? "")) return null;
75
+ if (args.some((arg) => WorkspaceVersionCheck.#infoFlags.has(arg))) return null;
76
+ const installed = WorkspaceVersionCheck.installedAkanVersion(workspaceRoot);
77
+ if (!installed || installed === cliVersion) return null;
78
+ const pinnedCli = WorkspaceVersionCheck.#versionAt(path.join(workspaceRoot, "node_modules/@akanjs/cli"));
79
+ const runner = pinnedCli === installed ? ["bunx"] : ["bunx", "-p", `@akanjs/cli@${installed}`];
80
+ const rerun = [...runner, "akan", ...args].map(WorkspaceVersionCheck.#quote).join(" ");
81
+ const [, prerelease = ""] = cliVersion.split("-");
82
+ const tag = prerelease.split(".")[0];
83
+ const update = `akan update${WorkspaceVersionCheck.#updateTags.has(tag) ? ` --tag ${tag}` : ""}`;
84
+ return { args, cliVersion, installed, pinnedCli, rerun, update };
85
+ }
86
+
87
+ static #lineOf(version: string) {
88
+ return version.split("-")[0]?.split(".").slice(0, 2).join(".");
89
+ }
90
+
41
91
  static #versionAt(packageDir: string) {
42
92
  const packageJsonPath = path.join(packageDir, "package.json");
43
93
  if (!existsSync(packageJsonPath)) return null;