@akanjs/devkit 3.3.0-rc.9 → 4.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/DEV_RUNTIME_KNOBS.md +1 -1
  2. package/README.ko.md +7 -1
  3. package/README.md +7 -1
  4. package/akanApp/akanApp.host.test.ts +3 -1
  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 +269 -18
  13. package/akanConfig/akanConfig.ts +104 -210
  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 +212 -0
  20. package/akanConfig/index.ts +3 -0
  21. package/akanConfig/nativeFileSettings.ts +33 -0
  22. package/akanConfig/types.ts +4 -0
  23. package/app/appBin.test.ts +63 -0
  24. package/app/appBin.ts +50 -0
  25. package/app/applicationBuildReporter.test.ts +51 -1
  26. package/app/applicationBuildReporter.ts +6 -1
  27. package/app/applicationBuildRunner.test.ts +358 -5
  28. package/app/applicationBuildRunner.ts +221 -31
  29. package/app/clientServerBoundary.test.ts +115 -0
  30. package/app/clientServerBoundary.ts +89 -0
  31. package/app/dictionarySizes.test.ts +40 -0
  32. package/app/dictionarySizes.ts +95 -0
  33. package/app/routeFilesReport.test.ts +59 -0
  34. package/app/routeFilesReport.ts +46 -0
  35. package/app/routeJsBudget.ts +18 -4
  36. package/artifact/implicitRootLayout.test.ts +19 -0
  37. package/artifact/implicitRootLayout.ts +16 -2
  38. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  39. package/artifact/storeBootstrap.test.ts +28 -0
  40. package/artifact/storeBootstrap.ts +64 -8
  41. package/biome.base.json +7 -5
  42. package/codeAgent/index.ts +1 -34
  43. package/codeAgent/skills/akan-agent/SKILL.md +2 -2
  44. package/codeAgent/skills/akan-debug/SKILL.md +8 -3
  45. package/codeAgent/skills/akan-deps/SKILL.md +10 -3
  46. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  47. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  48. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  49. package/codeAgent/skills/akan-page/SKILL.md +65 -30
  50. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  51. package/codeAgent/skills/akan-runtime/SKILL.md +21 -1
  52. package/codeAgent/skills/akan-service/SKILL.md +21 -20
  53. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  54. package/codeAgent/skills/akan-ui/SKILL.md +16 -21
  55. package/codeAgent/skills/akan-validate/SKILL.md +8 -2
  56. package/commandDecorators/command.ts +28 -12
  57. package/commandDecorators/commandBuilder.ts +8 -1
  58. package/commandDecorators/commandDecorators.test.ts +70 -3
  59. package/commandDecorators/helpFormatter.ts +14 -12
  60. package/context/akanContext.ts +2 -0
  61. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  62. package/csrE2e/ssrRegistry.e2e.test.ts +108 -22
  63. package/docs/apiReference.test.ts +25 -0
  64. package/docs/apiReference.ts +38 -5
  65. package/docs/declarationReader.ts +30 -0
  66. package/executors/appExecutor.ts +26 -12
  67. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  68. package/executors/clientRuntimeKeys.fixture.json +393 -0
  69. package/executors/clientRuntimeKeys.test.ts +1690 -0
  70. package/executors/executor.ts +14 -6
  71. package/executors/executors.test.ts +155 -1
  72. package/executors/pkgExecutor.ts +2 -1
  73. package/executors/sysExecutor.ts +112 -8
  74. package/executors/workspaceExecutor.ts +7 -4
  75. package/frontendBuild/allRoutesBuilder.ts +99 -7
  76. package/frontendBuild/autoImportSync.ts +3 -2
  77. package/frontendBuild/buildRouteClient.test.ts +684 -6
  78. package/frontendBuild/clientBuildTypes.ts +26 -0
  79. package/frontendBuild/clientEntriesBundler.ts +49 -1
  80. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  81. package/frontendBuild/clientEntryDiscovery.ts +134 -12
  82. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  83. package/frontendBuild/clientEntryGroups.ts +61 -0
  84. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  85. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  86. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  87. package/frontendBuild/csrDevPatcher.test.ts +4 -5
  88. package/frontendBuild/csrDevPatcher.ts +37 -11
  89. package/frontendBuild/csrDevTypes.ts +9 -0
  90. package/frontendBuild/devBarrelImports.test.ts +124 -0
  91. package/frontendBuild/devBarrelImports.ts +81 -21
  92. package/frontendBuild/devChangePlanner.ts +0 -1
  93. package/frontendBuild/devRegistryBundler.ts +4 -2
  94. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  95. package/frontendBuild/devRouteRuntime.ts +167 -0
  96. package/frontendBuild/dictionaryAssetBuilder.test.ts +408 -0
  97. package/frontendBuild/dictionaryAssetBuilder.ts +185 -17
  98. package/frontendBuild/dictionaryConstants.ts +136 -0
  99. package/frontendBuild/dictionaryOwnParts.ts +88 -0
  100. package/frontendBuild/dictionaryPackState.ts +131 -0
  101. package/frontendBuild/dictionaryPacking.test.ts +207 -0
  102. package/frontendBuild/dictionaryPacking.ts +160 -0
  103. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  104. package/frontendBuild/dictionaryRoutes.ts +227 -0
  105. package/frontendBuild/frontendBuild.test.ts +5 -3
  106. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  107. package/frontendBuild/pagesBundleBuilder.ts +78 -2
  108. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  109. package/frontendBuild/precompressArtifacts.ts +34 -8
  110. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  111. package/frontendBuild/renderedEntries.ts +144 -0
  112. package/frontendBuild/routeClientBuilder.ts +407 -43
  113. package/frontendBuild/routeHandoffs.test.ts +155 -0
  114. package/frontendBuild/routeHandoffs.ts +117 -0
  115. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  116. package/frontendBuild/routeModulePreloads.ts +20 -11
  117. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  118. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  119. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  120. package/frontendBuild/routeRuntimePays.ts +117 -0
  121. package/frontendBuild/ssrBaseArtifactBuilder.ts +30 -35
  122. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  123. package/frontendBuild/ssrDevBundler.ts +66 -11
  124. package/frontendBuild/vendorFileImports.test.ts +254 -0
  125. package/frontendBuild/vendorFileImports.ts +163 -0
  126. package/frontendBuild/vendorNarrowing.test.ts +47 -3
  127. package/frontendBuild/vendorNarrowing.ts +38 -2
  128. package/frontendBuild/vendorSpecifiers.ts +2 -0
  129. package/guideline/agentAssets.ts +1 -1
  130. package/incrementalBuilder/buildBatch.proc.ts +27 -1
  131. package/incrementalBuilder/buildBatchProtocol.ts +1 -0
  132. package/incrementalBuilder/builderWatch.ts +11 -1
  133. package/incrementalBuilder/incrementalBuilder.proc.test.ts +159 -0
  134. package/incrementalBuilder/incrementalBuilder.proc.ts +31 -3
  135. package/incrementalBuilder/pendingMetadata.test.ts +27 -0
  136. package/incrementalBuilder/pendingMetadata.ts +19 -0
  137. package/integration/devStability.integration.test.ts +46 -21
  138. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  139. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  140. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  141. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  142. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  143. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  144. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  145. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  146. package/lint/biomeBase.test.ts +50 -3
  147. package/lint/biomeBase.ts +1 -1
  148. package/lint/biomeCheck.test.ts +162 -0
  149. package/lint/biomeCheck.ts +131 -0
  150. package/lint/linter.test.ts +16 -11
  151. package/lint/no-arbitrary-color.grit +5 -0
  152. package/lint/no-conditional-st-hook.grit +5 -1
  153. package/lint/no-daisyui-legacy-class.grit +8 -0
  154. package/lint/no-document-cookie.grit +3 -0
  155. package/lint/no-inline-color.grit +10 -2
  156. package/lint/no-oversized-list-limit.grit +2 -0
  157. package/lint/no-raw-palette-class.grit +7 -0
  158. package/lint/no-unpublished-form-setter.grit +2 -0
  159. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  160. package/lint/no-web-storage.grit +3 -0
  161. package/lint/withheldEnvFile.ts +17 -0
  162. package/mobile/desktopBin.ts +2 -2
  163. package/mobile/desktopServerStage.test.ts +18 -3
  164. package/mobile/desktopServerStage.ts +7 -2
  165. package/mobile/nativeApp.test.ts +7 -5
  166. package/mobile/nativeApp.ts +2 -2
  167. package/mobile/nativeConfig.test.ts +17 -1
  168. package/mobile/nativeConfig.ts +11 -6
  169. package/mobile/nativePublicEnv.ts +1 -1
  170. package/mobile/serverBundleSecrets.ts +43 -0
  171. package/package.json +11 -12
  172. package/packageExports.test.ts +3 -2
  173. package/preview/PreviewView.ts +25 -3
  174. package/quality/dictionaryKeys.test.ts +356 -0
  175. package/quality/dictionaryKeys.ts +488 -0
  176. package/quality/objectImportReport.test.ts +36 -0
  177. package/quality/objectImportReport.ts +105 -0
  178. package/quality/qualityScanner.ts +1 -1
  179. package/quality/routeRuntimeReport.test.ts +91 -0
  180. package/quality/routeRuntimeReport.ts +121 -0
  181. package/quality/runtimeConstantFacts.ts +71 -0
  182. package/quality/runtimeConstantGraph.ts +123 -0
  183. package/quality/runtimeConstantReads.ts +116 -0
  184. package/quality/runtimeImports.test.ts +190 -0
  185. package/quality/runtimeImports.ts +233 -0
  186. package/quality/runtimeKeyNames.ts +46 -0
  187. package/quality/runtimeLexicalScope.ts +132 -0
  188. package/quality/runtimeMarkerReach.test.ts +84 -0
  189. package/quality/runtimeMarkerReach.ts +255 -0
  190. package/quality/runtimeModuleFacts.ts +290 -0
  191. package/quality/runtimeNameTable.test.ts +172 -0
  192. package/quality/runtimeNameTable.ts +477 -0
  193. package/quality/runtimeScopeReport.test.ts +123 -0
  194. package/quality/runtimeScopeReport.ts +167 -0
  195. package/quality/runtimeSliceKey.ts +269 -0
  196. package/quality/runtimeSyntax.ts +133 -0
  197. package/quality/runtimeTable.fixture.ts +189 -0
  198. package/quality/runtimeUse.test.ts +737 -0
  199. package/quality/runtimeUse.ts +696 -0
  200. package/quality/runtimeUseReadable.test.ts +393 -0
  201. package/quality/ssrScanner.test.ts +13 -0
  202. package/quality/ssrScanner.ts +1 -1
  203. package/quality/translatorBindings.ts +187 -0
  204. package/test/fakeTerminal.ts +45 -0
  205. package/test/secretEnvFixture.ts +134 -0
  206. package/test/testHelpers.ts +11 -0
  207. package/transforms/barrelAnalyzer.ts +24 -2
  208. package/transforms/barrelImportsPlugin.ts +121 -32
  209. package/transforms/exportReach.test.ts +162 -0
  210. package/transforms/exportReach.ts +308 -0
  211. package/transforms/frameworkObjects.fixture.tsx +58 -0
  212. package/transforms/frameworkObjects.test.ts +54 -0
  213. package/transforms/modelReference.test.ts +196 -0
  214. package/transforms/modelReference.ts +39 -0
  215. package/transforms/moduleParts.test.ts +225 -0
  216. package/transforms/moduleParts.ts +418 -0
  217. package/transforms/objectImportEdits.ts +150 -0
  218. package/transforms/objectMemberImports.test.ts +633 -0
  219. package/transforms/objectMemberImports.ts +571 -0
  220. package/transforms/objectMemberLookup.ts +150 -0
  221. package/transforms/objectModule.test.ts +307 -0
  222. package/transforms/objectModule.ts +482 -0
  223. package/transforms/objectModuleAnalyzer.ts +104 -0
  224. package/transforms/partImports.test.ts +76 -0
  225. package/transforms/partImports.ts +110 -0
  226. package/transforms/partModules.test.ts +187 -0
  227. package/transforms/partModules.ts +90 -0
  228. package/transforms/partPurity.ts +124 -0
  229. package/transforms/reactIconImports.test.ts +231 -0
  230. package/transforms/reactIconImports.ts +325 -0
  231. package/transforms/routeConstants.ts +122 -0
  232. package/transforms/routeRuntime.test.ts +835 -0
  233. package/transforms/routeRuntime.ts +703 -0
  234. package/transforms/routeRuntimeEdits.ts +92 -0
  235. package/transforms/routeRuntimeGraph.ts +66 -0
  236. package/transforms/routeRuntimePlan.ts +244 -0
  237. package/transforms/secretEnvDeclaration.test.ts +208 -0
  238. package/transforms/secretEnvDeclaration.ts +213 -0
  239. package/transforms/secretEnvFile.test.ts +117 -0
  240. package/transforms/secretEnvFile.ts +113 -0
  241. package/transforms/secretEnvName.test.ts +54 -0
  242. package/transforms/secretEnvName.ts +29 -0
  243. package/transforms/secretEnvSource.test.ts +148 -0
  244. package/transforms/secretEnvSource.ts +166 -0
  245. package/transforms/serverEnvEvaluationError.ts +11 -0
  246. package/transforms/serverEnvPlugin.test.ts +2 -1
  247. package/transforms/serverEnvPlugin.ts +13 -0
  248. package/transforms/serverEnvProfile.test.ts +129 -2
  249. package/transforms/serverEnvProfile.ts +126 -40
  250. package/transforms/serverEnvSecrets.test.ts +292 -0
  251. package/transforms/signalDescriptors.test.ts +280 -0
  252. package/transforms/signalDescriptors.ts +227 -0
  253. package/transforms/thisFreeExports.ts +87 -0
  254. package/transforms/transforms.test.ts +177 -0
  255. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  256. package/tunnel/createTunnel.ts +5 -1
  257. package/tunnel/ssh2Module.test.ts +37 -0
  258. package/tunnel/ssh2Module.ts +28 -0
  259. package/tunnel/sshTunnel.ts +4 -2
  260. package/typecheck/projectTypecheck.test.ts +32 -1
  261. package/typecheck/projectTypecheck.ts +3 -3
  262. package/typecheck/typeChecker.test.ts +49 -0
  263. package/typecheck/typeChecker.ts +9 -7
  264. package/typecheck/withheldDiagnostics.ts +41 -0
  265. package/util/devInstallCommand.ts +7 -0
  266. package/util/jsonFormatter.test.ts +13 -9
  267. package/workflow/executor.ts +6 -2
  268. package/workflow/index.ts +1 -0
  269. package/workflow/plan.ts +36 -7
  270. package/workflow/types.ts +1 -1
  271. package/workflow/uiTarget.ts +50 -0
  272. package/workspace/envSeed.test.ts +30 -1
  273. package/workspace/envSeed.ts +30 -1
  274. package/workspace/mainCheckout.test.ts +55 -0
  275. package/workspace/mainCheckout.ts +38 -0
  276. package/workspace/scanInfo.test.ts +39 -0
  277. package/workspace/scanInfo.ts +55 -6
  278. package/workspace/slicePlanner.ts +2 -1
  279. package/workspace/workspaceLayout.test.ts +22 -1
  280. package/workspace/workspaceLayout.ts +3 -3
  281. package/CHANGELOG.md +0 -2904
  282. package/codeAgent/agent/AkanCodeCompaction.ts +0 -49
  283. package/codeAgent/agent/AkanCodeServices.ts +0 -122
  284. package/codeAgent/agent/AkanContextFiles.ts +0 -94
  285. package/codeAgent/agent/CodeAgent.ts +0 -626
  286. package/codeAgent/agent/CodeAgentAllowed.ts +0 -35
  287. package/codeAgent/agent/CodeAgentAsks.ts +0 -66
  288. package/codeAgent/agent/CodeAgentCommandLine.ts +0 -372
  289. package/codeAgent/agent/CodeAgentEventMapper.ts +0 -225
  290. package/codeAgent/agent/CodeAgentGate.ts +0 -258
  291. package/codeAgent/agent/CodeAgentProxy.ts +0 -83
  292. package/codeAgent/agent/CodeAgentRpcHost.ts +0 -109
  293. package/codeAgent/agent/CodeAgentRpcListener.ts +0 -195
  294. package/codeAgent/agent/CodeAgentStreamPrinter.ts +0 -86
  295. package/codeAgent/agent/CodeAgentSuspended.ts +0 -85
  296. package/codeAgent/agent/CodeAgentUi.ts +0 -47
  297. package/codeAgent/agent/CodeMailbox.ts +0 -148
  298. package/codeAgent/agent/CodeSessionFork.ts +0 -56
  299. package/codeAgent/agent/CodeSessionIndex.ts +0 -78
  300. package/codeAgent/agent/SubagentPool.ts +0 -219
  301. package/codeAgent/agent/WorkspaceTrust.ts +0 -200
  302. package/codeAgent/agent/akanCodeCompaction.test.ts +0 -36
  303. package/codeAgent/agent/akanCodeModel.ts +0 -47
  304. package/codeAgent/agent/akanCodeServices.test.ts +0 -54
  305. package/codeAgent/agent/akanContextFiles.test.ts +0 -116
  306. package/codeAgent/agent/akanSystemPrompt.ts +0 -50
  307. package/codeAgent/agent/codeAgent.test.ts +0 -337
  308. package/codeAgent/agent/codeAgentCommandLine.test.ts +0 -212
  309. package/codeAgent/agent/codeAgentContract.test.ts +0 -755
  310. package/codeAgent/agent/codeAgentHosts.ts +0 -30
  311. package/codeAgent/agent/codeAgentProxy.test.ts +0 -126
  312. package/codeAgent/agent/codeAgentRpcListener.test.ts +0 -215
  313. package/codeAgent/agent/codeAgentSuspended.test.ts +0 -47
  314. package/codeAgent/agent/codeMailbox.test.ts +0 -76
  315. package/codeAgent/agent/codeSessionFork.test.ts +0 -58
  316. package/codeAgent/agent/codeSessionIndex.test.ts +0 -77
  317. package/codeAgent/agent/consoleToStderr.ts +0 -8
  318. package/codeAgent/agent/jsonLines.ts +0 -29
  319. package/codeAgent/agent/stringArg.ts +0 -5
  320. package/codeAgent/feedback/DevLogFeedback.ts +0 -82
  321. package/codeAgent/feedback/PreviewFeedback.ts +0 -46
  322. package/codeAgent/feedback/TurnFeedback.ts +0 -98
  323. package/codeAgent/feedback/VerifyFeedback.ts +0 -39
  324. package/codeAgent/tools/AkanCli.ts +0 -51
  325. package/codeAgent/tools/AkanCodePlugins.ts +0 -142
  326. package/codeAgent/tools/AkanEditScope.ts +0 -53
  327. package/codeAgent/tools/AkanEnvKeys.ts +0 -50
  328. package/codeAgent/tools/AkanToolPack.ts +0 -86
  329. package/codeAgent/tools/AkanVerifier.ts +0 -30
  330. package/codeAgent/tools/AskToolPack.ts +0 -99
  331. package/codeAgent/tools/DeepSeekWeb.ts +0 -127
  332. package/codeAgent/tools/MailToolPack.ts +0 -76
  333. package/codeAgent/tools/McpClient.ts +0 -209
  334. package/codeAgent/tools/McpOAuth.ts +0 -233
  335. package/codeAgent/tools/McpOAuthLoopback.ts +0 -64
  336. package/codeAgent/tools/McpServerConfig.ts +0 -131
  337. package/codeAgent/tools/McpSignIn.ts +0 -158
  338. package/codeAgent/tools/McpTokenStore.ts +0 -128
  339. package/codeAgent/tools/McpToolPack.ts +0 -206
  340. package/codeAgent/tools/SessionToolPack.ts +0 -91
  341. package/codeAgent/tools/WebToolPack.ts +0 -315
  342. package/codeAgent/tools/akanCodePlugins.test.ts +0 -954
  343. package/codeAgent/tools/askToolPack.test.ts +0 -116
  344. package/codeAgent/tools/deepSeekWeb.test.ts +0 -113
  345. package/codeAgent/tools/mcpOAuth.test.ts +0 -648
  346. package/codeAgent/tools/mcpServerConfig.test.ts +0 -341
  347. package/piDependencyPins.test.ts +0 -45
@@ -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,37 @@ 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
+
88
130
  test("writes beside main.js the env its Dockerfile sets, so a host without the image runs the build as is", async () => {
89
131
  const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
90
132
  const config = new AkanAppConfig(
@@ -94,9 +136,12 @@ console.info(new SampleService().name);
94
136
  {},
95
137
  { repoName: "akanjs", serveDomain: "akanjs.com", env: "local", portOffset: 0, workspaceRoot: root },
96
138
  );
139
+ const dist = new Executor("dist", root);
140
+ const printed = spyOn(dist.logger, "rawLog").mockImplementation(() => undefined);
97
141
  const app = {
98
142
  getConfig: async () => config,
99
- dist: new Executor("dist", root),
143
+ getScanInfo: () => ({ getLibs: () => [] }),
144
+ dist,
100
145
  workspace: { workspaceRoot: root },
101
146
  logger: { warn: () => undefined },
102
147
  } as unknown as App;
@@ -113,6 +158,10 @@ console.info(new SampleService().name);
113
158
  expect(await builtEnv()).toEqual(config.getProductionEnv("debug"));
114
159
  expect(await builtEnv()).toEqual(await dockerfileEnv());
115
160
  expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_APP_NAME: "portal", AKAN_PUBLIC_ENV: "debug" });
161
+ expect((await readFile(path.join(root, ".dockerignore"), "utf8")).split("\n")).toEqual(
162
+ expect.arrayContaining(["sqlite", "local", "runtime", "data", ".akan/artifact/image-cache", "node_modules"]),
163
+ );
164
+ expect(printed).not.toHaveBeenCalled();
116
165
  await new ApplicationBuildRunner(app).buildAppMeta();
117
166
  expect(await builtEnv()).toMatchObject({ AKAN_PUBLIC_ENV: "local" });
118
167
  expect(await builtEnv()).toEqual(await dockerfileEnv());
@@ -121,6 +170,268 @@ console.info(new SampleService().name);
121
170
  }
122
171
  });
123
172
 
173
+ test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
174
+ const { root, workspace } = await createTempApp("portal");
175
+ await writeSecretEnvFixture(root, { app: "portal" });
176
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
177
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
178
+ for (const key of keys) delete process.env[key];
179
+ await writeFile(
180
+ path.join(root, ".env"),
181
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
182
+ );
183
+ const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
184
+ const app = AppExecutor.from(workspace, "portal");
185
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
186
+ app.prepareCommand = async () => {
187
+ throw new Error("stopped before the phases");
188
+ };
189
+ const runner = new ApplicationBuildRunner(app, options);
190
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
191
+ await runner.buildAppMeta();
192
+ const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
193
+ [key: string]: string;
194
+ };
195
+ const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
196
+ const dockerfileEnv = Object.fromEntries(
197
+ dockerfile
198
+ .split("\n")
199
+ .filter((line) => line.startsWith("ENV "))
200
+ .map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
201
+ );
202
+ expect(env).toEqual(dockerfileEnv);
203
+ expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
204
+ return env;
205
+ };
206
+ const names =
207
+ "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";
208
+ try {
209
+ const read = await metaOf({ secretEnv: "read" });
210
+ expect(read.AKAN_ENV_NAMES).toBe(names);
211
+ expect(read).not.toHaveProperty("AKAN_ENV_FALLBACK");
212
+ expect(await metaOf({ secretEnv: "inline" })).toMatchObject({
213
+ AKAN_ENV_NAMES: names,
214
+ AKAN_ENV_FALLBACK: "image",
215
+ });
216
+ const carried = await metaOf({});
217
+ expect(carried).not.toHaveProperty("AKAN_ENV_NAMES");
218
+ expect(carried).not.toHaveProperty("AKAN_ENV_FALLBACK");
219
+ } finally {
220
+ for (const key of keys) {
221
+ if (shellEnv[key] === undefined) delete process.env[key];
222
+ else process.env[key] = shellEnv[key];
223
+ }
224
+ await rm(root, { recursive: true, force: true });
225
+ }
226
+ });
227
+
228
+ test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
229
+ const { root, workspace } = await createTempApp("portal");
230
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
231
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
232
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
233
+ for (const key of keys) delete process.env[key];
234
+ await writeFile(
235
+ path.join(root, ".env"),
236
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
237
+ );
238
+ const app = AppExecutor.from(workspace, "portal");
239
+ let prepared = false;
240
+ app.prepareCommand = async () => {
241
+ prepared = true;
242
+ throw new Error("prepared");
243
+ };
244
+ try {
245
+ const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
246
+ .build()
247
+ .catch((error: Error) => error.message);
248
+ expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
249
+ expect(holdsSentinel(String(failure))).toBe(false);
250
+ expect(prepared).toBe(false);
251
+ } finally {
252
+ for (const key of keys) {
253
+ if (shellEnv[key] === undefined) delete process.env[key];
254
+ else process.env[key] = shellEnv[key];
255
+ }
256
+ await rm(root, { recursive: true, force: true });
257
+ }
258
+ });
259
+
260
+ 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, and an --inline-secrets build warns and holds the env as written", async () => {
261
+ const { root, workspace } = await createTempApp("portal");
262
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
263
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
264
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
265
+ for (const key of keys) delete process.env[key];
266
+ await writeFile(
267
+ path.join(root, ".env"),
268
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
269
+ );
270
+ const started = async (secretEnv: "read" | "inline") => {
271
+ const app = AppExecutor.from(workspace, "portal");
272
+ const warnings: string[] = [];
273
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
274
+ warnings.push(message);
275
+ });
276
+ app.prepareCommand = async () => {
277
+ throw new Error("stopped before the phases");
278
+ };
279
+ const runner = new ApplicationBuildRunner(app, { secretEnv });
280
+ const failure = await runner.build().then(
281
+ () => "",
282
+ (error: Error) => error.message,
283
+ );
284
+ return { app, runner, failure, warnings };
285
+ };
286
+ const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
287
+ await runner.buildAppMeta();
288
+ return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
289
+ [key: string]: string;
290
+ };
291
+ };
292
+ const place =
293
+ /env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
294
+ try {
295
+ const stopped = await started("read");
296
+ expect(stopped.failure).toMatch(place);
297
+ expect(stopped.failure).toContain("Make the file load at that line");
298
+ expect(holdsSentinel(stopped.failure)).toBe(false);
299
+
300
+ const inlined = await started("inline");
301
+ expect(inlined.failure).toBe("stopped before the phases");
302
+ expect(inlined.warnings).toHaveLength(1);
303
+ expect(inlined.warnings[0]).toMatch(place);
304
+ expect(inlined.warnings[0]).toStartWith("--inline-secrets: env.server.ts could not be evaluated");
305
+ expect(holdsSentinel(inlined.warnings.join())).toBe(false);
306
+ const written = await envOf(inlined);
307
+ expect(written).not.toHaveProperty("AKAN_ENV_NAMES");
308
+ expect(written).not.toHaveProperty("AKAN_ENV_FALLBACK");
309
+
310
+ process.env.ZQ_HOSTS = "a.example.test,b.example.test";
311
+ const built = await started("read");
312
+ expect(built.failure).toBe("stopped before the phases");
313
+ expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
314
+ } finally {
315
+ for (const key of keys) {
316
+ if (shellEnv[key] === undefined) delete process.env[key];
317
+ else process.env[key] = shellEnv[key];
318
+ }
319
+ await rm(root, { recursive: true, force: true });
320
+ }
321
+ });
322
+
323
+ 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 () => {
324
+ const { root, workspace } = await createTempApp("portal");
325
+ await writeComputedSecretFixture(root, "portal");
326
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
327
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
328
+ for (const key of keys) delete process.env[key];
329
+ await writeFile(
330
+ path.join(root, ".env"),
331
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
332
+ );
333
+ const started = async (secretEnv: "read" | "inline") => {
334
+ const app = AppExecutor.from(workspace, "portal");
335
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
336
+ let prepared = false;
337
+ app.prepareCommand = async () => {
338
+ prepared = true;
339
+ throw new Error("stopped before the phases");
340
+ };
341
+ const failure = await new ApplicationBuildRunner(app, { secretEnv }).build().then(
342
+ () => "",
343
+ (error: Error) => error.message,
344
+ );
345
+ return { failure, prepared: () => prepared };
346
+ };
347
+ try {
348
+ const stopped = await started("read");
349
+ expect(stopped.prepared()).toBe(false);
350
+ expect(stopped.failure).toStartWith(
351
+ `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`,
352
+ );
353
+ expect(holdsSentinel(stopped.failure)).toBe(false);
354
+ for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
355
+ const inlined = await started("inline");
356
+ expect(inlined.prepared()).toBe(true);
357
+ expect(inlined.failure).toBe("stopped before the phases");
358
+ } finally {
359
+ for (const key of keys) {
360
+ if (shellEnv[key] === undefined) delete process.env[key];
361
+ else process.env[key] = shellEnv[key];
362
+ }
363
+ await rm(root, { recursive: true, force: true });
364
+ }
365
+ });
366
+
367
+ 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 () => {
368
+ const { root, workspace } = await createTempApp("portal");
369
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
370
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
371
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
372
+ for (const key of keys) delete process.env[key];
373
+ await writeFile(
374
+ path.join(root, ".env"),
375
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
376
+ );
377
+ const runnerOf = async (secretEnv: "read" | "inline") => {
378
+ const app = AppExecutor.from(workspace, "portal");
379
+ const warnings: string[] = [];
380
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
381
+ warnings.push(message);
382
+ });
383
+ app.prepareCommand = async () => {
384
+ throw new Error("stopped before the phases");
385
+ };
386
+ const runner = new ApplicationBuildRunner(app, { secretEnv });
387
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
388
+ return { app, runner, warnings };
389
+ };
390
+ try {
391
+ const { app, runner, warnings } = await runnerOf("read");
392
+ await mkdir(app.dist.cwdPath, { recursive: true });
393
+ await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
394
+ await runner.assertSecretsLeftOut();
395
+ expect(warnings).toEqual([]);
396
+ await writeFile(
397
+ path.join(app.dist.cwdPath, "chunk-a.js"),
398
+ `const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
399
+ );
400
+ await runner.assertSecretsLeftOut();
401
+ expect(warnings).toHaveLength(1);
402
+ expect(warnings[0]).toContain(
403
+ "\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
404
+ );
405
+ expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
406
+ await writeFile(
407
+ path.join(app.dist.cwdPath, "chunk-b.js"),
408
+ `const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
409
+ );
410
+ const failure = await runner.assertSecretsLeftOut().then(
411
+ () => "",
412
+ (error: Error) => error.message,
413
+ );
414
+ expect(failure).toStartWith(
415
+ [
416
+ "The build holds secret values the server reads from its process env, so it stops here:",
417
+ " chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
418
+ " chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
419
+ "",
420
+ ].join("\n"),
421
+ );
422
+ expect(holdsSentinel(failure)).toBe(false);
423
+ const inlined = await runnerOf("inline");
424
+ await inlined.runner.assertSecretsLeftOut();
425
+ expect(inlined.warnings.join("\n")).not.toContain("also in what this build wrote");
426
+ } finally {
427
+ for (const key of keys) {
428
+ if (shellEnv[key] === undefined) delete process.env[key];
429
+ else process.env[key] = shellEnv[key];
430
+ }
431
+ await rm(root, { recursive: true, force: true });
432
+ }
433
+ });
434
+
124
435
  test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
125
436
  const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
126
437
  const config = new AkanAppConfig(
@@ -133,6 +444,7 @@ console.info(new SampleService().name);
133
444
  const warnings: string[] = [];
134
445
  const app = {
135
446
  getConfig: async () => config,
447
+ getScanInfo: () => ({ getLibs: () => [] }),
136
448
  dist: new Executor("dist", root),
137
449
  workspace: { workspaceRoot: root },
138
450
  logger: { warn: (message: string) => warnings.push(message) },
@@ -379,16 +691,16 @@ console.info(new SampleService().name);
379
691
  expect(order).toEqual(["routes"]);
380
692
  });
381
693
 
382
- test("akan typecheck names the script/ files nothing imports, and a build's typecheck leaves them out", async () => {
694
+ test("akan typecheck asks for the tests and script/ files nothing imports, and a build's typecheck does not", async () => {
383
695
  const { root, app } = await createTempApp("portal");
384
696
  const run = spyOn(ProjectTypecheck.prototype, "run").mockImplementation(async () => "");
385
697
  try {
386
698
  const runner = new ApplicationBuildRunner(app);
387
699
  await runner.typecheck({ tests: true });
388
700
  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");
701
+ const [checked, built] = run.mock.calls.map(([, options]) => options?.tests);
702
+ expect(checked).toBe(true);
703
+ expect(built).toBeUndefined();
392
704
  } finally {
393
705
  run.mockRestore();
394
706
  await rm(root, { recursive: true, force: true });
@@ -455,6 +767,47 @@ console.info(new SampleService().name);
455
767
  }
456
768
  });
457
769
 
770
+ test("main.js sets the build's env before a package the bundle leaves outside loads", async () => {
771
+ const { root, workspace } = await createTempApp("portal");
772
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
773
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
774
+ await Promise.all(["main.ts", "server.ts"].map((file) => writeFile(path.join(root, "apps", "portal", file), "")));
775
+ const app = AppExecutor.from(workspace, "portal");
776
+ app.prepareCommand = async () => ({ env: {} });
777
+ const bundle = spyOn(Bun, "build").mockImplementation(
778
+ async () => ({ success: true, outputs: [], logs: [] }) as unknown as Bun.BuildOutput,
779
+ );
780
+ try {
781
+ await new ApplicationBuildRunner(app, { verify: true }).build();
782
+ const configs = bundle.mock.calls.map(([config]) => config);
783
+ const envModule = configs.find(({ entrypoints }) =>
784
+ entrypoints.some((entry) => entry.endsWith("loadBuildEnv.ts")),
785
+ );
786
+ const main = configs.find(({ entrypoints }) => entrypoints.some((entry) => entry.endsWith("main.ts")));
787
+ bundle.mockRestore();
788
+ if (!envModule || !main) throw new Error("the build made no env module or no main bundle");
789
+ const { entry: mainBundle } = main.naming as { entry: string };
790
+ await Bun.build(envModule);
791
+ const dist = app.dist.cwdPath;
792
+ await mkdir(path.join(dist, "node_modules", "probe"), { recursive: true });
793
+ await writeFile(path.join(dist, "node_modules", "probe", "index.js"), "module.exports = process.env.NODE_ENV;\n");
794
+ await writeFile(path.join(dist, "akan.env.json"), '{ "NODE_ENV": "production" }\n');
795
+ await writeFile(path.join(dist, mainBundle), 'import mode from "probe";\nconsole.log(mode);\n');
796
+ const { NODE_ENV: _mode, ...env } = process.env;
797
+ const proc = Bun.spawnSync([process.execPath, "main.js"], { cwd: dist, env, stdout: "pipe", stderr: "pipe" });
798
+
799
+ expect(proc.stderr.toString()).toBe("");
800
+ expect(proc.stdout.toString()).toBe("production\n");
801
+ } finally {
802
+ bundle.mockRestore();
803
+ for (const key of keys) {
804
+ if (shellEnv[key] === undefined) delete process.env[key];
805
+ else process.env[key] = shellEnv[key];
806
+ }
807
+ await rm(root, { recursive: true, force: true });
808
+ }
809
+ });
810
+
458
811
  test("a verify build writes to dist/verify/<app> and leaves the full build in dist/apps/<app> as it was", async () => {
459
812
  const { root, workspace } = await createTempApp("portal");
460
813
  const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;