@akanjs/devkit 3.3.0-rc.4 → 3.3.0-rc.40

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 (250) hide show
  1. package/CHANGELOG.md +618 -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 +133 -6
  22. package/app/dictionarySizes.ts +91 -0
  23. package/app/routeFilesReport.test.ts +59 -0
  24. package/app/routeFilesReport.ts +46 -0
  25. package/app/routeJsBudget.ts +18 -4
  26. package/artifact/implicitRootLayout.test.ts +19 -0
  27. package/artifact/implicitRootLayout.ts +16 -2
  28. package/artifact/implicitRootLayoutRender.test.tsx +4 -1
  29. package/artifact/storeBootstrap.test.ts +28 -0
  30. package/artifact/storeBootstrap.ts +64 -8
  31. package/biome.base.json +6 -4
  32. package/codeAgent/agent/CodeAgent.ts +36 -16
  33. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  34. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  35. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  36. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  37. package/codeAgent/agent/codeAgent.test.ts +62 -0
  38. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  39. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  40. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  41. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  42. package/codeAgent/skills/akan-deps/SKILL.md +3 -2
  43. package/codeAgent/skills/akan-err/SKILL.md +13 -8
  44. package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
  45. package/codeAgent/skills/akan-module/SKILL.md +2 -2
  46. package/codeAgent/skills/akan-page/SKILL.md +31 -20
  47. package/codeAgent/skills/akan-query/SKILL.md +13 -20
  48. package/codeAgent/skills/akan-runtime/SKILL.md +20 -0
  49. package/codeAgent/skills/akan-service/SKILL.md +2 -5
  50. package/codeAgent/skills/akan-transport/SKILL.md +5 -14
  51. package/codeAgent/skills/akan-ui/SKILL.md +2 -5
  52. package/context/akanContext.ts +2 -0
  53. package/docs/apiReference.test.ts +9 -0
  54. package/docs/apiReference.ts +14 -0
  55. package/executors/appExecutor.ts +3 -1
  56. package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
  57. package/executors/clientRuntimeKeys.fixture.json +393 -0
  58. package/executors/clientRuntimeKeys.test.ts +1690 -0
  59. package/executors/executors.test.ts +2 -0
  60. package/executors/sysExecutor.ts +70 -4
  61. package/executors/workspaceExecutor.ts +7 -4
  62. package/frontendBuild/allRoutesBuilder.ts +88 -7
  63. package/frontendBuild/autoImportSync.ts +3 -2
  64. package/frontendBuild/buildRouteClient.test.ts +580 -12
  65. package/frontendBuild/clientBuildTypes.ts +26 -0
  66. package/frontendBuild/clientEntriesBundler.ts +49 -1
  67. package/frontendBuild/clientEntryDiscovery.test.ts +308 -1
  68. package/frontendBuild/clientEntryDiscovery.ts +135 -13
  69. package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
  70. package/frontendBuild/csrDevModuleCompiler.ts +44 -8
  71. package/frontendBuild/csrDevPatcher.ts +33 -7
  72. package/frontendBuild/csrDevTypes.ts +9 -0
  73. package/frontendBuild/devBarrelImports.test.ts +154 -0
  74. package/frontendBuild/devBarrelImports.ts +83 -23
  75. package/frontendBuild/devRegistryBundler.ts +4 -2
  76. package/frontendBuild/devRouteRuntime.test.ts +492 -0
  77. package/frontendBuild/devRouteRuntime.ts +167 -0
  78. package/frontendBuild/dictionaryAssetBuilder.test.ts +324 -0
  79. package/frontendBuild/dictionaryAssetBuilder.ts +165 -16
  80. package/frontendBuild/dictionaryConstants.ts +136 -0
  81. package/frontendBuild/dictionaryPacking.test.ts +142 -0
  82. package/frontendBuild/dictionaryPacking.ts +135 -0
  83. package/frontendBuild/dictionaryRoutes.test.ts +251 -0
  84. package/frontendBuild/dictionaryRoutes.ts +227 -0
  85. package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
  86. package/frontendBuild/pagesBundleBuilder.ts +81 -3
  87. package/frontendBuild/precompressArtifacts.test.ts +22 -0
  88. package/frontendBuild/precompressArtifacts.ts +22 -8
  89. package/frontendBuild/registryMetadataFingerprint.ts +3 -3
  90. package/frontendBuild/renderedEntries.ts +144 -0
  91. package/frontendBuild/routeClientBuilder.ts +340 -29
  92. package/frontendBuild/routeHandoffs.test.ts +155 -0
  93. package/frontendBuild/routeHandoffs.ts +117 -0
  94. package/frontendBuild/routeModulePreloads.test.ts +32 -0
  95. package/frontendBuild/routeModulePreloads.ts +20 -11
  96. package/frontendBuild/routeRuntimeCheck.test.ts +280 -0
  97. package/frontendBuild/routeRuntimeCheck.ts +248 -0
  98. package/frontendBuild/routeRuntimePays.test.ts +143 -0
  99. package/frontendBuild/routeRuntimePays.ts +117 -0
  100. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  101. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  102. package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
  103. package/frontendBuild/ssrDevBundler.test.ts +150 -1
  104. package/frontendBuild/ssrDevBundler.ts +66 -11
  105. package/frontendBuild/vendorFileImports.test.ts +254 -0
  106. package/frontendBuild/vendorFileImports.ts +163 -0
  107. package/frontendBuild/vendorNarrowing.ts +28 -0
  108. package/frontendBuild/vendorSpecifiers.ts +2 -0
  109. package/incrementalBuilder/buildBatch.proc.ts +9 -9
  110. package/incrementalBuilder/buildBatchProtocol.ts +1 -1
  111. package/incrementalBuilder/builderBoot.ts +5 -5
  112. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  113. package/incrementalBuilder/builderLanes.ts +2 -2
  114. package/incrementalBuilder/builderWatch.ts +8 -8
  115. package/incrementalBuilder/csrRegistry.ts +4 -4
  116. package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
  117. package/incrementalBuilder/incrementalBuilder.proc.ts +27 -8
  118. package/incrementalBuilder/ssrRegistry.ts +6 -6
  119. package/index.ts +1 -1
  120. package/integration/renderAdmissionSoak.test.ts +99 -0
  121. package/integration/renderAdmissionSoak.ts +609 -0
  122. package/lint/__fixtures__/no-arbitrary-color/every-color-function/bad.tsx +11 -0
  123. package/lint/__fixtures__/no-arbitrary-color/every-color-function/good.tsx +2 -0
  124. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/bad.tsx +34 -0
  125. package/lint/__fixtures__/no-daisyui-legacy-class/every-class/good.tsx +2 -0
  126. package/lint/__fixtures__/no-inline-color/every-color-function/bad.tsx +10 -0
  127. package/lint/__fixtures__/no-inline-color/every-color-function/good.tsx +2 -0
  128. package/lint/__fixtures__/no-raw-palette-class/every-palette/bad.tsx +22 -0
  129. package/lint/__fixtures__/no-raw-palette-class/every-palette/good.tsx +2 -0
  130. package/lint/biomeBase.test.ts +23 -3
  131. package/lint/biomeCheck.test.ts +145 -0
  132. package/lint/biomeCheck.ts +131 -0
  133. package/lint/no-arbitrary-color.grit +5 -0
  134. package/lint/no-conditional-st-hook.grit +5 -1
  135. package/lint/no-daisyui-legacy-class.grit +8 -0
  136. package/lint/no-document-cookie.grit +3 -0
  137. package/lint/no-inline-color.grit +10 -2
  138. package/lint/no-oversized-list-limit.grit +2 -0
  139. package/lint/no-raw-palette-class.grit +7 -0
  140. package/lint/no-unpublished-form-setter.grit +2 -0
  141. package/lint/no-web-only-api-outside-webkit.grit +5 -0
  142. package/lint/no-web-storage.grit +3 -0
  143. package/lint/withheldEnvFile.ts +17 -0
  144. package/mobile/desktopBin.ts +2 -2
  145. package/mobile/desktopServerStage.ts +1 -0
  146. package/mobile/nativeApp.test.ts +7 -5
  147. package/mobile/nativeApp.ts +2 -2
  148. package/mobile/nativeConfig.test.ts +96 -1
  149. package/mobile/nativeConfig.ts +46 -12
  150. package/mobile/serverBundleSecrets.ts +43 -0
  151. package/package.json +15 -169
  152. package/packageExports.test.ts +38 -24
  153. package/quality/dictionaryKeys.test.ts +356 -0
  154. package/quality/dictionaryKeys.ts +488 -0
  155. package/quality/objectImportReport.test.ts +36 -0
  156. package/quality/objectImportReport.ts +105 -0
  157. package/quality/qualityScanner.ts +1 -1
  158. package/quality/routeRuntimeReport.test.ts +91 -0
  159. package/quality/routeRuntimeReport.ts +121 -0
  160. package/quality/runtimeConstantFacts.ts +71 -0
  161. package/quality/runtimeConstantGraph.ts +123 -0
  162. package/quality/runtimeConstantReads.ts +116 -0
  163. package/quality/runtimeImports.test.ts +190 -0
  164. package/quality/runtimeImports.ts +233 -0
  165. package/quality/runtimeKeyNames.ts +46 -0
  166. package/quality/runtimeLexicalScope.ts +132 -0
  167. package/quality/runtimeMarkerReach.test.ts +84 -0
  168. package/quality/runtimeMarkerReach.ts +255 -0
  169. package/quality/runtimeModuleFacts.ts +290 -0
  170. package/quality/runtimeNameTable.test.ts +172 -0
  171. package/quality/runtimeNameTable.ts +477 -0
  172. package/quality/runtimeScopeReport.test.ts +123 -0
  173. package/quality/runtimeScopeReport.ts +167 -0
  174. package/quality/runtimeSliceKey.ts +269 -0
  175. package/quality/runtimeSyntax.ts +133 -0
  176. package/quality/runtimeTable.fixture.ts +189 -0
  177. package/quality/runtimeUse.test.ts +737 -0
  178. package/quality/runtimeUse.ts +696 -0
  179. package/quality/runtimeUseReadable.test.ts +393 -0
  180. package/quality/ssrScanner.test.ts +13 -0
  181. package/quality/ssrScanner.ts +1 -1
  182. package/quality/translatorBindings.ts +187 -0
  183. package/test/secretEnvFixture.ts +134 -0
  184. package/test/testHelpers.ts +11 -0
  185. package/transforms/barrelAnalyzer.ts +26 -4
  186. package/transforms/barrelImportsPlugin.ts +121 -32
  187. package/transforms/exportReach.test.ts +162 -0
  188. package/transforms/exportReach.ts +308 -0
  189. package/transforms/frameworkObjects.fixture.tsx +58 -0
  190. package/transforms/frameworkObjects.test.ts +54 -0
  191. package/transforms/modelReference.test.ts +196 -0
  192. package/transforms/modelReference.ts +39 -0
  193. package/transforms/moduleParts.test.ts +225 -0
  194. package/transforms/moduleParts.ts +418 -0
  195. package/transforms/objectImportEdits.ts +150 -0
  196. package/transforms/objectMemberImports.test.ts +629 -0
  197. package/transforms/objectMemberImports.ts +571 -0
  198. package/transforms/objectMemberLookup.ts +150 -0
  199. package/transforms/objectModule.test.ts +307 -0
  200. package/transforms/objectModule.ts +482 -0
  201. package/transforms/objectModuleAnalyzer.ts +104 -0
  202. package/transforms/partImports.test.ts +76 -0
  203. package/transforms/partImports.ts +110 -0
  204. package/transforms/partModules.test.ts +187 -0
  205. package/transforms/partModules.ts +90 -0
  206. package/transforms/partPurity.ts +124 -0
  207. package/transforms/reactIconImports.test.ts +231 -0
  208. package/transforms/reactIconImports.ts +325 -0
  209. package/transforms/routeConstants.ts +122 -0
  210. package/transforms/routeRuntime.test.ts +835 -0
  211. package/transforms/routeRuntime.ts +703 -0
  212. package/transforms/routeRuntimeEdits.ts +92 -0
  213. package/transforms/routeRuntimeGraph.ts +66 -0
  214. package/transforms/routeRuntimePlan.ts +244 -0
  215. package/transforms/secretEnvDeclaration.test.ts +208 -0
  216. package/transforms/secretEnvDeclaration.ts +213 -0
  217. package/transforms/secretEnvFile.test.ts +117 -0
  218. package/transforms/secretEnvFile.ts +113 -0
  219. package/transforms/secretEnvName.test.ts +54 -0
  220. package/transforms/secretEnvName.ts +29 -0
  221. package/transforms/secretEnvSource.test.ts +148 -0
  222. package/transforms/secretEnvSource.ts +166 -0
  223. package/transforms/serverEnvEvaluationError.ts +11 -0
  224. package/transforms/serverEnvPlugin.test.ts +2 -1
  225. package/transforms/serverEnvPlugin.ts +13 -0
  226. package/transforms/serverEnvProfile.test.ts +115 -2
  227. package/transforms/serverEnvProfile.ts +117 -40
  228. package/transforms/serverEnvSecrets.test.ts +292 -0
  229. package/transforms/signalDescriptors.test.ts +280 -0
  230. package/transforms/signalDescriptors.ts +227 -0
  231. package/transforms/thisFreeExports.ts +87 -0
  232. package/transforms/transforms.test.ts +180 -3
  233. package/transforms/tsconfigPackageResolver.test.ts +1 -0
  234. package/tunnel/createTunnel.test.ts +29 -8
  235. package/tunnel/createTunnel.ts +18 -11
  236. package/typecheck/projectTypecheck.test.ts +29 -0
  237. package/typecheck/typeChecker.test.ts +49 -0
  238. package/typecheck/typeChecker.ts +9 -7
  239. package/typecheck/withheldDiagnostics.ts +41 -0
  240. package/util/fileEditor.ts +1 -0
  241. package/util/selectModel.ts +1 -0
  242. package/workflow/executor.ts +6 -2
  243. package/workflow/index.ts +1 -0
  244. package/workflow/plan.ts +36 -7
  245. package/workflow/types.ts +1 -1
  246. package/workflow/uiTarget.ts +50 -0
  247. package/workspace/getRelatedCnsts.ts +7 -0
  248. package/workspace/scanInfo.test.ts +39 -0
  249. package/workspace/scanInfo.ts +48 -5
  250. package/workspace/workspaceLayout.ts +1 -0
@@ -645,6 +645,85 @@ else {
645
645
  }
646
646
  }, 60_000);
647
647
 
648
+ test("a route whose client entries an earlier route built still reads their dictionary groups, and one this builder never built loads the whole file", async () => {
649
+ const { root } = track(await createTempApp("demo", path.join(import.meta.dir, "..", "local")));
650
+ const appDir = path.join(root, "apps/demo");
651
+ await writeText(
652
+ path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
653
+ `const { generation, needs } = JSON.parse(process.argv[2]);
654
+ if (needs.includes("ssr")) await import(${JSON.stringify(path.join(import.meta.dir, "buildBatch.proc.ts"))});
655
+ else {
656
+ process.once("disconnect", () => {});
657
+ process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
658
+ }
659
+ `,
660
+ );
661
+ await writeText(path.join(appDir, "akan.config.ts"), "export default {};\n");
662
+ await writeText(path.join(appDir, "env/env.client.ts"), "export const env = {} as const;\n");
663
+ const pages = {
664
+ first: path.join(appDir, "page/_index.tsx"),
665
+ same: path.join(appDir, "page/same.tsx"),
666
+ more: path.join(appDir, "page/more.tsx"),
667
+ lone: path.join(appDir, "page/lone.tsx"),
668
+ };
669
+ await writeText(pages.lone, 'import { Lone } from "../ui/Lone";\nexport default Lone;\n');
670
+ await writeText(pages.first, 'import { Card } from "../ui/Card";\nexport default Card;\n');
671
+ await writeText(pages.same, 'import { Card } from "../ui/Card";\nexport default Card;\n');
672
+ await writeText(
673
+ pages.more,
674
+ 'import { Card } from "../ui/Card";\nimport { Note } from "../ui/Note";\nexport default () => [Card, Note];\n',
675
+ );
676
+ const card = path.join(appDir, "ui/Card.tsx");
677
+ await writeText(card, '"use client";\nimport { Label } from "./Label";\nexport const Card = () => Label();\n');
678
+ await writeText(
679
+ path.join(appDir, "ui/Label.tsx"),
680
+ 'declare const l: (key: string) => string;\nexport const Label = () => l("memo.title");\n',
681
+ );
682
+ await writeText(path.join(appDir, "ui/Note.tsx"), '"use client";\nexport const Note = () => null;\n');
683
+ const lone = path.join(appDir, "ui/Lone.tsx");
684
+ await writeText(lone, '"use client";\nexport const Lone = () => null;\n');
685
+
686
+ const messages: BuilderMessage[] = [];
687
+ const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
688
+ cwd: appDir,
689
+ env: {
690
+ ...process.env,
691
+ AKAN_WORKSPACE_ROOT: root,
692
+ AKAN_PUBLIC_APP_NAME: "demo",
693
+ AKAN_PUBLIC_REPO_NAME: "repo",
694
+ AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
695
+ AKAN_PUBLIC_ENV: "local",
696
+ AKAN_WATCH: "0",
697
+ },
698
+ stdio: ["ignore", "ignore", "ignore"],
699
+ serialization: "advanced",
700
+ ipc: (message: BuilderMessage) => {
701
+ messages.push(message);
702
+ },
703
+ });
704
+ const buildRoute = async (id: number, routeId: string, seed: string, knownEntries: string[]) => {
705
+ proc.send({ type: "build-route", id, routeId, seeds: [seed], knownEntries, generation: 3 } satisfies BuilderReq);
706
+ await until(proc, `build-route-res ${id}`, () =>
707
+ messages.some((message) => message.type === "build-route-res" && message.id === id),
708
+ );
709
+ const res = messages.find((message) => message.type === "build-route-res" && message.id === id);
710
+ if (res?.type !== "build-route-res" || !res.ok) throw new Error(`route ${routeId} did not build`);
711
+ return res.data;
712
+ };
713
+ try {
714
+ await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
715
+ const first = await buildRoute(1, "page:/", pages.first, []);
716
+ expect(first.newEntries).toEqual([card]);
717
+ expect(first.dictionaryGroups).toEqual(["base", "memo"]);
718
+ expect((await buildRoute(2, "page:/more", pages.more, [card])).dictionaryGroups).toEqual(["base", "memo"]);
719
+ expect((await buildRoute(3, "page:/same", pages.same, [card])).dictionaryGroups).toEqual(["base", "memo"]);
720
+ expect((await buildRoute(4, "page:/lone", pages.lone, [lone])).dictionaryGroups).toBeNull();
721
+ } finally {
722
+ proc.kill();
723
+ await proc.exited;
724
+ }
725
+ }, 60_000);
726
+
648
727
  test("a failed boot build waits for the save that fixes it, and the builder it recovers continues the generation and watches", async () => {
649
728
  const { root } = track(await createTempApp("demo"));
650
729
  const appDir = path.join(root, "apps/demo");
@@ -1,12 +1,4 @@
1
1
  import path from "node:path";
2
- // Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
3
- // and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
4
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
5
- import type { App } from "@akanjs/devkit/commandDecorators";
6
- import { AppExecutor, type PageRoot, WorkspaceExecutor } from "@akanjs/devkit/executors";
7
- import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
8
- import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
9
- import { RouteClientBuilder } from "@akanjs/devkit/frontendBuild/routeClientBuilder";
10
2
  import { Logger } from "akanjs/common";
11
3
  import type {
12
4
  BaseBuildArtifact,
@@ -18,6 +10,15 @@ import type {
18
10
  BuildRouteResultPayload,
19
11
  ChangeBatch,
20
12
  } from "akanjs/server";
13
+ // Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
14
+ // and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
15
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
16
+ import type { App } from "../commandDecorators";
17
+ import { AppExecutor, type PageRoot, WorkspaceExecutor } from "../executors";
18
+ import type { ClientEntryDiscovery, ClientModuleImport } from "../frontendBuild/clientBuildTypes";
19
+ import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
20
+ import { DictionaryRoutes } from "../frontendBuild/dictionaryRoutes";
21
+ import { RouteClientBuilder } from "../frontendBuild/routeClientBuilder";
21
22
  import type { BatchWork, BuildBatchRequest, BuildBatchResult, OptimizedFonts } from "./buildBatchProtocol";
22
23
  import { BuildBatchRunner } from "./buildBatchRunner";
23
24
  import { BuilderBoot, type IncrementalBuilderOptions } from "./builderBoot";
@@ -44,6 +45,8 @@ class IncrementalBuilder {
44
45
  #discoveredThrough = 0;
45
46
  /** How often each reason sent a registry save to a build worker this session: the resident patcher's miss rate. */
46
47
  readonly #delegations = new Map<string, number>();
48
+ //? A route build bundles only entries no earlier route built: the dictionary walk reads every build's graph.
49
+ readonly #dictionaryGraph = new Map<string, readonly ClientModuleImport[]>();
47
50
  readonly #lanes: BuilderLanes;
48
51
  readonly #csr: CsrRegistry;
49
52
  readonly #ssr: SsrRegistry;
@@ -113,6 +116,7 @@ class IncrementalBuilder {
113
116
  browser: "registry",
114
117
  }).build();
115
118
  await this.#ssr.ensureSsrEntries(delta.registryEntries ?? []);
119
+ const dictionaryGroups = await this.#dictionaryGroupsOf(msg.seeds, delta);
116
120
  this.#logger.verbose(`build-route ok routeId=${msg.routeId} newEntries=${delta.newEntries.length}`);
117
121
  //? The builder's generation, not the route cache's: the cache's does not move when a fixed file maps to no entry,
118
122
  //? so the rebuild's ok would carry the failure's own number.
@@ -131,6 +135,7 @@ class IncrementalBuilder {
131
135
  routeId: msg.routeId,
132
136
  generation: msg.generation,
133
137
  seenGeneration,
138
+ dictionaryGroups,
134
139
  } as BuildRouteResultPayload,
135
140
  };
136
141
  } catch (err) {
@@ -147,6 +152,20 @@ class IncrementalBuilder {
147
152
  }
148
153
  }
149
154
 
155
+ //? A route whose groups could not be read loads the whole page file, as one with a key no build can follow does.
156
+ async #dictionaryGroupsOf(
157
+ seeds: string[],
158
+ { clientGraph, discoveredEntries, newEntries }: Awaited<ReturnType<RouteClientBuilder["build"]>>,
159
+ ): Promise<string[] | null> {
160
+ for (const [module, imports] of clientGraph ?? []) this.#dictionaryGraph.set(module, imports);
161
+ const entries = discoveredEntries ?? newEntries;
162
+ const route = { seeds, entries, importsByModule: this.#dictionaryGraph, discovery: this.#discovery };
163
+ return DictionaryRoutes.ofBuiltRoute(this.#app, route).catch((error: unknown) => {
164
+ this.#logger.warn(`dictionary groups of the route could not be read: ${String(error)}`);
165
+ return null;
166
+ });
167
+ }
168
+
150
169
  // Exits so the OS reclaims the bundler arenas; the host spawns the replacement.
151
170
  async shutdown(reason: string): Promise<void> {
152
171
  if (this.#lanes.shuttingDown) return;
@@ -1,14 +1,14 @@
1
1
  import { rm } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
4
- import type { App } from "@akanjs/devkit/commandDecorators";
5
- import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
6
- import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
- import { ServerGraphFile } from "@akanjs/devkit/frontendBuild/serverGraphFile";
8
- import { SsrDevBundler } from "@akanjs/devkit/frontendBuild/ssrDevBundler";
9
3
  import type { Logger } from "akanjs/common";
10
4
  import type { HmrTrace } from "akanjs/server";
11
5
  import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
6
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
7
+ import type { App } from "../commandDecorators";
8
+ import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
9
+ import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
10
+ import { ServerGraphFile } from "../frontendBuild/serverGraphFile";
11
+ import { SsrDevBundler } from "../frontendBuild/ssrDevBundler";
12
12
  import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
13
13
  import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
14
14
  import { BuilderChannel } from "./builderChannel";
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // XXX: types only. A value import from this barrel loads every facet (ink, typescript, ssh2, …) into the process;
2
- // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/util/fileSys`) and never
2
+ // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/frontendBuild`) and never
3
3
  // "fix" a TS1362 by widening an entry back to `export *`.
4
4
  export type * from "./akanApp";
5
5
  export type * from "./akanConfig";
@@ -0,0 +1,99 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { RenderAdmissionSoak } from "./renderAdmissionSoak";
6
+
7
+ const roots: string[] = [];
8
+
9
+ const workspace = () => {
10
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "akan-soak-"));
11
+ roots.push(root);
12
+ fs.mkdirSync(path.join(root, "apps", "shop", "page"), { recursive: true });
13
+ return { root, pageDir: RenderAdmissionSoak.pageDirOf(root, "shop") };
14
+ };
15
+
16
+ const until = async (check: () => boolean, what: string) => {
17
+ const deadline = Date.now() + 20_000;
18
+ while (!check()) {
19
+ if (Date.now() > deadline) throw new Error(`timed out waiting for ${what}`);
20
+ await Bun.sleep(20);
21
+ }
22
+ };
23
+
24
+ afterEach(() => {
25
+ for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
26
+ });
27
+
28
+ describe("RenderAdmissionSoak page", () => {
29
+ test("refuses a `page/soak` the app already has, and leaves it as it was", () => {
30
+ const { pageDir } = workspace();
31
+ fs.mkdirSync(pageDir);
32
+ fs.writeFileSync(path.join(pageDir, "_index.tsx"), "export default null;");
33
+
34
+ expect(() => RenderAdmissionSoak.injectPage(pageDir)).toThrow("this script did not create it");
35
+ expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
36
+ RenderAdmissionSoak.removePage(pageDir);
37
+ expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
38
+ });
39
+
40
+ test("removes only what it wrote, and the directory only when nothing else is left in it", () => {
41
+ const { pageDir } = workspace();
42
+ RenderAdmissionSoak.injectPage(pageDir);
43
+ expect(fs.readdirSync(pageDir).sort()).toEqual([".render-admission-soak.json", "io.tsx"]);
44
+ fs.writeFileSync(path.join(pageDir, "notes.tsx"), "export default null;");
45
+
46
+ RenderAdmissionSoak.removePage(pageDir);
47
+ expect(fs.readdirSync(pageDir)).toEqual(["notes.tsx"]);
48
+
49
+ const fresh = workspace().pageDir;
50
+ RenderAdmissionSoak.injectPage(fresh);
51
+ RenderAdmissionSoak.removePage(fresh);
52
+ expect(fs.existsSync(fresh)).toBe(false);
53
+ });
54
+
55
+ test("takes over the page an earlier run of its own left behind", () => {
56
+ const { pageDir } = workspace();
57
+ RenderAdmissionSoak.injectPage(pageDir);
58
+ fs.writeFileSync(path.join(pageDir, "io.tsx"), "stale");
59
+
60
+ RenderAdmissionSoak.injectPage(pageDir);
61
+ expect(fs.readFileSync(path.join(pageDir, "io.tsx"), "utf8")).toContain("akanjs/client");
62
+ });
63
+
64
+ test("a soak stopped while it builds removes its page and stops the build", async () => {
65
+ const { root, pageDir } = workspace();
66
+ const cli = path.join(root, "cli.ts");
67
+ const started = path.join(root, "build.pid");
68
+ fs.writeFileSync(
69
+ cli,
70
+ `await Bun.write(${JSON.stringify(started)}, String(process.pid));\nawait Bun.sleep(60_000);\n`,
71
+ );
72
+ const soak = Bun.spawn(
73
+ [
74
+ "bun",
75
+ path.join(import.meta.dir, "renderAdmissionSoak.ts"),
76
+ "shop",
77
+ "--prepare",
78
+ `--root=${root}`,
79
+ `--cli=${cli}`,
80
+ ],
81
+ { stdout: "ignore", stderr: "ignore" },
82
+ );
83
+ await until(() => fs.existsSync(started), "the build to start");
84
+ expect(fs.existsSync(path.join(pageDir, "io.tsx"))).toBe(true);
85
+ const buildPid = Number(fs.readFileSync(started, "utf8"));
86
+
87
+ soak.kill("SIGTERM");
88
+ expect(await soak.exited).toBe(130);
89
+ expect(fs.existsSync(pageDir)).toBe(false);
90
+ await until(() => {
91
+ try {
92
+ process.kill(buildPid, 0);
93
+ return false;
94
+ } catch {
95
+ return true;
96
+ }
97
+ }, "the build to stop");
98
+ }, 30_000);
99
+ });