@akanjs/devkit 3.3.0-rc.3 → 3.3.0-rc.31

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 (229) hide show
  1. package/CHANGELOG.md +547 -0
  2. package/DEV_RUNTIME_KNOBS.md +1 -1
  3. package/README.ko.md +3 -2
  4. package/README.md +3 -3
  5. package/akanApp/akanApp.host.test.ts +1 -1
  6. package/akanApp/akanApp.host.ts +11 -0
  7. package/akanConfig/akanBin.ts +4 -0
  8. package/akanConfig/akanConfig.test.ts +66 -7
  9. package/akanConfig/akanConfig.ts +53 -204
  10. package/akanConfig/akanWorkers.test.ts +39 -0
  11. package/akanConfig/akanWorkers.ts +32 -0
  12. package/akanConfig/desktopServerConfig.ts +96 -0
  13. package/akanConfig/dockerImage.ts +37 -0
  14. package/akanConfig/nativeKeys.ts +52 -0
  15. package/akanConfig/types.ts +1 -0
  16. package/app/appBin.test.ts +63 -0
  17. package/app/appBin.ts +50 -0
  18. package/app/applicationBuildReporter.test.ts +32 -0
  19. package/app/applicationBuildReporter.ts +4 -0
  20. package/app/applicationBuildRunner.test.ts +275 -0
  21. package/app/applicationBuildRunner.ts +126 -5
  22. package/app/dictionarySizes.ts +94 -0
  23. package/artifact/implicitRootLayout.test.ts +19 -0
  24. package/artifact/implicitRootLayout.ts +16 -2
  25. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  26. package/artifact/storeBootstrap.test.ts +28 -0
  27. package/artifact/storeBootstrap.ts +60 -8
  28. package/biome.base.json +5 -1
  29. package/codeAgent/agent/CodeAgent.ts +36 -16
  30. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  31. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  32. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  33. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  34. package/codeAgent/agent/codeAgent.test.ts +62 -0
  35. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  36. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  37. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  38. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  39. package/codeAgent/skills/akan-deps/SKILL.md +3 -2
  40. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  41. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  42. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  43. package/codeAgent/skills/akan-page/SKILL.md +4 -14
  44. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  45. package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
  46. package/codeAgent/skills/akan-service/SKILL.md +2 -5
  47. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  48. package/codeAgent/skills/akan-ui/SKILL.md +2 -5
  49. package/context/akanContext.ts +2 -0
  50. package/docs/apiReference.test.ts +9 -0
  51. package/docs/apiReference.ts +14 -0
  52. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  53. package/executors/clientRuntimeKeys.fixture.json +393 -0
  54. package/executors/clientRuntimeKeys.test.ts +1591 -0
  55. package/executors/executors.test.ts +2 -0
  56. package/executors/sysExecutor.ts +66 -3
  57. package/executors/workspaceExecutor.ts +7 -4
  58. package/frontendBuild/allRoutesBuilder.ts +72 -3
  59. package/frontendBuild/autoImportSync.ts +3 -2
  60. package/frontendBuild/buildRouteClient.test.ts +515 -12
  61. package/frontendBuild/clientBuildTypes.ts +15 -0
  62. package/frontendBuild/clientEntriesBundler.ts +38 -0
  63. package/frontendBuild/clientEntryDiscovery.test.ts +95 -1
  64. package/frontendBuild/clientEntryDiscovery.ts +88 -7
  65. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  66. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  67. package/frontendBuild/csrDevPatcher.ts +33 -7
  68. package/frontendBuild/csrDevTypes.ts +9 -0
  69. package/frontendBuild/devBarrelImports.test.ts +100 -0
  70. package/frontendBuild/devBarrelImports.ts +82 -23
  71. package/frontendBuild/devRegistryBundler.ts +4 -2
  72. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  73. package/frontendBuild/devRouteRuntime.ts +167 -0
  74. package/frontendBuild/dictionaryAssetBuilder.test.ts +316 -0
  75. package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
  76. package/frontendBuild/dictionaryConstants.ts +82 -0
  77. package/frontendBuild/dictionaryPacking.test.ts +84 -0
  78. package/frontendBuild/dictionaryPacking.ts +92 -0
  79. package/frontendBuild/dictionaryRoutes.test.ts +186 -0
  80. package/frontendBuild/dictionaryRoutes.ts +225 -0
  81. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  82. package/frontendBuild/pagesBundleBuilder.ts +81 -3
  83. package/frontendBuild/precompressArtifacts.ts +7 -0
  84. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  85. package/frontendBuild/routeClientBuilder.ts +288 -15
  86. package/frontendBuild/routeHandoffs.test.ts +145 -0
  87. package/frontendBuild/routeHandoffs.ts +115 -0
  88. package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
  89. package/frontendBuild/routeRuntimeCheck.ts +241 -0
  90. package/frontendBuild/routeRuntimePays.test.ts +137 -0
  91. package/frontendBuild/routeRuntimePays.ts +117 -0
  92. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  93. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  94. package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
  95. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  96. package/frontendBuild/ssrDevBundler.ts +66 -11
  97. package/frontendBuild/vendorFileImports.test.ts +254 -0
  98. package/frontendBuild/vendorFileImports.ts +163 -0
  99. package/frontendBuild/vendorNarrowing.ts +28 -0
  100. package/frontendBuild/vendorSpecifiers.ts +2 -0
  101. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  102. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  103. package/incrementalBuilder/builderBoot.ts +5 -5
  104. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  105. package/incrementalBuilder/builderLanes.ts +2 -2
  106. package/incrementalBuilder/builderWatch.ts +8 -8
  107. package/incrementalBuilder/csrRegistry.ts +4 -4
  108. package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
  109. package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
  110. package/incrementalBuilder/ssrRegistry.ts +6 -6
  111. package/index.ts +1 -1
  112. package/integration/renderAdmissionSoak.test.ts +99 -0
  113. package/integration/renderAdmissionSoak.ts +609 -0
  114. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  115. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  116. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  117. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  118. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  119. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  120. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  121. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  122. package/lint/biomeCheck.test.ts +145 -0
  123. package/lint/biomeCheck.ts +131 -0
  124. package/lint/no-arbitrary-color.grit +5 -0
  125. package/lint/no-conditional-st-hook.grit +5 -1
  126. package/lint/no-daisyui-legacy-class.grit +8 -0
  127. package/lint/no-document-cookie.grit +3 -0
  128. package/lint/no-inline-color.grit +10 -2
  129. package/lint/no-oversized-list-limit.grit +2 -0
  130. package/lint/no-raw-palette-class.grit +7 -0
  131. package/lint/no-unpublished-form-setter.grit +2 -0
  132. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  133. package/lint/no-web-storage.grit +3 -0
  134. package/lint/withheldEnvFile.ts +17 -0
  135. package/mobile/desktopBin.ts +2 -2
  136. package/mobile/desktopServerStage.ts +1 -0
  137. package/mobile/nativeApp.test.ts +7 -5
  138. package/mobile/nativeApp.ts +2 -2
  139. package/mobile/nativeConfig.test.ts +96 -1
  140. package/mobile/nativeConfig.ts +46 -12
  141. package/mobile/serverBundleSecrets.ts +43 -0
  142. package/package.json +15 -169
  143. package/packageExports.test.ts +38 -24
  144. package/quality/dictionaryKeys.test.ts +173 -0
  145. package/quality/dictionaryKeys.ts +415 -0
  146. package/quality/objectImportReport.test.ts +36 -0
  147. package/quality/objectImportReport.ts +102 -0
  148. package/quality/qualityScanner.ts +1 -1
  149. package/quality/routeRuntimeReport.test.ts +91 -0
  150. package/quality/routeRuntimeReport.ts +121 -0
  151. package/quality/runtimeConstantFacts.ts +71 -0
  152. package/quality/runtimeConstantGraph.ts +123 -0
  153. package/quality/runtimeConstantReads.ts +116 -0
  154. package/quality/runtimeImports.test.ts +190 -0
  155. package/quality/runtimeImports.ts +233 -0
  156. package/quality/runtimeKeyNames.ts +46 -0
  157. package/quality/runtimeLexicalScope.ts +132 -0
  158. package/quality/runtimeMarkerReach.test.ts +84 -0
  159. package/quality/runtimeMarkerReach.ts +255 -0
  160. package/quality/runtimeModuleFacts.ts +290 -0
  161. package/quality/runtimeNameTable.test.ts +172 -0
  162. package/quality/runtimeNameTable.ts +477 -0
  163. package/quality/runtimeScopeReport.test.ts +123 -0
  164. package/quality/runtimeScopeReport.ts +167 -0
  165. package/quality/runtimeSliceKey.ts +269 -0
  166. package/quality/runtimeSyntax.ts +133 -0
  167. package/quality/runtimeTable.fixture.ts +189 -0
  168. package/quality/runtimeUse.test.ts +737 -0
  169. package/quality/runtimeUse.ts +696 -0
  170. package/quality/runtimeUseReadable.test.ts +393 -0
  171. package/quality/ssrScanner.test.ts +13 -0
  172. package/quality/ssrScanner.ts +1 -1
  173. package/test/secretEnvFixture.ts +134 -0
  174. package/test/testHelpers.ts +11 -0
  175. package/transforms/barrelAnalyzer.ts +26 -4
  176. package/transforms/barrelImportsPlugin.ts +82 -14
  177. package/transforms/frameworkObjects.fixture.tsx +58 -0
  178. package/transforms/frameworkObjects.test.ts +54 -0
  179. package/transforms/modelReference.test.ts +196 -0
  180. package/transforms/modelReference.ts +39 -0
  181. package/transforms/objectImportEdits.ts +150 -0
  182. package/transforms/objectMemberImports.test.ts +347 -0
  183. package/transforms/objectMemberImports.ts +537 -0
  184. package/transforms/objectModule.test.ts +237 -0
  185. package/transforms/objectModule.ts +458 -0
  186. package/transforms/objectModuleAnalyzer.ts +104 -0
  187. package/transforms/reactIconImports.test.ts +231 -0
  188. package/transforms/reactIconImports.ts +325 -0
  189. package/transforms/routeConstants.ts +122 -0
  190. package/transforms/routeRuntime.test.ts +835 -0
  191. package/transforms/routeRuntime.ts +703 -0
  192. package/transforms/routeRuntimeEdits.ts +92 -0
  193. package/transforms/routeRuntimeGraph.ts +66 -0
  194. package/transforms/routeRuntimePlan.ts +244 -0
  195. package/transforms/secretEnvDeclaration.test.ts +208 -0
  196. package/transforms/secretEnvDeclaration.ts +213 -0
  197. package/transforms/secretEnvFile.test.ts +117 -0
  198. package/transforms/secretEnvFile.ts +113 -0
  199. package/transforms/secretEnvName.test.ts +54 -0
  200. package/transforms/secretEnvName.ts +29 -0
  201. package/transforms/secretEnvSource.test.ts +148 -0
  202. package/transforms/secretEnvSource.ts +166 -0
  203. package/transforms/serverEnvEvaluationError.ts +11 -0
  204. package/transforms/serverEnvPlugin.test.ts +2 -1
  205. package/transforms/serverEnvPlugin.ts +13 -0
  206. package/transforms/serverEnvProfile.test.ts +115 -2
  207. package/transforms/serverEnvProfile.ts +117 -40
  208. package/transforms/serverEnvSecrets.test.ts +292 -0
  209. package/transforms/signalDescriptors.test.ts +280 -0
  210. package/transforms/signalDescriptors.ts +227 -0
  211. package/transforms/thisFreeExports.ts +87 -0
  212. package/transforms/transforms.test.ts +180 -3
  213. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  214. package/tunnel/createTunnel.test.ts +29 -8
  215. package/tunnel/createTunnel.ts +18 -11
  216. package/typecheck/projectTypecheck.test.ts +29 -0
  217. package/typecheck/typeChecker.test.ts +49 -0
  218. package/typecheck/typeChecker.ts +9 -7
  219. package/typecheck/withheldDiagnostics.ts +41 -0
  220. package/util/fileEditor.ts +1 -0
  221. package/util/selectModel.ts +1 -0
  222. package/workflow/executor.ts +6 -2
  223. package/workflow/index.ts +1 -0
  224. package/workflow/plan.ts +36 -7
  225. package/workflow/types.ts +1 -1
  226. package/workflow/uiTarget.ts +50 -0
  227. package/workspace/getRelatedCnsts.ts +7 -0
  228. package/workspace/scanInfo.ts +1 -1
  229. package/workspace/workspaceLayout.ts +1 -0
@@ -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,37 @@
1
+ import { type Arch, archs, type DockerRun } from "./types";
2
+
3
+ //? A Bun bump changes both: `docker buildx imagetools inspect oven/bun:<version>-slim` prints the new multi-arch digest.
4
+ export const BUN_IMAGE_PIN = {
5
+ version: "1.4.4",
6
+ digest: "sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4",
7
+ } as const;
8
+ // `1-slim` floats to whichever Bun is newest at build time, one the framework was never tested on.
9
+ export const DEFAULT_DOCKER_IMAGE = `oven/bun:${BUN_IMAGE_PIN.version}-slim@${BUN_IMAGE_PIN.digest}`;
10
+ //? oven/bun's `bun` user, numeric so a kubelet can check `runAsNonRoot` without reading the image's passwd file.
11
+ export const DOCKER_RUN_USER = "1000:1000";
12
+ //? The directories the server writes, its code staying read-only; an empty named volume mounted on one takes its owner.
13
+ export const DOCKER_WRITE_DIRS = [
14
+ "/workspace/sqlite",
15
+ "/workspace/local",
16
+ "/workspace/runtime",
17
+ "/workspace/data",
18
+ "/workspace/.akan/artifact/image-cache",
19
+ ];
20
+
21
+ export const dockerRunScripts = (runs: DockerRun[]) =>
22
+ runs.map((run) =>
23
+ typeof run === "string"
24
+ ? `RUN ${run}`
25
+ : Object.entries(run)
26
+ .map(
27
+ ([arch, script]) => `RUN if [ "$TARGETARCH" = "${arch}" ]; then \
28
+ ${script}; \
29
+ fi`,
30
+ )
31
+ .join("\n"),
32
+ );
33
+
34
+ export const dockerImageScript = (image: string | { [key in Arch]?: string }) =>
35
+ typeof image === "string"
36
+ ? `FROM ${image}`
37
+ : archs.map((arch) => `FROM ${image[arch] ?? DEFAULT_DOCKER_IMAGE} AS ${arch}`).join("\n");
@@ -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;
@@ -27,6 +27,7 @@ export type {
27
27
  AkanSyncContext,
28
28
  AkanWebConfig,
29
29
  AkanWebOption,
30
+ AkanWorkersConfig,
30
31
  AppConfig,
31
32
  AppConfigInput,
32
33
  AppConfigResult,
@@ -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
+ });
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,
@@ -52,6 +57,33 @@ describe("ApplicationBuildReporter.printSummary", () => {
52
57
  );
53
58
  });
54
59
 
60
+ test("prints each locale's dictionary size, and its API description file's where the build split one out", async () => {
61
+ const artifactDir = await tempRoot();
62
+ await mkdir(path.join(artifactDir, "dict"));
63
+ await writeFile(path.join(artifactDir, "dict/en.js"), "x".repeat(4096));
64
+ await writeFile(path.join(artifactDir, "dict/en.js.br"), "x".repeat(1100));
65
+ await writeFile(path.join(artifactDir, "dict/en-api.js"), "y");
66
+ await writeFile(path.join(artifactDir, "dict/ko.js"), "z");
67
+ const dictAssets = {
68
+ en: {
69
+ url: "/_akan/dict/en.js",
70
+ relPath: "dict/en.js",
71
+ parts: { api: { url: "/_akan/dict/en-api.js", relPath: "dict/en-api.js" } },
72
+ },
73
+ ko: { url: "/_akan/dict/ko.js", relPath: "dict/ko.js" },
74
+ };
75
+ await writeFile(path.join(artifactDir, "base-artifact.json"), JSON.stringify({ dictAssets }));
76
+ ApplicationBuildReporter.printSummary({ ...resultFor("main"), artifactDir });
77
+
78
+ const lines = rawLog.mock.calls.map(([line = ""]) => line);
79
+ const en = lines.find((line) => line.startsWith("Dictionary en:"));
80
+ expect(en).toMatch(/^Dictionary en: 1\.1KB brotli on every page, API descriptions \d+B where shown$/);
81
+ expect(lines.find((line) => line.startsWith("Dictionary ko:"))).toMatch(
82
+ /^Dictionary ko: \d+B brotli on every page$/,
83
+ );
84
+ expect(lines.indexOf(en ?? "")).toBeLessThan(lines.indexOf(`Route artifacts: ${artifactDir}`));
85
+ });
86
+
55
87
  test("prints only the route JS budget warnings for a quiet build", () => {
56
88
  const routeJsWarnings = [{ file: "apps/shop/akan.budget.json", message: "unreadable", fix: "correct it" }];
57
89
  ApplicationBuildReporter.printRouteJsWarnings({ routeJsWarnings });
@@ -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 {
@@ -43,6 +44,9 @@ export class ApplicationBuildReporter {
43
44
  ApplicationBuildReporter.printRouteJsWarnings(result);
44
45
  Logger.rawLog("");
45
46
  }
47
+ const dictionaries = DictionarySizes.of(result.artifactDir);
48
+ for (const size of dictionaries) Logger.rawLog(DictionarySizes.format(size));
49
+ if (dictionaries.length) Logger.rawLog("");
46
50
  Logger.rawLog(`Route artifacts: ${result.artifactDir}`);
47
51
  Logger.rawLog(`Server output: ${result.outputDir}`);
48
52
  Logger.rawLog(`Done in ${ApplicationBuildReporter.formatDuration(result.durationMs)}`);