Skip to content

Conversation

@cryptodev-2s
Copy link
Contributor

@cryptodev-2s cryptodev-2s commented Nov 5, 2025

Description

Adds a new check-deps command to automatically detect, validate, and update dependency bump entries in CHANGELOGs.

Usage

# Detect and validate
yarn check-dependency-bumps

# Auto-fix
yarn check-dependency-bumps --fix --pr 1234

Key Features

  • Detects dependency bumps from git diffs in package.json files
  • Validates exact versions in changelog entries (catches stale entries)
  • Auto-updates changelogs with --fix flag
  • Preserves PR history when bumping same dependency multiple times
  • Release-aware - adds entries to ## [X.Y.Z] section when package version changes, or [Unreleased] otherwise
  • Repository agnostic - reads repo URL from package.json

Example:

# Before (PR #7007):
- Bump `@metamask/transaction-controller` from `^61.0.0` to `^61.1.0` ([#7007](...))

# After fix (PR #1234):
- Bump `@metamask/transaction-controller` from `^61.0.0` to `^62.0.0` ([#7007](...), [#1234](...))

Implementation

New files:

  • src/check-dependency-bumps.ts + tests (24 tests)
  • src/changelog-validator.ts + tests (27 tests)

Modified:

  • src/command-line-arguments.ts - Added check-deps command
  • src/main.ts - Command routing
  • Updated test files for command structure

Coverage: 100% (statements, branches, functions, lines) - 340 passing tests

Testing in MetaMask/core

# Build tool
cd /path/to/create-release-branch && yarn build

# From core
cd /path/to/core
git checkout -b test-dep-bumps

# In one or more packages, modify package.json to:
# - Bump some dependencies
# - Bump some peerDependencies  
# - Bump some devDependencies (to verify they're correctly excluded)
# - Change the package version (to test release detection)

git add . && git commit -m "Test: bump dependencies"

# Validate
node /path/to/create-release-branch/dist/cli.js check-deps

# Fix without PR number
node /path/to/create-release-branch/dist/cli.js check-deps --fix

# Fix with PR number
node /path/to/create-release-branch/dist/cli.js check-deps --fix --pr 4532

# Validate with github-tools (https://github.com/MetaMask/github-tools)
cd /path/to/github-tools
yarn run changelog:check "/path/to/core" "main" "4532"

Note

Introduces a CLI to detect dependency bumps from git diffs and validate/update changelog entries, with command routing and comprehensive tests.

  • CLI:
    • Add check-deps command (src/check-dependency-bumps.ts) to detect dependency bumps from git diffs, validate changelogs, and optionally auto-fix with PR linking.
    • Route commands in src/main.ts; parse new options in src/command-line-arguments.ts.
  • Changelog Validation:
    • New module src/changelog-validator.ts to validate and update CHANGELOG.md (supports Unreleased and release sections, preserves/concats PRs, BREAKING for peerDeps).
    • Shared types in src/types.ts.
  • Release Flow:
    • Guard determineInitialParameters for release-only; tests updated accordingly.
  • Docs/Changelog:
    • Update CHANGELOG.md with check-deps feature and usage.
  • Tests:
    • Extensive unit tests for checker, validator, CLI routing, and initial parameters.

Written by Cursor Bugbot for commit 9b796b6. This will update automatically on new commits. Configure here.

@cryptodev-2s cryptodev-2s force-pushed the feat/add-dependency-bump-checker branch 4 times, most recently from a88a703 to e9b5b6c Compare November 6, 2025 14:11
@cryptodev-2s cryptodev-2s marked this pull request as ready for review November 6, 2025 14:11
@cryptodev-2s cryptodev-2s requested a review from a team as a code owner November 6, 2025 14:11
Introduces a new tool to automatically detect dependency version changes
and validate/update changelog entries accordingly.

Features:
- Detects dependency bumps from git diffs in package.json files
- Validates changelog entries with exact version matching
- Automatically updates changelogs with missing or outdated entries
- Smart PR reference concatenation when updating existing entries
- Dynamically reads repository URLs and package names
- Validates by default with optional --fix flag for updates

Usage:
  yarn check-dependency-bumps           # Validate changelogs
  yarn check-dependency-bumps --fix     # Auto-update changelogs
  yarn check-dependency-bumps --fix --pr 1234  # With PR number
@cryptodev-2s cryptodev-2s force-pushed the feat/add-dependency-bump-checker branch from e9b5b6c to abcda3f Compare November 6, 2025 15:28
Optimizes package name resolution by reading package.json inline during
git diff parsing instead of in a separate enrichment pass.

Changes:
- Make parseDiff async to read package names inline
- Remove enrichWithPackageNames function (no longer needed)
- Read packageName immediately when first encountering a package
- Simplify validateChangelogs and updateChangelogs signatures
- Remove packageNames parameter (now part of PackageInfo)

Benefits:
- Single-pass processing (parse + enrich in one step)
- Simpler code flow (24 lines removed)
- Better data locality (package info complete at creation)
- Cleaner API (functions receive unified PackageChanges structure)

Test coverage maintained: 100% (339 passing tests)
await writeFile(changelogPath, await updatedChangelog.toString());

stdout.write(
`✅ ${packageDirName}: Updated ${entriesToUpdate.length} and added ${entriesToAdd.length} changelog entries\n`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Grammatical pluralization gap in changelog updates

Missing singular/plural handling for the "added" count in the combined update message. When both updating and adding entries, the message always uses "changelog entries" (plural) even when only 1 entry is added. The message should use conditional pluralization like: ${entriesToAdd.length} changelog ${entriesToAdd.length === 1 ? 'entry' : 'entries'} to be grammatically correct and consistent with other messages in the codebase (see lines 340 and 420).

Fix in Cursor Fix in Web

@mcmire
Copy link
Contributor

mcmire commented Nov 12, 2025

@cryptodev-2s I haven't had time to review this yet, but I have one initial thought:

Should we rename check-deps to validate? My thought is that we will want to include some more validation steps in the future (e.g. #176), and if we group everything under validate it will create room for that work.

@cryptodev-2s
Copy link
Contributor Author

@cryptodev-2s I haven't had time to review this yet, but I have one initial thought:

Should we rename check-deps to validate? My thought is that we will want to include some more validation steps in the future (e.g. #176), and if we group everything under validate it will create room for that work.

Good point about future validation commands! However, I think check-deps should remain separate from release validation (#176) since:

  1. Different scope: check-deps works on any branch (feature branches included), not just release branches
  2. Independent use case: Validating dependency changelog entries is useful outside the release process
  3. Clear separation: Release-specific validation (Add command for validating release branch #176) deserves its own command

Suggestion:

Side note: Given we're adding more commands beyond release creation, we could consider renaming the package to something like @metamask/monorepo-tools in a future major version. But that's a separate discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants