Skip to content

feat(changeset): add changeset when pnpm catalogs change #2641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions packages/changesets-renovate/src/pnpm-catalogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import fs from 'node:fs'
import path from 'node:path'
import { execSync } from 'node:child_process'
import * as yaml from 'js-yaml'
import glob from 'fast-glob'

const OLD_FILE = 'catalog-old.yaml'
const NEW_FILE = 'catalog.yaml' // your live catalog

function loadCatalog(filePath) {
const content = fs.readFileSync(filePath, 'utf8')
const parsed = yaml.load(content)
return parsed.catalog || {}
}

// Step 1: Load catalogs
const oldCatalog = loadCatalog(OLD_FILE)
const newCatalog = loadCatalog(NEW_FILE)

// Step 2: Find changed deps
const changedDeps = Object.entries(newCatalog)
.filter(
([pkg, newVersion]) => oldCatalog[pkg] && oldCatalog[pkg] !== newVersion,
)
.map(([pkg]) => pkg)

if (changedDeps.length === 0) {
console.log('✅ No catalog dependency changes.')
process.exit(0)
}

console.log('📦 Changed dependencies:', changedDeps)

// Step 3: Find affected packages
const packageJsonPaths = glob.sync('packages/*/package.json')
const affectedPackages = new Set()

for (const pkgJsonPath of packageJsonPaths) {
const json = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'))
const deps = {
...json.dependencies,
...json.devDependencies,
...json.peerDependencies,
}

for (const dep of changedDeps) {
if (deps?.[dep]) {
const dirName = path.basename(path.dirname(pkgJsonPath))
affectedPackages.add(dirName)
}
}
}

if (affectedPackages.size === 0) {
console.log('📦 No packages affected by catalog changes.')
process.exit(0)
}

// Step 4: Generate changesets
for (const pkg of affectedPackages) {
console.log(`✏ Creating changeset for ${pkg}...`)
execSync(
`npx changeset --empty --include=${pkg} --summary="Bump dependency from catalog update"`,
{
stdio: 'inherit',
},
)
}

console.log('✅ Done creating changesets.')
Loading