@akanjs/devkit 3.2.0-rc.9 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) 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 +132 -3
  7. package/akanApp/akanApp.host.ts +146 -1216
  8. package/akanApp/akanApp.host.wiring.test.ts +727 -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 +392 -0
  14. package/akanApp/devBuildStatusBoard.ts +128 -0
  15. package/akanApp/devBuilder.ts +196 -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/processRss.ts +61 -0
  22. package/akanConfig/akanConfig.test.ts +45 -17
  23. package/akanConfig/akanConfig.ts +10 -10
  24. package/akanConfig/akanWorkspaceConfig.ts +1 -1
  25. package/akanConfig/productionLockfile.ts +1 -1
  26. package/apiReport/apiReport.test.ts +34 -3
  27. package/apiReport/apiReportDiff.ts +35 -1
  28. package/apiReport/apiReportPolicy.ts +3 -2
  29. package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
  30. package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
  31. package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
  32. package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
  33. package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
  34. package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
  35. package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
  36. package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
  37. package/artifact/implicitRootLayout.test.ts +71 -3
  38. package/artifact/implicitRootLayout.ts +9 -3
  39. package/artifact/implicitRootLayoutRender.test.tsx +297 -0
  40. package/biome.base.json +2 -1
  41. package/cloud/cloudApi.test.ts +1 -1
  42. package/cloud/configLock.test.ts +1 -1
  43. package/cloud/globalConfig.test.ts +1 -1
  44. package/cloud/globalConfig.ts +1 -1
  45. package/cloud/updatePackUpload.test.ts +1 -1
  46. package/codeAgent/agent/AkanCodeEnv.ts +1 -1
  47. package/codeAgent/agent/AkanCodeServices.ts +23 -0
  48. package/codeAgent/agent/akanCodePaths.ts +1 -1
  49. package/codeAgent/agent/akanCodeServices.test.ts +54 -0
  50. package/codeAgent/agent/akanSystemPrompt.ts +1 -1
  51. package/codeAgent/agent/codeAgent.test.ts +1 -1
  52. package/codeAgent/skills/akan-debug/SKILL.md +8 -5
  53. package/codeAgent/skills/akan-err/SKILL.md +7 -0
  54. package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
  55. package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
  56. package/codeAgent/skills/akan-validate/SKILL.md +3 -3
  57. package/codeAgent/tools/AkanCli.ts +1 -1
  58. package/codeAgent/tools/AkanToolPack.ts +2 -2
  59. package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
  60. package/commandDecorators/command.ts +35 -6
  61. package/commandDecorators/commandBuilder.ts +1 -1
  62. package/commandDecorators/commandDecorators.test.ts +107 -6
  63. package/commandDecorators/targetMeta.ts +2 -0
  64. package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
  65. package/commandDecorators/workspaceVersionCheck.ts +64 -14
  66. package/context/akanContext.ts +576 -0
  67. package/context/akanContextInspection.ts +296 -0
  68. package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
  69. package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
  70. package/context/doctor/agentGuideCheck.ts +81 -0
  71. package/context/doctor/configLeftoverCheck.ts +35 -0
  72. package/context/doctor/doctorFindings.ts +70 -0
  73. package/context/doctor/generatedFreshness.ts +56 -0
  74. package/context/doctor/moduleShapeCheck.ts +88 -0
  75. package/context/doctor/recipeDuplicateCheck.ts +42 -0
  76. package/context/doctor/recipeIndexCheck.ts +87 -0
  77. package/context/doctor/rootShapeCheck.ts +55 -0
  78. package/context/doctor/workflowScope.ts +97 -0
  79. package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
  80. package/context/safeRead.ts +9 -0
  81. package/csrE2e/csrE2eHarness.fixture.ts +1 -1
  82. package/devkitUtils.test.ts +39 -5
  83. package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
  84. package/{apiReference.ts → docs/apiReference.ts} +2 -2
  85. package/docs/errorCodeReference.test.ts +282 -0
  86. package/docs/errorCodeReference.ts +71 -0
  87. package/docs/errorCodeScan.ts +551 -0
  88. package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
  89. package/executors/appExecutor.ts +448 -0
  90. package/executors/commandExecutionError.ts +53 -0
  91. package/executors/executor.ts +527 -0
  92. package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
  93. package/{executors.test.ts → executors/executors.test.ts} +76 -15
  94. package/executors/index.ts +8 -0
  95. package/executors/libExecutor.ts +23 -0
  96. package/executors/moduleExecutor.ts +18 -0
  97. package/executors/pkgExecutor.ts +129 -0
  98. package/executors/sysExecutor.ts +301 -0
  99. package/executors/workspaceExecutor.ts +277 -0
  100. package/frontendBuild/allRoutesBuilder.test.ts +1 -1
  101. package/frontendBuild/autoImportSync.test.ts +1 -1
  102. package/frontendBuild/autoImportSync.ts +1 -1
  103. package/frontendBuild/buildRouteClient.test.ts +1 -1
  104. package/frontendBuild/clientEntriesBundler.test.ts +1 -1
  105. package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
  106. package/frontendBuild/csrDevArtifactWriter.ts +1 -1
  107. package/frontendBuild/cssCompiler.test.ts +3 -2
  108. package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
  109. package/frontendBuild/devGeneratedIndexSync.ts +7 -38
  110. package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
  111. package/frontendBuild/fontOptimizer.test.ts +1 -1
  112. package/frontendBuild/fontPruner.test.ts +1 -1
  113. package/frontendBuild/frontendBuild.test.ts +3 -3
  114. package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
  115. package/frontendBuild/hmrWatcher.test.ts +1 -1
  116. package/frontendBuild/hmrWatcher.ts +22 -1
  117. package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
  118. package/frontendBuild/mcpAppViewBuilder.ts +1 -1
  119. package/frontendBuild/nativeCore.test.ts +1 -1
  120. package/frontendBuild/optionalPeers.test.ts +36 -8
  121. package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
  122. package/frontendBuild/pagesBundleBuilder.ts +1 -1
  123. package/frontendBuild/precompressArtifacts.test.ts +1 -1
  124. package/frontendBuild/precompressArtifacts.ts +19 -6
  125. package/frontendBuild/serverGraphFile.ts +1 -1
  126. package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
  127. package/frontendBuild/ssrDevBundler.test.ts +1 -1
  128. package/frontendBuild/vendorImportScanner.test.ts +1 -1
  129. package/frontendBuild/vendorNarrowing.test.ts +1 -1
  130. package/frontendBuild/watchRootResolver.test.ts +1 -1
  131. package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
  132. package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
  133. package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
  134. package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
  135. package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
  136. package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
  137. package/{prompter.ts → guideline/prompter.ts} +2 -3
  138. package/incrementalBuilder/buildBatch.proc.ts +14 -4
  139. package/incrementalBuilder/buildBatchProtocol.ts +2 -0
  140. package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
  141. package/incrementalBuilder/buildBatchRunner.ts +17 -4
  142. package/incrementalBuilder/builderBoot.ts +106 -0
  143. package/incrementalBuilder/builderBuildStatus.ts +23 -0
  144. package/incrementalBuilder/builderChannel.test.ts +1 -1
  145. package/incrementalBuilder/builderChannel.ts +11 -0
  146. package/incrementalBuilder/builderGraphPayloads.ts +3 -3
  147. package/incrementalBuilder/builderLanes.ts +157 -0
  148. package/incrementalBuilder/builderWatch.ts +213 -0
  149. package/incrementalBuilder/csrRegistry.ts +234 -0
  150. package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
  151. package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
  152. package/incrementalBuilder/ssrRegistry.ts +282 -0
  153. package/index.ts +22 -22
  154. package/integration/devStability.integration.test.ts +62 -56
  155. package/integration/devStabilityHarness.test.ts +1 -1
  156. package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
  157. package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
  158. package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
  159. package/lint/gritRules.test.ts +1 -1
  160. package/{linter.test.ts → lint/linter.test.ts} +1 -1
  161. package/lint/no-import-common-err.grit +31 -0
  162. package/lint/no-init-fetch-in-client.grit +1 -1
  163. package/mobile/desktopBin.test.ts +1 -1
  164. package/mobile/desktopRelease.test.ts +1 -1
  165. package/mobile/desktopServerStage.test.ts +2 -2
  166. package/mobile/desktopServerStage.ts +1 -1
  167. package/mobile/nativeApi.test.ts +1 -1
  168. package/mobile/nativeApp.test.ts +1 -1
  169. package/mobile/nativeConfig.test.ts +1 -1
  170. package/mobile/nativePluginFolders.test.ts +1 -1
  171. package/mobile/nativePublicEnv.test.ts +1 -1
  172. package/mobile/nativeWebDir.test.ts +1 -1
  173. package/mobile/serverBundleSecrets.test.ts +1 -1
  174. package/mobile/tarWriter.test.ts +1 -1
  175. package/mobile/updatePackFolder.test.ts +1 -1
  176. package/package.json +173 -9
  177. package/packageExports.test.ts +20 -2
  178. package/piDependencyPins.test.ts +1 -1
  179. package/pipeline/PipelineDefinition.ts +1 -1
  180. package/platformTest/IdleWatchedProcess.test.ts +1 -1
  181. package/platformTest/LinuxDockerTarget.ts +1 -1
  182. package/platformTest/PlatformTestRun.test.ts +1 -1
  183. package/platformTest/TestSnapshot.test.ts +1 -1
  184. package/platformTest/WindowsSshTarget.ts +1 -1
  185. package/preview/previewView.test.ts +23 -1
  186. package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
  187. package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
  188. package/quality/bareErrorScanner.ts +126 -0
  189. package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
  190. package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
  191. package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
  192. package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
  193. package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
  194. package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
  195. package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
  196. package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
  197. package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
  198. package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
  199. package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
  200. package/quality/workspaceSourceFiles.ts +82 -0
  201. package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
  202. package/{subspace.ts → subspace/subspace.ts} +5 -5
  203. package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
  204. package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
  205. package/{testHelpers.ts → test/testHelpers.ts} +37 -1
  206. package/transforms/barrelAnalyzer.ts +31 -10
  207. package/transforms/browserDirnamePlugin.test.ts +1 -1
  208. package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
  209. package/transforms/mcpAppPageTrimmer.test.ts +1 -1
  210. package/transforms/pureLazyMarker.test.ts +1 -1
  211. package/transforms/serverEnvPlugin.test.ts +1 -1
  212. package/transforms/serverEnvProfile.test.ts +1 -1
  213. package/transforms/sideEffectImportOrder.test.ts +1 -1
  214. package/transforms/transforms.test.ts +52 -2
  215. package/transforms/tsconfigPackageResolver.test.ts +1 -1
  216. package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
  217. package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
  218. package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
  219. package/typecheck/projectTypecheck.test.ts +23 -1
  220. package/typecheck/projectTypecheck.ts +10 -2
  221. package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
  222. package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
  223. package/typecheck/typecheck.proc.ts +6 -2
  224. package/typecheck/typecheckFailure.ts +1 -1
  225. package/util/errorReport.ts +66 -0
  226. package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
  227. package/workflow/constantSource.ts +187 -0
  228. package/workflow/dictionarySource.ts +184 -0
  229. package/workflow/executor.ts +6 -9
  230. package/workflow/fieldExpression.ts +153 -0
  231. package/workflow/fieldLabel.ts +61 -0
  232. package/workflow/fieldOrder.ts +117 -0
  233. package/workflow/fieldType.ts +2 -1
  234. package/workflow/guardCatalog.test.ts +1 -1
  235. package/workflow/keyRename.ts +1 -1
  236. package/workflow/moduleIndex.test.ts +2 -2
  237. package/workflow/moduleIndex.ts +2 -2
  238. package/workflow/modulePaths.ts +27 -0
  239. package/workflow/mutationScaffold.ts +7 -15
  240. package/workflow/mutationSource.ts +2 -1
  241. package/workflow/plan.ts +2 -1
  242. package/workflow/primitiveReport.ts +78 -0
  243. package/workflow/rolloutGate.test.ts +1 -1
  244. package/workflow/rolloutGate.ts +1 -1
  245. package/workflow/serviceSource.ts +33 -0
  246. package/workflow/signalSource.ts +96 -0
  247. package/workflow/source.ts +50 -1100
  248. package/workflow/sourceAst.ts +30 -0
  249. package/workflow/sourceImports.ts +105 -0
  250. package/workflow/sourceText.ts +13 -0
  251. package/workflow/templateSource.ts +30 -0
  252. package/workflow/testSource.ts +31 -0
  253. package/workflow/types.ts +1 -1
  254. package/workflow/uiPolicy.ts +1 -1
  255. package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
  256. package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
  257. package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
  258. package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
  259. package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
  260. package/{envSeed.ts → workspace/envSeed.ts} +1 -1
  261. package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
  262. package/{libSource.ts → workspace/libSource.ts} +1 -1
  263. package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
  264. package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
  265. package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
  266. package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
  267. package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
  268. package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
  269. package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
  270. package/akanContext.ts +0 -1083
  271. package/executors.ts +0 -1749
  272. /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
  273. /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
  274. /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
  275. /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
  276. /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
  277. /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
  278. /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
  279. /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
  280. /package/{linter.ts → lint/linter.ts} +0 -0
  281. /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
  282. /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
  283. /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
  284. /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
  285. /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
  286. /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
  287. /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
  288. /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
  289. /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
  290. /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
  291. /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
  292. /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
  293. /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
  294. /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
  295. /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
  296. /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
  297. /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
  298. /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
  299. /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
  300. /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
  301. /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
  302. /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
  303. /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
  304. /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
  305. /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
  306. /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
  307. /package/{storeSource.ts → quality/storeSource.ts} +0 -0
  308. /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
  309. /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
  310. /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
  311. /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
  312. /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
  313. /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
  314. /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
  315. /package/{writePath.ts → quality/writePath.ts} +0 -0
  316. /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
  317. /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
  318. /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
  319. /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
  320. /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
  321. /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
  322. /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
  323. /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
  324. /package/{fileSys.ts → util/fileSys.ts} +0 -0
  325. /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
  326. /package/{selectModel.ts → util/selectModel.ts} +0 -0
  327. /package/{semver.test.ts → util/semver.test.ts} +0 -0
  328. /package/{semver.ts → util/semver.ts} +0 -0
  329. /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
  330. /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
  331. /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
  332. /package/{spinner.ts → util/spinner.ts} +0 -0
  333. /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
  334. /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
  335. /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
  336. /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
  337. /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
  338. /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
  339. /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
  340. /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
  341. /package/{types.ts → workspace/types.ts} +0 -0
@@ -0,0 +1,527 @@
1
+ import {
2
+ type ChildProcess,
3
+ type ExecOptions,
4
+ exec,
5
+ type ForkOptions,
6
+ fork,
7
+ type SpawnOptions,
8
+ spawn,
9
+ } from "node:child_process";
10
+ import { copyFile, cp as cpEntry, mkdir, readdir as readDirEntries, rm, stat } from "node:fs/promises";
11
+ import path from "node:path";
12
+ import { capitalize, Logger, toError } from "akanjs/common";
13
+ import { $ } from "bun";
14
+ import chalk from "chalk";
15
+ import { Linter } from "../lint/linter";
16
+ import { ProjectTypecheck } from "../typecheck/projectTypecheck";
17
+ // Type-only: `getTypeChecker` loads it on demand to keep `typescript` out of the resident module graph.
18
+ import type { TypeChecker } from "../typecheck/typeChecker";
19
+ import { FileSys, getDirname } from "../util/fileSys";
20
+ import { JsonFormatter } from "../util/jsonFormatter";
21
+ import { Spinner } from "../util/spinner";
22
+ import type { AppInfo, LibInfo } from "../workspace/scanInfo";
23
+ import type { FileContent, PackageJson, TsConfigJson } from "../workspace/types";
24
+ import { CommandExecutionError } from "./commandExecutionError";
25
+
26
+ export interface WrittenFileContent extends FileContent {
27
+ written: boolean;
28
+ }
29
+
30
+ const staticTemplateFileExtensions = new Set(
31
+ ".avif .bmp .cjs .css .eot .gif .html .ico .jpeg .jpg .js .json .map .md .mjs .mp3 .mp4 .ogg .otf .pdf .png .svg"
32
+ .split(" ")
33
+ .concat(".ttf .txt .wasm .wav .webm .webp .woff .woff2 .xml".split(" ")),
34
+ );
35
+
36
+ export const execEmoji = {
37
+ workspace: "🏠",
38
+ app: "🚀",
39
+ lib: "🔧",
40
+ pkg: "📦",
41
+ dist: "💿",
42
+ module: "⚙️",
43
+ default: "✈️",
44
+ };
45
+
46
+ const withCapitalizedDict = (dict: { [key: string]: string } = {}) => ({
47
+ ...dict,
48
+ ...Object.fromEntries(Object.entries(dict).map(([key, value]) => [capitalize(key), capitalize(value)])),
49
+ });
50
+
51
+ export class Executor {
52
+ static verbose = false;
53
+ static setVerbose(verbose: boolean) {
54
+ Executor.verbose = verbose;
55
+ }
56
+
57
+ name: string;
58
+ logger: Logger;
59
+ logs: string[];
60
+ cwdPath: string;
61
+ emoji = execEmoji.default;
62
+ typeChecker: TypeChecker | null = null;
63
+ linter: Linter | null = null;
64
+ constructor(name: string, cwdPath: string) {
65
+ this.name = name;
66
+ this.logger = new Logger(name);
67
+ this.logs = [] as string[];
68
+ this.cwdPath = cwdPath;
69
+ }
70
+ #stdout(data: Buffer) {
71
+ if (Executor.verbose) Logger.raw(chalk.dim(data.toString()));
72
+ }
73
+ #stderr(data: Buffer) {
74
+ Logger.raw(chalk.red(data.toString()));
75
+ }
76
+ #settle(
77
+ proc: ChildProcess,
78
+ target: { command: string; args?: string[]; cwd: string },
79
+ { onClose = false, keepLogs = false, redStderr = false } = {},
80
+ ): Promise<{ code: number | null; signal: NodeJS.Signals | null; stdout: string }> {
81
+ let stdout = "";
82
+ let stderr = "";
83
+ proc.stdout?.on("data", (data: Buffer) => {
84
+ stdout += data.toString();
85
+ if (keepLogs) this.logs.push(data.toString());
86
+ this.#stdout(data);
87
+ });
88
+ proc.stderr?.on("data", (data: Buffer) => {
89
+ stderr += data.toString();
90
+ if (keepLogs) this.logs.push(data.toString());
91
+ if (redStderr) this.#stderr(data);
92
+ else this.#stdout(data); // 정상로그도 stderr로 나옴
93
+ });
94
+ return new Promise((resolve, reject) => {
95
+ proc.on("error", (cause) =>
96
+ reject(new CommandExecutionError({ ...target, code: null, signal: null, stdout, stderr, cause })),
97
+ );
98
+ proc.on(onClose ? "close" : "exit", (code: number | null, signal: NodeJS.Signals | null) => {
99
+ if ((onClose ? code !== 0 : code) || signal)
100
+ reject(new CommandExecutionError({ ...target, code, signal, stdout, stderr }));
101
+ else resolve({ code, signal, stdout });
102
+ });
103
+ });
104
+ }
105
+ exec(command: string, options: ExecOptions = {}): Promise<unknown> {
106
+ const target = { command, cwd: options.cwd?.toString() ?? this.cwdPath };
107
+ const proc = exec(command, { cwd: this.cwdPath, ...options });
108
+ return this.#settle(proc, target).then(({ code, signal }) => ({ code, signal }));
109
+ }
110
+
111
+ spawn(command: string, args: string[] = [], options: SpawnOptions = {}): Promise<string> {
112
+ const target = { command, args, cwd: options.cwd?.toString() ?? this.cwdPath };
113
+ const proc = spawn(command, args, { cwd: this.cwdPath, ...options });
114
+ return this.#settle(proc, target, { onClose: true, keepLogs: true }).then(({ stdout }) => stdout);
115
+ }
116
+ spawnSync(command: string, args: string[] = [], options: SpawnOptions = {}): ChildProcess {
117
+ return spawn(command, args, { cwd: this.cwdPath, ...options });
118
+ }
119
+ fork(modulePath: string, args: string[] = [], options: ForkOptions = {}): Promise<unknown> {
120
+ const target = { command: modulePath, args, cwd: options.cwd?.toString() ?? this.cwdPath };
121
+ const proc = fork(modulePath, args, { cwd: this.cwdPath, ...options });
122
+ return this.#settle(proc, target, { redStderr: true }).then(({ code, signal }) => ({ code, signal }));
123
+ }
124
+ getPath(filePath: string) {
125
+ if (path.isAbsolute(filePath)) return filePath;
126
+ if (filePath.startsWith(".")) return path.join(this.cwdPath, filePath);
127
+ const baseParts = this.cwdPath.split(/[\\/]/).filter(Boolean);
128
+ const targetParts = filePath.split(/[\\/]/).filter(Boolean);
129
+
130
+ let overlapLength = 0;
131
+ for (let i = 1; i <= Math.min(baseParts.length, targetParts.length); i++) {
132
+ let isOverlap = true;
133
+ for (let j = 0; j < i; j++)
134
+ if (baseParts[baseParts.length - i + j] !== targetParts[j]) {
135
+ isOverlap = false;
136
+ break;
137
+ }
138
+ if (isOverlap) overlapLength = i;
139
+ }
140
+ return path.join(this.cwdPath, ...targetParts.slice(overlapLength));
141
+ }
142
+ async mkdir(dirPath: string) {
143
+ const writePath = this.getPath(dirPath);
144
+ if (!(await FileSys.dirExists(writePath))) await mkdir(writePath, { recursive: true });
145
+ this.logger.verbose(`Make directory ${writePath}`);
146
+ return this;
147
+ }
148
+ async readdir(dirPath: string): Promise<string[]> {
149
+ const readPath = this.getPath(dirPath);
150
+ try {
151
+ const glob = new Bun.Glob("*");
152
+ return Array.from(glob.scanSync({ cwd: readPath, onlyFiles: false })).sort();
153
+ } catch {
154
+ return [];
155
+ }
156
+ }
157
+ async getAllFiles(pattern = "**/*", { cwd }: { cwd?: string } = {}): Promise<string[]> {
158
+ const glob = new Bun.Glob(pattern);
159
+ return Array.from(glob.scanSync({ cwd: cwd ?? this.cwdPath, onlyFiles: true })).sort();
160
+ }
161
+ async getFilesAndDirs(dirPath: string): Promise<{ files: string[]; dirs: string[] }> {
162
+ const fullDirPath = this.getPath(dirPath);
163
+ const glob = new Bun.Glob("*");
164
+ const files = Array.from(glob.scanSync({ cwd: fullDirPath, onlyFiles: true })).sort();
165
+ const allEntries = Array.from(glob.scanSync({ cwd: fullDirPath, onlyFiles: false })).sort();
166
+ const dirs = allEntries.filter((entry) => !files.includes(entry));
167
+ return { files, dirs };
168
+ }
169
+ async exists(filePath: string) {
170
+ return await FileSys.exists(this.getPath(filePath));
171
+ }
172
+ async remove(filePath: string) {
173
+ const readPath = this.getPath(filePath);
174
+ if (await FileSys.fileExists(readPath)) await FileSys.delete(readPath);
175
+ this.logger.verbose(`Remove file ${readPath}`);
176
+ return this;
177
+ }
178
+ async removeDir(dirPath: string) {
179
+ //* XXX: `path.join(…, ".")` drops a trailing slash: `rm -rf link/` wipes the target, `rm -rf link` only unlinks.
180
+ const readPath = path.join(this.getPath(dirPath), ".");
181
+ if (await FileSys.entryExists(readPath)) await rm(readPath, { recursive: true, force: true });
182
+ this.logger.verbose(`Remove directory ${readPath}`);
183
+ return this;
184
+ }
185
+ async writeFile(
186
+ filePath: string,
187
+ content: string | object,
188
+ { overwrite = true, silent = false }: { overwrite?: boolean; silent?: boolean } = {},
189
+ ): Promise<WrittenFileContent> {
190
+ const writePath = this.getPath(filePath);
191
+ const dir = path.dirname(writePath);
192
+ if (!(await FileSys.dirExists(dir))) await mkdir(dir, { recursive: true });
193
+ let contentStr = typeof content === "string" ? content : JsonFormatter.stringify(content, writePath);
194
+ let written = true;
195
+
196
+ if (await FileSys.fileExists(writePath)) {
197
+ const currentContent = await FileSys.readText(writePath);
198
+ if (currentContent === contentStr || !overwrite) {
199
+ this.logger.verbose(`File ${writePath} is unchanged`);
200
+ contentStr = currentContent;
201
+ written = false;
202
+ } else {
203
+ await FileSys.writeText(writePath, contentStr);
204
+ if (Logger.isVerbose()) this.logger.rawLog(chalk.yellow(`File Update: ${filePath}`));
205
+ }
206
+ } else {
207
+ await FileSys.writeText(writePath, contentStr);
208
+ if (!silent) this.logger.rawLog(chalk.green(`File Create: ${filePath}`));
209
+ }
210
+ return { filePath: writePath, content: contentStr, written };
211
+ }
212
+ async writeJson(filePath: string, content: object) {
213
+ await this.writeFile(filePath, content);
214
+ }
215
+ async getLocalFile(targetPath: string) {
216
+ const filePath = path.isAbsolute(targetPath) ? targetPath : targetPath.replace(this.cwdPath, "");
217
+ const content = await this.readFile(filePath);
218
+ return { filePath, content };
219
+ }
220
+ async readFile(filePath: string) {
221
+ return await FileSys.readText(this.getPath(filePath));
222
+ }
223
+ async readJson(filePath: string) {
224
+ return await FileSys.readJson<object>(this.getPath(filePath));
225
+ }
226
+ async cp(srcPath: string, destPath: string, { dereference = false }: { dereference?: boolean } = {}) {
227
+ const src = this.getPath(srcPath);
228
+ const dest = this.getPath(destPath);
229
+ if (!(await FileSys.exists(src))) return;
230
+ const isDirectory = (await stat(src)).isDirectory();
231
+ if (!(await FileSys.exists(dest)) && isDirectory) await mkdir(dest, { recursive: true });
232
+ //* `cp -r` keeps symlinks on GNU but follows them on macOS; Windows has no `cp -r <dir>/.` and rarely the
233
+ //* privilege a symlink needs, so it always copies real files.
234
+ if (dereference || process.platform === "win32")
235
+ await cpEntry(src, dest, { recursive: isDirectory, dereference: true, force: true });
236
+ else await $`cp -r ${src}${isDirectory ? "/." : ""} ${dest}`;
237
+ }
238
+ log(msg: string) {
239
+ this.logger.info(msg);
240
+ return this;
241
+ }
242
+ verbose(msg: string) {
243
+ this.logger.verbose(msg);
244
+ return this;
245
+ }
246
+ debug(msg: string) {
247
+ this.logger.debug(msg);
248
+ return this;
249
+ }
250
+ spinning(msg: string, { prefix = `${this.emoji}${this.name}`, indent = 0, enableSpin = !Executor.verbose } = {}) {
251
+ return new Spinner(msg, { prefix, indent, enableSpin }).start();
252
+ }
253
+
254
+ #tsconfig: TsConfigJson | null = null;
255
+ async getTsConfig(pathname = "tsconfig.json", { refresh }: { refresh?: boolean } = {}): Promise<TsConfigJson> {
256
+ if (this.#tsconfig && !refresh) return this.#tsconfig;
257
+ let tsconfig = (await this.readJson(pathname)) as TsConfigJson;
258
+ if (tsconfig.extends) {
259
+ const base = await this.getTsConfig(tsconfig.extends, { refresh });
260
+ tsconfig = { ...base, ...tsconfig, compilerOptions: { ...base.compilerOptions, ...tsconfig.compilerOptions } };
261
+ }
262
+ this.#tsconfig = tsconfig;
263
+ return tsconfig;
264
+ }
265
+ async setTsConfig(tsconfig: TsConfigJson) {
266
+ await this.writeJson("tsconfig.json", tsconfig);
267
+ this.#tsconfig = tsconfig;
268
+ }
269
+
270
+ #packageJson: PackageJson | null = null;
271
+ async getPackageJson({ refresh }: { refresh?: boolean } = {}): Promise<PackageJson> {
272
+ if (this.#packageJson && !refresh) return this.#packageJson;
273
+ const packageJson = (await this.readJson("package.json")) as PackageJson;
274
+ this.#packageJson = packageJson;
275
+ return packageJson;
276
+ }
277
+ async setPackageJson(packageJson: PackageJson) {
278
+ await this.writeJson("package.json", packageJson);
279
+ this.#packageJson = packageJson;
280
+ }
281
+
282
+ #gitignorePatterns: string[] = [];
283
+ async getGitignorePatterns(): Promise<string[]> {
284
+ if (this.#gitignorePatterns.length) return this.#gitignorePatterns;
285
+ const gitignore = await this.readFile(".gitignore");
286
+ this.#gitignorePatterns = gitignore
287
+ .split("\n")
288
+ .map((line) => line.trim())
289
+ .filter((line) => !!line && !line.startsWith("#"));
290
+ return this.#gitignorePatterns;
291
+ }
292
+
293
+ async #applyTemplateFile(
294
+ {
295
+ templatePath,
296
+ targetPath,
297
+ scanInfo,
298
+ overwrite = true,
299
+ dryRun = false,
300
+ }: {
301
+ templatePath: string;
302
+ targetPath: string;
303
+ scanInfo?: AppInfo | LibInfo | null;
304
+ overwrite?: boolean;
305
+ dryRun?: boolean;
306
+ },
307
+ dict: { [key: string]: string } = {},
308
+ options: { [key: string]: unknown } = {},
309
+ ): Promise<WrittenFileContent | null> {
310
+ const convertPath = (target: string) =>
311
+ Object.entries(dict).reduce(
312
+ (converted, [key, value]) => converted.replace(new RegExp(`__${key}__`, "g"), value),
313
+ target,
314
+ );
315
+ if (targetPath.endsWith(".ts") || targetPath.endsWith(".tsx")) {
316
+ const getContent = (await import(templatePath)) as {
317
+ default: (
318
+ scanInfo: AppInfo | LibInfo | null,
319
+ dict: { [key: string]: string },
320
+ options?: { [key: string]: unknown },
321
+ ) => Promise<string | null | { filename: string; content: string }>;
322
+ };
323
+ const result = await getContent.default(scanInfo ?? null, dict, options);
324
+ if (result === null) return null;
325
+ const filename = typeof result === "object" ? result.filename : path.basename(targetPath).replace(".js", ".ts");
326
+ const content = typeof result === "object" ? result.content : result;
327
+ const convertedTargetPath = convertPath(`${path.dirname(targetPath)}/${filename}`);
328
+ if (dryRun) return { filePath: this.getPath(convertedTargetPath), content, written: false };
329
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
330
+ return this.writeFile(convertedTargetPath, content, { overwrite });
331
+ } else if (targetPath.endsWith(".template")) {
332
+ const content = await FileSys.readText(templatePath);
333
+ const convertedTargetPath = convertPath(targetPath.slice(0, -9));
334
+ const convertedContent = Object.entries(dict).reduce(
335
+ (data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value),
336
+ content,
337
+ );
338
+ if (dryRun) return { filePath: this.getPath(convertedTargetPath), content: convertedContent, written: false };
339
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
340
+ return this.writeFile(convertedTargetPath, convertedContent, { overwrite });
341
+ } else if (staticTemplateFileExtensions.has(path.extname(targetPath).toLowerCase())) {
342
+ const convertedTargetPath = convertPath(targetPath);
343
+ const writePath = this.getPath(convertedTargetPath);
344
+ if (dryRun) return { filePath: writePath, content: "", written: false };
345
+ if (!overwrite && (await FileSys.fileExists(writePath)))
346
+ return { filePath: writePath, content: "", written: false };
347
+ const dirname = path.dirname(writePath);
348
+ if (!(await FileSys.dirExists(dirname))) await mkdir(dirname, { recursive: true });
349
+ await copyFile(templatePath, writePath);
350
+ this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
351
+ return { filePath: writePath, content: "", written: true };
352
+ } else return null;
353
+ }
354
+ async _applyTemplate({
355
+ basePath,
356
+ template,
357
+ scanInfo,
358
+ dict = {},
359
+ options = {},
360
+ overwrite = true,
361
+ dryRun = false,
362
+ }: {
363
+ basePath: string;
364
+ template: string;
365
+ scanInfo?: AppInfo | LibInfo | null;
366
+ dict?: { [key: string]: string };
367
+ options?: { [key: string]: unknown };
368
+ overwrite?: boolean;
369
+ dryRun?: boolean;
370
+ }): Promise<WrittenFileContent[]> {
371
+ const templateRoot = await this.#resolveTemplateRoot();
372
+ const templatePath = `${templateRoot}${template ? `/${template}` : ""}`;
373
+ if ((await stat(templatePath)).isFile()) {
374
+ const fileContent = await this.#applyTemplateFile(
375
+ {
376
+ templatePath,
377
+ targetPath: path.join(basePath, path.basename(templatePath)),
378
+ scanInfo,
379
+ overwrite,
380
+ dryRun,
381
+ },
382
+ dict,
383
+ options,
384
+ );
385
+ return fileContent ? [fileContent] : ([] as WrittenFileContent[]);
386
+ } else {
387
+ const subdirs = await readDirEntries(templatePath);
388
+ const fileContents = (
389
+ await Promise.all(
390
+ subdirs.map(async (subdir) => {
391
+ const subpath = path.join(templatePath, subdir);
392
+ if ((await stat(subpath)).isFile()) {
393
+ const fileContent = await this.#applyTemplateFile(
394
+ {
395
+ templatePath: subpath,
396
+ targetPath: path.join(basePath, subdir),
397
+ scanInfo,
398
+ overwrite,
399
+ dryRun,
400
+ },
401
+ dict,
402
+ options,
403
+ );
404
+ return fileContent ? [fileContent] : ([] as WrittenFileContent[]);
405
+ } else
406
+ return await this._applyTemplate({
407
+ basePath: path.join(basePath, subdir),
408
+ template: path.join(template, subdir),
409
+ scanInfo,
410
+ dict,
411
+ overwrite,
412
+ dryRun,
413
+ options,
414
+ });
415
+ }),
416
+ )
417
+ ).flat();
418
+ return fileContents;
419
+ }
420
+ }
421
+ async #resolveTemplateRoot() {
422
+ const candidates = [
423
+ path.resolve(getDirname(import.meta.url), "templates"),
424
+ path.resolve(getDirname(import.meta.url), "../../cli/templates"),
425
+ ];
426
+ for (const candidate of candidates) {
427
+ if (await FileSys.dirExists(candidate)) return candidate;
428
+ }
429
+ return candidates[0];
430
+ }
431
+ async applyTemplate(options: {
432
+ basePath: string;
433
+ template: string;
434
+ scanInfo?: AppInfo | LibInfo | null;
435
+ dict?: { [key: string]: string };
436
+ options?: { [key: string]: unknown };
437
+ overwrite?: boolean;
438
+ dryRun?: boolean;
439
+ }): Promise<FileContent[]> {
440
+ const fileContents = await this._applyTemplate({ ...options, dict: withCapitalizedDict(options.dict) });
441
+ await this.#formatAppliedTemplate(fileContents.filter((fileContent) => fileContent.written));
442
+ return fileContents;
443
+ }
444
+
445
+ // Best-effort: `create-akan-workspace` scaffolds before `bun install`, with no local Biome binary yet, so a
446
+ // template emits Biome's form itself (`templates/biomeForm.ts`).
447
+ async #formatAppliedTemplate(fileContents: FileContent[]) {
448
+ const filePaths = fileContents
449
+ .map((fileContent) => fileContent.filePath)
450
+ .filter((filePath) => filePath.endsWith(".ts") || filePath.endsWith(".tsx"));
451
+ if (filePaths.length === 0) return;
452
+ try {
453
+ const { fixed } = await this.getLinter().fixFiles(filePaths);
454
+ if (fixed.length > 0) this.logger.verbose(`Formatted ${fixed.length} scaffolded file(s)`);
455
+ } catch (err) {
456
+ this.logger.verbose(`Skipped formatting scaffolded files: ${toError(err).message}`);
457
+ }
458
+ }
459
+ // Async so `typescript` (~65MB resident) loads only in the commands that typecheck.
460
+ async getTypeChecker() {
461
+ const { TypeChecker } = await import("../typecheck/typeChecker");
462
+ this.typeChecker ??= new TypeChecker(this);
463
+ return this.typeChecker;
464
+ }
465
+ async typeCheck(filePath: string) {
466
+ const path = this.getPath(filePath);
467
+ const typeChecker = await this.getTypeChecker();
468
+ const { fileDiagnostics, fileErrors, fileWarnings } = typeChecker.check(path);
469
+ const message = typeChecker.formatDiagnostics(fileDiagnostics);
470
+ return { fileDiagnostics, fileErrors, fileWarnings, message };
471
+ }
472
+ async typeCheckAsync(filePath: string) {
473
+ const path = this.getPath(filePath);
474
+ const entry = await ProjectTypecheck.workerEntry(process.cwd());
475
+ const proc = Bun.spawn([process.execPath, entry], {
476
+ cwd: this.cwdPath,
477
+ env: {
478
+ ...process.env,
479
+ AKAN_TYPECHECK_CWD: this.cwdPath,
480
+ AKAN_TYPECHECK_FILE: path,
481
+ },
482
+ stdout: "pipe",
483
+ stderr: "pipe",
484
+ });
485
+ const [stdout, stderr, exitCode] = await Promise.all([
486
+ new Response(proc.stdout).text(),
487
+ new Response(proc.stderr).text(),
488
+ proc.exited,
489
+ ]);
490
+ if (exitCode !== 0) throw new Error((stderr || stdout).trim() || `Typecheck failed with exit code ${exitCode}`);
491
+
492
+ const result = JSON.parse(stdout) as {
493
+ fileDiagnosticsCount: number;
494
+ fileErrorsCount: number;
495
+ fileWarningsCount: number;
496
+ message: string;
497
+ };
498
+ return {
499
+ fileDiagnostics: Array.from({ length: result.fileDiagnosticsCount }),
500
+ fileErrors: Array.from({ length: result.fileErrorsCount }),
501
+ fileWarnings: Array.from({ length: result.fileWarningsCount }),
502
+ message: result.message,
503
+ };
504
+ }
505
+ getLinter() {
506
+ this.linter ??= new Linter(this.cwdPath);
507
+ return this.linter;
508
+ }
509
+ async lint(
510
+ filePath: string,
511
+ { fix = false, dryRun = false }: { fix?: boolean; dryRun?: boolean } = {},
512
+ ): Promise<{
513
+ results: unknown[];
514
+ message: string;
515
+ errors: unknown[];
516
+ warnings: unknown[];
517
+ }> {
518
+ const path = this.getPath(filePath);
519
+ const linter = this.getLinter();
520
+ const { results, errors, warnings } = await linter.lint(path, {
521
+ fix,
522
+ dryRun,
523
+ });
524
+ const message = linter.formatLintResults(results);
525
+ return { results, message, errors, warnings };
526
+ }
527
+ }
@@ -16,7 +16,7 @@ mock.module("node:fs/promises", () => ({
16
16
  return await realSymlink(...args);
17
17
  },
18
18
  }));
19
- const { AppExecutor, WorkspaceExecutor } = await import("./executors");
19
+ const { AppExecutor, WorkspaceExecutor } = await import("./");
20
20
 
21
21
  const { lstat, mkdir, mkdtemp, readFile, rm, writeFile } = fsPromises;
22
22
  const originalEnv = { ...process.env };
@@ -2,17 +2,8 @@ import { describe, expect, spyOn, test } from "bun:test";
2
2
  import { existsSync } from "node:fs";
3
3
  import { lstat, mkdir, readFile, readlink, rm, stat, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
- import { AkanAppConfig } from "./akanConfig";
6
- import {
7
- AppExecutor,
8
- CommandExecutionError,
9
- Executor,
10
- type LibExecutor,
11
- PkgExecutor,
12
- WorkspaceExecutor,
13
- } from "./executors";
14
- import { DevGeneratedIndexSync } from "./frontendBuild/devGeneratedIndexSync";
15
- import { AppInfo } from "./scanInfo";
5
+ import { AkanAppConfig } from "../akanConfig";
6
+ import { DevGeneratedIndexSync } from "../frontendBuild/devGeneratedIndexSync";
16
7
  import {
17
8
  createTempApp,
18
9
  createTempLib,
@@ -23,8 +14,10 @@ import {
23
14
  tempRoots,
24
15
  writeJson,
25
16
  writeText,
26
- } from "./testHelpers";
27
- import type { PackageJson } from "./types";
17
+ } from "../test/testHelpers";
18
+ import { AppInfo } from "../workspace/scanInfo";
19
+ import type { PackageJson } from "../workspace/types";
20
+ import { AppExecutor, CommandExecutionError, Executor, type LibExecutor, PkgExecutor, WorkspaceExecutor } from "./";
28
21
 
29
22
  isolateEnv();
30
23
  const makeTempRoot = tempDirs("akan-devkit-");
@@ -48,6 +41,27 @@ const rootPackageJson = (extra: Partial<PackageJson> = {}): PackageJson => ({
48
41
  ...extra,
49
42
  });
50
43
 
44
+ describe("executors module graph", () => {
45
+ test("the executors barrel and each file beside it load first in a fresh process", async () => {
46
+ const entries: string[] = [];
47
+ for await (const file of new Bun.Glob("*.ts").scan({ cwd: import.meta.dir }))
48
+ if (!file.endsWith(".test.ts")) entries.push(file);
49
+ const failures = await Promise.all(
50
+ entries.map(async (entry) => {
51
+ const proc = Bun.spawn([process.execPath, "-e", `await import(${JSON.stringify(`./${entry}`)})`], {
52
+ cwd: import.meta.dir,
53
+ stdout: "ignore",
54
+ stderr: "pipe",
55
+ });
56
+ const [code, stderr] = await Promise.all([proc.exited, new Response(proc.stderr).text()]);
57
+ return code === 0 ? null : `${entry}: ${stderr.split("\n").find((line) => line.includes("error:")) ?? stderr}`;
58
+ }),
59
+ );
60
+ expect(entries.length).toBeGreaterThan(8);
61
+ expect(failures.filter((failure) => failure !== null)).toEqual([]);
62
+ });
63
+ });
64
+
51
65
  describe("Executor filesystem helpers", () => {
52
66
  test("reports command failures with command context and captured output", async () => {
53
67
  const root = await makeTempRoot();
@@ -303,7 +317,7 @@ describe("Executor filesystem helpers", () => {
303
317
  const exec = new Executor("fixture", root);
304
318
 
305
319
  await exec.applyTemplate({ basePath: "app", template: "app", dict: { appName: "demo" }, options: { libs: [] } });
306
- const templateRoot = path.resolve(import.meta.dir, "../cli/templates/app/public");
320
+ const templateRoot = path.resolve(import.meta.dir, "../../cli/templates/app/public");
307
321
  await expect(readFile(path.join(root, "app/public/apple-touch-icon.png"))).resolves.toEqual(
308
322
  await readFile(path.join(templateRoot, "apple-touch-icon.png")),
309
323
  );
@@ -1027,6 +1041,33 @@ describe("Workspace and app executor environment contracts", () => {
1027
1041
 
1028
1042
  await expect(app.getPageKeys({ refresh: true })).resolves.toEqual(["./(docs)/_layout.tsx"]);
1029
1043
  });
1044
+
1045
+ const levelBoundaryLayout = [
1046
+ "export const LevelBoundary = ({ children }) => children;",
1047
+ "export default function Layout({ children }) { return children; }",
1048
+ "",
1049
+ ].join("\n");
1050
+
1051
+ test("refuses a LevelBoundary export on the app's root layout, which the generated one would ignore", async () => {
1052
+ const app = await makeRouteValidationApp("root-level-boundary", "export default {};\n", {
1053
+ "_layout.tsx": levelBoundaryLayout,
1054
+ });
1055
+
1056
+ await expect(app.getPageKeys({ refresh: true })).rejects.toThrow(
1057
+ /unsupported export "LevelBoundary" in .*page[\\/]_layout\.tsx: LevelBoundary belongs to the root layout Akan\.js generates, which never reads one from an app's layout/,
1058
+ );
1059
+ });
1060
+
1061
+ test("refuses a LevelBoundary export on a grouped root layout under the app's own, naming the grouped file", async () => {
1062
+ const app = await makeRouteValidationApp("nested-root-level-boundary", "export default {};\n", {
1063
+ "_layout.tsx": "export default function Layout({ children }) { return children; }\n",
1064
+ "(home)/_layout.tsx": levelBoundaryLayout,
1065
+ });
1066
+
1067
+ await expect(app.getPageKeys({ refresh: true })).rejects.toThrow(
1068
+ /unsupported export "LevelBoundary" in .*page[\\/]\(home\)[\\/]_layout\.tsx: LevelBoundary belongs to the root layout Akan\.js generates/,
1069
+ );
1070
+ });
1030
1071
  });
1031
1072
 
1032
1073
  test("accepts head route exports during page key discovery", async () => {
@@ -1304,6 +1345,26 @@ describe("WorkspaceExecutor listing", () => {
1304
1345
  });
1305
1346
 
1306
1347
  describe("SysExecutor module listing", () => {
1348
+ test("reads an app's and a lib's constants from that sys's own folder", async () => {
1349
+ const { root, workspace, app } = trackRoot(await createTempApp("demo"));
1350
+ const appConstant = "export const owner = 'app';\n";
1351
+ const libConstant = "export const owner = 'lib';\n";
1352
+ await writeText(path.join(root, "apps/demo/lib/post/post.constant.ts"), appConstant);
1353
+ await writeText(path.join(root, "libs/shared/lib/user/user.constant.ts"), libConstant);
1354
+ await writeText(path.join(root, "libs/shared/akan.config.ts"), "export default {};\n");
1355
+ await mkdir(path.join(root, "libs/shared/lib/__scalar"), { recursive: true });
1356
+ const contents = (files: { content: string }[]) => files.map((file) => file.content);
1357
+
1358
+ const scan = spyOn(AppInfo, "fromExecutor").mockResolvedValue({ getLibs: () => ["shared"] } as never);
1359
+ expect(process.cwd()).not.toBe(root);
1360
+ try {
1361
+ expect(contents(await workspace.getConstantFiles())).toEqual([appConstant, libConstant]);
1362
+ expect(contents(await app.getConstantFilesWithLibs())).toEqual([appConstant, libConstant]);
1363
+ } finally {
1364
+ scan.mockRestore();
1365
+ }
1366
+ });
1367
+
1307
1368
  test("lists only the module folders that hold the module's own file", async () => {
1308
1369
  const root = await makeTempRoot();
1309
1370
  const lib = path.join(root, "apps/modlist/lib");
@@ -1472,7 +1533,7 @@ describe("SysExecutor scan", () => {
1472
1533
  test.skipIf(!hasBiome)(
1473
1534
  "writes env.server.type.ts the way Biome prints it, spreading libs in dependency order",
1474
1535
  async () => {
1475
- const { default: getContent } = (await import("../cli/templates/env/_env.server.type")) as {
1536
+ const { default: getContent } = (await import("../../cli/templates/env/_env.server.type")) as {
1476
1537
  default: (scanInfo: unknown) => { content: string };
1477
1538
  };
1478
1539
  const libs = ["util", "shared", "shopAdmin", "shop", "a10", "a9"];
@@ -0,0 +1,8 @@
1
+ export { AppExecutor, type AppRouteSource, type PageRoot } from "./appExecutor";
2
+ export { CommandExecutionError, type CommandExecutionErrorOptions } from "./commandExecutionError";
3
+ export { Executor, execEmoji, type WrittenFileContent } from "./executor";
4
+ export { LibExecutor } from "./libExecutor";
5
+ export { ModuleExecutor } from "./moduleExecutor";
6
+ export { PkgExecutor } from "./pkgExecutor";
7
+ export { SysExecutor } from "./sysExecutor";
8
+ export { parseEnvFile, WorkspaceExecutor } from "./workspaceExecutor";