@akanjs/devkit 3.3.0-rc.5 → 3.3.0-rc.51

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 (264) hide show
  1. package/CHANGELOG.md +686 -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 +70 -10
  9. package/akanConfig/akanConfig.ts +71 -206
  10. package/akanConfig/akanWorkers.test.ts +73 -0
  11. package/akanConfig/akanWorkers.ts +61 -0
  12. package/akanConfig/desktopServerConfig.ts +96 -0
  13. package/akanConfig/dockerImage.ts +39 -0
  14. package/akanConfig/index.ts +1 -0
  15. package/akanConfig/nativeKeys.ts +52 -0
  16. package/akanConfig/types.ts +1 -0
  17. package/app/appBin.test.ts +63 -0
  18. package/app/appBin.ts +50 -0
  19. package/app/applicationBuildReporter.test.ts +49 -0
  20. package/app/applicationBuildReporter.ts +5 -0
  21. package/app/applicationBuildRunner.test.ts +279 -4
  22. package/app/applicationBuildRunner.ts +147 -12
  23. package/app/dictionarySizes.ts +91 -0
  24. package/app/routeFilesReport.test.ts +59 -0
  25. package/app/routeFilesReport.ts +46 -0
  26. package/app/routeJsBudget.ts +18 -4
  27. package/artifact/implicitRootLayout.test.ts +19 -0
  28. package/artifact/implicitRootLayout.ts +16 -2
  29. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  30. package/artifact/storeBootstrap.test.ts +28 -0
  31. package/artifact/storeBootstrap.ts +64 -8
  32. package/biome.base.json +7 -5
  33. package/codeAgent/agent/CodeAgent.ts +36 -16
  34. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  35. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  36. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  37. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  38. package/codeAgent/agent/codeAgent.test.ts +62 -0
  39. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  40. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  41. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  42. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  43. package/codeAgent/skills/akan-deps/SKILL.md +3 -2
  44. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  45. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  46. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  47. package/codeAgent/skills/akan-page/SKILL.md +34 -26
  48. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  49. package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
  50. package/codeAgent/skills/akan-service/SKILL.md +10 -11
  51. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  52. package/codeAgent/skills/akan-ui/SKILL.md +2 -5
  53. package/context/akanContext.ts +2 -0
  54. package/csrE2e/devHmrLatency.e2e.test.ts +1 -1
  55. package/docs/apiReference.test.ts +9 -0
  56. package/docs/apiReference.ts +14 -0
  57. package/executors/appExecutor.ts +10 -5
  58. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  59. package/executors/clientRuntimeKeys.fixture.json +393 -0
  60. package/executors/clientRuntimeKeys.test.ts +1690 -0
  61. package/executors/executor.ts +12 -4
  62. package/executors/executors.test.ts +24 -0
  63. package/executors/sysExecutor.ts +80 -5
  64. package/executors/workspaceExecutor.ts +7 -4
  65. package/frontendBuild/allRoutesBuilder.ts +99 -7
  66. package/frontendBuild/autoImportSync.ts +3 -2
  67. package/frontendBuild/buildRouteClient.test.ts +686 -13
  68. package/frontendBuild/clientBuildTypes.ts +26 -0
  69. package/frontendBuild/clientEntriesBundler.ts +49 -1
  70. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  71. package/frontendBuild/clientEntryDiscovery.ts +136 -14
  72. package/frontendBuild/clientEntryGroups.test.ts +77 -0
  73. package/frontendBuild/clientEntryGroups.ts +61 -0
  74. package/frontendBuild/csrDevArtifactWriter.ts +2 -2
  75. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  76. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  77. package/frontendBuild/csrDevPatcher.test.ts +1 -1
  78. package/frontendBuild/csrDevPatcher.ts +33 -7
  79. package/frontendBuild/csrDevTypes.ts +9 -0
  80. package/frontendBuild/devBarrelImports.test.ts +154 -0
  81. package/frontendBuild/devBarrelImports.ts +83 -23
  82. package/frontendBuild/devRegistryBundler.ts +4 -2
  83. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  84. package/frontendBuild/devRouteRuntime.ts +167 -0
  85. package/frontendBuild/dictionaryAssetBuilder.test.ts +329 -0
  86. package/frontendBuild/dictionaryAssetBuilder.ts +165 -16
  87. package/frontendBuild/dictionaryConstants.ts +136 -0
  88. package/frontendBuild/dictionaryPacking.test.ts +142 -0
  89. package/frontendBuild/dictionaryPacking.ts +135 -0
  90. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  91. package/frontendBuild/dictionaryRoutes.ts +227 -0
  92. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  93. package/frontendBuild/pagesBundleBuilder.ts +81 -3
  94. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  95. package/frontendBuild/precompressArtifacts.ts +22 -8
  96. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  97. package/frontendBuild/renderedEntries.ts +144 -0
  98. package/frontendBuild/routeClientBuilder.ts +407 -43
  99. package/frontendBuild/routeHandoffs.test.ts +155 -0
  100. package/frontendBuild/routeHandoffs.ts +117 -0
  101. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  102. package/frontendBuild/routeModulePreloads.ts +20 -11
  103. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  104. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  105. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  106. package/frontendBuild/routeRuntimePays.ts +117 -0
  107. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  108. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  109. package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
  110. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  111. package/frontendBuild/ssrDevBundler.ts +66 -11
  112. package/frontendBuild/vendorFileImports.test.ts +254 -0
  113. package/frontendBuild/vendorFileImports.ts +163 -0
  114. package/frontendBuild/vendorNarrowing.ts +28 -0
  115. package/frontendBuild/vendorSpecifiers.ts +2 -0
  116. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  117. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  118. package/incrementalBuilder/builderBoot.ts +5 -5
  119. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  120. package/incrementalBuilder/builderLanes.ts +2 -2
  121. package/incrementalBuilder/builderWatch.ts +8 -8
  122. package/incrementalBuilder/csrRegistry.ts +4 -4
  123. package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
  124. package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
  125. package/incrementalBuilder/ssrRegistry.ts +6 -6
  126. package/index.ts +1 -1
  127. package/integration/renderAdmissionSoak.test.ts +99 -0
  128. package/integration/renderAdmissionSoak.ts +609 -0
  129. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  130. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  131. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  132. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  133. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  134. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  135. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  136. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  137. package/lint/biomeBase.test.ts +50 -3
  138. package/lint/biomeBase.ts +1 -1
  139. package/lint/biomeCheck.test.ts +162 -0
  140. package/lint/biomeCheck.ts +131 -0
  141. package/lint/linter.test.ts +16 -11
  142. package/lint/no-arbitrary-color.grit +5 -0
  143. package/lint/no-conditional-st-hook.grit +5 -1
  144. package/lint/no-daisyui-legacy-class.grit +8 -0
  145. package/lint/no-document-cookie.grit +3 -0
  146. package/lint/no-inline-color.grit +10 -2
  147. package/lint/no-oversized-list-limit.grit +2 -0
  148. package/lint/no-raw-palette-class.grit +7 -0
  149. package/lint/no-unpublished-form-setter.grit +2 -0
  150. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  151. package/lint/no-web-storage.grit +3 -0
  152. package/lint/withheldEnvFile.ts +17 -0
  153. package/mobile/desktopBin.ts +2 -2
  154. package/mobile/desktopServerStage.test.ts +9 -2
  155. package/mobile/desktopServerStage.ts +1 -0
  156. package/mobile/nativeApp.test.ts +7 -5
  157. package/mobile/nativeApp.ts +2 -2
  158. package/mobile/nativeConfig.test.ts +96 -1
  159. package/mobile/nativeConfig.ts +46 -12
  160. package/mobile/nativePublicEnv.ts +1 -1
  161. package/mobile/serverBundleSecrets.ts +43 -0
  162. package/package.json +15 -169
  163. package/packageExports.test.ts +38 -24
  164. package/quality/dictionaryKeys.test.ts +356 -0
  165. package/quality/dictionaryKeys.ts +488 -0
  166. package/quality/objectImportReport.test.ts +36 -0
  167. package/quality/objectImportReport.ts +105 -0
  168. package/quality/qualityScanner.ts +1 -1
  169. package/quality/routeRuntimeReport.test.ts +91 -0
  170. package/quality/routeRuntimeReport.ts +121 -0
  171. package/quality/runtimeConstantFacts.ts +71 -0
  172. package/quality/runtimeConstantGraph.ts +123 -0
  173. package/quality/runtimeConstantReads.ts +116 -0
  174. package/quality/runtimeImports.test.ts +190 -0
  175. package/quality/runtimeImports.ts +233 -0
  176. package/quality/runtimeKeyNames.ts +46 -0
  177. package/quality/runtimeLexicalScope.ts +132 -0
  178. package/quality/runtimeMarkerReach.test.ts +84 -0
  179. package/quality/runtimeMarkerReach.ts +255 -0
  180. package/quality/runtimeModuleFacts.ts +290 -0
  181. package/quality/runtimeNameTable.test.ts +172 -0
  182. package/quality/runtimeNameTable.ts +477 -0
  183. package/quality/runtimeScopeReport.test.ts +123 -0
  184. package/quality/runtimeScopeReport.ts +167 -0
  185. package/quality/runtimeSliceKey.ts +269 -0
  186. package/quality/runtimeSyntax.ts +133 -0
  187. package/quality/runtimeTable.fixture.ts +189 -0
  188. package/quality/runtimeUse.test.ts +737 -0
  189. package/quality/runtimeUse.ts +696 -0
  190. package/quality/runtimeUseReadable.test.ts +393 -0
  191. package/quality/ssrScanner.test.ts +13 -0
  192. package/quality/ssrScanner.ts +1 -1
  193. package/quality/translatorBindings.ts +187 -0
  194. package/test/secretEnvFixture.ts +134 -0
  195. package/test/testHelpers.ts +11 -0
  196. package/transforms/barrelAnalyzer.ts +26 -4
  197. package/transforms/barrelImportsPlugin.ts +121 -32
  198. package/transforms/exportReach.test.ts +162 -0
  199. package/transforms/exportReach.ts +308 -0
  200. package/transforms/frameworkObjects.fixture.tsx +58 -0
  201. package/transforms/frameworkObjects.test.ts +54 -0
  202. package/transforms/modelReference.test.ts +196 -0
  203. package/transforms/modelReference.ts +39 -0
  204. package/transforms/moduleParts.test.ts +225 -0
  205. package/transforms/moduleParts.ts +418 -0
  206. package/transforms/objectImportEdits.ts +150 -0
  207. package/transforms/objectMemberImports.test.ts +633 -0
  208. package/transforms/objectMemberImports.ts +571 -0
  209. package/transforms/objectMemberLookup.ts +150 -0
  210. package/transforms/objectModule.test.ts +307 -0
  211. package/transforms/objectModule.ts +482 -0
  212. package/transforms/objectModuleAnalyzer.ts +104 -0
  213. package/transforms/partImports.test.ts +76 -0
  214. package/transforms/partImports.ts +110 -0
  215. package/transforms/partModules.test.ts +187 -0
  216. package/transforms/partModules.ts +90 -0
  217. package/transforms/partPurity.ts +124 -0
  218. package/transforms/reactIconImports.test.ts +231 -0
  219. package/transforms/reactIconImports.ts +325 -0
  220. package/transforms/routeConstants.ts +122 -0
  221. package/transforms/routeRuntime.test.ts +835 -0
  222. package/transforms/routeRuntime.ts +703 -0
  223. package/transforms/routeRuntimeEdits.ts +92 -0
  224. package/transforms/routeRuntimeGraph.ts +66 -0
  225. package/transforms/routeRuntimePlan.ts +244 -0
  226. package/transforms/secretEnvDeclaration.test.ts +208 -0
  227. package/transforms/secretEnvDeclaration.ts +213 -0
  228. package/transforms/secretEnvFile.test.ts +117 -0
  229. package/transforms/secretEnvFile.ts +113 -0
  230. package/transforms/secretEnvName.test.ts +54 -0
  231. package/transforms/secretEnvName.ts +29 -0
  232. package/transforms/secretEnvSource.test.ts +148 -0
  233. package/transforms/secretEnvSource.ts +166 -0
  234. package/transforms/serverEnvEvaluationError.ts +11 -0
  235. package/transforms/serverEnvPlugin.test.ts +2 -1
  236. package/transforms/serverEnvPlugin.ts +13 -0
  237. package/transforms/serverEnvProfile.test.ts +115 -2
  238. package/transforms/serverEnvProfile.ts +117 -40
  239. package/transforms/serverEnvSecrets.test.ts +292 -0
  240. package/transforms/signalDescriptors.test.ts +280 -0
  241. package/transforms/signalDescriptors.ts +227 -0
  242. package/transforms/thisFreeExports.ts +87 -0
  243. package/transforms/transforms.test.ts +180 -3
  244. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  245. package/tunnel/createTunnel.test.ts +29 -8
  246. package/tunnel/createTunnel.ts +18 -11
  247. package/typecheck/projectTypecheck.test.ts +32 -1
  248. package/typecheck/projectTypecheck.ts +3 -3
  249. package/typecheck/typeChecker.test.ts +49 -0
  250. package/typecheck/typeChecker.ts +9 -7
  251. package/typecheck/withheldDiagnostics.ts +41 -0
  252. package/util/fileEditor.ts +1 -0
  253. package/util/selectModel.ts +1 -0
  254. package/workflow/executor.ts +6 -2
  255. package/workflow/index.ts +1 -0
  256. package/workflow/plan.ts +36 -7
  257. package/workflow/types.ts +1 -1
  258. package/workflow/uiTarget.ts +50 -0
  259. package/workspace/getRelatedCnsts.ts +7 -0
  260. package/workspace/scanInfo.test.ts +39 -0
  261. package/workspace/scanInfo.ts +55 -6
  262. package/workspace/slicePlanner.ts +1 -1
  263. package/workspace/workspaceLayout.test.ts +5 -1
  264. package/workspace/workspaceLayout.ts +3 -0
@@ -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 },
@@ -96,6 +107,7 @@ console.info(new SampleService().name);
96
107
  );
97
108
  const app = {
98
109
  getConfig: async () => config,
110
+ getScanInfo: () => ({ getLibs: () => [] }),
99
111
  dist: new Executor("dist", root),
100
112
  workspace: { workspaceRoot: root },
101
113
  logger: { warn: () => undefined },
@@ -121,6 +133,268 @@ console.info(new SampleService().name);
121
133
  }
122
134
  });
123
135
 
136
+ test("an image build names the secrets its server reads beside main.js and in its Dockerfile, and holds no value of them", async () => {
137
+ const { root, workspace } = await createTempApp("portal");
138
+ await writeSecretEnvFixture(root, { app: "portal" });
139
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
140
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
141
+ for (const key of keys) delete process.env[key];
142
+ await writeFile(
143
+ path.join(root, ".env"),
144
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
145
+ );
146
+ const metaOf = async (options: ConstructorParameters<typeof ApplicationBuildRunner>[1]) => {
147
+ const app = AppExecutor.from(workspace, "portal");
148
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
149
+ app.prepareCommand = async () => {
150
+ throw new Error("stopped before the phases");
151
+ };
152
+ const runner = new ApplicationBuildRunner(app, options);
153
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
154
+ await runner.buildAppMeta();
155
+ const env = JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
156
+ [key: string]: string;
157
+ };
158
+ const dockerfile = await readFile(path.join(app.dist.cwdPath, "Dockerfile"), "utf8");
159
+ const dockerfileEnv = Object.fromEntries(
160
+ dockerfile
161
+ .split("\n")
162
+ .filter((line) => line.startsWith("ENV "))
163
+ .map((line) => line.slice("ENV ".length).split(/=(.*)/s).slice(0, 2)),
164
+ );
165
+ expect(env).toEqual(dockerfileEnv);
166
+ expect(holdsSentinel(`${JSON.stringify(env)}${dockerfile}`)).toBe(false);
167
+ return env;
168
+ };
169
+ const names =
170
+ "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";
171
+ try {
172
+ const read = await metaOf({ secretEnv: "read" });
173
+ expect(read.AKAN_ENV_NAMES).toBe(names);
174
+ expect(read).not.toHaveProperty("AKAN_ENV_FALLBACK");
175
+ expect(await metaOf({ secretEnv: "inline" })).toMatchObject({
176
+ AKAN_ENV_NAMES: names,
177
+ AKAN_ENV_FALLBACK: "image",
178
+ });
179
+ const carried = await metaOf({});
180
+ expect(carried).not.toHaveProperty("AKAN_ENV_NAMES");
181
+ expect(carried).not.toHaveProperty("AKAN_ENV_FALLBACK");
182
+ } finally {
183
+ for (const key of keys) {
184
+ if (shellEnv[key] === undefined) delete process.env[key];
185
+ else process.env[key] = shellEnv[key];
186
+ }
187
+ await rm(root, { recursive: true, force: true });
188
+ }
189
+ });
190
+
191
+ test("an image build stops before any phase at a secret whose variable the platform owns, without printing it", async () => {
192
+ const { root, workspace } = await createTempApp("portal");
193
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n pwd: "sentinel-pwd-1b84",' });
194
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
195
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
196
+ for (const key of keys) delete process.env[key];
197
+ await writeFile(
198
+ path.join(root, ".env"),
199
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
200
+ );
201
+ const app = AppExecutor.from(workspace, "portal");
202
+ let prepared = false;
203
+ app.prepareCommand = async () => {
204
+ prepared = true;
205
+ throw new Error("prepared");
206
+ };
207
+ try {
208
+ const failure = await new ApplicationBuildRunner(app, { secretEnv: "read" })
209
+ .build()
210
+ .catch((error: Error) => error.message);
211
+ expect(failure).toContain("`pwd` is a secret a build would read from the environment variable PWD");
212
+ expect(holdsSentinel(String(failure))).toBe(false);
213
+ expect(prepared).toBe(false);
214
+ } finally {
215
+ for (const key of keys) {
216
+ if (shellEnv[key] === undefined) delete process.env[key];
217
+ else process.env[key] = shellEnv[key];
218
+ }
219
+ await rm(root, { recursive: true, force: true });
220
+ }
221
+ });
222
+
223
+ 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 () => {
224
+ const { root, workspace } = await createTempApp("portal");
225
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: '\n hosts: process.env.ZQ_HOSTS!.split(","),' });
226
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN", "ZQ_HOSTS"] as const;
227
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
228
+ for (const key of keys) delete process.env[key];
229
+ await writeFile(
230
+ path.join(root, ".env"),
231
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
232
+ );
233
+ const started = async (secretEnv: "read" | "inline") => {
234
+ const app = AppExecutor.from(workspace, "portal");
235
+ const warnings: string[] = [];
236
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
237
+ warnings.push(message);
238
+ });
239
+ app.prepareCommand = async () => {
240
+ throw new Error("stopped before the phases");
241
+ };
242
+ const runner = new ApplicationBuildRunner(app, { secretEnv });
243
+ const failure = await runner.build().then(
244
+ () => "",
245
+ (error: Error) => error.message,
246
+ );
247
+ return { app, runner, failure, warnings };
248
+ };
249
+ const envOf = async ({ app, runner }: Awaited<ReturnType<typeof started>>) => {
250
+ await runner.buildAppMeta();
251
+ return JSON.parse(await readFile(path.join(app.dist.cwdPath, "akan.env.json"), "utf8")) as {
252
+ [key: string]: string;
253
+ };
254
+ };
255
+ const place =
256
+ /env\.server\.ts could not be evaluated to check it for secrets: TypeError at .*env\.server\.main\.ts:\d+/;
257
+ try {
258
+ const stopped = await started("read");
259
+ expect(stopped.failure).toMatch(place);
260
+ expect(stopped.failure).toContain("Make the file load at that line");
261
+ expect(holdsSentinel(stopped.failure)).toBe(false);
262
+
263
+ const inlined = await started("inline");
264
+ expect(inlined.failure).toBe("stopped before the phases");
265
+ expect(inlined.warnings).toHaveLength(1);
266
+ expect(inlined.warnings[0]).toMatch(place);
267
+ expect(inlined.warnings[0]).toStartWith("--inline-secrets: env.server.ts could not be evaluated");
268
+ expect(holdsSentinel(inlined.warnings.join())).toBe(false);
269
+ const written = await envOf(inlined);
270
+ expect(written).not.toHaveProperty("AKAN_ENV_NAMES");
271
+ expect(written).not.toHaveProperty("AKAN_ENV_FALLBACK");
272
+
273
+ process.env.ZQ_HOSTS = "a.example.test,b.example.test";
274
+ const built = await started("read");
275
+ expect(built.failure).toBe("stopped before the phases");
276
+ expect((await envOf(built)).AKAN_ENV_NAMES).toStartWith("JWT_SECRET,SECURITY__SSO__GOOGLE__CLIENT_SECRET,");
277
+ } finally {
278
+ for (const key of keys) {
279
+ if (shellEnv[key] === undefined) delete process.env[key];
280
+ else process.env[key] = shellEnv[key];
281
+ }
282
+ await rm(root, { recursive: true, force: true });
283
+ }
284
+ });
285
+
286
+ 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 () => {
287
+ const { root, workspace } = await createTempApp("portal");
288
+ await writeComputedSecretFixture(root, "portal");
289
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
290
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
291
+ for (const key of keys) delete process.env[key];
292
+ await writeFile(
293
+ path.join(root, ".env"),
294
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
295
+ );
296
+ const started = async (secretEnv: "read" | "inline") => {
297
+ const app = AppExecutor.from(workspace, "portal");
298
+ spyOn(app.logger, "warn").mockImplementation(() => undefined);
299
+ let prepared = false;
300
+ app.prepareCommand = async () => {
301
+ prepared = true;
302
+ throw new Error("stopped before the phases");
303
+ };
304
+ const failure = await new ApplicationBuildRunner(app, { secretEnv }).build().then(
305
+ () => "",
306
+ (error: Error) => error.message,
307
+ );
308
+ return { failure, prepared: () => prepared };
309
+ };
310
+ try {
311
+ const stopped = await started("read");
312
+ expect(stopped.prepared()).toBe(false);
313
+ expect(stopped.failure).toStartWith(
314
+ `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`,
315
+ );
316
+ expect(holdsSentinel(stopped.failure)).toBe(false);
317
+ for (const value of Object.values(computedSecrets)) expect(stopped.failure).not.toContain(value);
318
+ const inlined = await started("inline");
319
+ expect(inlined.prepared()).toBe(true);
320
+ expect(inlined.failure).toBe("stopped before the phases");
321
+ } finally {
322
+ for (const key of keys) {
323
+ if (shellEnv[key] === undefined) delete process.env[key];
324
+ else process.env[key] = shellEnv[key];
325
+ }
326
+ await rm(root, { recursive: true, force: true });
327
+ }
328
+ });
329
+
330
+ 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 () => {
331
+ const { root, workspace } = await createTempApp("portal");
332
+ await writeSecretEnvFixture(root, { app: "portal", mainExtra: twinSecretEnv.split("\n").slice(0, 3).join("\n") });
333
+ const keys = ["AKAN_PUBLIC_ENV", "AKAN_PUBLIC_REPO_NAME", "AKAN_PUBLIC_SERVE_DOMAIN"] as const;
334
+ const shellEnv = Object.fromEntries(keys.map((key) => [key, process.env[key]]));
335
+ for (const key of keys) delete process.env[key];
336
+ await writeFile(
337
+ path.join(root, ".env"),
338
+ "AKAN_PUBLIC_ENV=main\nAKAN_PUBLIC_REPO_NAME=repo\nAKAN_PUBLIC_SERVE_DOMAIN=akanjs.com\n",
339
+ );
340
+ const runnerOf = async (secretEnv: "read" | "inline") => {
341
+ const app = AppExecutor.from(workspace, "portal");
342
+ const warnings: string[] = [];
343
+ spyOn(app.logger, "warn").mockImplementation((message: string) => {
344
+ warnings.push(message);
345
+ });
346
+ app.prepareCommand = async () => {
347
+ throw new Error("stopped before the phases");
348
+ };
349
+ const runner = new ApplicationBuildRunner(app, { secretEnv });
350
+ await expect(runner.build()).rejects.toThrow("stopped before the phases");
351
+ return { app, runner, warnings };
352
+ };
353
+ try {
354
+ const { app, runner, warnings } = await runnerOf("read");
355
+ await mkdir(app.dist.cwdPath, { recursive: true });
356
+ await writeFile(path.join(app.dist.cwdPath, "server.js"), 'const env = { hostname: "app.example.test" };\n');
357
+ await runner.assertSecretsLeftOut();
358
+ expect(warnings).toEqual([]);
359
+ await writeFile(
360
+ path.join(app.dist.cwdPath, "chunk-a.js"),
361
+ `const cache = { name: ${JSON.stringify(twinSecrets.plain)} };\n`,
362
+ );
363
+ await runner.assertSecretsLeftOut();
364
+ expect(warnings).toHaveLength(1);
365
+ expect(warnings[0]).toContain(
366
+ "\n cache.password (CACHE__PASSWORD): chunk-a.js; the env's cache.name holds the same string\n",
367
+ );
368
+ expect(holdsSentinel(warnings[0] ?? "")).toBe(false);
369
+ await writeFile(
370
+ path.join(app.dist.cwdPath, "chunk-b.js"),
371
+ `const key = ${JSON.stringify(secretEnvSentinels.google)};\nconst label = ${JSON.stringify(twinSecrets.long)};\n`,
372
+ );
373
+ const failure = await runner.assertSecretsLeftOut().then(
374
+ () => "",
375
+ (error: Error) => error.message,
376
+ );
377
+ expect(failure).toStartWith(
378
+ [
379
+ "The build holds secret values the server reads from its process env, so it stops here:",
380
+ " chunk-b.js holds the value of security.sso.google.clientSecret (SECURITY__SSO__GOOGLE__CLIENT_SECRET)",
381
+ " chunk-b.js holds the value of audit.password (AUDIT__PASSWORD), which the env's audit.label holds as well",
382
+ "",
383
+ ].join("\n"),
384
+ );
385
+ expect(holdsSentinel(failure)).toBe(false);
386
+ const inlined = await runnerOf("inline");
387
+ await inlined.runner.assertSecretsLeftOut();
388
+ expect(inlined.warnings.join("\n")).not.toContain("also in what this build wrote");
389
+ } finally {
390
+ for (const key of keys) {
391
+ if (shellEnv[key] === undefined) delete process.env[key];
392
+ else process.env[key] = shellEnv[key];
393
+ }
394
+ await rm(root, { recursive: true, force: true });
395
+ }
396
+ });
397
+
124
398
  test("writes the pruned lockfile beside package.json, or warns and leaves the image's install unlocked", async () => {
125
399
  const root = await mkdtemp(path.join(os.tmpdir(), "akan-build-meta-"));
126
400
  const config = new AkanAppConfig(
@@ -133,6 +407,7 @@ console.info(new SampleService().name);
133
407
  const warnings: string[] = [];
134
408
  const app = {
135
409
  getConfig: async () => config,
410
+ getScanInfo: () => ({ getLibs: () => [] }),
136
411
  dist: new Executor("dist", root),
137
412
  workspace: { workspaceRoot: root },
138
413
  logger: { warn: (message: string) => warnings.push(message) },
@@ -379,16 +654,16 @@ console.info(new SampleService().name);
379
654
  expect(order).toEqual(["routes"]);
380
655
  });
381
656
 
382
- test("akan typecheck names the script/ files nothing imports, and a build's typecheck leaves them out", async () => {
657
+ test("akan typecheck asks for the tests and script/ files nothing imports, and a build's typecheck does not", async () => {
383
658
  const { root, app } = await createTempApp("portal");
384
659
  const run = spyOn(ProjectTypecheck.prototype, "run").mockImplementation(async () => "");
385
660
  try {
386
661
  const runner = new ApplicationBuildRunner(app);
387
662
  await runner.typecheck({ tests: true });
388
663
  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");
664
+ const [checked, built] = run.mock.calls.map(([, options]) => options?.tests);
665
+ expect(checked).toBe(true);
666
+ expect(built).toBeUndefined();
392
667
  } finally {
393
668
  run.mockRestore();
394
669
  await rm(root, { recursive: true, force: true });
@@ -1,12 +1,16 @@
1
1
  import path from "node:path";
2
2
  import { toError } from "akanjs/common";
3
+ import { AppWorkerPath } from "akanjs/server/appWorkerPath";
3
4
  import { BUILD_ENV_FILE } from "akanjs/server/lifecycle/buildEnv";
5
+ import { SecretEnv } from "akanjs/server/lifecycle/secretEnv";
4
6
  import type { BunPlugin } from "bun";
7
+ import { AkanBin } from "../akanConfig/akanBin";
5
8
  import { ProductionLockfile } from "../akanConfig/productionLockfile";
6
9
  import type { App } from "../commandDecorators";
7
10
  import { parseEnvFile, WorkspaceExecutor } from "../executors";
8
11
  import {
9
12
  AllRoutesBuilder,
13
+ type BuildAllRoutesResult,
10
14
  CsrArtifactBuilder,
11
15
  FontPruner,
12
16
  NARROWABLE_VENDOR_SPECIFIERS,
@@ -14,16 +18,24 @@ import {
14
18
  SsrBaseArtifactBuilder,
15
19
  VendorImportScanner,
16
20
  } from "../frontendBuild";
21
+ import { ServerBundleSecrets } from "../mobile/serverBundleSecrets";
22
+ import { RouteRuntimeReport } from "../quality/routeRuntimeReport";
23
+ import { SecretEnvDeclaration, type SecretEnvDeclared } from "../transforms/secretEnvDeclaration";
24
+ import { SecretEnvFile } from "../transforms/secretEnvFile";
25
+ import { ServerEnvEvaluationError } from "../transforms/serverEnvEvaluationError";
17
26
  import { createServerEnvPlugin } from "../transforms/serverEnvPlugin";
18
27
  import { ServerEnvProfile } from "../transforms/serverEnvProfile";
19
28
  import { ProjectTypecheck } from "../typecheck/projectTypecheck";
20
29
  import { Spinner } from "../util/spinner";
21
30
  import type { BaseDevEnv, PackageJson } from "../workspace/types";
22
- import type {
23
- ApplicationBuildPhaseResult,
24
- ApplicationBuildProgressReporter,
25
- ApplicationBuildResult,
31
+ import { AppBin } from "./appBin";
32
+ import {
33
+ type ApplicationBuildPhaseResult,
34
+ type ApplicationBuildProgressReporter,
35
+ ApplicationBuildReporter,
36
+ type ApplicationBuildResult,
26
37
  } from "./applicationBuildReporter";
38
+ import { RouteFilesReport } from "./routeFilesReport";
27
39
  import { RouteJsBudget, type RouteJsBudgetMode, type RouteJsBudgetStatus, type RouteJsSize } from "./routeJsBudget";
28
40
 
29
41
  export interface TypecheckOptions {
@@ -59,6 +71,12 @@ export interface ApplicationBuildRunnerOptions {
59
71
  environment?: string;
60
72
  /** Bundles `env/env.server.<environment>.<profile>.ts`, which may hold no secret, in place of the environment's file. */
61
73
  profile?: string;
74
+ /**
75
+ * An image build's: `read` leaves the server env's secret strings out of the server, which reads each from its process
76
+ * env, and `inline` keeps them in it as what an unset variable falls back to. Unset, as for the server a desktop app
77
+ * carries, or under a `profile`, the env files are bundled as written.
78
+ */
79
+ secretEnv?: "read" | "inline";
62
80
  /**
63
81
  * `enforce` fails on an overage, a route with no entry, or a missing or unreadable akan.budget.json; `update` and
64
82
  * `raise` rewrite the file first; `report` only warns.
@@ -109,6 +127,8 @@ export class ApplicationBuildRunner {
109
127
  #reporter?: BuildProgressReporter;
110
128
  #environment?: string;
111
129
  #profile?: string;
130
+ #secretEnv?: "read" | "inline";
131
+ #secrets: SecretEnvDeclared = { variables: [], unmoved: [], moved: [] };
112
132
  #budget: RouteJsBudgetMode;
113
133
  #modulesByRoute?: Record<string, string[]>;
114
134
  #spinner?: boolean;
@@ -123,6 +143,7 @@ export class ApplicationBuildRunner {
123
143
  reporter,
124
144
  environment,
125
145
  profile,
146
+ secretEnv,
126
147
  budget = "report",
127
148
  }: ApplicationBuildRunnerOptions = {},
128
149
  ) {
@@ -132,6 +153,7 @@ export class ApplicationBuildRunner {
132
153
  this.#reporter = reporter;
133
154
  this.#environment = environment;
134
155
  this.#profile = profile;
156
+ this.#secretEnv = profile ? undefined : secretEnv;
135
157
  this.#budget = budget;
136
158
  }
137
159
 
@@ -163,7 +185,9 @@ export class ApplicationBuildRunner {
163
185
 
164
186
  async build({ spinner = false }: BuildOptions = {}): Promise<BuildResult> {
165
187
  // serial build is needed because of Bun.build is unstable for parallel build
166
- this.#spinner = spinner;
188
+ //? ora writes to stderr, and to a file or a pipe it prints each phase twice, the end line in colour.
189
+ this.#spinner = spinner && process.stderr.isTTY;
190
+ if (spinner && !this.#spinner) this.#reporter ??= ApplicationBuildReporter.create();
167
191
  if (this.#verify) this.#app.useVerifyDist();
168
192
  const { web, assets, baseDevEnv } = await this.#app.getConfig();
169
193
  const environment = this.#environment ?? baseDevEnv.env;
@@ -172,6 +196,7 @@ export class ApplicationBuildRunner {
172
196
  //? Before any phase: a profile that would ship a secret stops the build, not the image after it.
173
197
  if (this.#profile)
174
198
  await ServerEnvProfile.assertShippable({ envDir: this.#envDir, environment, profile: this.#profile });
199
+ if (this.#secretEnv) await this.#declareSecrets(environment);
175
200
  await this.#runPhase("prepare", "Preparing output directory", () => this.#app.prepareCommand("build"));
176
201
  if (!this.#fast) await this.#runPhase("typecheck", "Typechecking", () => this.typecheck());
177
202
  await this.#runPhase(
@@ -186,7 +211,7 @@ export class ApplicationBuildRunner {
186
211
  async () => (web.ssr ? await this.#buildSsr() : null),
187
212
  (result) =>
188
213
  result
189
- ? `${result.allRoutes.manifest.routeIds.length} routes, ${result.allRoutes.manifest.knownEntries.length} entries`
214
+ ? ApplicationBuildRunner.#ssrSummary(result.allRoutes)
190
215
  : web.ssr
191
216
  ? "skipped"
192
217
  : "disabled by akan.config.ts web.ssr",
@@ -221,10 +246,68 @@ export class ApplicationBuildRunner {
221
246
  : "no files",
222
247
  );
223
248
  const routeJs = await this.#runBudgetPhase(environment);
249
+ await this.assertSecretsLeftOut();
224
250
  await this.#runPhase("metadata", "Writing production metadata", () => this.buildAppMeta());
251
+ this.#reportSecretEnv(environment);
225
252
  return this.#resultOf(environment, routeJs);
226
253
  }
227
254
 
255
+ //* A build that cannot load the env file cannot say what it left out, so it stops; under --inline-secrets, which
256
+ //* leaves nothing out, it goes on as a build without the setting does.
257
+ async #declareSecrets(environment: string) {
258
+ try {
259
+ this.#secrets = await SecretEnvDeclaration.of(this.#envDir, environment);
260
+ } catch (error) {
261
+ if (!(error instanceof ServerEnvEvaluationError)) throw error;
262
+ if (this.#secretEnv === "read")
263
+ throw new Error(
264
+ `${error.message}\nA build leaves the secret values of the server env out of what it writes, and names the variables the server reads them from by loading the env file: with no variable of this shell first, then with them. Make the file load at that line, by setting the variable it reads there in this shell or giving it a fallback, and build again. \`akan build --inline-secrets\` builds with the env files as written until akanjs 3.5.0 removes it.`,
265
+ );
266
+ this.#app.logger.warn(
267
+ `--inline-secrets: ${error.message}. The secret values of the server env could not be listed, so this build holds the env files as written: the server reads no secret from a variable of its process env, and names none at boot.`,
268
+ );
269
+ this.#secretEnv = undefined;
270
+ }
271
+ //? Before any phase, and by the env's value alone: a search of the files written misses a short or a plain one.
272
+ if (this.#secretEnv === "read" && this.#secrets.unmoved.length)
273
+ throw new Error(
274
+ SecretEnvFile.unmovedStop(
275
+ this.#app.name,
276
+ environment,
277
+ path
278
+ .relative(this.#app.workspace.workspaceRoot, path.join(this.#envDir, "env.server.ts"))
279
+ .replaceAll("\\", "/"),
280
+ this.#secrets.unmoved,
281
+ ),
282
+ );
283
+ }
284
+
285
+ //? Before the metadata phase: a build that still holds a secret gets no Dockerfile to build an image from.
286
+ async assertSecretsLeftOut() {
287
+ if (this.#secretEnv !== "read" || !this.#secrets.moved.length) return;
288
+ const { workspaceRoot } = this.#app.workspace;
289
+ const note = await new ServerBundleSecrets(workspaceRoot, this.#app.cwdPath).assertImageClean(
290
+ this.#app.dist.cwdPath,
291
+ this.#secrets.moved,
292
+ );
293
+ if (note) this.#app.logger.warn(note);
294
+ }
295
+
296
+ #reportSecretEnv(environment: string) {
297
+ const { variables } = this.#secrets;
298
+ const { logger, name } = this.#app;
299
+ const names = variables.map((variable) => variable.name).join(", ");
300
+ const count = `${variables.length} secret value${variables.length === 1 ? "" : "s"}`;
301
+ if (variables.length && this.#secretEnv === "inline")
302
+ logger.warn(
303
+ `--inline-secrets keeps ${count} of the server env in this build, where whoever can read the image reads them: ${names}. A variable the deployment sets still wins over the built-in value. akanjs 3.5.0 removes the flag: set them where the server is deployed and build without it.`,
304
+ );
305
+ else if (variables.length)
306
+ logger.info(
307
+ `The server reads ${count} from its process env when it starts, not from this build: ${names}. Set them where it is deployed; \`akan secret-env ${name} --env ${environment}\` lists them and writes them from the env file.`,
308
+ );
309
+ }
310
+
228
311
  #runBudgetPhase(environment: string) {
229
312
  return this.#runPhase(
230
313
  "budget",
@@ -268,13 +351,17 @@ export class ApplicationBuildRunner {
268
351
  "../../page/**/*.ts",
269
352
  "../../page/**/*.tsx",
270
353
  ...libPageIncludes,
271
- ...(options.tests ? ["../../script/**/*.ts"] : []),
272
354
  "../../../../pkgs/akanjs/*/types/**/*.d.ts",
273
355
  ],
274
356
  options,
275
357
  );
276
358
  }
277
359
 
360
+ static #ssrSummary({ manifest, runtimeReport }: BuildAllRoutesResult) {
361
+ const built = `${manifest.routeIds.length} routes, ${manifest.knownEntries.length} entries`;
362
+ return runtimeReport ? `${built}; ${RouteRuntimeReport.summary(runtimeReport)}` : built;
363
+ }
364
+
278
365
  async #runPhase<T>(
279
366
  id: BuildPhaseId,
280
367
  label: string,
@@ -305,10 +392,21 @@ export class ApplicationBuildRunner {
305
392
  const environment = this.#environment ?? akanConfig.baseDevEnv.env;
306
393
  const packageJson = akanConfig.getProductionPackageJson();
307
394
  const lockfile = await this.#pruneLockfile(packageJson);
308
- const dockerfile = akanConfig.dockerfileFor(environment, { lockfile: lockfile !== null });
395
+ const env = { ...akanConfig.getProductionEnv(environment), ...this.#secretEnvList() };
396
+ const carried = await new AppBin(this.#app, akanConfig).stageImage(this.#app.dist.cwdPath);
397
+ if (carried.length)
398
+ this.#app.logger.info(
399
+ typeof akanConfig.docker === "string"
400
+ ? `The build carries ${carried.join(", ")} in ${AppBin.dir}/<TARGETARCH>/; apps/${this.#app.name}/akan.config.ts writes its own Dockerfile, which puts that folder on PATH itself (ENV PATH=${AkanBin.imagePath(AppBin.dir)}).`
401
+ : `The image carries ${carried.join(", ")} from bin, first on its PATH.`,
402
+ );
403
+ const dockerfile = akanConfig.dockerfileFor(environment, {
404
+ lockfile: lockfile !== null,
405
+ env: { ...(carried.length ? { PATH: AkanBin.imagePath(AppBin.dir) } : {}), ...env },
406
+ });
309
407
  await Promise.all([
310
408
  this.#app.dist.writeJson("package.json", packageJson),
311
- this.#app.dist.writeJson(BUILD_ENV_FILE, akanConfig.getProductionEnv(environment)),
409
+ this.#app.dist.writeJson(BUILD_ENV_FILE, env),
312
410
  ...(lockfile !== null
313
411
  ? [this.#app.dist.writeFile(`${this.#app.dist.cwdPath}/${ProductionLockfile.fileName}`, lockfile)]
314
412
  : []),
@@ -321,6 +419,15 @@ export class ApplicationBuildRunner {
321
419
  ]);
322
420
  }
323
421
 
422
+ //? Names and kinds alone: the image carries the list of what its deployment owes, never a value.
423
+ #secretEnvList(): Record<string, string> {
424
+ if (!this.#secrets.variables.length) return {};
425
+ return {
426
+ [SecretEnv.listKey]: SecretEnv.format(this.#secrets.variables),
427
+ ...(this.#secretEnv === "inline" ? { [SecretEnv.fallbackKey]: "image" } : {}),
428
+ };
429
+ }
430
+
324
431
  async #pruneLockfile(packageJson: PackageJson): Promise<string | null> {
325
432
  try {
326
433
  return await ProductionLockfile.prune(this.#app.workspace.workspaceRoot, packageJson);
@@ -356,6 +463,7 @@ export class ApplicationBuildRunner {
356
463
  environment: this.#environment ?? baseEnv,
357
464
  environments: ["local", "testing", ...branches],
358
465
  profile: this.#profile,
466
+ secrets: this.#secretEnv,
359
467
  onLibEnv: (file, { profileFile, stripped }) => {
360
468
  if (profileFile || !stripped.length || this.#warnedLibEnvs.has(file)) return;
361
469
  this.#warnedLibEnvs.add(file);
@@ -418,13 +526,34 @@ export class ApplicationBuildRunner {
418
526
  naming: { entry: "console-runtime.[ext]", chunk: "chunk-[hash].[ext]" },
419
527
  });
420
528
  await this.#writeConsoleShim();
421
- const results = [mainResult, serverResult, rscWorkerResult, consoleRuntimeResult];
529
+ const workerResults = await this.#buildWorkers(backendConfig);
530
+ const results = [mainResult, serverResult, rscWorkerResult, consoleRuntimeResult, ...workerResults];
422
531
  return {
423
- entrypoints: backendEntryPoints.length + (rscWorkerResult ? 2 : 1),
532
+ entrypoints: backendEntryPoints.length + (rscWorkerResult ? 2 : 1) + workerResults.length,
424
533
  outputs: results.reduce((sum, result) => sum + (result?.outputs.length ?? 0), 1),
425
534
  };
426
535
  }
427
536
 
537
+ //* Never a chunk of server.js: the process that runs a worker loads nothing of the server, nor the server of it.
538
+ async #buildWorkers(backendConfig: Omit<Bun.BuildConfig, "entrypoints">) {
539
+ const results: Bun.BuildOutput[] = [];
540
+ for (const [name, { owner, entry }] of await this.#app.selectWorkers()) {
541
+ if (!(await Bun.file(entry).exists()))
542
+ throw new Error(
543
+ `${owner}: workers.${name} names ${path.relative(this.#app.workspace.workspaceRoot, entry)}, which does not exist.`,
544
+ );
545
+ results.push(
546
+ await this.#buildOrThrow(`worker ${name}`, {
547
+ ...backendConfig,
548
+ outdir: path.join(this.#app.dist.cwdPath, AppWorkerPath.dir),
549
+ entrypoints: [entry],
550
+ naming: { entry: `${name}.[ext]`, chunk: "chunk-[hash].[ext]" },
551
+ }),
552
+ );
553
+ }
554
+ return results;
555
+ }
556
+
428
557
  async #writeConsoleShim() {
429
558
  await Bun.write(
430
559
  path.join(this.#app.dist.cwdPath, "console.js"),
@@ -484,6 +613,7 @@ void run().catch((error) => {
484
613
  const base = await new SsrBaseArtifactBuilder(this.#app, "build", {
485
614
  serverEnv: this.#serverEnvPlugin(baseDevEnv.env, branches),
486
615
  vendorExports,
616
+ dictionaryRoutes: allRoutes.dictionaryRoutes,
487
617
  }).build();
488
618
  this.#modulesByRoute = (await routes.writeModulePreloads(base.runtimeChunks)).modulesByRoute();
489
619
  return { base, allRoutes };
@@ -493,11 +623,16 @@ void run().catch((error) => {
493
623
  //? verify build skips writing and measures in memory instead.
494
624
  async #measureRouteJs(environment: string): Promise<RouteJsMeasure | null> {
495
625
  if (this.#budget === "off" || !this.#modulesByRoute) return null;
496
- const sizes = await RouteJsBudget.measure(
626
+ const sizeByUrl = await RouteJsBudget.fileSizes(
497
627
  path.join(this.#app.dist.cwdPath, ".akan/artifact"),
498
628
  this.#modulesByRoute,
499
629
  { precompressed: !this.#verify },
500
630
  );
631
+ const sizes = RouteJsBudget.sizesOf(this.#modulesByRoute, sizeByUrl);
632
+ await RouteFilesReport.write(
633
+ this.#app.cwdPath,
634
+ RouteFilesReport.build(this.#app.name, this.#modulesByRoute, sizeByUrl),
635
+ );
501
636
  const budgetPath = path.join(this.#app.cwdPath, RouteJsBudget.fileName);
502
637
  const { summary: status, warnings } = await RouteJsBudget.check(sizes, {
503
638
  mode: this.#budget,