This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
JBZoo Composer-Diff is a PHP CLI tool that compares two versions of composer.lock files and shows what packages have changed. It's particularly useful for visualizing dependency changes after running composer update, providing detailed output in console, markdown, or JSON formats with links to compare views on package repositories.
- Built on Symfony Console and JBZoo CLI framework
- Single command application with
DiffActionas the main command (src/Commands/DiffAction.php) - Executable binary:
composer-diff(defined in composer.json bin section) - Entry point through the binary file
/composer-diff
Diff(src/Diff.php) - Main comparison logic with version change detection (New, Removed, Changed, Upgraded, Downgraded)Comparator(src/Comparator.php) - Orchestrates the comparison process between composer.lock filesComposerLock(src/ComposerLock.php) - Parses and extracts package data from composer.lock filesPackage(src/Package.php) - Represents individual package with version and URL informationUrl(src/Url.php) - Generates comparison URLs for different Git hosting platforms
Console- Default colored table output for terminalMarkdown- Generates markdown tables for PRs/documentationJsonOutput- Machine-readable JSON formatAbstractRender- Base class for all output formats
make build # Install dependencies and build phar
make update # Install/update dependencies and build pharmake test # Run PHPUnit tests
make test-all # Run all tests and code quality checks
make test-drupal # Test with real Drupal upgrade scenario
make test-manual # Run manual test examples with sample datamake codestyle # Run all linters and code style checksmake build-phar # Build composer-diff.phar executable
make create-symlink # Create symlink vendor/bin/composer-diff → build/composer-diff.phar# Basic usage (compares HEAD:composer.lock with ./composer.lock)
php ./vendor/bin/composer-diff
# Compare specific files
php ./composer-diff --source="old/composer.lock" --target="new/composer.lock"
# Different output formats
php ./composer-diff --output=markdown
php ./composer-diff --output=json
# Filter environments
php ./composer-diff --env=require # Production dependencies only
php ./composer-diff --env=require-dev # Development dependencies onlyThe tool identifies changes by:
- Version Comparison: Uses Composer's semantic versioning via
composer/semver - Hash Detection: Recognizes dev packages with commit hashes (40-character strings without dots)
- URL Generation: Creates compare links for GitHub, GitLab, and Bitbucket repositories
- Change Classification: Categorizes as New, Removed, Upgraded, Downgraded, Changed, or Same
- Unit Tests:
tests/directory with comprehensive coverage of all classes - Fixture Data:
tests/fixtures/contains realistic composer.lock samples for various scenarios - Integration Tests: Real-world examples like Drupal version comparisons
- Manual Testing: Built-in examples in Makefile for output verification
- New package installation
- Package removal
- Version upgrades/downgrades
- Dev branch changes (hash-based versions)
- Complex dependency matrices
- Different environment filtering (require vs require-dev)
Uses JBZoo's standardized development toolchain:
- Inherits comprehensive Makefile targets from
vendor/jbzoo/codestyle/src/init.Makefile - Automated code style, static analysis, and testing via
jbzoo/toolbox-dev - Consistent development experience across JBZoo ecosystem
- Builds standalone
build/composer-diff.pharexecutable - Supports global installation via
composer global require jbzoo/composer-diff - GitHub releases provide downloadable phar files
php: ^8.2withext-jsonandext-filterjbzoo/cli: ^7.2.4- Enhanced Symfony Console wrapperjbzoo/data: ^7.2- Data manipulation utilitiesjbzoo/markdown: ^7.0.2- Markdown generationsymfony/console: >=6.4,symfony/process: >=6.4composer/semver: >=1.0- Version comparison logic
jbzoo/toolbox-dev: ^7.3- Complete development toolchaincomposer/composer: >=2.0- For testing with real composer.lock files
src/
├── Commands/DiffAction.php # Main CLI command
├── Renders/ # Output format implementations
├── Diff.php # Core comparison logic
├── Comparator.php # Comparison orchestration
├── ComposerLock.php # Lock file parsing
├── Package.php # Package representation
├── Url.php # URL generation
└── Exception.php # Custom exceptions
tests/
├── fixtures/ # Test composer.lock files
│ ├── testComparingComplex/ # Complex change scenarios
│ ├── testDrupal/ # Real Drupal upgrade data
│ └── [scenario-name]/ # Various test cases
└── *Test.php # Unit tests for each class