@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
@@ -0,0 +1,73 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import path from "node:path";
3
+ import { AppWorkerPath } from "akanjs/server/appWorkerPath";
4
+ import { AkanWorkers, type LibWorkers } from "./akanWorkers";
5
+
6
+ const owner = "apps/face/akan.config.ts";
7
+ const published = process.env[AppWorkerPath.envKey];
8
+
9
+ afterEach(() => {
10
+ if (published === undefined) delete process.env[AppWorkerPath.envKey];
11
+ else process.env[AppWorkerPath.envKey] = published;
12
+ });
13
+
14
+ describe("AkanWorkers", () => {
15
+ test("resolves each entry against the folder that declares it", () => {
16
+ expect(AkanWorkers.parse({ vision: "srvkit/_vision/visionWorker.ts" }, owner, "/repo/apps/face")).toEqual({
17
+ vision: path.resolve("/repo/apps/face/srvkit/_vision/visionWorker.ts"),
18
+ });
19
+ expect(AkanWorkers.parse(undefined, owner, "/repo/apps/face")).toEqual({});
20
+ });
21
+
22
+ test("refuses a name that is no file name and an entry that is no relative source file", () => {
23
+ const parse = (declared: unknown) => () => AkanWorkers.parse(declared, owner, "/repo/apps/face");
24
+
25
+ expect(parse(["vision"])).toThrow(`${owner}: workers maps each worker's name to its entry file`);
26
+ expect(parse({ "../vision": "a.ts" })).toThrow("workers.../vision is not a name");
27
+ expect(parse({ vision: "/abs/visionWorker.ts" })).toThrow("workers.vision must be a .ts or .js file");
28
+ expect(parse({ vision: "srvkit/vision" })).toThrow("workers.vision must be a .ts or .js file");
29
+ expect(parse({ vision: 1 })).toThrow("workers.vision must be a .ts or .js file");
30
+ });
31
+
32
+ test("publishes the sources a source run spawns from, and takes them back when none is declared", () => {
33
+ const workers = AkanWorkers.parse({ vision: "visionWorker.ts" }, owner, "/repo/apps/face");
34
+
35
+ expect(AkanWorkers.publish(AkanWorkers.select({ owner, workers }, [], []))).toEqual(workers);
36
+ expect(AppWorkerPath.sources()).toEqual(workers);
37
+ AkanWorkers.publish(AkanWorkers.select({ owner, workers: {} }, [], []));
38
+ expect(process.env[AppWorkerPath.envKey]).toBeUndefined();
39
+ });
40
+
41
+ test("adds the workers of the libs named, and the declarer's own entry wins a name", () => {
42
+ const libWorkers: LibWorkers[] = [
43
+ {
44
+ lib: "edge",
45
+ workers: { vision: "/repo/libs/edge/srvkit/vision.worker.ts", encode: "/repo/libs/edge/encode.ts" },
46
+ },
47
+ { lib: "other", workers: { ocr: "/repo/libs/other/ocr.ts" } },
48
+ ];
49
+ const chosen = AkanWorkers.select({ owner, workers: { vision: "/repo/apps/face/vision.ts" } }, libWorkers, [
50
+ "edge",
51
+ ]);
52
+
53
+ expect(Object.fromEntries(chosen)).toEqual({
54
+ vision: { owner, entry: "/repo/apps/face/vision.ts" },
55
+ encode: { owner: "libs/edge/akan.config.ts", entry: "/repo/libs/edge/encode.ts" },
56
+ });
57
+ });
58
+
59
+ test("refuses one name two of the named libs declare differently, unless told to keep the first", () => {
60
+ const libWorkers: LibWorkers[] = [
61
+ { lib: "edge", workers: { vision: "/repo/libs/edge/vision.ts" } },
62
+ { lib: "lab", workers: { vision: "/repo/libs/lab/vision.ts" } },
63
+ ];
64
+ const select = (libs: string[], strict?: boolean) =>
65
+ AkanWorkers.select({ owner, workers: {} }, libWorkers, libs, { strict });
66
+
67
+ expect(() => select(["edge", "lab"])).toThrow(
68
+ `libs/edge/akan.config.ts and libs/lab/akan.config.ts declare workers.vision differently; declare it in ${owner} to pick one.`,
69
+ );
70
+ expect(select(["lab"]).get("vision")?.entry).toBe("/repo/libs/lab/vision.ts");
71
+ expect(select(["edge", "lab"], false).get("vision")?.entry).toBe("/repo/libs/edge/vision.ts");
72
+ });
73
+ });
@@ -0,0 +1,61 @@
1
+ import path from "node:path";
2
+ import { AppWorkerPath } from "akanjs/server/appWorkerPath";
3
+ import type { AkanWorkersConfig } from "./types";
4
+
5
+ export interface WorkerDeclarer {
6
+ owner: string;
7
+ workers: AkanWorkersConfig;
8
+ }
9
+
10
+ export interface LibWorkers {
11
+ lib: string;
12
+ workers: AkanWorkersConfig;
13
+ }
14
+
15
+ export class AkanWorkers {
16
+ static readonly entry = /\.(ts|mts|js|mjs)$/;
17
+
18
+ /** The declarer's own entries, then those of the libs named: its own wins a name, two libs may not differ on one. */
19
+ static select(own: WorkerDeclarer, libWorkers: LibWorkers[], libs: string[], { strict = true } = {}) {
20
+ const chosen = new Map<string, { owner: string; entry: string }>();
21
+ for (const [name, entry] of Object.entries(own.workers)) chosen.set(name, { owner: own.owner, entry });
22
+ for (const { lib, workers } of libWorkers) {
23
+ if (!libs.includes(lib)) continue;
24
+ const owner = `libs/${lib}/akan.config.ts`;
25
+ for (const [name, entry] of Object.entries(workers)) {
26
+ const held = chosen.get(name);
27
+ if (!held) chosen.set(name, { owner, entry });
28
+ else if (strict && held.owner !== own.owner && held.entry !== entry)
29
+ throw new Error(
30
+ `${held.owner} and ${owner} declare workers.${name} differently; declare it in ${own.owner} to pick one.`,
31
+ );
32
+ }
33
+ }
34
+ return chosen;
35
+ }
36
+
37
+ //? Published to `process.env`, as the route prefixes are: every process the CLI starts from source inherits it.
38
+ static publish(chosen: Map<string, { entry: string }>): AkanWorkersConfig {
39
+ const sources = Object.fromEntries([...chosen].map(([name, { entry }]) => [name, entry]));
40
+ if (chosen.size) process.env[AppWorkerPath.envKey] = JSON.stringify(sources);
41
+ else delete process.env[AppWorkerPath.envKey];
42
+ return sources;
43
+ }
44
+
45
+ static parse(declared: unknown, owner: string, baseDir: string): AkanWorkersConfig {
46
+ if (declared === undefined) return {};
47
+ if (!declared || typeof declared !== "object" || Array.isArray(declared))
48
+ throw new Error(`${owner}: workers maps each worker's name to its entry file`);
49
+ return Object.fromEntries(
50
+ Object.entries(declared).map(([name, entry]) => {
51
+ if (!AppWorkerPath.validName.test(name))
52
+ throw new Error(`${owner}: workers.${name} is not a name (letters, digits, - and _)`);
53
+ if (typeof entry !== "string" || !AkanWorkers.entry.test(entry) || path.isAbsolute(entry))
54
+ throw new Error(
55
+ `${owner}: workers.${name} must be a .ts or .js file, relative to this config (got ${JSON.stringify(entry)})`,
56
+ );
57
+ return [name, path.resolve(baseDir, entry)];
58
+ }),
59
+ );
60
+ }
61
+ }
@@ -0,0 +1,96 @@
1
+ import type { ServerPolicy } from "akanjs/native/api";
2
+ import { ServerEnvProfile } from "../transforms/serverEnvProfile";
3
+ import type { AkanNativeDesktopConfig } from "./types";
4
+
5
+ export class DesktopServerConfig {
6
+ //? `true` or `{ omit, profile, modules }`: lists trimmed once, so two targets that agree on them stage one server.
7
+ static resolve<T extends { server?: AkanNativeDesktopConfig["server"] }>(
8
+ desktop: T,
9
+ where: string,
10
+ configPath: string,
11
+ ): T {
12
+ const { server } = desktop;
13
+ if (server === undefined || typeof server === "boolean") return desktop;
14
+ if (!DesktopServerConfig.#isPlainObject(server))
15
+ throw new Error(`${where} in ${configPath} must be true or { omit, profile, modules }.`);
16
+ const names = (list: unknown, key: string, what: string) => {
17
+ if (list === undefined) return [];
18
+ if (!Array.isArray(list) || list.some((name) => typeof name !== "string" || !name.trim()))
19
+ throw new Error(`${where}.${key} in ${configPath} must be a list of ${what}.`);
20
+ return [...new Set(list.map((name: string) => name.trim()))].sort();
21
+ };
22
+ const { profile } = server;
23
+ if (profile !== undefined && (typeof profile !== "string" || !ServerEnvProfile.namePattern.test(profile)))
24
+ throw new Error(
25
+ `${where}.profile in ${configPath} names env/env.server.<env>.<profile>.ts: a lowercase-first name of letters, digits and dashes.`,
26
+ );
27
+ const modules = names(server.modules, "modules", "module names or @<operationMode> selectors");
28
+ const env = DesktopServerConfig.#env(server.env, where, configPath);
29
+ const { restart } = server;
30
+ if (restart !== undefined && restart !== "forever" && !(Number.isInteger(restart) && (restart as number) > 0))
31
+ throw new Error(`${where}.restart in ${configPath} must be "forever" or a count of crashes in a row from 1.`);
32
+ const watchdog = DesktopServerConfig.#watchdog(server.watchdog, where, configPath);
33
+ return {
34
+ ...desktop,
35
+ server: {
36
+ omit: names(server.omit, "omit", "package names"),
37
+ ...(profile ? { profile } : {}),
38
+ ...(modules.length ? { modules } : {}),
39
+ ...(Object.keys(env).length ? { env } : {}),
40
+ ...(restart !== undefined ? { restart } : {}),
41
+ ...(watchdog ? { watchdog } : {}),
42
+ },
43
+ };
44
+ }
45
+ //? The stage owns these: the operation mode, the database mode, what is served and the shutdown budget the shell's
46
+ //? quit waits on are what make it the carried server.
47
+ static readonly #stagedEnv = new Set([
48
+ "AKAN_PUBLIC_OPERATION_MODE",
49
+ "AKAN_DATABASE_MODE",
50
+ "AKAN_DATABASE_MODES",
51
+ "AKAN_SSR",
52
+ "AKAN_CSR",
53
+ "AKAN_MCP",
54
+ "AKAN_SHUTDOWN_TIMEOUT_MS",
55
+ "AKAN_MODULES",
56
+ ]);
57
+ static #env(env: unknown, where: string, configPath: string): Record<string, string> {
58
+ if (env === undefined) return {};
59
+ if (!DesktopServerConfig.#isPlainObject(env) || Object.values(env).some((value) => typeof value !== "string"))
60
+ throw new Error(`${where}.env in ${configPath} must be an object of strings.`);
61
+ const staged = Object.keys(env).filter((key) => DesktopServerConfig.#stagedEnv.has(key.toUpperCase()));
62
+ if (staged.length)
63
+ throw new Error(
64
+ `${where}.env in ${configPath} sets ${staged.join(", ")}, which the carried server's stage owns (modules: desktop.server.modules).`,
65
+ );
66
+ const secrets = ServerEnvProfile.secretPaths(env);
67
+ if (secrets.length)
68
+ throw new Error(
69
+ `${where}.env in ${configPath} holds secret-named values (${secrets.join(", ")}), and the app carries its env where anyone on the computer reads it. Leave them out.`,
70
+ );
71
+ return env as Record<string, string>;
72
+ }
73
+ //? The akan.config.ts shape, which takes `true` and fills in what is left out; the launcher reads what this returns
74
+ //? with serverPolicyOf in @akanjs/native, which devkit cannot load while it reads a config.
75
+ static #watchdog(watchdog: unknown, where: string, configPath: string): ServerPolicy["watchdog"] | null {
76
+ if (watchdog === undefined || watchdog === false) return null;
77
+ const options = watchdog === true ? {} : watchdog;
78
+ const whole = (value: unknown) => value === undefined || (Number.isInteger(value) && (value as number) > 0);
79
+ if (
80
+ !DesktopServerConfig.#isPlainObject(options) ||
81
+ Object.keys(options).some((key) => key !== "intervalMs" && key !== "failures") ||
82
+ !whole(options.intervalMs) ||
83
+ !whole(options.failures)
84
+ )
85
+ throw new Error(
86
+ `${where}.watchdog in ${configPath} must be true or { intervalMs, failures }, whole numbers from 1.`,
87
+ );
88
+ return {
89
+ intervalMs: (options.intervalMs as number | undefined) ?? 10_000,
90
+ failures: (options.failures as number | undefined) ?? 3,
91
+ };
92
+ }
93
+ static #isPlainObject(value: unknown): value is Record<string, unknown> {
94
+ return typeof value === "object" && value !== null && !Array.isArray(value);
95
+ }
96
+ }
@@ -0,0 +1,250 @@
1
+ import { EnvProfile } from "akanjs/server/lifecycle/envProfile";
2
+ import {
3
+ type Arch,
4
+ archs,
5
+ type DockerConfig,
6
+ type DockerImageConfig,
7
+ type DockerOption,
8
+ type DockerRun,
9
+ type LibDockerConfig,
10
+ } from "./types";
11
+
12
+ //? A Bun bump changes both: `docker buildx imagetools inspect oven/bun:<version>-slim` prints the new multi-arch digest.
13
+ export const BUN_IMAGE_PIN = {
14
+ version: "1.4.4",
15
+ digest: "sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4",
16
+ } as const;
17
+ // `1-slim` floats to whichever Bun is newest at build time, one the framework was never tested on.
18
+ export const DEFAULT_DOCKER_IMAGE = `oven/bun:${BUN_IMAGE_PIN.version}-slim@${BUN_IMAGE_PIN.digest}`;
19
+ //? oven/bun's `bun` user, numeric so a kubelet can check `runAsNonRoot` without reading the image's passwd file.
20
+ export const DOCKER_RUN_USER = "1000:1000";
21
+ //? Bun as PID 1 never waits for a process re-parented to it, which stays defunct; `-s` reaps under another init too.
22
+ export const DOCKER_INIT = ["tini", "-s", "--"];
23
+ export const DOCKER_BASE_PACKAGES = ["ca-certificates", "tzdata", "tini"] as const;
24
+ //? Every generated image runs these on its base; an image built with them is one `baseSetup: false` can start from.
25
+ export const DOCKER_BASE_RUNS = [
26
+ `apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ${DOCKER_BASE_PACKAGES.join(" ")} && rm -rf /var/lib/apt/lists/*`,
27
+ "ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime",
28
+ ];
29
+ //? The directories the server writes, its code staying read-only; an empty named volume mounted on one takes its owner.
30
+ export const DOCKER_WRITE_DIRS = [
31
+ "/workspace/sqlite",
32
+ "/workspace/local",
33
+ "/workspace/runtime",
34
+ "/workspace/data",
35
+ "/workspace/.akan/artifact/image-cache",
36
+ ];
37
+
38
+ export const DOCKER_VARIANT_FILE_PREFIX = "Dockerfile.";
39
+ export const DOCKER_IGNORED = [
40
+ ...DOCKER_WRITE_DIRS.map((dir) => dir.slice("/workspace/".length)),
41
+ "node_modules",
42
+ //? Copied in, a variant's Dockerfile would rebuild every other image's `COPY . .` layer when it alone changed.
43
+ `${DOCKER_VARIANT_FILE_PREFIX}*`,
44
+ ];
45
+ export const DOCKER_INSTALL_STAGE = "install";
46
+ //? Raised when the sections change: a tool editing the file then meets a number it does not know, and can say so.
47
+ export const DOCKERFILE_FORMAT = 1;
48
+ export const dockerfileSections = ["install-stage", "base", "pre-runs", "install", "post-runs", "app"] as const;
49
+ export type DockerfileSection = (typeof dockerfileSections)[number];
50
+ const DOCKERFILE_MARK = "# akan:";
51
+ const DOCKERFILE_HEAD = `${DOCKERFILE_MARK}dockerfile `;
52
+ //? Bun names the CPU x64 where Docker's TARGETARCH says amd64.
53
+ const DOCKER_INSTALL_TARGET = `--os linux --cpu "$(echo "$TARGETARCH" | sed s/amd64/x64/)"`;
54
+
55
+ const archGuard = (arch: string, script: string) => `if [ "$TARGETARCH" = "${arch}" ]; then \
56
+ ${script}; \
57
+ fi`;
58
+
59
+ export const dockerRunScripts = (runs: DockerRun[]) =>
60
+ runs.map((run) =>
61
+ typeof run === "string"
62
+ ? `RUN ${run}`
63
+ : Object.entries(run)
64
+ .map(([arch, script]) => `RUN ${archGuard(arch, script)}`)
65
+ .join("\n"),
66
+ );
67
+
68
+ //? A stage named by `TARGETARCH` is the only one a build resolves, so the other architecture's image is never pulled.
69
+ export const dockerImageScript = (image: string | { [key in Arch]?: string }) =>
70
+ typeof image === "string"
71
+ ? `FROM ${image}`
72
+ : [...archs.map((arch) => `FROM ${image[arch] ?? DEFAULT_DOCKER_IMAGE} AS ${arch}`), "FROM $TARGETARCH"].join("\n");
73
+
74
+ //? Docker ends an unquoted ENV value at a space; inside quotes it still expands `$NAME`.
75
+ const dockerEnvValue = (value: string) => (/[\s"'\\]/.test(value) ? JSON.stringify(value) : value);
76
+
77
+ const dockerEnvLines = (build: Record<string, string>, declared: Record<string, string>) => {
78
+ const lines = new Map(Object.entries(build).map(([key, value]) => [key, `ENV ${key}=${value}`]));
79
+ for (const [key, value] of Object.entries(declared)) lines.set(key, `ENV ${key}=${dockerEnvValue(value)}`);
80
+ return [...lines.values()];
81
+ };
82
+
83
+ export interface DockerfileParts {
84
+ env: Record<string, string>;
85
+ lockfile: boolean;
86
+ /** Instructions the final stage opens with. */
87
+ guard?: string;
88
+ }
89
+
90
+ const dockerInstallScripts = (
91
+ { installRuns, crossBuild }: Pick<DockerImageConfig, "installRuns" | "crossBuild">,
92
+ lockfile: boolean,
93
+ ) => {
94
+ const install = `bun install --production${lockfile ? " --frozen-lockfile" : ""}${crossBuild ? ` ${DOCKER_INSTALL_TARGET}` : ""}`;
95
+ //? In a subshell each: a step ending in `|| true` would otherwise forgive a failed `bun install` before it.
96
+ const steps = installRuns.flatMap((run) =>
97
+ typeof run === "string" ? [`( ${run} )`] : Object.entries(run).map(([arch, script]) => archGuard(arch, script)),
98
+ );
99
+ return [
100
+ "WORKDIR /workspace",
101
+ lockfile ? "COPY ./package.json ./bun.lock ./" : "COPY ./package.json ./package.json",
102
+ `RUN ${[install, ...steps].join(" \\\n && ")}`,
103
+ ];
104
+ };
105
+
106
+ const dockerfileSectionOf = (section: DockerfileSection, instructions: string[]) =>
107
+ instructions.length ? [`${DOCKERFILE_MARK}${section}`, ...instructions] : [];
108
+
109
+ export const dockerfileOf = (docker: DockerImageConfig, { env, lockfile, guard }: DockerfileParts) => {
110
+ const { image, preRuns, postRuns, command, crossBuild, baseSetup } = docker;
111
+ const install = dockerInstallScripts(docker, lockfile);
112
+ return [
113
+ `${DOCKERFILE_HEAD}${DOCKERFILE_FORMAT}`,
114
+ ...dockerfileSectionOf(
115
+ "install-stage",
116
+ crossBuild
117
+ ? [
118
+ //? One image for every target: the stage runs on the build machine, where a per-architecture image may not.
119
+ `FROM --platform=$BUILDPLATFORM ${typeof image === "string" ? image : DEFAULT_DOCKER_IMAGE} AS ${DOCKER_INSTALL_STAGE}`,
120
+ "ARG TARGETARCH",
121
+ ...install,
122
+ ]
123
+ : [],
124
+ ),
125
+ ...dockerfileSectionOf("base", [
126
+ dockerImageScript(image),
127
+ ...(guard ? [guard] : []),
128
+ ...(baseSetup ? dockerRunScripts(DOCKER_BASE_RUNS) : []),
129
+ "ARG TARGETARCH",
130
+ ]),
131
+ ...dockerfileSectionOf("pre-runs", dockerRunScripts(preRuns)),
132
+ ...dockerfileSectionOf(
133
+ "install",
134
+ crossBuild ? ["WORKDIR /workspace", `COPY --from=${DOCKER_INSTALL_STAGE} /workspace ./`] : install,
135
+ ),
136
+ ...dockerfileSectionOf("post-runs", dockerRunScripts(postRuns)),
137
+ ...dockerfileSectionOf("app", [
138
+ "COPY . .",
139
+ `RUN mkdir -p ${DOCKER_WRITE_DIRS.join(" ")} && chown ${DOCKER_RUN_USER} ${DOCKER_WRITE_DIRS.join(" ")}`,
140
+ ...dockerEnvLines(env, docker.env),
141
+ `USER ${DOCKER_RUN_USER}`,
142
+ `ENTRYPOINT ${JSON.stringify(DOCKER_INIT)}`,
143
+ `CMD ${JSON.stringify(command)}`,
144
+ ]),
145
+ ].join("\n");
146
+ };
147
+
148
+ export interface DockerfileLayout {
149
+ format: number;
150
+ /** Each section's lines under its marker, in the file's order; a newer format may name one this version lacks. */
151
+ sections: Map<string, string[]>;
152
+ }
153
+
154
+ export const dockerfileLayoutOf = (dockerfile: string): DockerfileLayout | null => {
155
+ const [head = "", ...lines] = dockerfile.split("\n");
156
+ if (!/^# akan:dockerfile \d+$/.test(head)) return null;
157
+ const sections = new Map<string, string[]>();
158
+ let current: string[] | null = null;
159
+ for (const line of lines) {
160
+ if (line.startsWith(DOCKERFILE_MARK)) {
161
+ current = [];
162
+ sections.set(line.slice(DOCKERFILE_MARK.length), current);
163
+ } else current?.push(line);
164
+ }
165
+ return { format: Number(head.slice(DOCKERFILE_HEAD.length)), sections };
166
+ };
167
+
168
+ /** First occurrence wins, so a step a lib and its app both declare becomes one layer. */
169
+ const dedupeDockerRuns = (runs: DockerRun[]): DockerRun[] => {
170
+ const byKey = new Map<string, DockerRun>();
171
+ for (const run of runs) byKey.set(typeof run === "string" ? run : JSON.stringify(run), run);
172
+ return [...byKey.values()];
173
+ };
174
+
175
+ const dockerEnvKeyPattern = /^[A-Za-z_][A-Za-z0-9_]*$/;
176
+ //? The name ends `Dockerfile.<name>`, which a shell, a CI step and `docker build -f` all take unquoted.
177
+ const dockerVariantNamePattern = /^[a-z][a-z0-9-]*$/;
178
+
179
+ const resolveDockerImage = (
180
+ docker: Partial<DockerImageConfig>,
181
+ libDocker: LibDockerConfig,
182
+ owner: string,
183
+ ): DockerImageConfig => {
184
+ const env = docker.env ?? {};
185
+ for (const [key, value] of Object.entries(env)) {
186
+ if (!dockerEnvKeyPattern.test(key))
187
+ throw new Error(`[docker] ${owner}.env names "${key}", which is not an environment variable name`);
188
+ if (/[\r\n]/.test(value))
189
+ throw new Error(`[docker] ${owner}.env.${key} holds a line break, which an ENV line cannot carry`);
190
+ }
191
+ const { image } = docker;
192
+ const baseSetup = docker.baseSetup ?? true;
193
+ //? The pinned default has no tini, the entrypoint: an image skipping the base step without one never starts.
194
+ if (!baseSetup && (!image || (typeof image !== "string" && archs.some((arch) => !image[arch]))))
195
+ throw new Error(
196
+ `[docker] ${owner}.baseSetup is false, so ${owner}.image has to name an image built with the base step, for every architecture`,
197
+ );
198
+ return {
199
+ image: image ?? DEFAULT_DOCKER_IMAGE,
200
+ preRuns: dedupeDockerRuns([...libDocker.preRuns, ...(docker.preRuns ?? [])]),
201
+ installRuns: dedupeDockerRuns([...libDocker.installRuns, ...(docker.installRuns ?? [])]),
202
+ postRuns: dedupeDockerRuns([...libDocker.postRuns, ...(docker.postRuns ?? [])]),
203
+ command: docker.command ?? ["bun", "main.js"],
204
+ crossBuild: docker.crossBuild ?? false,
205
+ baseSetup,
206
+ env,
207
+ };
208
+ };
209
+
210
+ //? A build carries a profile only when a variant names it; set as a plain `ENV`, the server would refuse to start.
211
+ const assertProfileNamed = (env: Record<string, string> | undefined, owner: string) => {
212
+ if (env && EnvProfile.key in env)
213
+ throw new Error(
214
+ `[docker] ${owner}.env sets ${EnvProfile.key}, which the build has to know to carry the profile: name it as docker.variants.<name>.profile`,
215
+ );
216
+ };
217
+
218
+ /** A declared Dockerfile string is verbatim, so a lib's steps are dropped rather than silently unapplied. */
219
+ export const resolveDocker = (docker: DockerOption | undefined, libDocker: LibDockerConfig): DockerConfig => {
220
+ if (typeof docker === "string") return docker;
221
+ assertProfileNamed(docker?.env, "docker");
222
+ return resolveDockerImage(docker ?? {}, libDocker, "docker");
223
+ };
224
+
225
+ export const resolveDockerVariants = (
226
+ docker: DockerOption | undefined,
227
+ libDocker: LibDockerConfig,
228
+ ): Record<string, DockerImageConfig> => {
229
+ if (typeof docker === "string" || !docker?.variants) return {};
230
+ const { variants, ...base } = docker;
231
+ return Object.fromEntries(
232
+ Object.entries(variants).map(([name, { profile, ...variant }]) => {
233
+ if (!dockerVariantNamePattern.test(name))
234
+ throw new Error(
235
+ `[docker] docker.variants names "${name}", which cannot end a file name: use lowercase letters, digits and "-"`,
236
+ );
237
+ assertProfileNamed(variant.env, `docker.variants.${name}`);
238
+ if (profile !== undefined && !EnvProfile.namePattern.test(profile))
239
+ throw new Error(
240
+ `[docker] docker.variants.${name}.profile is "${profile}", which is not a server env profile name: a lowercase-first name of letters, digits and dashes`,
241
+ );
242
+ const env = { ...base.env, ...variant.env, ...(profile ? { [EnvProfile.key]: profile } : {}) };
243
+ return [name, resolveDockerImage({ ...base, ...variant, env }, libDocker, `docker.variants.${name}`)];
244
+ }),
245
+ );
246
+ };
247
+
248
+ export const dockerProfilesOf = (variants: Record<string, DockerImageConfig>): string[] => [
249
+ ...new Set(Object.values(variants).flatMap(({ env }) => (env[EnvProfile.key] ? [env[EnvProfile.key]] : []))),
250
+ ];
@@ -1,4 +1,7 @@
1
1
  export * from "./akanBin";
2
2
  export * from "./akanConfig";
3
+ export * from "./akanPreview";
4
+ export * from "./akanWorkers";
3
5
  export * from "./akanWorkspaceConfig";
6
+ export * from "./dockerImage";
4
7
  export * from "./types";
@@ -0,0 +1,33 @@
1
+ import type { AkanNativeSettings } from "./types";
2
+
3
+ export class NativeFileSettings {
4
+ static readonly #androidFilePattern = /^(?:res\/[^/]+\/[^/]+|assets\/.+)$/;
5
+ static assert(settings: AkanNativeSettings, where: string, configPath: string) {
6
+ const check = (
7
+ files: Record<string, string> | undefined,
8
+ at: string,
9
+ valid: (to: string) => boolean,
10
+ shape: string,
11
+ ) => {
12
+ for (const [to, from] of Object.entries(files ?? {})) {
13
+ if (typeof from !== "string")
14
+ throw new Error(
15
+ `${at}["${to}"] in ${configPath} must name its source file, relative to the app folder, e.g. { "${shape}": "assets/chime.mp3" }.`,
16
+ );
17
+ if (!valid(to)) throw new Error(`${at}["${to}"] in ${configPath} must land at ${shape}.`);
18
+ }
19
+ };
20
+ check(
21
+ settings.ios?.files,
22
+ `${where}.ios.files`,
23
+ (to) => to.length > 0 && !to.startsWith("/") && !to.split("/").includes(".."),
24
+ "<path in the app bundle>",
25
+ );
26
+ check(
27
+ settings.android?.files,
28
+ `${where}.android.files`,
29
+ (to) => NativeFileSettings.#androidFilePattern.test(to),
30
+ "res/<type>/<file> or assets/<path>",
31
+ );
32
+ }
33
+ }
@@ -0,0 +1,52 @@
1
+ export const nativeKeys = {
2
+ native: [
3
+ "basePath",
4
+ "indexPath",
5
+ "appName",
6
+ "appId",
7
+ "fileName",
8
+ "version",
9
+ "buildNum",
10
+ "icon",
11
+ "splash",
12
+ "backgroundColor",
13
+ "permissions",
14
+ "plugins",
15
+ "deepLinks",
16
+ "updates",
17
+ "devtools",
18
+ "csp",
19
+ "openUrls",
20
+ "ios",
21
+ "android",
22
+ "desktop",
23
+ ],
24
+ ios: ["indexPath", "teamId", "infoPlist", "entitlements", "privacy", "files", "hideFormAccessoryBar"],
25
+ android: [
26
+ "indexPath",
27
+ "sha256CertFingerprints",
28
+ "googleServices",
29
+ "push",
30
+ "autoplay",
31
+ "manifest",
32
+ "application",
33
+ "activity",
34
+ "files",
35
+ ],
36
+ desktop: [
37
+ "indexPath",
38
+ "server",
39
+ "recovery",
40
+ "window",
41
+ "screenCapture",
42
+ "webview2",
43
+ "publisher",
44
+ "entitlements",
45
+ "dmg",
46
+ "externalView",
47
+ ],
48
+ externalView: ["allowOrigins", "evaluate", "sendKey"],
49
+ desktopServer: ["omit", "profile", "modules", "env", "restart", "watchdog"],
50
+ dmg: ["background", "background2x", "window", "iconSize", "textSize", "app", "applications"],
51
+ deepLinks: ["schemes", "domains"],
52
+ } as const;
@@ -22,11 +22,14 @@ export type {
22
22
  AkanNativeValue,
23
23
  AkanPlugin,
24
24
  AkanPluginNativeConfig,
25
+ AkanPreviewConfig,
26
+ AkanPreviewSignIn,
25
27
  AkanRouteConfig,
26
28
  AkanScanInfo,
27
29
  AkanSyncContext,
28
30
  AkanWebConfig,
29
31
  AkanWebOption,
32
+ AkanWorkersConfig,
30
33
  AppConfig,
31
34
  AppConfigInput,
32
35
  AppConfigResult,
@@ -43,6 +46,7 @@ export type {
43
46
  DockerImageConfig,
44
47
  DockerOption,
45
48
  DockerRun,
49
+ DockerVariantOption,
46
50
  FileConventionScanResult,
47
51
  LibAssetsConfig,
48
52
  LibConfig,
@@ -0,0 +1,63 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
+ import path from "node:path";
4
+ import type { AkanBinConfig } from "../akanConfig";
5
+ import { tempDirs } from "../test/testHelpers";
6
+ import { AppBin } from "./appBin";
7
+
8
+ const makeTempRoot = tempDirs("akan-app-bin-");
9
+ const script = "#!/bin/sh\necho carried\n";
10
+
11
+ const appBinOf = (root: string, bin: AkanBinConfig) => {
12
+ const app = {
13
+ name: "portal",
14
+ cwdPath: path.join(root, "apps/portal"),
15
+ getScanInfo: () => ({ getLibs: () => [] }),
16
+ logger: { info: () => {}, warn: () => {} },
17
+ };
18
+ return new AppBin(app as never, { app: { name: "portal" }, bin, libBins: [] } as never);
19
+ };
20
+
21
+ describe("AppBin", () => {
22
+ test("carries each declared Linux file under the name Docker gives its CPU", async () => {
23
+ const root = await makeTempRoot();
24
+ const dist = path.join(root, "dist");
25
+ for (const name of ["x64", "arm64", "mac"]) writeFileSync(path.join(root, name), `${script}# ${name}\n`);
26
+ const carried = await appBinOf(root, {
27
+ ffmpeg: {
28
+ "linux-x64": { path: path.join(root, "x64") },
29
+ "linux-arm64": { path: path.join(root, "arm64") },
30
+ "darwin-arm64": { path: path.join(root, "mac") },
31
+ },
32
+ }).stageImage(dist);
33
+
34
+ expect(carried).toEqual(["ffmpeg"]);
35
+ expect(readdirSync(path.join(dist, "bin")).toSorted()).toEqual(["amd64", "arm64"]);
36
+ expect(readFileSync(path.join(dist, "bin/amd64/ffmpeg"), "utf8")).toBe(`${script}# x64\n`);
37
+ expect(readFileSync(path.join(dist, "bin/arm64/ffmpeg"), "utf8")).toBe(`${script}# arm64\n`);
38
+ if (process.platform !== "win32") expect(statSync(path.join(dist, "bin/amd64/ffmpeg")).mode & 0o111).toBe(0o111);
39
+ });
40
+
41
+ test("leaves an entry with no Linux file to the image's own steps, and a stale folder out", async () => {
42
+ const root = await makeTempRoot();
43
+ const dist = path.join(root, "dist");
44
+ writeFileSync(path.join(root, "tool"), script);
45
+ await appBinOf(root, { tool: { "linux-x64": { path: path.join(root, "tool") } } }).stageImage(dist);
46
+ const carried = await appBinOf(root, { tool: { "darwin-arm64": { path: path.join(root, "tool") } } }).stageImage(
47
+ dist,
48
+ );
49
+
50
+ expect(carried).toEqual([]);
51
+ expect(readdirSync(dist)).toEqual([]);
52
+ });
53
+
54
+ test("names the declared executables this computer's PATH lacks", () => {
55
+ const which = (name: string) => (name === "ffmpeg" ? "/usr/bin/ffmpeg" : null);
56
+
57
+ expect(AppBin.missing(["ffmpeg"], which)).toBeNull();
58
+ expect(AppBin.missing([], which)).toBeNull();
59
+ expect(AppBin.missing(["ffmpeg", "ffprobe"], which)).toStartWith(
60
+ "bin declares ffprobe, which this computer's PATH",
61
+ );
62
+ });
63
+ });