Skip to content

Commit 9107712

Browse files
committed
feat(shared): add committed/ephemeral typegen cache path resolvers
Introduce getCommittedCacheDir() -> <cwd>/.appkit and getEphemeralStateDir() -> <cwd>/node_modules/.databricks/appkit as the single source of truth for typegen cache/state locations, co-located with spawn-lock.ts and re-exported from the shared root barrel. Rewire getSpawnLockPath to compose from getEphemeralStateDir (behavior-preserving, same resolved path). Foundation for relocating the typegen cache out of node_modules so it survives pnpm install on warehouse-less CI/CD. xavier loop: iteration 1 -- Phase 1 (resolvers) Co-authored-by: Isaac Signed-off-by: Atila Fassina <atila@fassina.eu>
1 parent 72dd0a6 commit 9107712

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os from "node:os";
2+
import path from "node:path";
3+
import { describe, expect, test } from "vitest";
4+
import { getCommittedCacheDir, getEphemeralStateDir } from "./cache-paths";
5+
6+
describe("cache-paths", () => {
7+
test("getCommittedCacheDir returns the .appkit directory under root", () => {
8+
const root = path.join(os.tmpdir(), "some-project");
9+
expect(getCommittedCacheDir(root)).toBe(path.join(root, ".appkit"));
10+
});
11+
12+
test("getCommittedCacheDir defaults to process.cwd() when no argument is given", () => {
13+
expect(getCommittedCacheDir()).toBe(path.join(process.cwd(), ".appkit"));
14+
});
15+
16+
test("getEphemeralStateDir returns node_modules/.databricks/appkit under root", () => {
17+
const root = path.join(os.tmpdir(), "some-project");
18+
expect(getEphemeralStateDir(root)).toBe(
19+
path.join(root, "node_modules", ".databricks", "appkit"),
20+
);
21+
});
22+
23+
test("getEphemeralStateDir defaults to process.cwd() when no argument is given", () => {
24+
expect(getEphemeralStateDir()).toBe(
25+
path.join(process.cwd(), "node_modules", ".databricks", "appkit"),
26+
);
27+
});
28+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import path from "node:path";
2+
3+
/**
4+
* Home for typegen COMMITTED caches (build inputs that must survive `pnpm
5+
* install` and travel with the app in git). Per-app, anchored at the app root.
6+
* The two caches (query/metric + serving) live here as `.appkit/*.json`.
7+
*
8+
* @param rootDir - project root. Defaults to the current working directory.
9+
* @returns absolute path to the committed cache directory.
10+
*/
11+
export function getCommittedCacheDir(rootDir: string = process.cwd()): string {
12+
return path.join(rootDir, ".appkit");
13+
}
14+
15+
/**
16+
* Home for typegen EPHEMERAL coordination state (worker spawn lock, ui-variant
17+
* choices). Stays under `node_modules/` — gitignored, cleared on clean install.
18+
* Never committed.
19+
*
20+
* @param rootDir - project root. Defaults to the current working directory.
21+
* @returns absolute path to the ephemeral state directory.
22+
*/
23+
export function getEphemeralStateDir(rootDir: string = process.cwd()): string {
24+
return path.join(rootDir, "node_modules", ".databricks", "appkit");
25+
}

packages/shared/src/cli/commands/spawn-lock.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
3+
import { getEphemeralStateDir } from "./cache-paths.js";
34

45
/**
56
* How long a spawn lock is considered fresh. A held lock newer than this means a
@@ -28,10 +29,7 @@ export const SPAWN_LOCK_STALE_MS = 6 * 60 * 1000;
2829
*/
2930
export function getSpawnLockPath(rootDir: string): string {
3031
return path.join(
31-
rootDir,
32-
"node_modules",
33-
".databricks",
34-
"appkit",
32+
getEphemeralStateDir(rootDir),
3533
".appkit-typegen-worker.lock",
3634
);
3735
}

packages/shared/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./agent";
22
export * from "./cache";
3+
export * from "./cli/commands/cache-paths";
34
export * from "./execute";
45
export * from "./genie";
56
export * from "./plugin";

0 commit comments

Comments
 (0)