@akanjs/devkit 3.3.0-rc.39 → 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.
package/CHANGELOG.md CHANGED
@@ -560,6 +560,13 @@
560
560
 
561
561
  - 1d8c8c2: `akan start` keeps `apps/<app>/.akan/cache` between runs, so a restart reuses the CSS class scan and the subset fonts instead of redoing them. Each entry names the akanjs and Bun versions and the build of the cache code that wrote it, and an entry another one wrote, or one cut short, is rebuilt.
562
562
  - 98931e4: `akan start` prints one line when the dev server is ready that says where the start's time went: what the CLI did before the builder, the base build and its parts, the backend's boot, and when the first artifact was on disk.
563
+ - 4795e71: `akan sync` lists an app's libs in one fixed order, and `akan.app.json` records the routes of the lib pages the same sync linked.
564
+
565
+ - **Libs are listed dependency first, by name where neither depends on the other.** The order came from which lib's scan finished first, so two syncs of an unchanged tree could rewrite the generated barrels (`lib/cnst.ts`, `lib/dict.ts`, `lib/sig.ts`, `lib/st.ts`, `client.ts`, `server.ts` and the rest) with the same libs in another order. A real workspace of nine libs had 58 generated files rewritten that way by the second sync of a clean checkout. `libDeps` in `akan.app.json` and `akan.lib.json` follows the same order.
566
+ - **`routes` in `akan.app.json` holds lib pages from the first sync.** With `syncPageLibs`, the manifest was written before the lib page folders were linked, so the first sync of a new checkout recorded the app's own routes only and a second sync added the rest.
567
+
568
+ **Expect one diff.** The first sync after this upgrade can reorder the lib imports and lists in generated files once, in every app and lib of a workspace. Nothing else in them changes, and a later sync leaves them alone.
569
+
563
570
  - 8bbe7c8: A Redis or Postgres tunnel to a cluster environment needs a configured credential: `SSH_TUNNEL_PRIVATE_KEY_PATH` (with `SSH_TUNNEL_PASSPHRASE` if the key has one), exported in the shell, or `SSH_TUNNEL_PASSWORD`. Without either, the tunnel fails before it dials, with an error naming both settings, instead of signing in with a built-in default credential and a warning. This removes an unsafe default. A key file the tunnel cannot read fails with an error naming the tunnel, `SSH_TUNNEL_PRIVATE_KEY_PATH` and the path.
564
571
 
565
572
  **Upgrading.** If `akan start` against a cluster environment opened its tunnel with neither setting, it now stops with that error in every database mode but `single`, where it logs the error and runs without Redis. Export `SSH_TUNNEL_PRIVATE_KEY_PATH` in the shell (a repository's dotenv file cannot set it), or set `SSH_TUNNEL_PASSWORD` to the password the cluster's tunnel endpoint expects. `SSH_TUNNEL_USERNAME` still defaults to `root`.
@@ -409,8 +409,10 @@ export class AppExecutor extends SysExecutor {
409
409
  })) as AppInfo;
410
410
  if (write) await this.syncAssets(scanInfo.getScanResult().libDeps);
411
411
  //* `scan` read the routes off the page tree this sync may be about to change, so re-read them.
412
- if (write && (await this.syncPages(scanInfo.getScanResult().libDeps)))
412
+ if (write && (await this.syncPages(scanInfo.getScanResult().libDeps))) {
413
413
  scanInfo.setRoutes(await this.getPageKeys({ refresh: true }));
414
+ await this.writeJson("akan.app.json", scanInfo.getScanResult());
415
+ }
414
416
  if (write) await this.#runPluginSyncAssets();
415
417
  return scanInfo;
416
418
  }
@@ -1591,11 +1591,11 @@ describe("a build of a three-scope workspace", () => {
1591
1591
  }, 240_000);
1592
1592
  });
1593
1593
 
1594
- const syncScript = (root: string, appName: string) => `
1594
+ const syncScript = (root: string, appName: string, method: "scan" | "scanSync" = "scan") => `
1595
1595
  const { AppExecutor } = await import(${devkitFile("executors/appExecutor.ts")});
1596
1596
  const { WorkspaceExecutor } = await import(${devkitFile("executors/workspaceExecutor.ts")});
1597
1597
  const [root, appName] = ${JSON.stringify([root, appName])};
1598
- await AppExecutor.from(new WorkspaceExecutor({ workspaceRoot: root, repoName: "repo" }), appName).scan();
1598
+ await AppExecutor.from(new WorkspaceExecutor({ workspaceRoot: root, repoName: "repo" }), appName).${method}();
1599
1599
  console.log("{}");
1600
1600
  `;
1601
1601
  const scopeFilesOf = async (root: string) => {
@@ -1642,21 +1642,49 @@ describe("the first sync of a new checkout", () => {
1642
1642
  },
1643
1643
  scanned: false,
1644
1644
  });
1645
- //? The scan result lists an app's libs in the order the file system hands their importers.
1646
- const manifest = `apps/${app}/akan.app.json`;
1647
1645
  const libDepsOf = (files: Record<string, string>) =>
1648
- (JSON.parse(files[manifest] ?? "{}") as { libDeps: string[] }).libDeps.toSorted((a, b) => a.localeCompare(b));
1646
+ (JSON.parse(files[`apps/${app}/akan.app.json`] ?? "{}") as { libDeps: string[] }).libDeps;
1649
1647
  //? Each in a process of its own: the scan orders libs among every lib the process has scanned, other tests' too.
1650
1648
  await evaluate(temp.root, syncScript(temp.root, app), app);
1651
1649
  const first = await scopeFilesOf(temp.root);
1652
1650
  await evaluate(temp.root, syncScript(temp.root, app), app);
1653
1651
  const second = await scopeFilesOf(temp.root);
1654
1652
  expect(libDepsOf(first)).toEqual([base, upper, top]);
1655
- expect({ ...first, [manifest]: libDepsOf(first) }).toEqual({ ...second, [manifest]: libDepsOf(second) });
1653
+ expect(first).toEqual(second);
1656
1654
  expect(first[`libs/${top}/lib/cnst.ts`]).toContain(`"@libs/${base}"`);
1657
1655
  const wholeConstants = Object.keys(first).filter(
1658
1656
  (file) => file.endsWith(".fetch.ts") && first[file]?.includes('from "../cnst"'),
1659
1657
  );
1660
1658
  expect(wholeConstants).toEqual([]);
1661
1659
  }, 240_000);
1660
+
1661
+ test("records the routes of the lib pages it links, and lists a lib after the libs it depends on", async () => {
1662
+ const [app, base, upper] = ["pier", "zinc", "amber"];
1663
+ const temp = await writeWorkspace({
1664
+ app,
1665
+ lib: base,
1666
+ libFiles: stockFiles,
1667
+ moreLibs: {
1668
+ [upper]: {
1669
+ "lib/option.ts": option,
1670
+ ...kitModuleNamed("org", "Org"),
1671
+ "ui/Items.tsx": `import { st } from "@libs/${base}/client";\nexport const Items = () => st.use.itemCount();\n`,
1672
+ "page/about/_index.tsx": "export default function Page() {\n return null;\n}\n",
1673
+ },
1674
+ },
1675
+ appFiles: {
1676
+ ...shopFilesOf(base),
1677
+ "akan.config.ts": "export default { syncPageLibs: true };\n",
1678
+ "ui/Orgs.tsx": `import { st } from "@libs/${upper}/client";\nexport const Orgs = () => st.use.orgCount();\n`,
1679
+ },
1680
+ scanned: false,
1681
+ });
1682
+ await evaluate(temp.root, syncScript(temp.root, app, "scanSync"), app);
1683
+ const manifest = JSON.parse(await Bun.file(path.join(temp.root, "apps", app, "akan.app.json")).text()) as {
1684
+ libDeps: string[];
1685
+ routes: string[];
1686
+ };
1687
+ expect(manifest.libDeps).toEqual([base, upper]);
1688
+ expect(manifest.routes).toContain(`./(libs)/(${upper})/about/_index.tsx`);
1689
+ }, 240_000);
1662
1690
  });
@@ -195,6 +195,7 @@ export class SysExecutor extends Executor {
195
195
  : await LibInfo.fromExecutor(this as unknown as LibExecutor, {
196
196
  refresh,
197
197
  });
198
+ scanInfo.orderLibDeps();
198
199
  //* Locked: `writeLib` rewrites dependency-lib barrels that other dev servers regenerate and watch too.
199
200
  if (write)
200
201
  await CodegenLock.run(this.workspace.workspaceRoot, `scan:${this.name}`, async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.3.0-rc.39",
3
+ "version": "3.3.0-rc.40",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -50,7 +50,7 @@
50
50
  "./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
51
51
  },
52
52
  "dependencies": {
53
- "@akanjs/language": "3.3.0-rc.39",
53
+ "@akanjs/language": "3.3.0-rc.40",
54
54
  "@earendil-works/pi-agent-core": "1.5.2",
55
55
  "@earendil-works/pi-ai": "1.5.2",
56
56
  "@earendil-works/pi-codemode": "1.5.2",
@@ -59,7 +59,7 @@
59
59
  "@earendil-works/pi-tui": "1.5.2",
60
60
  "@inquirer/prompts": "^8.7.3",
61
61
  "@tailwindcss/node": "^4.3.3",
62
- "akanjs": "3.3.0-rc.39",
62
+ "akanjs": "3.3.0-rc.40",
63
63
  "chalk": "^6.0.1",
64
64
  "commander": "^15.0.0",
65
65
  "dayjs": "^1.11.23",
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { LibInfo } from "./scanInfo";
3
+
4
+ const deps: Record<string, string[]> = {
5
+ zeta: [],
6
+ alpha: ["zeta", "mid"],
7
+ mid: ["zeta"],
8
+ beta: [],
9
+ omega: ["alpha", "mid", "zeta"],
10
+ };
11
+ const insertionOrders = [
12
+ ["zeta", "alpha", "mid", "beta", "omega"],
13
+ ["omega", "beta", "mid", "alpha", "zeta"],
14
+ ["alpha", "omega", "zeta", "mid", "beta"],
15
+ ["beta", "mid", "omega", "zeta", "alpha"],
16
+ ];
17
+
18
+ describe("LibInfo.orderOf", () => {
19
+ test("puts a lib after every lib it depends on, whatever order the libs were scanned in", () => {
20
+ for (const names of insertionOrders) {
21
+ const ordered = LibInfo.orderOf(new Map(names.map((name) => [name, deps[name] ?? []])));
22
+ expect(ordered).toEqual(["zeta", "mid", "alpha", "beta", "omega"]);
23
+ }
24
+ });
25
+
26
+ test("gives the same order whatever order a lib names its dependencies in", () => {
27
+ const reversed = new Map(Object.entries(deps).map(([name, libDeps]) => [name, libDeps.toReversed()]));
28
+ expect(LibInfo.orderOf(reversed)).toEqual(LibInfo.orderOf(new Map(Object.entries(deps))));
29
+ });
30
+
31
+ test("leaves out a dependency that was not scanned, and ends on libs that depend on each other", () => {
32
+ expect(LibInfo.orderOf(new Map([["solo", ["missing"]]]))).toEqual(["solo"]);
33
+ const cycle = new Map([
34
+ ["b", ["a"]],
35
+ ["a", ["b"]],
36
+ ]);
37
+ expect(LibInfo.orderOf(cycle)).toEqual(["b", "a"]);
38
+ });
39
+ });
@@ -283,6 +283,12 @@ class ScanInfo {
283
283
  this.#sortedLibs = null;
284
284
  }
285
285
 
286
+ orderLibDeps() {
287
+ const libIndices = LibInfo.getSortedLibIndices();
288
+ const indexOf = (libName: string) => libIndices.get(libName) ?? libIndices.size;
289
+ this.scanResult.libDeps.sort((a, b) => indexOf(a) - indexOf(b) || a.localeCompare(b));
290
+ }
291
+
286
292
  #sortedLibs: string[] | null = null;
287
293
  protected sortedLibs(libDeps: string[]) {
288
294
  if (this.#sortedLibs) return this.#sortedLibs;
@@ -413,14 +419,27 @@ export class LibInfo extends ScanInfo {
413
419
 
414
420
  static getSortedLibIndices() {
415
421
  if (LibInfo.#sortedLibIndices) return LibInfo.#sortedLibIndices;
416
- LibInfo.#sortedLibIndices = new Map(
417
- [...LibInfo.libInfos.entries()]
418
- .sort(([_, libInfoA], [__, libInfoB]) => (libInfoA.getScanResult().libDeps.includes(libInfoB.name) ? 1 : -1))
419
- .map(([libName], index) => [libName, index]),
422
+ const depsByLib = new Map(
423
+ [...LibInfo.libInfos].map(([libName, libInfo]) => [libName, libInfo.getScanResult().libDeps] as const),
420
424
  );
425
+ LibInfo.#sortedLibIndices = new Map(LibInfo.orderOf(depsByLib).map((libName, index) => [libName, index]));
421
426
  return LibInfo.#sortedLibIndices;
422
427
  }
423
428
 
429
+ //? Lib scans finish in an order that differs from run to run, so the order comes from names and dependencies alone.
430
+ static orderOf(depsByLib: ReadonlyMap<string, readonly string[]>): string[] {
431
+ const ordered: string[] = [];
432
+ const placed = new Set<string>();
433
+ const place = (libName: string) => {
434
+ if (placed.has(libName) || !depsByLib.has(libName)) return;
435
+ placed.add(libName);
436
+ for (const dependency of (depsByLib.get(libName) ?? []).toSorted((a, b) => a.localeCompare(b))) place(dependency);
437
+ ordered.push(libName);
438
+ };
439
+ for (const libName of [...depsByLib.keys()].sort((a, b) => a.localeCompare(b))) place(libName);
440
+ return ordered;
441
+ }
442
+
424
443
  static async fromExecutor(exec: LibExecutor, { refresh }: { refresh?: boolean } = {}) {
425
444
  const existingLibInfo = LibInfo.libInfos.get(exec.name);
426
445
  if (existingLibInfo && !refresh) return existingLibInfo;