From e07d3cb7e3de7f30475c37b73369f7369bad1abf Mon Sep 17 00:00:00 2001 From: Wes Mason Date: Mon, 6 Jul 2026 16:09:56 +0100 Subject: [PATCH] fix(llm-model-catalog): format generated files so they stop showing as modified generate.mjs wrote defaultPrices.ts and modelCatalog.ts with raw JSON.stringify (quoted keys, no trailing commas), but the committed files were oxfmt-formatted, so the generator output never matched HEAD. Any 'turbo run generate' (e.g. via 'pnpm run db:migrate') left both files dirty with an identical-data diff. Run oxfmt on the output as the final generate step so regeneration is a no-op. --- .../llm-model-catalog/scripts/generate.mjs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/internal-packages/llm-model-catalog/scripts/generate.mjs b/internal-packages/llm-model-catalog/scripts/generate.mjs index 430a4edb34d..37177c0959c 100644 --- a/internal-packages/llm-model-catalog/scripts/generate.mjs +++ b/internal-packages/llm-model-catalog/scripts/generate.mjs @@ -12,12 +12,19 @@ // - Catalog: pnpm run generate-catalog (uses Claude CLI to research models) import { readFileSync, writeFileSync, existsSync } from "node:fs"; +import { execFileSync } from "node:child_process"; import { join, dirname } from "node:path"; import { fileURLToPath } from "node:url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const srcDir = join(__dirname, "..", "src"); +// Generated files are checked in, so their output must match oxfmt (the repo +// formatter) exactly. JSON.stringify emits quoted keys and no trailing commas, +// which oxfmt rewrites, so without this the files show as modified every time +// `turbo run generate` runs (e.g. as part of `pnpm run db:migrate`). +const written = []; + // --- 1. Generate defaultPrices.ts from default-model-prices.json --- const pricesJsonPath = join(srcDir, "default-model-prices.json"); @@ -49,7 +56,9 @@ if (existsSync(pricesJsonPath)) { out += "export const defaultModelPrices: DefaultModelDefinition[] = "; out += JSON.stringify(stripped, null, 2) + ";\n"; - writeFileSync(join(srcDir, "defaultPrices.ts"), out); + const outPath = join(srcDir, "defaultPrices.ts"); + writeFileSync(outPath, out); + written.push(outPath); console.log(`Generated defaultPrices.ts (${stripped.length} models)`); } else { console.log("Skipping defaultPrices.ts — default-model-prices.json not found"); @@ -91,8 +100,19 @@ if (existsSync(catalogJsonPath)) { out += "export const modelCatalog: Record = "; out += JSON.stringify(data, null, 2) + ";\n"; - writeFileSync(join(srcDir, "modelCatalog.ts"), out); + const outPath = join(srcDir, "modelCatalog.ts"); + writeFileSync(outPath, out); + written.push(outPath); console.log(`Generated modelCatalog.ts (${Object.keys(data).length} entries)`); } else { console.log("Skipping modelCatalog.ts — model-catalog.json not found"); } + +// --- 3. Format generated files with oxfmt so they match the committed output --- + +if (written.length > 0) { + // execFileSync doesn't apply PATHEXT, so target pnpm's .cmd shim on Windows. + const pnpm = process.platform === "win32" ? "pnpm.cmd" : "pnpm"; + execFileSync(pnpm, ["exec", "oxfmt", ...written], { stdio: "inherit" }); + console.log(`Formatted ${written.length} file(s) with oxfmt`); +}