@akanjs/devkit 3.0.1 → 3.0.2-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +15 -2
  2. package/akanConfig/akanConfig.test.ts +3 -0
  3. package/akanConfig/akanConfig.ts +3 -1
  4. package/akanContext.ts +18 -1
  5. package/biome.base.json +8 -1
  6. package/commandDecorators/command.ts +3 -2
  7. package/commandDecorators/commandDecorators.test.ts +7 -0
  8. package/csrE2e/csrPageStack.e2e.test.ts +12 -3
  9. package/executors.test.ts +329 -4
  10. package/executors.ts +49 -47
  11. package/frontendBuild/csrArtifactBuilder.test.ts +34 -0
  12. package/frontendBuild/csrArtifactBuilder.ts +14 -8
  13. package/frontendBuild/csrDevModuleCompiler.ts +0 -1
  14. package/frontendBuild/csrDevResolver.ts +0 -2
  15. package/frontendBuild/devGeneratedIndexSync.test.ts +13 -1
  16. package/frontendBuild/devGeneratedIndexSync.ts +21 -4
  17. package/frontendBuild/frontendBuild.test.ts +1 -1
  18. package/jsonFormatter.test.ts +64 -0
  19. package/jsonFormatter.ts +78 -0
  20. package/lint/__fixtures__/README.md +12 -3
  21. package/lint/__fixtures__/no-double-brace-placeholder/bad.ts +22 -0
  22. package/lint/__fixtures__/no-double-brace-placeholder/fixture.json +1 -0
  23. package/lint/__fixtures__/no-double-brace-placeholder/good.ts +15 -0
  24. package/lint/__fixtures__/no-inline-color/bad.tsx +17 -0
  25. package/lint/__fixtures__/no-inline-color/good.tsx +13 -0
  26. package/lint/__fixtures__/no-throw-raw-error/bad.tsx +8 -0
  27. package/lint/__fixtures__/no-throw-raw-error/good.tsx +8 -1
  28. package/lint/__fixtures__/no-unguarded-endpoint/bad.ts +20 -0
  29. package/lint/__fixtures__/no-unguarded-endpoint/fixture.json +1 -0
  30. package/lint/__fixtures__/no-unguarded-endpoint/good.ts +28 -0
  31. package/lint/__fixtures__/no-web-only-api-outside-webkit/bad.tsx +7 -7
  32. package/lint/gritRules.test.ts +23 -15
  33. package/lint/no-double-brace-placeholder.grit +15 -0
  34. package/lint/no-inline-color.grit +21 -5
  35. package/lint/no-throw-raw-error.grit +18 -33
  36. package/lint/no-unguarded-endpoint.grit +73 -0
  37. package/manifestDependencies.ts +65 -0
  38. package/mobile/desktopBin.test.ts +1 -1
  39. package/mobile/desktopServerStage.test.ts +7 -4
  40. package/mobile/nativeApp.test.ts +57 -8
  41. package/mobile/nativeApp.ts +27 -9
  42. package/mobile/nativeConfig.test.ts +26 -4
  43. package/mobile/nativeConfig.ts +19 -1
  44. package/package.json +2 -2
  45. package/platformTest/LinuxDockerTarget.ts +1 -1
  46. package/platformTest/PlatformTestTarget.ts +3 -1
  47. package/platformTest/WindowsSshTarget.ts +1 -1
  48. package/qualityScanner.test.ts +51 -0
  49. package/qualityScanner.ts +22 -1
  50. package/scanInfo.ts +14 -2
  51. package/testHelpers.ts +17 -0
  52. package/transforms/transforms.test.ts +13 -0
  53. package/tsconfig.json +4 -15
  54. package/workspaceLayout.test.ts +24 -1
  55. package/workspaceLayout.ts +19 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @akanjs/devkit
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 4871ae5: New lint rule `no-static-in-object-light-model` for `*.constant.ts`: a `static` on an `XObject` or `LightX` class is an error. The full model `via(XObject, LightX, …)` mixes in their prototypes only, so such a static never reaches `X`; declare it on `XInput` (or a scalar), `X`, or `XInsight` instead.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [4871ae5]
12
+ - Updated dependencies [4871ae5]
13
+ - Updated dependencies [4871ae5]
14
+ - akanjs@3.1.0
15
+
3
16
  ## 3.0.0
4
17
 
5
18
  ### Minor Changes
@@ -542,11 +555,11 @@
542
555
 
543
556
  **Lint config now extends a config shipped in the package.** `@akanjs/devkit/biome.base.json` carries the
544
557
  formatter, the rule set, and every grit plugin registration; a workspace `biome.json` is `extends` plus its own
545
- `files.includes`. Biome resolves the specifier through node_modules (it does not consult the package `exports`
558
+ `files.includes`. Biome resolves the specifier through node*modules (it does not consult the package `exports`
546
559
  map), and `plugins` paths inside an extended config resolve from the entry config's directory, so the
547
560
  `./node_modules/@akanjs/devkit/lint/*.grit` form the template already used is correct. Rule changes now reach a
548
561
  workspace on `bun update` with no command to run. Two merge behaviours decided the split: `overrides` concatenate,
549
- so the generated-file opt-out moved there from `files.includes`, which _replaces_ and would silently drop the base
562
+ so the generated-file opt-out moved there from `files.includes`, which \_replaces* and would silently drop the base
550
563
  list the moment a workspace added one exclusion of its own. Because Biome moves rules between groups across minors
551
564
  (`noUnnecessaryConditions` is `nursery` at 2.4 and `suspicious` at 2.5, and the old position is a hard error), the
552
565
  base config and the Biome version travel together: `biomeBase.ts` pins the version `createWorkspace` installs
@@ -678,6 +678,9 @@ describe("AkanAppConfig", () => {
678
678
  expect(make({ native: { server: { url: "http://x" } } })).toThrow(
679
679
  "native.server in apps/portal/akan.config.ts is not a native setting",
680
680
  );
681
+ expect(make({ native: { desktop: { dmg: { backgroundImage: "bg.png" } } } })).toThrow(
682
+ "native.desktop.dmg.backgroundImage in apps/portal/akan.config.ts is not a native setting",
683
+ );
681
684
  });
682
685
 
683
686
  test("derives a repo-scoped default appId and records an explicit native section", () => {
@@ -401,8 +401,9 @@ export class AkanAppConfig implements AppConfigResult {
401
401
  "activity",
402
402
  "files",
403
403
  ],
404
- desktop: ["indexPath", "server", "recovery", "window", "screenCapture", "entitlements"],
404
+ desktop: ["indexPath", "server", "recovery", "window", "screenCapture", "entitlements", "dmg"],
405
405
  desktopServer: ["omit"],
406
+ dmg: ["background", "background2x", "window", "iconSize", "textSize", "app", "applications"],
406
407
  deepLinks: ["schemes", "domains"],
407
408
  } as const;
408
409
  //* Settings that moved when `mobile` became `native` are named with where they went, instead of "unknown".
@@ -440,6 +441,7 @@ export class AkanAppConfig implements AppConfigResult {
440
441
  `${where}.desktop.server`,
441
442
  "desktopServer",
442
443
  );
444
+ check(settings.desktop?.dmg, AkanAppConfig.#nativeKeys.dmg, `${where}.desktop.dmg`, "dmg");
443
445
  check(settings.deepLinks, AkanAppConfig.#nativeKeys.deepLinks, `${where}.deepLinks`, "deepLinks");
444
446
  }
445
447
  static readonly #androidFilePattern = /^(?:res\/[^/]+\/[^/]+|assets\/.+)$/;
package/akanContext.ts CHANGED
@@ -16,7 +16,14 @@ import {
16
16
  workflowRunArtifactPath,
17
17
  workflowSyncDir,
18
18
  } from "./workflow";
19
- import { isScannedRootEntry, rootAllowedDirs, rootAllowedFiles, rootEntryHintOf } from "./workspaceLayout";
19
+ import {
20
+ barrelFacetDirs,
21
+ facetIndexShadowOf,
22
+ isScannedRootEntry,
23
+ rootAllowedDirs,
24
+ rootAllowedFiles,
25
+ rootEntryHintOf,
26
+ } from "./workspaceLayout";
20
27
 
21
28
  export type AkanContextFormat = "json" | "markdown";
22
29
  export type AkanModuleKind = "domain" | "service" | "scalar";
@@ -676,6 +683,16 @@ export class AkanContextAnalyzer {
676
683
  ),
677
684
  );
678
685
  }
686
+ for (const facet of barrelFacetDirs)
687
+ for (const entry of await safeReadDir(path.join(sysPath, facet))) {
688
+ const shadow = entry.isDirectory() ? null : facetIndexShadowOf(`${facet}/${entry.name}`);
689
+ if (!shadow) continue;
690
+ const entryPath = `${sys.path}/${facet}/${entry.name}`;
691
+ report(
692
+ { severity: "error", code: "facet-index-shadowed", path: entryPath, message: `${entryPath} ${shadow}` },
693
+ repairAction("generated", `akan sync ${sys.name}`, `Delete ${entryPath} by hand, then sync.`, false),
694
+ );
695
+ }
679
696
  }
680
697
 
681
698
  const agentDrift = await AkanContextAnalyzer.#agentGuideDrift(workspace);
package/biome.base.json CHANGED
@@ -186,7 +186,14 @@
186
186
  },
187
187
  {
188
188
  "includes": ["{apps,libs}/**/*.signal.ts"],
189
- "plugins": ["./node_modules/@akanjs/devkit/lint/no-redeclare-predefined-endpoint.grit"]
189
+ "plugins": [
190
+ "./node_modules/@akanjs/devkit/lint/no-redeclare-predefined-endpoint.grit",
191
+ "./node_modules/@akanjs/devkit/lint/no-unguarded-endpoint.grit"
192
+ ]
193
+ },
194
+ {
195
+ "includes": ["{apps,libs}/**/*.dictionary.ts"],
196
+ "plugins": ["./node_modules/@akanjs/devkit/lint/no-double-brace-placeholder.grit"]
190
197
  },
191
198
  {
192
199
  "includes": ["{apps,libs}/**/*.Util.tsx", "{apps,libs}/**/*.Zone.tsx"],
@@ -128,6 +128,8 @@ export const getOptionValue = async (argMeta: ArgMeta, opt: Record<string, unkno
128
128
  assertEnumChoice(argMeta, opt[argMeta.name]);
129
129
  return convertArgValue(opt[argMeta.name] as string, type ?? "string");
130
130
  } else if (defaultValue !== undefined) return defaultValue;
131
+ //? Before the choices: a nullable option left out means something (`--arch`: this computer's), so it is not asked.
132
+ else if (nullable) return null;
131
133
 
132
134
  if (enumChoices) {
133
135
  const choices = normalizeEnumChoices(
@@ -135,8 +137,7 @@ export const getOptionValue = async (argMeta: ArgMeta, opt: Record<string, unkno
135
137
  );
136
138
  if (choices.length === 1) return choices[0]?.value;
137
139
  return await select({ message: ask ?? desc ?? `Select the ${name} value`, choices });
138
- } else if (nullable) return null;
139
- else if (type === "boolean") {
140
+ } else if (type === "boolean") {
140
141
  const message = ask ?? desc ?? `Do you want to set ${name}? ${desc ? ` (${desc})` : ""}: `;
141
142
  return await confirm({ message });
142
143
  } else return convertArgValue(await input({ message: inputMessageOf(argMeta) }), type ?? "string");
@@ -277,6 +277,13 @@ describe("enum arg choices", () => {
277
277
  ).toBe("anything");
278
278
  });
279
279
 
280
+ test("a nullable option left out is null, not a prompt for one of its choices", async () => {
281
+ const arch = { ...optionMeta(["arm64", "x64"]), name: "arch" };
282
+ expect(await getOptionValue({ ...arch, argsOption: { ...arch.argsOption, nullable: true } }, {}, context)).toBe(
283
+ null,
284
+ );
285
+ });
286
+
280
287
  test("an option with no enum is unaffected", async () => {
281
288
  expect(await getOptionValue(optionMeta(undefined), { format: "whatever" }, context)).toBe("whatever");
282
289
  });
@@ -209,13 +209,22 @@ describe.skipIf(!CsrE2eHarness.enabled)("CSR page stack (minimal, /e2e/stack)",
209
209
  expect(await csr.reloaded()).toBe(false);
210
210
  }, 60_000);
211
211
 
212
- test("an async render that throws is logged with its route instead of leaving a blank page in silence", async () => {
212
+ test("an async render that throws is logged with its route and shows a retry instead of a blank page", async () => {
213
213
  await csr.open("/e2e/stack/broken");
214
- await csr.waitFor(() => true);
215
- await Bun.sleep(500);
214
+ await csr.waitFor(() => !!document.querySelector("[role=alert] button"), { timeout: 10_000 });
216
215
  expect(
217
216
  csr.consoleMessages().some((line) => /render of page \d+ of \S*\/e2e\/stack\/broken failed/.test(line)),
218
217
  ).toBe(true);
218
+ const failure = await csr.evaluate(() => {
219
+ const alert = document.querySelector("[role=alert]");
220
+ const button = alert?.querySelector("button");
221
+ return {
222
+ message: alert?.querySelector("p")?.textContent ?? "",
223
+ retry: button?.textContent ?? "",
224
+ painted: button ? getComputedStyle(button).backgroundColor !== "rgba(0, 0, 0, 0)" : false,
225
+ };
226
+ });
227
+ expect(failure).toEqual({ message: "This page could not be loaded.", retry: "Try again", painted: true });
219
228
  }, 60_000);
220
229
 
221
230
  test("the memory frame trace records navigation without writing it to the console", async () => {
package/executors.test.ts CHANGED
@@ -1,15 +1,33 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { describe, expect, spyOn, test } from "bun:test";
2
2
  import { existsSync } from "node:fs";
3
3
  import { lstat, mkdir, readFile, readlink, rm, stat, writeFile } from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { AkanAppConfig } from "./akanConfig";
6
- import { AppExecutor, CommandExecutionError, Executor, PkgExecutor, WorkspaceExecutor } from "./executors";
6
+ import {
7
+ AppExecutor,
8
+ CommandExecutionError,
9
+ Executor,
10
+ type LibExecutor,
11
+ PkgExecutor,
12
+ WorkspaceExecutor,
13
+ } from "./executors";
14
+ import { DevGeneratedIndexSync } from "./frontendBuild/devGeneratedIndexSync";
7
15
  import { AppInfo } from "./scanInfo";
8
- import { isolateEnv, tempDirs, writeJson, writeText } from "./testHelpers";
16
+ import {
17
+ createTempLib,
18
+ formatWithBiome,
19
+ hasBiome,
20
+ isolateEnv,
21
+ tempDirs,
22
+ tempRoots,
23
+ writeJson,
24
+ writeText,
25
+ } from "./testHelpers";
9
26
  import type { PackageJson } from "./types";
10
27
 
11
28
  isolateEnv();
12
29
  const makeTempRoot = tempDirs("akan-devkit-");
30
+ const trackRoot = tempRoots();
13
31
 
14
32
  const PAGE_SOURCE = "export default function Page() {\n return null;\n}\n";
15
33
 
@@ -309,11 +327,16 @@ describe("Workspace and app executor environment contracts", () => {
309
327
  expect(env.EXTRA).toBe("ok");
310
328
 
311
329
  const shellOperationMode = process.env.AKAN_PUBLIC_OPERATION_MODE;
330
+ const shellServerPort = process.env.AKAN_PUBLIC_SERVER_PORT;
312
331
  process.env.AKAN_PUBLIC_OPERATION_MODE = "local";
332
+ process.env.AKAN_PUBLIC_SERVER_PORT = "8282";
313
333
  const prepared = await app.prepareCommand("build");
314
334
  const bakedOperationMode = process.env.AKAN_PUBLIC_OPERATION_MODE;
335
+ const bakedServerPort = process.env.AKAN_PUBLIC_SERVER_PORT;
315
336
  if (shellOperationMode === undefined) delete process.env.AKAN_PUBLIC_OPERATION_MODE;
316
337
  else process.env.AKAN_PUBLIC_OPERATION_MODE = shellOperationMode;
338
+ if (shellServerPort !== undefined) process.env.AKAN_PUBLIC_SERVER_PORT = shellServerPort;
339
+ expect(bakedServerPort).toBeUndefined();
317
340
  expect(bakedOperationMode).toBeUndefined();
318
341
  expect(prepared.env.AKAN_COMMAND_TYPE).toBe("build");
319
342
  expect(prepared.env.AKAN_PUBLIC_BASE_PATHS).toBe("admin");
@@ -327,7 +350,7 @@ describe("Workspace and app executor environment contracts", () => {
327
350
  expect((await stat(path.join(root, "dist/apps/demo/public"))).isDirectory()).toBe(true);
328
351
  });
329
352
 
330
- test("akan start clears the dev output and keeps native builds, update releases and the bin downloads", async () => {
353
+ test("akan start clears the dev output and keeps the bin downloads and a native folder from before dist/native", async () => {
331
354
  const root = await makeTempRoot();
332
355
  process.env.AKAN_PUBLIC_REPO_NAME = "repo";
333
356
  process.env.AKAN_PUBLIC_SERVE_DOMAIN = "example.com";
@@ -1055,3 +1078,305 @@ describe("SysExecutor module listing", () => {
1055
1078
  ]);
1056
1079
  });
1057
1080
  });
1081
+
1082
+ interface ScannableLibOptions {
1083
+ root?: Pick<PackageJson, "dependencies" | "devDependencies">;
1084
+ manifest?: Partial<PackageJson>;
1085
+ config?: string;
1086
+ files?: Record<string, string>;
1087
+ }
1088
+
1089
+ //* `LibInfo.libInfos` caches a scan by lib name for the whole file, so every test passes a name of its own.
1090
+ const createScannableLib = async (
1091
+ libName: string,
1092
+ { root = {}, manifest = {}, config = "export default {};\n", files = {} }: ScannableLibOptions = {},
1093
+ ) => {
1094
+ const temp = trackRoot(await createTempLib(libName));
1095
+ const libDir = path.join(temp.root, "libs", libName);
1096
+ await writeJson(path.join(temp.root, "package.json"), {
1097
+ name: "repo",
1098
+ version: "1.0.0",
1099
+ description: "repo",
1100
+ ...root,
1101
+ });
1102
+ await writeJson(path.join(libDir, "package.json"), {
1103
+ type: "module",
1104
+ name: `@${libName}`,
1105
+ version: "0.0.1",
1106
+ ...manifest,
1107
+ });
1108
+ await writeJson(path.join(libDir, "tsconfig.json"), { compilerOptions: { target: "ESNext", paths: {} } });
1109
+ await writeText(path.join(libDir, "akan.config.ts"), config);
1110
+ await mkdir(path.join(libDir, "lib", "__scalar"), { recursive: true });
1111
+ for (const [file, content] of Object.entries(files)) await writeText(path.join(libDir, file), content);
1112
+ return { ...temp, libDir };
1113
+ };
1114
+
1115
+ describe("SysExecutor scan", () => {
1116
+ test("gives a facet folder with nothing to export an empty barrel, so a barrel a deleted file left heals", async () => {
1117
+ const { lib } = await createScannableLib("barrelheal", {
1118
+ files: {
1119
+ "common/index.ts": 'export * from "./commonLogic";\n',
1120
+ "webkit/thing.helper.ts": "export const thing = 1;\n",
1121
+ },
1122
+ });
1123
+
1124
+ await lib.scan();
1125
+
1126
+ expect(await lib.readFile("common/index.ts")).toBe("export {};\n");
1127
+ expect(await lib.readFile("webkit/index.ts")).toBe("export {};\n");
1128
+ expect(await lib.exists("ui")).toBe(false);
1129
+ });
1130
+
1131
+ test("imports into the generated lib/dict.ts and lib/srv.ts only the helpers their code calls", async () => {
1132
+ const { lib: bare } = await createScannableLib("nomodulelib");
1133
+ await bare.scan();
1134
+ expect(await bare.readFile("lib/dict.ts")).toContain(
1135
+ 'import { makeDictionary, makeTrans, dictionary as base } from "akanjs/dictionary";',
1136
+ );
1137
+ const bareSrv = await bare.readFile("lib/srv.ts");
1138
+ for (const unused of ["ServiceModel", '"./cnst"', '"./db"']) expect(bareSrv).not.toContain(unused);
1139
+
1140
+ const { lib: full } = await createScannableLib("allmodulelib", {
1141
+ files: {
1142
+ "lib/post/post.constant.ts": "export class Post {}\n",
1143
+ "lib/post/post.service.ts": "export class PostService {}\n",
1144
+ "lib/_mail/mail.service.ts": "export class MailService {}\n",
1145
+ "lib/__scalar/money/money.constant.ts": "export class Money {}\n",
1146
+ },
1147
+ });
1148
+ await full.scan();
1149
+ expect(await full.readFile("lib/dict.ts")).toContain(
1150
+ "import { makeDictionary, makeTrans, registerScalarTrans, registerServiceTrans, registerModelTrans, dictionary as base }",
1151
+ );
1152
+ const fullSrv = await full.readFile("lib/srv.ts");
1153
+ expect(fullSrv).toContain('import { ServiceModel } from "akanjs/service";');
1154
+ expect(fullSrv).toContain('import * as cnst from "./cnst";\nimport * as db from "./db";');
1155
+ });
1156
+
1157
+ test.skipIf(!hasBiome)("writes barrels, module indexes and akan.lib.json the way Biome prints them", async () => {
1158
+ const component = "export const C = () => null;\n";
1159
+ const uiFiles = ["QRCode", "Qa", "SSOButton", "Select", "Icon10", "Icon2"].map((name) => [
1160
+ `ui/${name}.tsx`,
1161
+ component,
1162
+ ]);
1163
+ const srvkitFiles = ["aB", "aa", "a10", "a9"].map((name) => [`srvkit/${name}.ts`, "export const x = 1;\n"]);
1164
+ const moduleFiles = ["Template", "Unit", "View"].map((role) => [`lib/post/Post.${role}.tsx`, component]);
1165
+ const { root, lib, libDir } = await createScannableLib("biomestable", {
1166
+ files: Object.fromEntries([
1167
+ ...uiFiles,
1168
+ ...srvkitFiles,
1169
+ ...moduleFiles,
1170
+ ["lib/post/post.constant.ts", "export class Post {}\n"],
1171
+ ]),
1172
+ });
1173
+ expect(await formatWithBiome('export * from "./b";\nexport * from "./a";\n', "libs/x/srvkit/index.ts")).toBe(
1174
+ 'export * from "./a";\nexport * from "./b";\n',
1175
+ );
1176
+
1177
+ await lib.scan();
1178
+
1179
+ expect(await lib.readFile("ui/index.ts")).toBe(
1180
+ ["Icon2", "Icon10", "Qa", "QRCode", "Select", "SSOButton"].map((name) => `export * from "./${name}";\n`).join(""),
1181
+ );
1182
+ expect(await lib.readFile("srvkit/index.ts")).toBe(
1183
+ ["a9", "a10", "aa", "aB"].map((name) => `export * from "./${name}";\n`).join(""),
1184
+ );
1185
+ for (const file of ["ui/index.ts", "srvkit/index.ts", "lib/post/index.ts", "akan.lib.json"]) {
1186
+ const generated = await lib.readFile(file);
1187
+ expect(await formatWithBiome(generated, `libs/biomestable/${file}`)).toBe(generated);
1188
+ }
1189
+ const devSync = new DevGeneratedIndexSync({ workspaceRoot: root });
1190
+ const events = ["ui/QRCode.tsx", "srvkit/a9.ts", "lib/post"].map((file) => path.join(libDir, file));
1191
+ expect(await devSync.syncForBatch(events)).toEqual({ changedFiles: [], errors: [] });
1192
+ });
1193
+
1194
+ test("refuses a hand-written ui/index.tsx beside the generated barrel, naming the file and the fix", async () => {
1195
+ const { lib } = await createScannableLib("shadowedbarrel", {
1196
+ files: {
1197
+ "ui/Chat.tsx": "export const Chat = () => null;\n",
1198
+ "ui/index.tsx": 'export { Chat } from "./Chat";\n',
1199
+ "ui/Page/index.tsx": 'export { Inner } from "./Inner";\n',
1200
+ "ui/Page/index_.tsx": '"use client";\nexport { Inner } from "./Inner";\n',
1201
+ },
1202
+ });
1203
+
1204
+ const error = await lib.scan().catch((caught: unknown) => caught);
1205
+
1206
+ expect(error).toBeInstanceOf(Error);
1207
+ const { message } = error as Error;
1208
+ expect(message).toContain("libs/shadowedbarrel/ui/index.tsx: shadows the generated ui/index.ts");
1209
+ expect(message).toContain("Delete it");
1210
+ expect(message).not.toContain("ui/Page/");
1211
+ });
1212
+ });
1213
+
1214
+ describe("SysExecutor dependency sync", () => {
1215
+ const root: Pick<PackageJson, "dependencies" | "devDependencies"> = {
1216
+ dependencies: {
1217
+ chalk: "^5.6.2",
1218
+ esbuild: "^0.25.0",
1219
+ lodash: "^4.17.21",
1220
+ react: "19.3.0",
1221
+ "react-dom": "19.3.0",
1222
+ sharp: "^0.34.0",
1223
+ zod: "3.25.76",
1224
+ },
1225
+ devDependencies: { dayjs: "^1.11.20", "happy-dom": "20.11.2", typescript: "^6.0.3" },
1226
+ };
1227
+ const readManifest = async (libDir: string) =>
1228
+ (await Bun.file(path.join(libDir, "package.json")).json()) as PackageJson;
1229
+ const silenced = (lib: LibExecutor) => ({
1230
+ info: spyOn(lib.logger, "info").mockImplementation(() => undefined),
1231
+ warn: spyOn(lib.logger, "warn").mockImplementation(() => undefined),
1232
+ });
1233
+
1234
+ test("prunes what the root declares and nothing imports, and keeps and warns once about what it does not", async () => {
1235
+ const { lib, libDir } = await createScannableLib("prunedeps", {
1236
+ root,
1237
+ manifest: {
1238
+ dependencies: { lodash: "^4.0.0", "react-dom": "19.2.6", "left-pad": "^1.3.0", "is-odd": "^3.0.1" },
1239
+ devDependencies: {},
1240
+ },
1241
+ files: { "srvkit/pad.ts": 'import padStart from "lodash/padStart";\nexport const pad = padStart;\n' },
1242
+ });
1243
+ const { info, warn } = silenced(lib);
1244
+
1245
+ await lib.scan();
1246
+
1247
+ expect((await readManifest(libDir)).dependencies).toEqual({
1248
+ lodash: "^4.17.21",
1249
+ "left-pad": "^1.3.0",
1250
+ "is-odd": "^3.0.1",
1251
+ });
1252
+ expect(info).toHaveBeenCalledTimes(1);
1253
+ expect(info.mock.calls[0]?.[0]).toContain(": react-dom (");
1254
+ expect(warn).toHaveBeenCalledTimes(1);
1255
+ expect(warn.mock.calls[0]?.[0]).toContain("libs/prunedeps/package.json lists left-pad, is-odd");
1256
+ });
1257
+
1258
+ test("keeps what externalLibs, trustedDependencies or akan.keepDependencies names", async () => {
1259
+ const akan = { keepDependencies: ["chalk"] };
1260
+ const { lib, libDir } = await createScannableLib("keptdeps", {
1261
+ root,
1262
+ config: 'export default { externalLibs: ["sharp"], trustedDependencies: ["esbuild"] };\n',
1263
+ manifest: {
1264
+ dependencies: { sharp: "^0.33.0", esbuild: "^0.24.0", chalk: "^5.0.0", "react-dom": "19.2.6" },
1265
+ devDependencies: {},
1266
+ akan,
1267
+ },
1268
+ });
1269
+ silenced(lib);
1270
+
1271
+ await lib.scan();
1272
+
1273
+ const manifest = await readManifest(libDir);
1274
+ expect(manifest.dependencies).toEqual({ sharp: "^0.34.0", esbuild: "^0.25.0", chalk: "^5.6.2" });
1275
+ expect(manifest.akan).toEqual(akan);
1276
+ });
1277
+
1278
+ test("gives every surviving entry the root version, leaving peer, optional and the akan source alone", async () => {
1279
+ const untouched = {
1280
+ peerDependencies: { react: "^19.0.0" },
1281
+ optionalDependencies: { fsevents: "^2.3.3" },
1282
+ akan: { source: { origin: "akanjs", sha: "3.0.0", hash: "0f0f", syncedAt: "2026-01-01T00:00:00.000Z" } },
1283
+ };
1284
+ const { lib, libDir } = await createScannableLib("realigneddeps", {
1285
+ root,
1286
+ manifest: {
1287
+ dependencies: { react: "19.2.7", lodash: "^4.0.0" },
1288
+ devDependencies: { dayjs: "^1.11.13" },
1289
+ ...untouched,
1290
+ },
1291
+ files: {
1292
+ "ui/Thing.tsx": 'import { useState } from "react";\nexport const Thing = () => useState(0);\n',
1293
+ "srvkit/pick.ts": 'import pick from "lodash/pick";\nexport const pickOf = pick;\n',
1294
+ },
1295
+ });
1296
+ silenced(lib);
1297
+
1298
+ await lib.scan();
1299
+
1300
+ const manifest = await readManifest(libDir);
1301
+ expect(manifest.dependencies).toEqual({ react: "19.3.0", lodash: "^4.17.21" });
1302
+ expect(manifest.devDependencies).toEqual({ dayjs: "^1.11.20" });
1303
+ expect(manifest).toMatchObject(untouched);
1304
+ });
1305
+
1306
+ test("keeps the existing order, appends new names sorted, and a second scan rewrites nothing", async () => {
1307
+ const { lib, libDir } = await createScannableLib("ordereddeps", {
1308
+ root,
1309
+ manifest: { dependencies: { zod: "3.25.76", lodash: "^4.17.21" }, devDependencies: {} },
1310
+ files: {
1311
+ "srvkit/uses.ts": [
1312
+ 'import { z } from "zod";',
1313
+ 'import chunk from "lodash/chunk";',
1314
+ 'import { createElement } from "react";',
1315
+ 'import chalk from "chalk";',
1316
+ "export const uses = [z, chunk, createElement, chalk];",
1317
+ "",
1318
+ ].join("\n"),
1319
+ },
1320
+ });
1321
+ silenced(lib);
1322
+
1323
+ await lib.scan();
1324
+ const manifestFile = path.join(libDir, "package.json");
1325
+ const [first, { mtimeMs }] = await Promise.all([readFile(manifestFile, "utf8"), stat(manifestFile)]);
1326
+ expect(Object.keys((JSON.parse(first) as PackageJson).dependencies ?? {})).toEqual([
1327
+ "zod",
1328
+ "lodash",
1329
+ "chalk",
1330
+ "react",
1331
+ ]);
1332
+
1333
+ await lib.scan({ refresh: true });
1334
+ expect(await readFile(manifestFile, "utf8")).toBe(first);
1335
+ expect((await stat(manifestFile)).mtimeMs).toBe(mtimeMs);
1336
+ });
1337
+
1338
+ test("moves a type-only import to devDependencies", async () => {
1339
+ const { lib, libDir } = await createScannableLib("typeonlydeps", {
1340
+ root,
1341
+ manifest: { dependencies: { zod: "3.25.76" }, devDependencies: {} },
1342
+ files: { "common/schema.ts": 'import type { ZodType } from "zod";\nexport type Schema = ZodType;\n' },
1343
+ });
1344
+ silenced(lib);
1345
+
1346
+ await lib.scan();
1347
+
1348
+ const manifest = await readManifest(libDir);
1349
+ expect(manifest.dependencies).toEqual({});
1350
+ expect(manifest.devDependencies).toEqual({ zod: "3.25.76" });
1351
+ });
1352
+
1353
+ test("leaves a runtime import the root lists only in devDependencies in devDependencies", async () => {
1354
+ const { lib, libDir } = await createScannableLib("devonlydeps", {
1355
+ root,
1356
+ manifest: { dependencies: {}, devDependencies: { "happy-dom": "20.0.0" } },
1357
+ files: {
1358
+ "srvkit/dom.ts": 'import { Window } from "happy-dom";\nexport const createWindow = () => new Window();\n',
1359
+ },
1360
+ });
1361
+ silenced(lib);
1362
+
1363
+ await lib.scan();
1364
+
1365
+ const manifest = await readManifest(libDir);
1366
+ expect(manifest.dependencies).toEqual({});
1367
+ expect(manifest.devDependencies).toEqual({ "happy-dom": "20.11.2" });
1368
+ });
1369
+
1370
+ test("has written the manifest by the time scan returns", async () => {
1371
+ const { lib, libDir } = await createScannableLib("settleddeps", {
1372
+ root,
1373
+ manifest: { dependencies: { "react-dom": "19.2.6" }, devDependencies: {} },
1374
+ files: { "srvkit/pick.ts": 'import pick from "lodash/pick";\nexport const pickOf = pick;\n' },
1375
+ });
1376
+ silenced(lib);
1377
+
1378
+ await lib.scan({ writeLib: false });
1379
+
1380
+ expect((await readManifest(libDir)).dependencies).toEqual({ lodash: "^4.17.21" });
1381
+ });
1382
+ });