@akanjs/devkit 3.3.0-rc.7 → 3.3.0-rc.71

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 (360) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +10 -3
  3. package/README.md +10 -4
  4. package/akanApp/akanApp.host.test.ts +4 -2
  5. package/akanApp/akanApp.host.ts +26 -2
  6. package/akanApp/akanApp.host.wiring.test.ts +111 -0
  7. package/akanApp/devHostPolicy.ts +5 -0
  8. package/akanApp/devMetadataRestart.ts +93 -0
  9. package/akanApp/devRecycler.test.ts +2 -0
  10. package/akanApp/devRecycler.ts +9 -0
  11. package/akanConfig/akanBin.ts +4 -0
  12. package/akanConfig/akanConfig.test.ts +358 -21
  13. package/akanConfig/akanConfig.ts +113 -272
  14. package/akanConfig/akanPreview.test.ts +28 -0
  15. package/akanConfig/akanPreview.ts +24 -0
  16. package/akanConfig/akanWorkers.test.ts +73 -0
  17. package/akanConfig/akanWorkers.ts +61 -0
  18. package/akanConfig/desktopServerConfig.ts +96 -0
  19. package/akanConfig/dockerImage.ts +250 -0
  20. package/akanConfig/index.ts +3 -0
  21. package/akanConfig/nativeFileSettings.ts +33 -0
  22. package/akanConfig/nativeKeys.ts +52 -0
  23. package/akanConfig/types.ts +4 -0
  24. package/app/appBin.test.ts +63 -0
  25. package/app/appBin.ts +50 -0
  26. package/app/applicationBuildReporter.test.ts +51 -1
  27. package/app/applicationBuildReporter.ts +6 -1
  28. package/app/applicationBuildRunner.test.ts +427 -5
  29. package/app/applicationBuildRunner.ts +232 -37
  30. package/app/clientServerBoundary.test.ts +115 -0
  31. package/app/clientServerBoundary.ts +89 -0
  32. package/app/dictionarySizes.test.ts +40 -0
  33. package/app/dictionarySizes.ts +95 -0
  34. package/app/routeFilesReport.test.ts +59 -0
  35. package/app/routeFilesReport.ts +46 -0
  36. package/app/routeJsBudget.ts +18 -4
  37. package/artifact/implicitRootLayout.test.ts +19 -0
  38. package/artifact/implicitRootLayout.ts +16 -2
  39. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  40. package/artifact/storeBootstrap.test.ts +28 -0
  41. package/artifact/storeBootstrap.ts +64 -8
  42. package/biome.base.json +7 -5
  43. package/codeAgent/index.ts +1 -34
  44. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  45. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  46. package/codeAgent/skills/akan-debug/SKILL.md +8 -3
  47. package/codeAgent/skills/akan-deps/SKILL.md +10 -3
  48. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  49. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  50. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  51. package/codeAgent/skills/akan-page/SKILL.md +65 -30
  52. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  53. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  54. package/codeAgent/skills/akan-service/SKILL.md +21 -20
  55. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  56. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  57. package/codeAgent/skills/akan-validate/SKILL.md +8 -2
  58. package/commandDecorators/command.ts +28 -12
  59. package/commandDecorators/commandBuilder.ts +8 -1
  60. package/commandDecorators/commandDecorators.test.ts +70 -3
  61. package/commandDecorators/helpFormatter.ts +14 -12
  62. package/context/akanContext.ts +2 -0
  63. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  64. package/csrE2e/ssrRegistry.e2e.test.ts +108 -22
  65. package/docs/apiReference.test.ts +25 -0
  66. package/docs/apiReference.ts +38 -5
  67. package/docs/declarationReader.ts +30 -0
  68. package/executors/appExecutor.ts +26 -12
  69. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  70. package/executors/clientRuntimeKeys.fixture.json +393 -0
  71. package/executors/clientRuntimeKeys.test.ts +1690 -0
  72. package/executors/executor.ts +14 -6
  73. package/executors/executors.test.ts +155 -1
  74. package/executors/pkgExecutor.ts +2 -1
  75. package/executors/sysExecutor.ts +112 -8
  76. package/executors/workspaceExecutor.ts +7 -4
  77. package/frontendBuild/allRoutesBuilder.ts +99 -7
  78. package/frontendBuild/autoImportSync.ts +3 -2
  79. package/frontendBuild/buildRouteClient.test.ts +686 -13
  80. package/frontendBuild/clientBuildTypes.ts +26 -0
  81. package/frontendBuild/clientEntriesBundler.ts +49 -1
  82. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  83. package/frontendBuild/clientEntryDiscovery.ts +136 -14
  84. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  85. package/frontendBuild/clientEntryGroups.ts +61 -0
  86. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  87. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  88. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  89. package/frontendBuild/csrDevPatcher.test.ts +4 -5
  90. package/frontendBuild/csrDevPatcher.ts +37 -11
  91. package/frontendBuild/csrDevTypes.ts +9 -0
  92. package/frontendBuild/devBarrelImports.test.ts +154 -0
  93. package/frontendBuild/devBarrelImports.ts +83 -23
  94. package/frontendBuild/devChangePlanner.ts +0 -1
  95. package/frontendBuild/devRegistryBundler.ts +4 -2
  96. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  97. package/frontendBuild/devRouteRuntime.ts +167 -0
  98. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  99. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  100. package/frontendBuild/dictionaryConstants.ts +136 -0
  101. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  102. package/frontendBuild/dictionaryPackState.ts +131 -0
  103. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  104. package/frontendBuild/dictionaryPacking.ts +160 -0
  105. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  106. package/frontendBuild/dictionaryRoutes.ts +227 -0
  107. package/frontendBuild/frontendBuild.test.ts +5 -3
  108. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  109. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  110. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  111. package/frontendBuild/precompressArtifacts.ts +34 -8
  112. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  113. package/frontendBuild/renderedEntries.ts +144 -0
  114. package/frontendBuild/routeClientBuilder.ts +407 -43
  115. package/frontendBuild/routeHandoffs.test.ts +155 -0
  116. package/frontendBuild/routeHandoffs.ts +117 -0
  117. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  118. package/frontendBuild/routeModulePreloads.ts +20 -11
  119. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  120. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  121. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  122. package/frontendBuild/routeRuntimePays.ts +117 -0
  123. package/frontendBuild/ssrBaseArtifactBuilder.ts +30 -35
  124. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  125. package/frontendBuild/ssrDevBundler.ts +66 -11
  126. package/frontendBuild/vendorFileImports.test.ts +254 -0
  127. package/frontendBuild/vendorFileImports.ts +163 -0
  128. package/frontendBuild/vendorNarrowing.test.ts +47 -3
  129. package/frontendBuild/vendorNarrowing.ts +38 -2
  130. package/frontendBuild/vendorSpecifiers.ts +2 -0
  131. package/guideline/agentAssets.ts +1 -1
  132. package/incrementalBuilder/buildBatch.proc.ts +35 -9
  133. package/incrementalBuilder/buildBatchProtocol.ts +2 -1
  134. package/incrementalBuilder/builderBoot.ts +5 -5
  135. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  136. package/incrementalBuilder/builderLanes.ts +2 -2
  137. package/incrementalBuilder/builderWatch.ts +19 -9
  138. package/incrementalBuilder/csrRegistry.ts +4 -4
  139. package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
  140. package/incrementalBuilder/incrementalBuilder.proc.ts +38 -10
  141. package/incrementalBuilder/pendingMetadata.test.ts +27 -0
  142. package/incrementalBuilder/pendingMetadata.ts +19 -0
  143. package/incrementalBuilder/ssrRegistry.ts +6 -6
  144. package/index.ts +1 -1
  145. package/integration/devResourceProbe.ts +14 -0
  146. package/integration/devStability.integration.test.ts +46 -21
  147. package/integration/renderAdmissionSoak.test.ts +99 -0
  148. package/integration/renderAdmissionSoak.ts +615 -0
  149. package/integration/ssrMemoryProbe.ts +5 -0
  150. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  151. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  152. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  153. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  154. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  155. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  156. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  157. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  158. package/lint/biomeBase.test.ts +50 -3
  159. package/lint/biomeBase.ts +1 -1
  160. package/lint/biomeCheck.test.ts +162 -0
  161. package/lint/biomeCheck.ts +131 -0
  162. package/lint/linter.test.ts +16 -11
  163. package/lint/no-arbitrary-color.grit +5 -0
  164. package/lint/no-conditional-st-hook.grit +5 -1
  165. package/lint/no-daisyui-legacy-class.grit +8 -0
  166. package/lint/no-document-cookie.grit +3 -0
  167. package/lint/no-inline-color.grit +10 -2
  168. package/lint/no-oversized-list-limit.grit +2 -0
  169. package/lint/no-raw-palette-class.grit +7 -0
  170. package/lint/no-unpublished-form-setter.grit +2 -0
  171. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  172. package/lint/no-web-storage.grit +3 -0
  173. package/lint/withheldEnvFile.ts +17 -0
  174. package/mobile/desktopBin.ts +2 -2
  175. package/mobile/desktopServerStage.test.ts +18 -3
  176. package/mobile/desktopServerStage.ts +7 -2
  177. package/mobile/nativeApp.test.ts +13 -5
  178. package/mobile/nativeApp.ts +9 -4
  179. package/mobile/nativeConfig.test.ts +96 -1
  180. package/mobile/nativeConfig.ts +46 -12
  181. package/mobile/nativePublicEnv.ts +1 -1
  182. package/mobile/serverBundleSecrets.ts +43 -0
  183. package/package.json +22 -178
  184. package/packageExports.test.ts +39 -24
  185. package/preview/PreviewView.ts +25 -3
  186. package/quality/dictionaryKeys.test.ts +356 -0
  187. package/quality/dictionaryKeys.ts +488 -0
  188. package/quality/objectImportReport.test.ts +36 -0
  189. package/quality/objectImportReport.ts +105 -0
  190. package/quality/qualityScanner.ts +1 -1
  191. package/quality/routeRuntimeReport.test.ts +91 -0
  192. package/quality/routeRuntimeReport.ts +121 -0
  193. package/quality/runtimeConstantFacts.ts +71 -0
  194. package/quality/runtimeConstantGraph.ts +123 -0
  195. package/quality/runtimeConstantReads.ts +116 -0
  196. package/quality/runtimeImports.test.ts +190 -0
  197. package/quality/runtimeImports.ts +233 -0
  198. package/quality/runtimeKeyNames.ts +46 -0
  199. package/quality/runtimeLexicalScope.ts +132 -0
  200. package/quality/runtimeMarkerReach.test.ts +84 -0
  201. package/quality/runtimeMarkerReach.ts +255 -0
  202. package/quality/runtimeModuleFacts.ts +290 -0
  203. package/quality/runtimeNameTable.test.ts +172 -0
  204. package/quality/runtimeNameTable.ts +477 -0
  205. package/quality/runtimeScopeReport.test.ts +123 -0
  206. package/quality/runtimeScopeReport.ts +167 -0
  207. package/quality/runtimeSliceKey.ts +269 -0
  208. package/quality/runtimeSyntax.ts +133 -0
  209. package/quality/runtimeTable.fixture.ts +189 -0
  210. package/quality/runtimeUse.test.ts +737 -0
  211. package/quality/runtimeUse.ts +696 -0
  212. package/quality/runtimeUseReadable.test.ts +393 -0
  213. package/quality/ssrScanner.test.ts +13 -0
  214. package/quality/ssrScanner.ts +1 -1
  215. package/quality/translatorBindings.ts +187 -0
  216. package/test/fakeTerminal.ts +45 -0
  217. package/test/secretEnvFixture.ts +134 -0
  218. package/test/testHelpers.ts +11 -0
  219. package/transforms/barrelAnalyzer.ts +26 -4
  220. package/transforms/barrelImportsPlugin.ts +121 -32
  221. package/transforms/exportReach.test.ts +162 -0
  222. package/transforms/exportReach.ts +308 -0
  223. package/transforms/frameworkObjects.fixture.tsx +58 -0
  224. package/transforms/frameworkObjects.test.ts +54 -0
  225. package/transforms/modelReference.test.ts +196 -0
  226. package/transforms/modelReference.ts +39 -0
  227. package/transforms/moduleParts.test.ts +225 -0
  228. package/transforms/moduleParts.ts +418 -0
  229. package/transforms/objectImportEdits.ts +150 -0
  230. package/transforms/objectMemberImports.test.ts +633 -0
  231. package/transforms/objectMemberImports.ts +571 -0
  232. package/transforms/objectMemberLookup.ts +150 -0
  233. package/transforms/objectModule.test.ts +307 -0
  234. package/transforms/objectModule.ts +482 -0
  235. package/transforms/objectModuleAnalyzer.ts +104 -0
  236. package/transforms/partImports.test.ts +76 -0
  237. package/transforms/partImports.ts +110 -0
  238. package/transforms/partModules.test.ts +187 -0
  239. package/transforms/partModules.ts +90 -0
  240. package/transforms/partPurity.ts +124 -0
  241. package/transforms/reactIconImports.test.ts +231 -0
  242. package/transforms/reactIconImports.ts +325 -0
  243. package/transforms/routeConstants.ts +122 -0
  244. package/transforms/routeRuntime.test.ts +835 -0
  245. package/transforms/routeRuntime.ts +703 -0
  246. package/transforms/routeRuntimeEdits.ts +92 -0
  247. package/transforms/routeRuntimeGraph.ts +66 -0
  248. package/transforms/routeRuntimePlan.ts +244 -0
  249. package/transforms/secretEnvDeclaration.test.ts +211 -0
  250. package/transforms/secretEnvDeclaration.ts +219 -0
  251. package/transforms/secretEnvFile.test.ts +117 -0
  252. package/transforms/secretEnvFile.ts +113 -0
  253. package/transforms/secretEnvName.test.ts +54 -0
  254. package/transforms/secretEnvName.ts +29 -0
  255. package/transforms/secretEnvSource.test.ts +152 -0
  256. package/transforms/secretEnvSource.ts +197 -0
  257. package/transforms/serverEnvEvaluationError.ts +11 -0
  258. package/transforms/serverEnvPlugin.test.ts +118 -1
  259. package/transforms/serverEnvPlugin.ts +95 -2
  260. package/transforms/serverEnvProfile.test.ts +129 -2
  261. package/transforms/serverEnvProfile.ts +133 -43
  262. package/transforms/serverEnvSecrets.test.ts +268 -0
  263. package/transforms/signalDescriptors.test.ts +280 -0
  264. package/transforms/signalDescriptors.ts +227 -0
  265. package/transforms/thisFreeExports.ts +87 -0
  266. package/transforms/transforms.test.ts +180 -3
  267. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  268. package/tunnel/createTunnel.test.ts +29 -8
  269. package/tunnel/createTunnel.ts +22 -11
  270. package/tunnel/ssh2Module.test.ts +37 -0
  271. package/tunnel/ssh2Module.ts +28 -0
  272. package/tunnel/sshTunnel.ts +4 -2
  273. package/typecheck/projectTypecheck.test.ts +32 -1
  274. package/typecheck/projectTypecheck.ts +3 -3
  275. package/typecheck/typeChecker.test.ts +49 -0
  276. package/typecheck/typeChecker.ts +9 -7
  277. package/typecheck/withheldDiagnostics.ts +41 -0
  278. package/util/devInstallCommand.ts +7 -0
  279. package/util/fileEditor.ts +1 -0
  280. package/util/jsonFormatter.test.ts +13 -9
  281. package/util/selectModel.ts +1 -0
  282. package/workflow/executor.ts +6 -2
  283. package/workflow/index.ts +1 -0
  284. package/workflow/plan.ts +36 -7
  285. package/workflow/types.ts +1 -1
  286. package/workflow/uiTarget.ts +50 -0
  287. package/workspace/envSeed.test.ts +30 -1
  288. package/workspace/envSeed.ts +30 -1
  289. package/workspace/getRelatedCnsts.ts +7 -0
  290. package/workspace/mainCheckout.test.ts +55 -0
  291. package/workspace/mainCheckout.ts +38 -0
  292. package/workspace/scanInfo.test.ts +39 -0
  293. package/workspace/scanInfo.ts +55 -6
  294. package/workspace/slicePlanner.ts +2 -1
  295. package/workspace/workspaceLayout.test.ts +22 -1
  296. package/workspace/workspaceLayout.ts +3 -3
  297. package/CHANGELOG.md +0 -2718
  298. package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
  299. package/codeAgent/agent/AkanCodeServices.ts +0 -122
  300. package/codeAgent/agent/AkanContextFiles.ts +0 -94
  301. package/codeAgent/agent/CodeAgent.ts +0 -606
  302. package/codeAgent/agent/CodeAgentAsks.ts +0 -66
  303. package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
  304. package/codeAgent/agent/CodeAgentGate.ts +0 -239
  305. package/codeAgent/agent/CodeAgentProxy.ts +0 -83
  306. package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
  307. package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
  308. package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
  309. package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
  310. package/codeAgent/agent/CodeAgentUi.ts +0 -47
  311. package/codeAgent/agent/CodeMailbox.ts +0 -148
  312. package/codeAgent/agent/CodeSessionFork.ts +0 -56
  313. package/codeAgent/agent/CodeSessionIndex.ts +0 -78
  314. package/codeAgent/agent/SubagentPool.ts +0 -219
  315. package/codeAgent/agent/WorkspaceTrust.ts +0 -200
  316. package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
  317. package/codeAgent/agent/akanCodeModel.ts +0 -47
  318. package/codeAgent/agent/akanCodeServices.test.ts +0 -54
  319. package/codeAgent/agent/akanContextFiles.test.ts +0 -116
  320. package/codeAgent/agent/akanSystemPrompt.ts +0 -50
  321. package/codeAgent/agent/codeAgent.test.ts +0 -275
  322. package/codeAgent/agent/codeAgentContract.test.ts +0 -643
  323. package/codeAgent/agent/codeAgentHosts.ts +0 -30
  324. package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
  325. package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
  326. package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
  327. package/codeAgent/agent/codeMailbox.test.ts +0 -76
  328. package/codeAgent/agent/codeSessionFork.test.ts +0 -58
  329. package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
  330. package/codeAgent/agent/consoleToStderr.ts +0 -8
  331. package/codeAgent/agent/jsonLines.ts +0 -29
  332. package/codeAgent/agent/stringArg.ts +0 -5
  333. package/codeAgent/feedback/DevLogFeedback.ts +0 -82
  334. package/codeAgent/feedback/PreviewFeedback.ts +0 -46
  335. package/codeAgent/feedback/TurnFeedback.ts +0 -98
  336. package/codeAgent/feedback/VerifyFeedback.ts +0 -39
  337. package/codeAgent/tools/AkanCli.ts +0 -51
  338. package/codeAgent/tools/AkanCodePlugins.ts +0 -142
  339. package/codeAgent/tools/AkanEditScope.ts +0 -53
  340. package/codeAgent/tools/AkanEnvKeys.ts +0 -50
  341. package/codeAgent/tools/AkanToolPack.ts +0 -86
  342. package/codeAgent/tools/AkanVerifier.ts +0 -30
  343. package/codeAgent/tools/AskToolPack.ts +0 -99
  344. package/codeAgent/tools/DeepSeekWeb.ts +0 -127
  345. package/codeAgent/tools/MailToolPack.ts +0 -76
  346. package/codeAgent/tools/McpClient.ts +0 -209
  347. package/codeAgent/tools/McpOAuth.ts +0 -233
  348. package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
  349. package/codeAgent/tools/McpServerConfig.ts +0 -131
  350. package/codeAgent/tools/McpSignIn.ts +0 -158
  351. package/codeAgent/tools/McpTokenStore.ts +0 -128
  352. package/codeAgent/tools/McpToolPack.ts +0 -206
  353. package/codeAgent/tools/SessionToolPack.ts +0 -91
  354. package/codeAgent/tools/WebToolPack.ts +0 -315
  355. package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
  356. package/codeAgent/tools/askToolPack.test.ts +0 -116
  357. package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
  358. package/codeAgent/tools/mcpOAuth.test.ts +0 -648
  359. package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
  360. package/piDependencyPins.test.ts +0 -45
package/app/appBin.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { chmod, mkdir, rm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import type { AkanAppConfig, BinPlatform } from "../akanConfig";
4
+ import type { App } from "../commandDecorators";
5
+ import { DesktopBin } from "../mobile/desktopBin";
6
+
7
+ //* `akan build` cannot know the CPU `docker build` targets, so the image carries every declared Linux file by Docker's arch name.
8
+ export class AppBin {
9
+ static readonly dir = "bin";
10
+ static readonly imageArchs: { [dockerArch: string]: BinPlatform } = { amd64: "linux-x64", arm64: "linux-arm64" };
11
+
12
+ constructor(
13
+ readonly app: App,
14
+ readonly config: AkanAppConfig,
15
+ ) {}
16
+
17
+ static missing(names: string[], which: (name: string) => string | null = Bun.which): string | null {
18
+ const missing = names.filter((name) => !which(name));
19
+ if (!missing.length) return null;
20
+ return `bin declares ${missing.join(", ")}, which this computer's PATH does not have: a dev server that spawns ${missing.length === 1 ? "it" : "one"} by name fails until it is installed here. The image and the desktop app carry their own.`;
21
+ }
22
+
23
+ async #chosen() {
24
+ const scanInfo = this.app.getScanInfo({ allowEmpty: true }) ?? (await this.app.scan({ write: false }));
25
+ return DesktopBin.select(this.config, scanInfo.getLibs());
26
+ }
27
+
28
+ async names(): Promise<string[]> {
29
+ return [...(await this.#chosen()).keys()];
30
+ }
31
+
32
+ async stageImage(distDir: string): Promise<string[]> {
33
+ const dir = path.join(distDir, AppBin.dir);
34
+ await rm(dir, { recursive: true, force: true });
35
+ const fetcher = new DesktopBin(this.app, this.config);
36
+ const carried = new Set<string>();
37
+ for (const [name, { owner, platforms }] of await this.#chosen())
38
+ for (const [dockerArch, platform] of Object.entries(AppBin.imageArchs)) {
39
+ const source = platforms[platform];
40
+ if (!source) continue;
41
+ const executable = await fetcher.executable(`${owner}: bin.${name}.${platform}`, source);
42
+ const target = path.join(dir, dockerArch, name);
43
+ await mkdir(path.dirname(target), { recursive: true });
44
+ await Bun.write(target, Bun.file(executable));
45
+ await chmod(target, 0o755);
46
+ carried.add(name);
47
+ }
48
+ return [...carried];
49
+ }
50
+ }
@@ -1,7 +1,12 @@
1
1
  import { afterEach, describe, expect, spyOn, test } from "bun:test";
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import path from "node:path";
2
4
  import { Logger } from "akanjs/common";
5
+ import { tempDirs } from "../test/testHelpers";
3
6
  import { ApplicationBuildReporter, type ApplicationBuildResult } from "./applicationBuildReporter";
4
7
 
8
+ const tempRoot = tempDirs("akan-devkit-build-reporter-");
9
+
5
10
  const resultFor = (environment: string): ApplicationBuildResult => ({
6
11
  phases: [],
7
12
  durationMs: 1_200,
@@ -14,7 +19,7 @@ describe("ApplicationBuildReporter.printSummary", () => {
14
19
  const rawLog = spyOn(Logger, "rawLog").mockImplementation(() => undefined);
15
20
  afterEach(() => rawLog.mockClear());
16
21
 
17
- test("names the flag and the variables a deployed build needs when the build is for local", () => {
22
+ test("names the flag and the variables a deployed build needs, in under 220 characters, when the build is for local", () => {
18
23
  ApplicationBuildReporter.printSummary(resultFor("local"));
19
24
 
20
25
  const notice = rawLog.mock.calls.map(([line]) => line).at(-1);
@@ -22,6 +27,7 @@ describe("ApplicationBuildReporter.printSummary", () => {
22
27
  for (const part of ["akan build <app> --env main", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"])
23
28
  expect(notice).toContain(part);
24
29
  expect(notice).not.toContain("dev routes");
30
+ expect(String(notice).length).toBeLessThan(220);
25
31
  });
26
32
 
27
33
  test("adds nothing to a build for a deployed environment", () => {
@@ -52,6 +58,33 @@ describe("ApplicationBuildReporter.printSummary", () => {
52
58
  );
53
59
  });
54
60
 
61
+ test("prints each locale's dictionary size, and its API description file's where the build split one out", async () => {
62
+ const artifactDir = await tempRoot();
63
+ await mkdir(path.join(artifactDir, "dict"));
64
+ await writeFile(path.join(artifactDir, "dict/en.js"), "x".repeat(4096));
65
+ await writeFile(path.join(artifactDir, "dict/en.js.br"), "x".repeat(1100));
66
+ await writeFile(path.join(artifactDir, "dict/en-api.js"), "y");
67
+ await writeFile(path.join(artifactDir, "dict/ko.js"), "z");
68
+ const dictAssets = {
69
+ en: {
70
+ url: "/_akan/dict/en.js",
71
+ relPath: "dict/en.js",
72
+ parts: { api: { url: "/_akan/dict/en-api.js", relPath: "dict/en-api.js" } },
73
+ },
74
+ ko: { url: "/_akan/dict/ko.js", relPath: "dict/ko.js" },
75
+ };
76
+ await writeFile(path.join(artifactDir, "base-artifact.json"), JSON.stringify({ dictAssets }));
77
+ ApplicationBuildReporter.printSummary({ ...resultFor("main"), artifactDir });
78
+
79
+ const lines = rawLog.mock.calls.map(([line = ""]) => line);
80
+ const en = lines.find((line) => line.startsWith("Dictionary en:"));
81
+ expect(en).toMatch(/^Dictionary en: 1\.1KB brotli on every page, API descriptions \d+B where shown$/);
82
+ expect(lines.find((line) => line.startsWith("Dictionary ko:"))).toMatch(
83
+ /^Dictionary ko: \d+B brotli on every page$/,
84
+ );
85
+ expect(lines.indexOf(en ?? "")).toBeLessThan(lines.indexOf(`Route artifacts: ${artifactDir}`));
86
+ });
87
+
55
88
  test("prints only the route JS budget warnings for a quiet build", () => {
56
89
  const routeJsWarnings = [{ file: "apps/shop/akan.budget.json", message: "unreadable", fix: "correct it" }];
57
90
  ApplicationBuildReporter.printRouteJsWarnings({ routeJsWarnings });
@@ -73,3 +106,20 @@ describe("ApplicationBuildReporter.printSummary", () => {
73
106
  );
74
107
  });
75
108
  });
109
+
110
+ describe("ApplicationBuildReporter.create", () => {
111
+ const rawLog = spyOn(Logger, "rawLog").mockImplementation(() => undefined);
112
+ afterEach(() => rawLog.mockClear());
113
+
114
+ test("prints one uncoloured line per finished phase and nothing when one starts, and a failed one to stderr", () => {
115
+ const reporter = ApplicationBuildReporter.create();
116
+ reporter.phaseStart?.({ id: "ssr", label: "Building SSR route artifacts" });
117
+ reporter.phaseDone?.({ id: "ssr", label: "Building SSR route artifacts", durationMs: 3_100, summary: "2 routes" });
118
+ reporter.phaseFail?.({ id: "csr", label: "Building CSR assets" }, new Error("boom"));
119
+
120
+ expect(rawLog.mock.calls).toEqual([
121
+ ["✓ Building SSR route artifacts: 2 routes (3.1s)"],
122
+ ["✗ Building CSR assets failed", undefined, "error"],
123
+ ]);
124
+ });
125
+ });
@@ -1,5 +1,6 @@
1
1
  import { Logger } from "akanjs/common";
2
2
  import { ErrorReport } from "../util/errorReport";
3
+ import { DictionarySizes } from "./dictionarySizes";
3
4
  import { RouteJsBudget, type RouteJsBudgetWarning, type RouteJsSize } from "./routeJsBudget";
4
5
 
5
6
  export interface ApplicationBuildPhaseResult {
@@ -30,6 +31,7 @@ export class ApplicationBuildReporter {
30
31
  static create(): ApplicationBuildProgressReporter {
31
32
  return {
32
33
  phaseDone: (phase) => Logger.rawLog(ApplicationBuildReporter.formatPhaseLine(phase)),
34
+ phaseFail: (phase) => Logger.rawLog(`✗ ${phase.label} failed`, undefined, "error"),
33
35
  };
34
36
  }
35
37
 
@@ -43,6 +45,9 @@ export class ApplicationBuildReporter {
43
45
  ApplicationBuildReporter.printRouteJsWarnings(result);
44
46
  Logger.rawLog("");
45
47
  }
48
+ const dictionaries = DictionarySizes.of(result.artifactDir);
49
+ for (const size of dictionaries) Logger.rawLog(DictionarySizes.format(size));
50
+ if (dictionaries.length) Logger.rawLog("");
46
51
  Logger.rawLog(`Route artifacts: ${result.artifactDir}`);
47
52
  Logger.rawLog(`Server output: ${result.outputDir}`);
48
53
  Logger.rawLog(`Done in ${ApplicationBuildReporter.formatDuration(result.durationMs)}`);
@@ -54,7 +59,7 @@ export class ApplicationBuildReporter {
54
59
  }
55
60
 
56
61
  static readonly localBuildNotice =
57
- "Built for local: the server runs without endpoint rate limits, and boots on local defaults (Redis on localhost, the first database mode) where a deployment would stop to ask. For a host others can reach, run `akan build <app> --env main` with AKAN_PUBLIC_REPO_NAME and AKAN_PUBLIC_SERVE_DOMAIN set in the shell or the workspace .env.";
62
+ "Built for local: no endpoint rate limits, Redis on localhost and the first database mode. For a host others can reach, `akan build <app> --env main` with AKAN_PUBLIC_REPO_NAME and AKAN_PUBLIC_SERVE_DOMAIN set.";
58
63
 
59
64
  static formatError(error: unknown, workspaceRoot = process.cwd()): string {
60
65
  return ErrorReport.format(error, workspaceRoot);
@@ -8,6 +8,16 @@ import type { App } from "../commandDecorators";
8
8
  import { AppExecutor, Executor } from "../executors";
9
9
  import { AllRoutesBuilder, type BuildAllRoutesResult, VendorNarrowing } from "../frontendBuild";
10
10
  import { bundleDefine } from "../frontendBuild/bundleDefine";
11
+ import {
12
+ computedSecretKeys,
13
+ computedSecrets,
14
+ holdsSentinel,
15
+ secretEnvSentinels,
16
+ twinSecretEnv,
17
+ twinSecrets,
18
+ writeComputedSecretFixture,
19
+ writeSecretEnvFixture,
20
+ } from "../test/secretEnvFixture";
11
21
  import { createTempApp } from "../test/testHelpers";
12
22
  import { ProjectTypecheck } from "../typecheck/projectTypecheck";
13
23
  import { AKAN_BACKEND_MINIFY, AKAN_OPTIONAL_BACKEND_EXTERNALS, ApplicationBuildRunner } from "./applicationBuildRunner";
@@ -71,6 +81,7 @@ console.info(new SampleService().name);
71
81
  );
72
82
  const app = {
73
83
  getConfig: async () => config,
84
+ getScanInfo: () => ({ getLibs: () => [] }),
74
85
  dist: new Executor("dist", root),
75
86
  workspace: { workspaceRoot: root },
76
87
  logger: { warn: () => undefined },
@@ -85,6 +96,67 @@ console.info(new SampleService().name);
85
96
  }
86
97
  });
87
98
 
99
+ test("writes each docker variant beside the Dockerfile as Dockerfile.<name>, for the build's environment", async () => {
100
+ const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
101
+ const config = new AkanAppConfig(
102
+ { name: "portal" } as never,
103
+ [],
104
+ { name: "repo", version: "1.0.0", description: "repo" },
105
+ { docker: { variants: { edge: { env: { AKAN_PUBLIC_OPERATION_MODE: "edge" } } } } },
106
+ { repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
107
+ );
108
+ const app = {
109
+ getConfig: async () => config,
110
+ getScanInfo: () => ({ getLibs: () => [] }),
111
+ dist: new Executor("dist", root),
112
+ workspace: { workspaceRoot: root },
113
+ logger: { warn: () => undefined },
114
+ } as unknown as App;
115
+ try {
116
+ await new ApplicationBuildRunner(app, { environment: "debug" }).buildAppMeta();
117
+ const image = await readFile(path.join(root, "Dockerfile"), "utf8");
118
+ const edge = await readFile(path.join(root, "Dockerfile.edge"), "utf8");
119
+ expect(image).toContain("ENV AKAN_PUBLIC_OPERATION_MODE=cloud\n");
120
+ expect(edge).toBe(
121
+ image.replace("ENV AKAN_PUBLIC_OPERATION_MODE=cloud\n", "ENV AKAN_PUBLIC_OPERATION_MODE=edge\n"),
122
+ );
123
+ expect(edge).toContain("ENV AKAN_PUBLIC_ENV=debug\n");
124
+ expect((await readFile(path.join(root, ".dockerignore"), "utf8")).split("\n")).toContain("Dockerfile.*");
125
+ } finally {
126
+ await rm(root, { recursive: true, force: true });
127
+ }
128
+ });
129
+
130
+ test("a variant on an env profile names it and asks for none of the secret env values the image's own lists", async () => {
131
+ const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
132
+ const config = new AkanAppConfig(
133
+ { name: "portal" } as never,
134
+ [],
135
+ { name: "repo", version: "1.0.0", description: "repo" },
136
+ { docker: { variants: { edge: { profile: "edge" }, mirror: {} } } },
137
+ { repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
138
+ );
139
+ const app = {
140
+ getConfig: async () => config,
141
+ getScanInfo: () => ({ getLibs: () => [] }),
142
+ dist: new Executor("dist", root),
143
+ workspace: { workspaceRoot: root },
144
+ logger: { warn: () => undefined },
145
+ } as unknown as App;
146
+ const runner = new ApplicationBuildRunner(app, { environment: "debug" });
147
+ try {
148
+ await runner.buildAppMeta();
149
+ const [image, edge, mirror] = await Promise.all(
150
+ ["Dockerfile", "Dockerfile.edge", "Dockerfile.mirror"].map((name) => readFile(path.join(root, name), "utf8")),
151
+ );
152
+ expect(edge).toContain("ENV AKAN_ENV_PROFILE=edge\n");
153
+ expect(image).not.toContain("AKAN_ENV_PROFILE");
154
+ expect(mirror).toBe(image);
155
+ } finally {
156
+ await rm(root, { recursive: true, force: true });
157
+ }
158
+ });
159
+
88
160
  test("writes beside main.js the env its Dockerfile sets, so a host without the image runs the build as is", async () => {
89
161
  const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
90
162
  const config = new AkanAppConfig(
@@ -94,9 +166,12 @@ console.info(new SampleService().name);
94
166
  {},
95
167
  { repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
96
168
  );
169
+ const dist = new Executor("dist", root);
170
+ const printed = spyOn(dist.logger, "rawLog").mockImplementation(() => undefined);
97
171
  const app = {
98
172
  getConfig: async () => config,
99
- dist: new Executor("dist", root),
173
+ getScanInfo: () => ({ getLibs: () => [] }),
174
+ dist,
100
175
  workspace: { workspaceRoot: root },
101
176
  logger: { warn: () => undefined },
102
177
  } as unknown as App;
@@ -113,6 +188,10 @@ console.info(new SampleService().name);
113
188
  expect(await builtEnv()).toEqual(config.getProductionEnv("debug"));
114
189
  expect(await builtEnv()).toEqual(await dockerfileEnv());
115
190
  expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_APP_NAME: "portal", AKAN_PUBLIC_ENV: "debug" });
191
+ expect((await readFile(path.join(root, ".dockerignore"), "utf8")).split("\n")).toEqual(
192
+ expect.arrayContaining(["sqlite", "local", "runtime", "data", ".akan/artifact/image-cache", "node_modules"]),
193
+ );
194
+ expect(printed).not.toHaveBeenCalled();
116
195
  await new ApplicationBuildRunner(app).buildAppMeta();
117
196
  expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_ENV: "local" });
118
197
  expect(await builtEnv()).toEqual(await dockerfileEnv());
@@ -121,6 +200,307 @@ console.info(new SampleService().name);
121
200
  }
122
201
  });
123
202
 
203
+ test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
204
+ const { root, workspace } = await createTempApp("portal");
205
+ await writeSecretEnvFixture(root, { app: "portal" });
206
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
207
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
208
+ for (const key of keys) delete process.env[key];
209
+ await writeFile(
210
+ path.join(root, ".env"),
211
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
212
+ );
213
+ const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
214
+ const app = AppExecutor.from(workspace, "portal");
215
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
216
+ app.prepareCommand = async () => {
217
+ throw new Error("stopped before the phases");
218
+ };
219
+ const runner = new ApplicationBuildRunner(app, options);
220
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
221
+ await runner.buildAppMeta();
222
+ const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
223
+ [key: string]: string;
224
+ };
225
+ const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
226
+ const dockerfileEnv = Object.fromEntries(
227
+ dockerfile
228
+ .split("\n")
229
+ .filter((line) => line.startsWith("ENV "))
230
+ .map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
231
+ );
232
+ expect(env).toEqual(dockerfileEnv);
233
+ expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
234
+ return env;
235
+ };
236
+ const names =
237
+ "JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,MAILER__AUTH__PASS,OBJECT_STORAGE__ENDPOINT,DISCORD__TOKENS:json,DISCORD__WEBHOOK,PUSH_NOTI__FIREBASE__PRIVATE_KEY:multiline,MESSAGE__API_SECRET,MESSAGE__SENDER_PASSWORD,POSTGRES_URL|DATABASE_URL";
238
+ try {
239
+ expect((await metaOf({ secretEnv: "read" })).AKAN_ENV_NAMES).toBe(names);
240
+ expect(await metaOf({})).not.toHaveProperty("AKAN_ENV_NAMES");
241
+ } finally {
242
+ for (const key of keys) {
243
+ if (shellEnv[key] === undefined) delete process.env[key];
244
+ else process.env[key] = shellEnv[key];
245
+ }
246
+ await rm(root, { recursive: true, force: true });
247
+ }
248
+ });
249
+
250
+ test("an image build checks each profile its variants name before any phase, and that variant's Dockerfile lists no secret env name", async () => {
251
+ const { root, workspace } = await createTempApp("portal");
252
+ await writeSecretEnvFixture(root, { app: "portal" });
253
+ await writeFile(
254
+ path.join(root, "apps/portal/akan.config.ts"),
255
+ 'export default { docker: { variants: { edge: { profile: "edge" } } } };\n',
256
+ );
257
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
258
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
259
+ for (const key of keys) delete process.env[key];
260
+ await writeFile(
261
+ path.join(root, ".env"),
262
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
263
+ );
264
+ const started = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
265
+ const app = AppExecutor.from(workspace, "portal");
266
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
267
+ app.prepareCommand = async () => {
268
+ throw new Error("stopped before the phases");
269
+ };
270
+ const runner = new ApplicationBuildRunner(app, options);
271
+ const failure = await runner.build().then(
272
+ () => "",
273
+ (error: Error) => error.message,
274
+ );
275
+ return { app, runner, failure };
276
+ };
277
+ const profileFile = path.join(root, "apps/portal/env/env.server.main.edge.ts");
278
+ try {
279
+ expect((await started({ secretEnv: "read" })).failure).toContain(
280
+ 'The server env profile "edge" bundles env/env.server.main.edge.ts',
281
+ );
282
+ expect((await started({})).failure).toBe("stopped before the phases");
283
+
284
+ await writeFile(profileFile, 'export const env = { mailer: { auth: { pass: "sentinel-edge-pass" } } };\n');
285
+ const secret = await started({ secretEnv: "read" });
286
+ expect(secret.failure).toContain("env/env.server.main.edge.ts holds secret-named values");
287
+ expect(secret.failure).not.toContain("sentinel-edge-pass");
288
+
289
+ await writeFile(profileFile, 'export const env = { hostname: "edge-host" };\n');
290
+ const { app, runner, failure } = await started({ secretEnv: "read" });
291
+ expect(failure).toBe("stopped before the phases");
292
+ await runner.buildAppMeta();
293
+ const [image, edge] = await Promise.all(
294
+ ["Dockerfile", "Dockerfile.edge"].map((name) => readFile(path.join(app.dist.cwdPath, name), "utf8")),
295
+ );
296
+ expect(image).toContain("ENV AKAN_ENV_NAMES=JWT_SECRET,");
297
+ expect(image).not.toContain("AKAN_ENV_PROFILE");
298
+ expect(edge).toContain("ENV AKAN_ENV_PROFILE=edge\n");
299
+ expect(edge).not.toContain("AKAN_ENV_NAMES");
300
+ expect(edge.replace("ENV AKAN_ENV_PROFILE=edge\n", "")).toBe(image.replace(/ENV AKAN_ENV_NAMES=.*\n/, ""));
301
+ } finally {
302
+ for (const key of keys) {
303
+ if (shellEnv[key] === undefined) delete process.env[key];
304
+ else process.env[key] = shellEnv[key];
305
+ }
306
+ await rm(root, { recursive: true, force: true });
307
+ }
308
+ });
309
+
310
+ test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
311
+ const { root, workspace } = await createTempApp("portal");
312
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
313
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
314
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
315
+ for (const key of keys) delete process.env[key];
316
+ await writeFile(
317
+ path.join(root, ".env"),
318
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
319
+ );
320
+ const app = AppExecutor.from(workspace, "portal");
321
+ let prepared = false;
322
+ app.prepareCommand = async () => {
323
+ prepared = true;
324
+ throw new Error("prepared");
325
+ };
326
+ try {
327
+ const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
328
+ .build()
329
+ .catch((error: Error) => error.message);
330
+ expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
331
+ expect(holdsSentinel(String(failure))).toBe(false);
332
+ expect(prepared).toBe(false);
333
+ } finally {
334
+ for (const key of keys) {
335
+ if (shellEnv[key] === undefined) delete process.env[key];
336
+ else process.env[key] = shellEnv[key];
337
+ }
338
+ await rm(root, { recursive: true, force: true });
339
+ }
340
+ });
341
+
342
+ test("an env file that needs a variable of the shell to load builds with it set; without it a build stops at the place", async () => {
343
+ const { root, workspace } = await createTempApp("portal");
344
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
345
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
346
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
347
+ for (const key of keys) delete process.env[key];
348
+ await writeFile(
349
+ path.join(root, ".env"),
350
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
351
+ );
352
+ const started = async () => {
353
+ const app = AppExecutor.from(workspace, "portal");
354
+ const warnings: string[] = [];
355
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
356
+ warnings.push(message);
357
+ });
358
+ app.prepareCommand = async () => {
359
+ throw new Error("stopped before the phases");
360
+ };
361
+ const runner = new ApplicationBuildRunner(app, { secretEnv: "read" });
362
+ const failure = await runner.build().then(
363
+ () => "",
364
+ (error: Error) => error.message,
365
+ );
366
+ return { app, runner, failure, warnings };
367
+ };
368
+ const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
369
+ await runner.buildAppMeta();
370
+ return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
371
+ [key: string]: string;
372
+ };
373
+ };
374
+ const place =
375
+ /env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
376
+ try {
377
+ const stopped = await started();
378
+ expect(stopped.failure).toMatch(place);
379
+ expect(stopped.failure).toEndWith(
380
+ "by setting the variable it reads there in this shell or giving it a fallback, and build again.",
381
+ );
382
+ expect(stopped.warnings).toEqual([]);
383
+ expect(holdsSentinel(stopped.failure)).toBe(false);
384
+
385
+ process.env.ZQ_HOSTS = "a.example.test,b.example.test";
386
+ const built = await started();
387
+ expect(built.failure).toBe("stopped before the phases");
388
+ expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
389
+ } finally {
390
+ for (const key of keys) {
391
+ if (shellEnv[key] === undefined) delete process.env[key];
392
+ else process.env[key] = shellEnv[key];
393
+ }
394
+ await rm(root, { recursive: true, force: true });
395
+ }
396
+ });
397
+
398
+ test("an image build stops before any phase at a secret the env file imports or computes, short or plain as it may be, naming the file and the keys alone", async () => {
399
+ const { root, workspace } = await createTempApp("portal");
400
+ await writeComputedSecretFixture(root, "portal");
401
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
402
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
403
+ for (const key of keys) delete process.env[key];
404
+ await writeFile(
405
+ path.join(root, ".env"),
406
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
407
+ );
408
+ const started = async () => {
409
+ const app = AppExecutor.from(workspace, "portal");
410
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
411
+ let prepared = false;
412
+ app.prepareCommand = async () => {
413
+ prepared = true;
414
+ throw new Error("stopped before the phases");
415
+ };
416
+ const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" }).build().then(
417
+ () => "",
418
+ (error: Error) => error.message,
419
+ );
420
+ return { failure, prepared: () => prepared };
421
+ };
422
+ try {
423
+ const stopped = await started();
424
+ expect(stopped.prepared()).toBe(false);
425
+ expect(stopped.failure).toStartWith(
426
+ `The server env of portal (main) holds 4 secret values this build cannot leave out, so it stops here: ${computedSecretKeys.join(", ")} (apps/portal/env/env.server.ts and what it imports).\n`,
427
+ );
428
+ expect(holdsSentinel(stopped.failure)).toBe(false);
429
+ for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
430
+ } finally {
431
+ for (const key of keys) {
432
+ if (shellEnv[key] === undefined) delete process.env[key];
433
+ else process.env[key] = shellEnv[key];
434
+ }
435
+ await rm(root, { recursive: true, force: true });
436
+ }
437
+ });
438
+
439
+ test("an image build stops before its metadata when a file it wrote holds a secret it left out of the env, and warns of a short one a plain key holds as well", async () => {
440
+ const { root, workspace } = await createTempApp("portal");
441
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
442
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
443
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
444
+ for (const key of keys) delete process.env[key];
445
+ await writeFile(
446
+ path.join(root, ".env"),
447
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
448
+ );
449
+ const runnerOf = async () => {
450
+ const app = AppExecutor.from(workspace, "portal");
451
+ const warnings: string[] = [];
452
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
453
+ warnings.push(message);
454
+ });
455
+ app.prepareCommand = async () => {
456
+ throw new Error("stopped before the phases");
457
+ };
458
+ const runner = new ApplicationBuildRunner(app, { secretEnv: "read" });
459
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
460
+ return { app, runner, warnings };
461
+ };
462
+ try {
463
+ const { app, runner, warnings } = await runnerOf();
464
+ await mkdir(app.dist.cwdPath, { recursive: true });
465
+ await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
466
+ await runner.assertSecretsLeftOut();
467
+ expect(warnings).toEqual([]);
468
+ await writeFile(
469
+ path.join(app.dist.cwdPath, "chunk-a.js"),
470
+ `const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
471
+ );
472
+ await runner.assertSecretsLeftOut();
473
+ expect(warnings).toHaveLength(1);
474
+ expect(warnings[0]).toContain(
475
+ "\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
476
+ );
477
+ expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
478
+ await writeFile(
479
+ path.join(app.dist.cwdPath, "chunk-b.js"),
480
+ `const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
481
+ );
482
+ const failure = await runner.assertSecretsLeftOut().then(
483
+ () => "",
484
+ (error: Error) => error.message,
485
+ );
486
+ expect(failure).toStartWith(
487
+ [
488
+ "The build holds secret values the server reads from its process env, so it stops here:",
489
+ " chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
490
+ " chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
491
+ "",
492
+ ].join("\n"),
493
+ );
494
+ expect(holdsSentinel(failure)).toBe(false);
495
+ } finally {
496
+ for (const key of keys) {
497
+ if (shellEnv[key] === undefined) delete process.env[key];
498
+ else process.env[key] = shellEnv[key];
499
+ }
500
+ await rm(root, { recursive: true, force: true });
501
+ }
502
+ });
503
+
124
504
  test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
125
505
  const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
126
506
  const config = new AkanAppConfig(
@@ -133,6 +513,7 @@ console.info(new SampleService().name);
133
513
  const warnings: string[] = [];
134
514
  const app = {
135
515
  getConfig: async () => config,
516
+ getScanInfo: () => ({ getLibs: () => [] }),
136
517
  dist: new Executor("dist", root),
137
518
  workspace: { workspaceRoot: root },
138
519
  logger: { warn: (message: string) => warnings.push(message) },
@@ -379,16 +760,16 @@ console.info(new SampleService().name);
379
760
  expect(order).toEqual(["routes"]);
380
761
  });
381
762
 
382
- test("akan typecheck names the script/ files nothing imports, and a build's typecheck leaves them out", async () => {
763
+ test("akan typecheck asks for the tests and script/ files nothing imports, and a build's typecheck does not", async () => {
383
764
  const { root, app } = await createTempApp("portal");
384
765
  const run = spyOn(ProjectTypecheck.prototype, "run").mockImplementation(async () => "");
385
766
  try {
386
767
  const runner = new ApplicationBuildRunner(app);
387
768
  await runner.typecheck({ tests: true });
388
769
  await runner.typecheck();
389
- const [checked, built] = run.mock.calls.map(([entries]) => entries);
390
- expect(checked).toContain("../../script/**/*.ts");
391
- expect(built).not.toContain("../../script/**/*.ts");
770
+ const [checked, built] = run.mock.calls.map(([, options]) => options?.tests);
771
+ expect(checked).toBe(true);
772
+ expect(built).toBeUndefined();
392
773
  } finally {
393
774
  run.mockRestore();
394
775
  await rm(root, { recursive: true, force: true });
@@ -455,6 +836,47 @@ console.info(new SampleService().name);
455
836
  }
456
837
  });
457
838
 
839
+ test("main.js sets the build's env before a package the bundle leaves outside loads", async () => {
840
+ const { root, workspace } = await createTempApp("portal");
841
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
842
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
843
+ await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(root, "apps", "portal", file), "")));
844
+ const app = AppExecutor.from(workspace, "portal");
845
+ app.prepareCommand = async () => ({ env: {} });
846
+ const bundle = spyOn(Bun, "build").mockImplementation(
847
+ async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
848
+ );
849
+ try {
850
+ await new ApplicationBuildRunner(app, { verify: true }).build();
851
+ const configs = bundle.mock.calls.map(([config]) => config);
852
+ const envModule = configs.find(({ entrypoints }) =>
853
+ entrypoints.some((entry) => entry.endsWith("loadBuildEnv.ts")),
854
+ );
855
+ const main = configs.find(({ entrypoints }) => entrypoints.some((entry) => entry.endsWith("main.ts")));
856
+ bundle.mockRestore();
857
+ if (!envModule || !main) throw new Error("the build made no env module or no main bundle");
858
+ const { entry: mainBundle } = main.naming as { entry: string };
859
+ await Bun.build(envModule);
860
+ const dist = app.dist.cwdPath;
861
+ await mkdir(path.join(dist, "node_modules", "probe"), { recursive: true });
862
+ await writeFile(path.join(dist, "node_modules", "probe", "index.js"), "module.exports = process.env.NODE_ENV;\n");
863
+ await writeFile(path.join(dist, "akan.env.json"), '{ "NODE_ENV": "production" }\n');
864
+ await writeFile(path.join(dist, mainBundle), 'import mode from "probe";\nconsole.log(mode);\n');
865
+ const { NODE_ENV: _mode, ...env } = process.env;
866
+ const proc = Bun.spawnSync([process.execPath, "main.js"], { cwd: dist, env, stdout: "pipe", stderr: "pipe" });
867
+
868
+ expect(proc.stderr.toString()).toBe("");
869
+ expect(proc.stdout.toString()).toBe("production\n");
870
+ } finally {
871
+ bundle.mockRestore();
872
+ for (const key of keys) {
873
+ if (shellEnv[key] === undefined) delete process.env[key];
874
+ else process.env[key] = shellEnv[key];
875
+ }
876
+ await rm(root, { recursive: true, force: true });
877
+ }
878
+ });
879
+
458
880
  test("a verify build writes to dist/verify/<app> and leaves the full build in dist/apps/<app> as it was", async () => {
459
881
  const { root, workspace } = await createTempApp("portal");
460
882
  const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;