feat(ui): the viewer's screens as @colbymchenry/codegraph-ui, behind one adapter (CG-61)
`ui/src` now builds two ways from one tree: the static app `codegraph ui` serves, and — via `svelte-package` — a Svelte library the Pro app imports. A forked component would be a second answer to the same question about the same graph, so there is no fork. Everything a screen knows arrives through a `GraphAdapter`: eleven methods answering the wire shapes verbatim, with `createHttpAdapter()` (the loopback JSON API) as the default and a host's in-process engine reads as the point. `lib/api.ts` became a one-line-per-call facade over it, which is why no call site in the views changed. The payload types moved to `lib/wire.ts` — no imports, no runtime — so a host can depend on the vocabulary alone. Two more seams and one guard: - `lib/navigation.ts` holds the href builders behind a `NavigationDriver`, so a host addresses its own URL space. The app's half — the hash parser and the live route, which attach window listeners at module scope — stays in `router.svelte.ts` and is pruned out of the package: rendering a Symbol view must not install a hash router in somebody else's application. - `lib/theme.css` carries the design tokens and maps Svelte Flow's `--xy-*` variables onto them, so a host never sees library defaults. Dark now also answers to a bare `[data-theme]`, which is how `<CodegraphUi theme>` themes a container rather than the document. - `scripts/check-ui-package.mjs` prunes the app's shell, resolves the extensionless specifiers svelte-package leaves behind, and asserts that nothing but `lib/adapter.js` reaches the network. The search box, its keyboard and its panel are one component now (`SearchPalette`), because splitting them is what breaks a palette. `__tests__/ui-package.test.ts` mounts the three screens from the package entry against a mock adapter in jsdom; it runs as a second vitest project so the `browser` resolve condition it needs cannot reach the engine's suites. Versioned with the engine. Prepared, not published: `private: true` is the guard and `pack-npm.sh` only packs a tarball under CODEGRAPH_PACK_UI=1.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Keep `@colbymchenry/codegraph-ui` on the engine's version number.
|
||||
*
|
||||
* The component package draws its screens from the engine's own JSON API, and
|
||||
* that API is versioned with the binary that serves it — a payload field can
|
||||
* appear or change shape in any engine release. So the two ship as one number:
|
||||
* `@colbymchenry/codegraph-ui@1.6.0` is the reader for `codegraph@1.6.0`, and a
|
||||
* host can pin them together without a compatibility table.
|
||||
*
|
||||
* This SYNCS rather than asserts, deliberately. The documented release flow is
|
||||
* "edit the version in package.json, run the Release workflow" — often as a
|
||||
* single-file edit in the GitHub web UI — and a check that failed the build
|
||||
* because a second file had not been edited would turn that into a two-step
|
||||
* dance for no gain. The same reasoning the workflow's package-lock sync step
|
||||
* already runs on.
|
||||
*
|
||||
* Idempotent: a re-run with the versions already equal writes nothing.
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = fileURLToPath(new URL('../package.json', import.meta.url));
|
||||
const ui = fileURLToPath(new URL('../ui/package.json', import.meta.url));
|
||||
|
||||
const engineVersion = JSON.parse(readFileSync(root, 'utf8')).version;
|
||||
const raw = readFileSync(ui, 'utf8');
|
||||
const manifest = JSON.parse(raw);
|
||||
|
||||
if (manifest.version === engineVersion) {
|
||||
console.log(`[sync-ui-version] ui already at ${engineVersion}`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// A targeted replacement, not a re-serialise: rewriting the whole file would
|
||||
// reformat a manifest a human maintains and bury the one-line change in noise.
|
||||
const next = raw.replace(
|
||||
/("version"\s*:\s*)"[^"]*"/,
|
||||
(_match, prefix) => `${prefix}"${engineVersion}"`
|
||||
);
|
||||
if (next === raw) {
|
||||
console.error('[sync-ui-version] could not find a "version" field in ui/package.json');
|
||||
process.exit(1);
|
||||
}
|
||||
writeFileSync(ui, next);
|
||||
console.log(`[sync-ui-version] ui ${manifest.version} -> ${engineVersion}`);
|
||||
Reference in New Issue
Block a user