|
11 | 11 | * pnpm tsx scripts/sync-provider-models.ts |
12 | 12 | */ |
13 | 13 |
|
| 14 | +import { execFileSync } from 'node:child_process' |
14 | 15 | import { readFile, writeFile } from 'node:fs/promises' |
15 | 16 | import { dirname, resolve } from 'node:path' |
16 | 17 | import { fileURLToPath } from 'node:url' |
@@ -496,6 +497,38 @@ function addToTypeMap( |
496 | 497 | return content.replace(pattern, () => `${match[1]}\n${newEntries}${match[2]}`) |
497 | 498 | } |
498 | 499 |
|
| 500 | +// --------------------------------------------------------------------------- |
| 501 | +// Git-based change detection |
| 502 | +// --------------------------------------------------------------------------- |
| 503 | + |
| 504 | +/** |
| 505 | + * Detect packages with uncommitted changes by running `git diff`. |
| 506 | + * This captures changes from ALL prior pipeline steps (e.g. convert-openrouter-models.ts) |
| 507 | + * not just the models added by this script. |
| 508 | + */ |
| 509 | +function detectChangedPackages(): Set<string> { |
| 510 | + const changed = new Set<string>() |
| 511 | + try { |
| 512 | + const diff = execFileSync( |
| 513 | + 'git', |
| 514 | + ['diff', 'HEAD', '--name-only', '--', 'packages/'], |
| 515 | + { encoding: 'utf-8', cwd: ROOT }, |
| 516 | + ).trim() |
| 517 | + if (!diff) return changed |
| 518 | + |
| 519 | + for (const line of diff.split('\n')) { |
| 520 | + // packages/typescript/ai-openrouter/... → @tanstack/ai-openrouter |
| 521 | + const match = line.match(/^packages\/typescript\/([\w-]+)\//) |
| 522 | + if (match) { |
| 523 | + changed.add(`@tanstack/${match[1]}`) |
| 524 | + } |
| 525 | + } |
| 526 | + } catch { |
| 527 | + // git not available (e.g. running outside a repo) — fall back to empty set |
| 528 | + } |
| 529 | + return changed |
| 530 | +} |
| 531 | + |
499 | 532 | // --------------------------------------------------------------------------- |
500 | 533 | // Main |
501 | 534 | // --------------------------------------------------------------------------- |
@@ -672,20 +705,23 @@ async function main() { |
672 | 705 | // Record this run's timestamp for future age-based filtering |
673 | 706 | await writeLastRunTimestamp() |
674 | 707 |
|
675 | | - // Create changeset if any models were added |
676 | | - if (totalAdded > 0) { |
677 | | - await createChangeset(changedPackages) |
| 708 | + // Detect all packages with uncommitted changes (includes changes from |
| 709 | + // convert-openrouter-models.ts which runs before this script) |
| 710 | + const allChangedPackages = detectChangedPackages() |
| 711 | + for (const pkg of changedPackages) { |
| 712 | + allChangedPackages.add(pkg) |
| 713 | + } |
| 714 | + |
| 715 | + if (allChangedPackages.size > 0) { |
| 716 | + await createChangeset(allChangedPackages) |
678 | 717 | } |
679 | 718 | } |
680 | 719 |
|
681 | 720 | /** |
682 | 721 | * Create or update the sync-models changeset file. |
683 | 722 | * If one already exists, merges the package lists. Otherwise creates a new one. |
684 | | - * Always includes @tanstack/ai-openrouter since the convert script regenerates it. |
685 | 723 | */ |
686 | 724 | async function createChangeset(changedPackages: Set<string>) { |
687 | | - changedPackages.add('@tanstack/ai-openrouter') |
688 | | - |
689 | 725 | const changesetDir = resolve(ROOT, '.changeset') |
690 | 726 | const { readdir } = await import('node:fs/promises') |
691 | 727 | const files = await readdir(changesetDir) |
|
0 commit comments