* Compute which catalog entries changed between the base ref and HEAD. * Returns Map >. Empty if no catalog files changed.
( rootDir: string, baseBranch: string, changedFiles: string[], )
| 411 | * Returns Map<catalogName, Set<depName>>. Empty if no catalog files changed. |
| 412 | */ |
| 413 | async function getChangedCatalogEntries( |
| 414 | rootDir: string, |
| 415 | baseBranch: string, |
| 416 | changedFiles: string[], |
| 417 | ): Promise<Map<string, Set<string>>> { |
| 418 | const catalogFileChanged = changedFiles.some((f) => (CATALOG_FILES as readonly string[]).includes(f)); |
| 419 | if (!catalogFileChanged) return new Map(); |
| 420 | |
| 421 | const baseRef = getBaseCompareRef(rootDir, baseBranch); |
| 422 | |
| 423 | const pm = await detectPackageManager(rootDir); |
| 424 | |
| 425 | // The workspace YAML that may hold catalogs: pnpm-workspace.yaml for pnpm, |
| 426 | // .yarnrc.yml for Yarn, and none for npm/bun (which use package.json). |
| 427 | const yamlFile = catalogYamlFile(pm); |
| 428 | |
| 429 | // Load "after" (current working tree state) |
| 430 | const afterYaml = |
| 431 | yamlFile && (await exists(resolve(rootDir, yamlFile))) ? await readText(resolve(rootDir, yamlFile)) : null; |
| 432 | const afterPkgJson = (await exists(resolve(rootDir, 'package.json'))) |
| 433 | ? await readText(resolve(rootDir, 'package.json')) |
| 434 | : null; |
| 435 | const afterCatalogs = parseCatalogs(afterYaml, afterPkgJson); |
| 436 | |
| 437 | // Load "before" (state at base ref). |
| 438 | const beforeYaml = yamlFile ? readFileAtRef(rootDir, baseRef, yamlFile) : null; |
| 439 | const beforePkgJson = readFileAtRef(rootDir, baseRef, 'package.json'); |
| 440 | const beforeCatalogs = parseCatalogs(beforeYaml, beforePkgJson); |
| 441 | |
| 442 | return diffCatalogMaps(beforeCatalogs, afterCatalogs); |
| 443 | } |
no test coverage detected
searching dependent graphs…