mirror of
https://github.com/cjpais/Handy.git
synced 2026-11-22 02:10:34 +08:00
* feat: use shared model catalog * fix: preserve other model quants on deletion * fix: offer retired model replacements * fix: preserve unreadable model caches * fix: report model deletion failures * refactor: simplify model availability and cache reuse * fix: match cached repos to the catalog by exact name HF repo ids are case-insensitive, so another tool can cache a catalog repo under other casing. Matching it case-insensitively relabelled the file with the catalog's casing, which on a case-sensitive filesystem points at a folder that doesn't exist, so the model vanished. Exact matching (as on main) keeps such a file listed under the casing it was found at. * fix: harden model deletion and catalog check on Windows
44 lines
1.7 KiB
TypeScript
44 lines
1.7 KiB
TypeScript
// The Rust app compiles in a copy of @handy-computer/models' catalog.json
|
|
// (src-tauri can't depend on node_modules: cargo-only builds never run bun
|
|
// install). This keeps the copy identical to the version pinned in
|
|
// package.json.
|
|
//
|
|
// bun run sync:catalog copy the package's catalog.json into src-tauri
|
|
// bun run check:catalog fail if the copy differs (CI)
|
|
import { readFileSync, writeFileSync } from "node:fs";
|
|
import { createRequire } from "node:module";
|
|
import { dirname, join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const source = require.resolve("@handy-computer/models/catalog.json");
|
|
const target = fileURLToPath(
|
|
new URL("../src-tauri/src/catalog/catalog.json", import.meta.url),
|
|
);
|
|
// The package's exports don't expose package.json; it sits beside the catalog.
|
|
const { version } = JSON.parse(
|
|
readFileSync(join(dirname(source), "package.json"), "utf8"),
|
|
) as { version: string };
|
|
|
|
const expected = readFileSync(source);
|
|
// Only a missing copy counts as "differs"; any other read error is rethrown
|
|
// rather than overwriting a file that couldn't be read.
|
|
let current: Buffer | undefined;
|
|
try {
|
|
current = readFileSync(target);
|
|
} catch (e) {
|
|
if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e;
|
|
}
|
|
|
|
if (current?.equals(expected)) {
|
|
console.log(`catalog.json matches @handy-computer/models@${version}`);
|
|
} else if (process.argv.includes("--check")) {
|
|
console.error(
|
|
`src-tauri/src/catalog/catalog.json differs from @handy-computer/models@${version}; run \`bun run sync:catalog\``,
|
|
);
|
|
process.exit(1);
|
|
} else {
|
|
writeFileSync(target, expected);
|
|
console.log(`catalog.json synced from @handy-computer/models@${version}`);
|
|
}
|