@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,234 @@
1
+ import { rm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
4
+ import type { App } from "@akanjs/devkit/commandDecorators";
5
+ import { CsrDevBundler } from "@akanjs/devkit/frontendBuild/csrDevBundler";
6
+ import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
+ import type { Logger } from "akanjs/common";
8
+ import type { BaseBuildArtifact, BuilderCsrReq, HmrTrace } from "akanjs/server";
9
+ import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
10
+ import type { BatchWork, BuildBatchRequest } from "./buildBatchProtocol";
11
+ import type { BuildBatchRunner } from "./buildBatchRunner";
12
+ import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
13
+ import { BuilderChannel } from "./builderChannel";
14
+ import type { BuilderLanes } from "./builderLanes";
15
+
16
+ interface CsrRegistryLinks {
17
+ generation: () => number;
18
+ artifact: () => BaseBuildArtifact;
19
+ batchRequest: (work: BatchWork) => Promise<BuildBatchRequest>;
20
+ countDelegation: (registry: "csr" | "ssr", reason: string) => string;
21
+ }
22
+
23
+ export class CsrRegistry {
24
+ readonly #app: App;
25
+ readonly #logger: Logger;
26
+ readonly #lanes: BuilderLanes;
27
+ readonly #batchRunner: BuildBatchRunner;
28
+ readonly #links: CsrRegistryLinks;
29
+ #shellKey: string | null = null;
30
+ #csrActive = CsrRegistry.#csrArmedByEnv();
31
+ #csrBundler: CsrDevBundler;
32
+ /** Null when `AKAN_DEV_CSR_PATCHER=off`: every CSR save then goes to a build worker, as before the patcher. */
33
+ #patcher: CsrDevPatcher | null;
34
+ /** A worker's full CSR build (arming, re-arming) that a patch must not race for the csr-dev directory. */
35
+ #csrGate: Promise<void> = Promise.resolve();
36
+ #csrArming = false;
37
+ #csrArms = 0;
38
+ #csrWasActive = false;
39
+ #csrArmSucceeded = false;
40
+
41
+ constructor(
42
+ app: App,
43
+ { logger, lanes, batchRunner }: { logger: Logger; lanes: BuilderLanes; batchRunner: BuildBatchRunner },
44
+ links: CsrRegistryLinks,
45
+ ) {
46
+ this.#app = app;
47
+ this.#logger = logger;
48
+ this.#lanes = lanes;
49
+ this.#batchRunner = batchRunner;
50
+ this.#links = links;
51
+ this.#csrBundler = new CsrDevBundler(app);
52
+ this.#patcher =
53
+ process.env.AKAN_DEV_CSR_PATCHER === "off" ? null : new CsrDevPatcher(this.#csrBundler, { resident: true });
54
+ }
55
+
56
+ get csrActive(): boolean {
57
+ return this.#csrActive;
58
+ }
59
+
60
+ get csrArming(): boolean {
61
+ return this.#csrArming;
62
+ }
63
+
64
+ get patcher(): CsrDevPatcher | null {
65
+ return this.#patcher;
66
+ }
67
+
68
+ // True when the save has to go to a build worker: the patcher handed it back, or threw (the worker reports why).
69
+ async patchCsr(generation: number, files: string[], trace: HmrTrace): Promise<boolean> {
70
+ const patcher = this.#patcher;
71
+ if (!patcher) return true;
72
+ await this.#csrGate;
73
+ // The arming build this save waited for failed: CSR is off again, and the next request arms it anew.
74
+ if (!this.#csrActive) return false;
75
+ const started = Date.now();
76
+ const marker = path.join(this.#csrBundler.outDir, CSR_DEV_PATCHING_MARKER);
77
+ await Bun.write(marker, String(process.pid));
78
+ try {
79
+ const result = await patcher.update(files, {
80
+ announce: (update) => {
81
+ const now = Date.now();
82
+ BuilderChannel.emit({
83
+ type: "csr-updated",
84
+ data: {
85
+ generation: update.generation,
86
+ mode: "registry",
87
+ reload: update.reload,
88
+ reason: update.reason,
89
+ patchUrl: update.patchUrl,
90
+ changedIds: update.changedIds,
91
+ trace: { ...trace, patchAt: now, sentAt: now },
92
+ },
93
+ });
94
+ },
95
+ });
96
+ if (result.kind === "delegate") {
97
+ this.#logger.verbose(
98
+ `csr-patch handed to a build worker (${this.#links.countDelegation("csr", result.reason)}): ${result.reason}`,
99
+ );
100
+ return true;
101
+ }
102
+ sendBuildStatus("csr", { generation, ok: true, files });
103
+ this.#logger.verbose(
104
+ result.kind === "unchanged"
105
+ ? `csr-patch unchanged (${Date.now() - started}ms)`
106
+ : `csr-patch generation=${result.update.generation} ${result.update.reload ? `reload (${result.update.reason})` : `patch modules=${result.update.changedIds.length}`} (${Date.now() - started}ms)`,
107
+ );
108
+ return false;
109
+ } catch (err) {
110
+ const message = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
111
+ if (isCompileError(err)) {
112
+ sendBuildStatus("csr", { generation, ok: false, files, message });
113
+ return false;
114
+ }
115
+ this.#logger.verbose(`csr-patch threw; a build worker takes this save: ${message}`);
116
+ patcher.forget();
117
+ return true;
118
+ } finally {
119
+ await rm(marker, { force: true });
120
+ }
121
+ }
122
+
123
+ // On demand: dev serves CSR only via the opt-in `/__csr` and `?csr=true` routes; once built, it rebuilds every save.
124
+ async handleBuildCsr(msg: BuilderCsrReq): Promise<void> {
125
+ if (msg.shell) {
126
+ await this.#buildShell(msg);
127
+ return;
128
+ }
129
+ //? Armed now, not when the build lands: a save handled meanwhile then patches CSR behind #csrGate instead of skipping.
130
+ this.#beginCsrArm();
131
+ this.#csrActive = true;
132
+ const armed = this.#lanes.workQueue.enqueue("build-csr", async (): Promise<void> => {
133
+ const started = Date.now();
134
+ let error: string | undefined;
135
+ try {
136
+ // Not relayed: an on-demand CSR build is request/response, and its error travels in the response.
137
+ const result = await this.#batchRunner.run(
138
+ await this.#links.batchRequest({ generation: this.#links.generation(), needs: ["csr"], changedFiles: [] }),
139
+ );
140
+ error = result.errors.csr;
141
+ } catch (err) {
142
+ error = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
143
+ }
144
+ if (error) {
145
+ this.#logger.error(`csr-build failed: ${error}`);
146
+ await BuilderChannel.send({ type: "build-csr-res", id: msg.id, ok: false, error });
147
+ return;
148
+ }
149
+ this.#csrArmSucceeded = true;
150
+ this.#patcher?.forget();
151
+ this.#logger.info(`csr-build ok on demand (${Date.now() - started}ms); rebuilding CSR on every save now`);
152
+ await BuilderChannel.send({ type: "build-csr-res", id: msg.id, ok: true });
153
+ });
154
+ this.#csrGate = this.#armingCsr(armed);
155
+ await armed;
156
+ }
157
+
158
+ // Asked on every view read and rebuilt only when a save moved the generation or the css it inlines, instead of armed
159
+ // per save: a restarted builder has no last build to trust, and so rebuilds once on the next read.
160
+ async #buildShell(msg: BuilderCsrReq): Promise<void> {
161
+ await this.#lanes.workQueue.enqueue("build-shell", async (): Promise<void> => {
162
+ const generation = this.#links.generation();
163
+ //? A save moves the generation before its css compile lands, so a shell built in between holds the old css.
164
+ const shellKey = `${generation}:${JSON.stringify(this.#links.artifact().cssAssets)}`;
165
+ let error: string | undefined;
166
+ if (this.#shellKey !== shellKey)
167
+ try {
168
+ const result = await this.#batchRunner.run(
169
+ await this.#links.batchRequest({ generation, needs: ["shell"], changedFiles: [] }),
170
+ );
171
+ error = result.errors.shell;
172
+ if (!error) this.#shellKey = shellKey;
173
+ } catch (err) {
174
+ error = ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot);
175
+ }
176
+ await BuilderChannel.send(
177
+ error
178
+ ? { type: "build-csr-res", id: msg.id, ok: false, error }
179
+ : { type: "build-csr-res", id: msg.id, ok: true },
180
+ );
181
+ });
182
+ }
183
+
184
+ //? Settled by the last of the arming builds in flight, not by each: two requests that both fail would otherwise leave
185
+ //? CSR on (the second saw the first's optimistic flag as where it started), and the first to finish would let saves
186
+ //? patch CSR first while the second still builds.
187
+ #beginCsrArm(): void {
188
+ if (this.#csrArms === 0) {
189
+ this.#csrWasActive = this.#csrActive;
190
+ this.#csrArmSucceeded = false;
191
+ }
192
+ this.#csrArms += 1;
193
+ this.#csrArming = true;
194
+ }
195
+
196
+ #armingCsr(armed: Promise<void>): Promise<void> {
197
+ const settle = () => {
198
+ this.#csrArms -= 1;
199
+ if (this.#csrArms > 0) return;
200
+ this.#csrArming = false;
201
+ this.#csrActive = this.#csrWasActive || this.#csrArmSucceeded;
202
+ };
203
+ return armed.then(settle, settle);
204
+ }
205
+
206
+ static #csrArmedByEnv() {
207
+ return process.env.AKAN_DEV_CSR_REBUILD === "1";
208
+ }
209
+
210
+ // The env flag carries an armed CSR session across builder restarts, so the replacement rebuilds it after ready.
211
+ async rearmCsrFromEnv(): Promise<void> {
212
+ if (!CsrRegistry.#csrArmedByEnv()) return;
213
+ this.#beginCsrArm();
214
+ this.#csrActive = true;
215
+ //? The env keeps CSR armed whatever this build does, as it did before the builder restarted.
216
+ this.#csrArmSucceeded = true;
217
+ const rearmed = this.#lanes.workQueue.enqueue("build-csr-rearm", async () => {
218
+ //? Relayed, unlike an on-demand build: a rebuild for a metadata save must reach the CSR tabs as their reload.
219
+ const result = await this.#batchRunner.run(
220
+ await this.#links.batchRequest({ generation: this.#links.generation(), needs: ["csr"], changedFiles: [] }),
221
+ (msg) => BuilderChannel.emit(msg),
222
+ );
223
+ this.#patcher?.forget();
224
+ if (result.errors.csr) this.#logger.error(`csr-rearm failed: ${result.errors.csr}`);
225
+ else this.#logger.verbose("csr-rearm ok; this session had CSR armed before the builder restarted");
226
+ });
227
+ this.#csrGate = this.#armingCsr(rearmed);
228
+ await rearmed.catch((err: unknown) =>
229
+ this.#logger.error(
230
+ `csr-rearm failed: ${ApplicationBuildReporter.formatError(err, this.#app.workspace.workspaceRoot)}`,
231
+ ),
232
+ );
233
+ }
234
+ }
@@ -1,12 +1,14 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import path from "node:path";
3
3
  import type { BuilderMessage, BuilderReq } from "akanjs/server";
4
- import { createTempApp, tempRoots, writeText } from "../testHelpers";
4
+ import { createTempApp, tempRoots, writeText } from "../test/testHelpers";
5
5
 
6
6
  const track = tempRoots();
7
7
 
8
8
  const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
9
9
 
10
+ const crashWindowMs = 2_000;
11
+
10
12
  const until = async (proc: Bun.Subprocess, what: string, condition: () => boolean, timeoutMs = 20_000) => {
11
13
  const deadline = Date.now() + timeoutMs;
12
14
  while (!condition()) {
@@ -20,9 +22,11 @@ describe("incremental builder process", () => {
20
22
  const { root } = track(await createTempApp("demo"));
21
23
  const appDir = path.join(root, "apps/demo");
22
24
  // The batch runner looks under the workspace root first: a stand-in for the boot build, which needs a whole app.
25
+ // Each stand-in waits for the runner's release, as the real worker does: one exiting at once can lose all it sent.
23
26
  await writeText(
24
27
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
25
28
  `const { generation } = JSON.parse(process.argv[2]);
29
+ process.once("disconnect", () => {});
26
30
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
27
31
  `,
28
32
  );
@@ -90,6 +94,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
90
94
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
91
95
  `const { generation, needs } = JSON.parse(process.argv[2]);
92
96
  const errors = needs.includes("base") ? {} : { shell: "handed " + needs.join(",") };
97
+ process.once("disconnect", () => {});
93
98
  process.send({ type: "build-batch-result", data: { generation, errors, artifact: {}, optimizedFonts: { css: "", files: [] } } });
94
99
  `,
95
100
  );
@@ -135,6 +140,7 @@ process.send({ type: "build-batch-result", data: { generation, errors, artifact:
135
140
  await writeText(
136
141
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
137
142
  `const { generation } = JSON.parse(process.argv[2]);
143
+ process.once("disconnect", () => {});
138
144
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
139
145
  `,
140
146
  );
@@ -237,6 +243,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
237
243
  await writeText(
238
244
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
239
245
  `const { generation } = JSON.parse(process.argv[2]);
246
+ process.once("disconnect", () => {});
240
247
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
241
248
  `,
242
249
  );
@@ -299,6 +306,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
299
306
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
300
307
  `const { generation, needs } = JSON.parse(process.argv[2]);
301
308
  require("node:fs").appendFileSync(${JSON.stringify(ledger)}, needs.join(",") + "\\n");
309
+ process.once("disconnect", () => {});
302
310
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
303
311
  `,
304
312
  );
@@ -357,6 +365,7 @@ process.on("disconnect", orphaned);
357
365
  const deadline = Date.now() + 15_000;
358
366
  if (needs.includes("ssr")) while (!fs.existsSync(${JSON.stringify(gate)}) && Date.now() < deadline) await Bun.sleep(20);
359
367
  const css = needs.includes("ssr") ? { cssAssets: ${JSON.stringify(landed)} } : {};
368
+ process.once("disconnect", () => {});
360
369
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] }, ...css } });
361
370
  process.off("disconnect", orphaned);
362
371
  `,
@@ -417,6 +426,7 @@ if (needs.includes("ssr")) {
417
426
  fs.appendFileSync(${JSON.stringify(runs)}, Date.now() + "\\n");
418
427
  if (fs.readFileSync(${JSON.stringify(runs)}, "utf8").trim().split("\\n").length <= 2) process.exit(1);
419
428
  }
429
+ process.once("disconnect", () => {});
420
430
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
421
431
  `,
422
432
  );
@@ -435,6 +445,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
435
445
  AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
436
446
  AKAN_PUBLIC_ENV: "local",
437
447
  AKAN_WATCH: "0",
448
+ AKAN_DEV_SSR_CRASH_RETRY_MS: String(crashWindowMs),
438
449
  },
439
450
  stdio: ["ignore", "ignore", "ignore"],
440
451
  serialization: "advanced",
@@ -445,11 +456,10 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
445
456
  const ssrRuns = async () =>
446
457
  (await Bun.file(runs).exists()) ? (await Bun.file(runs).text()).trim().split("\n").map(Number) : [];
447
458
  try {
448
- //? boot-armed waits out the 10s crash window first, so 20s left a loaded machine too little for the rest.
449
- await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"), 30_000);
459
+ await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
450
460
  const [first = 0, second = 0] = await ssrRuns();
451
461
  expect(await ssrRuns()).toHaveLength(2);
452
- expect(second - first).toBeGreaterThanOrEqual(9_500);
462
+ expect(second - first).toBeGreaterThanOrEqual(crashWindowMs - 500);
453
463
  proc.send({
454
464
  type: "build-route",
455
465
  id: 1,
@@ -463,7 +473,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
463
473
  const deadline = Date.now() + 15_000;
464
474
  while ((await ssrRuns()).length < 3 && Date.now() < deadline) await wait(100);
465
475
  const [, retried = 0, third = 0] = await ssrRuns();
466
- expect(third - retried).toBeGreaterThanOrEqual(9_500);
476
+ expect(third - retried).toBeGreaterThanOrEqual(crashWindowMs - 500);
467
477
  } finally {
468
478
  proc.kill();
469
479
  await proc.exited;
@@ -483,6 +493,7 @@ if (needs.includes("ssr")) {
483
493
  fs.appendFileSync(${JSON.stringify(runs)}, Date.now() + "\\n");
484
494
  if (fs.readFileSync(${JSON.stringify(runs)}, "utf8").trim().split("\\n").length === 2) process.exit(1);
485
495
  }
496
+ process.once("disconnect", () => {});
486
497
  process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
487
498
  `,
488
499
  );
@@ -501,6 +512,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
501
512
  AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
502
513
  AKAN_PUBLIC_ENV: "local",
503
514
  AKAN_WATCH: "0",
515
+ AKAN_DEV_SSR_CRASH_RETRY_MS: String(crashWindowMs),
504
516
  },
505
517
  stdio: ["ignore", "ignore", "ignore"],
506
518
  serialization: "advanced",
@@ -524,7 +536,7 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
524
536
  const deadline = Date.now() + 20_000;
525
537
  while ((await ssrRuns()).length < 3 && Date.now() < deadline) await wait(100);
526
538
  const [, killed = 0, retried = 0] = await ssrRuns();
527
- expect(retried - killed).toBeGreaterThanOrEqual(9_500);
539
+ expect(retried - killed).toBeGreaterThanOrEqual(crashWindowMs - 500);
528
540
  } finally {
529
541
  proc.kill();
530
542
  await proc.exited;
@@ -539,7 +551,10 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
539
551
  path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
540
552
  `const { generation, needs } = JSON.parse(process.argv[2]);
541
553
  if (needs.includes("ssr")) await import(${JSON.stringify(path.join(import.meta.dir, "buildBatch.proc.ts"))});
542
- else process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
554
+ else {
555
+ process.once("disconnect", () => {});
556
+ process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
557
+ }
543
558
  `,
544
559
  );
545
560
  await writeText(path.join(appDir, "env/env.client.ts"), "export const env = {} as const;\n");
@@ -588,4 +603,83 @@ else process.send({ type: "build-batch-result", data: { generation, errors: {},
588
603
  await proc.exited;
589
604
  }
590
605
  }, 60_000);
606
+
607
+ test("a failed boot build waits for the save that fixes it, and the builder it recovers continues the generation and watches", async () => {
608
+ const { root } = track(await createTempApp("demo"));
609
+ const appDir = path.join(root, "apps/demo");
610
+ const ledger = path.join(root, "batches.log");
611
+ const fixed = path.join(root, "boot-fixed");
612
+ // A stand-in batch: the boot build fails until the fix lands, and every batch logs its needs and generation.
613
+ await writeText(
614
+ path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
615
+ `import fs from "node:fs";
616
+ const { generation, needs } = JSON.parse(process.argv[2]);
617
+ fs.appendFileSync(${JSON.stringify(ledger)}, needs.join(",") + " " + generation + "\\n");
618
+ const errors = needs.includes("base") && !fs.existsSync(${JSON.stringify(fixed)}) ? { base: "the boot is broken" } : {};
619
+ process.once("disconnect", () => {});
620
+ process.send({ type: "build-batch-result", data: { generation, errors, artifact: {}, optimizedFonts: { css: "", files: [] } } });
621
+ `,
622
+ );
623
+ const page = path.join(appDir, "page/_index.tsx");
624
+ await writeText(page, "export default () => null;\n");
625
+ const messages: BuilderMessage[] = [];
626
+ const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
627
+ cwd: appDir,
628
+ env: {
629
+ ...process.env,
630
+ AKAN_WORKSPACE_ROOT: root,
631
+ AKAN_PUBLIC_APP_NAME: "demo",
632
+ AKAN_PUBLIC_REPO_NAME: "repo",
633
+ AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
634
+ AKAN_PUBLIC_ENV: "local",
635
+ AKAN_BUILDER_INITIAL_GENERATION: "5",
636
+ AKAN_DEV_CSR_PATCHER: "off",
637
+ AKAN_LOG_STDOUT_LEVEL: "info",
638
+ },
639
+ stdio: ["ignore", "pipe", "ignore"],
640
+ serialization: "advanced",
641
+ ipc: (message: BuilderMessage) => {
642
+ messages.push(message);
643
+ },
644
+ });
645
+ let stdout = "";
646
+ const decoder = new TextDecoder();
647
+ const reading = (async () => {
648
+ for await (const chunk of proc.stdout) stdout += decoder.decode(chunk, { stream: true });
649
+ })();
650
+ const sent = (type: BuilderMessage["type"]) => messages.filter((message) => message.type === type);
651
+ try {
652
+ await until(proc, "boot-armed", () => sent("boot-armed").length === 1);
653
+ proc.send({ type: "build-graph", id: 1 } satisfies BuilderMessage);
654
+ await until(proc, "build-graph-res", () => sent("build-graph-res").length === 1);
655
+ //? Degraded mode sends boot-armed before its watcher starts, and a save made before then is never seen.
656
+ await until(proc, "the degraded watcher's log line", () => stdout.includes("[degraded] watching"));
657
+ await writeText(fixed, "");
658
+ await writeText(page, "export default () => 1;\n");
659
+ await until(proc, "the recovered builder's boot-armed", () => sent("boot-armed").length === 2);
660
+ await writeText(page, "export default () => 2;\n");
661
+ await until(proc, "the recovered builder's invalidate", () =>
662
+ messages.some((message) => message.type === "invalidate" && message.generation === 9),
663
+ );
664
+ } finally {
665
+ proc.kill();
666
+ await proc.exited;
667
+ await reading;
668
+ }
669
+ expect(sent("build-status")[0]).toMatchObject({
670
+ data: { generation: 6, phase: "pages", ok: false, message: "Boot build failed: the boot is broken" },
671
+ });
672
+ expect(sent("build-graph-res")[0]).toMatchObject({
673
+ id: 1,
674
+ ok: false,
675
+ error: expect.stringContaining("recovering from a failed boot build"),
676
+ });
677
+ expect(sent("builder-ready")).toHaveLength(2);
678
+ expect((await Bun.file(ledger).text()).trim().split("\n").slice(0, 4)).toEqual([
679
+ "base 0",
680
+ "base 0",
681
+ "pages,css 8",
682
+ "ssr 8",
683
+ ]);
684
+ }, 60_000);
591
685
  });