|
12 | 12 | [](https://github.com/JBZoo/Composer-Diff/blob/master/LICENSE)
|
13 | 13 |
|
14 | 14 |
|
| 15 | +A powerful CLI tool for visualizing changes in Composer dependencies after running `composer update`. Compare two `composer.lock` files and see exactly what packages were added, removed, upgraded, or downgraded with beautiful output formatting and direct links to changelogs. |
| 16 | + |
| 17 | +## Table of Contents |
| 18 | + |
15 | 19 | <!--ts-->
|
16 |
| - * [Why?](#why) |
| 20 | + * [Features](#features) |
17 | 21 | * [Installation](#installation)
|
18 |
| - * [Usage](#usage) |
| 22 | + * [Via Composer (Recommended)](#via-composer-recommended) |
| 23 | + * [Standalone PHAR](#standalone-phar) |
| 24 | + * [Basic Usage](#basic-usage) |
19 | 25 | * [Help Description](#help-description)
|
20 | 26 | * [Output Examples](#output-examples)
|
21 | 27 | * [Default view (--output=console)](#default-view---outputconsole)
|
22 | 28 | * [Markdown Output (--output=markdown)](#markdown-output---outputmarkdown)
|
23 | 29 | * [JSON Output (--output=json)](#json-output---outputjson)
|
| 30 | + * [Advanced Usage](#advanced-usage) |
| 31 | + * [Compare Specific Files](#compare-specific-files) |
| 32 | + * [Environment Filtering](#environment-filtering) |
| 33 | + * [Output Formatting](#output-formatting) |
| 34 | + * [Real-world Examples](#real-world-examples) |
| 35 | + * [Requirements](#requirements) |
| 36 | + * [Architecture](#architecture) |
| 37 | + * [Change Detection Logic](#change-detection-logic) |
| 38 | + * [Supported Git Platforms](#supported-git-platforms) |
| 39 | + * [Development](#development) |
| 40 | + * [Setup](#setup) |
| 41 | + * [Testing](#testing) |
| 42 | + * [Building PHAR](#building-phar) |
24 | 43 | * [Roadmap](#roadmap)
|
25 |
| - * [Unit tests and check code style](#unit-tests-and-check-code-style) |
26 | 44 | * [License](#license)
|
27 | 45 | * [See Also](#see-also)
|
28 | 46 | <!--te-->
|
29 | 47 |
|
30 | 48 |
|
31 |
| -## Why? |
32 |
| - |
33 |
| -See what packages have been changed after you run `composer update` by comparing `composer.lock` to the `git show HEAD:composer.lock`. |
| 49 | +## Features |
34 | 50 |
|
| 51 | +- **Visual Dependency Tracking**: See exactly what changed after `composer update` with color-coded output |
| 52 | +- **Multiple Output Formats**: Console tables, Markdown for PRs, or JSON for automation and CI/CD pipelines |
| 53 | +- **Smart Version Detection**: Automatically detects upgrades, downgrades, new, removed, and changed packages |
| 54 | +- **Direct Links to Changes**: Generates comparison URLs for GitHub, GitLab, and Bitbucket repositories |
| 55 | +- **Environment Filtering**: Compare production (`require`) and development (`require-dev`) dependencies separately or together |
| 56 | +- **Git Integration**: Compare current lock file with any git reference (HEAD, branches, tags) |
| 57 | +- **Dev Package Support**: Handles dev branches with commit hash detection and comparison |
| 58 | +- **CI/CD Friendly**: Perfect for automated workflows, deployment pipelines, and Pull Request automation |
| 59 | +- **PHAR Distribution**: Standalone executable or Composer installation options |
35 | 60 |
|
36 | 61 | ## Installation
|
37 | 62 |
|
38 |
| -```shell |
39 |
| -composer require jbzoo/composer-diff # For specific project |
40 |
| -composer global require jbzoo/composer-diff # As global tool |
| 63 | +### Via Composer (Recommended) |
| 64 | + |
| 65 | +```bash |
| 66 | +# Install for specific project |
| 67 | +composer require jbzoo/composer-diff |
| 68 | + |
| 69 | +# Install globally |
| 70 | +composer global require jbzoo/composer-diff |
| 71 | +``` |
| 72 | + |
| 73 | +### Standalone PHAR |
41 | 74 |
|
42 |
| -# OR use phar file. |
| 75 | +```bash |
| 76 | +# Download latest release |
43 | 77 | wget https://github.com/JBZoo/Composer-Diff/releases/latest/download/composer-diff.phar
|
| 78 | + |
| 79 | +# Make it executable |
| 80 | +chmod +x composer-diff.phar |
44 | 81 | ```
|
45 | 82 |
|
46 |
| -## Usage |
| 83 | +## Basic Usage |
47 | 84 |
|
48 | 85 | ```bash
|
| 86 | +# Update your dependencies first |
49 | 87 | composer update
|
50 | 88 |
|
51 |
| -# if it's installed via composer |
52 |
| -php ./vendor/bin/composer-diff |
53 |
| - |
54 |
| -# OR (if installed globally) |
| 89 | +# Show what changed (compares HEAD:composer.lock with ./composer.lock) |
55 | 90 | composer-diff
|
56 | 91 |
|
57 |
| -# OR (if you downloaded phar file) |
| 92 | +# If installed locally in project |
| 93 | +php ./vendor/bin/composer-diff |
| 94 | + |
| 95 | +# If using PHAR file |
58 | 96 | php composer-diff.phar
|
59 | 97 | ```
|
60 | 98 |
|
@@ -215,6 +253,128 @@ Rendered in your readme or PR/MR description:
|
215 | 253 | ```
|
216 | 254 |
|
217 | 255 |
|
| 256 | +## Advanced Usage |
| 257 | + |
| 258 | +### Compare Specific Files |
| 259 | +```bash |
| 260 | +# Compare two specific composer.lock files |
| 261 | +composer-diff --source="old/composer.lock" --target="new/composer.lock" |
| 262 | + |
| 263 | +# Compare Git references |
| 264 | +composer-diff --source="HEAD~1:composer.lock" --target="HEAD:composer.lock" |
| 265 | + |
| 266 | +# Compare with specific branch or tag |
| 267 | +composer-diff --source="v1.0.0:composer.lock" --target="./composer.lock" |
| 268 | +``` |
| 269 | + |
| 270 | +### Environment Filtering |
| 271 | +```bash |
| 272 | +# Production dependencies only |
| 273 | +composer-diff --env=require |
| 274 | + |
| 275 | +# Development dependencies only |
| 276 | +composer-diff --env=require-dev |
| 277 | + |
| 278 | +# Both environments (default) |
| 279 | +composer-diff --env=both |
| 280 | +``` |
| 281 | + |
| 282 | +### Output Formatting |
| 283 | +```bash |
| 284 | +# Markdown output for Pull Requests |
| 285 | +composer-diff --output=markdown |
| 286 | + |
| 287 | +# JSON output for automation |
| 288 | +composer-diff --output=json |
| 289 | + |
| 290 | +# Hide comparison links |
| 291 | +composer-diff --no-links |
| 292 | + |
| 293 | +# Strict mode (exit code 1 if differences found) |
| 294 | +composer-diff --strict |
| 295 | +``` |
| 296 | + |
| 297 | +### Real-world Examples |
| 298 | +```bash |
| 299 | +# Generate PR description after update |
| 300 | +composer update |
| 301 | +composer-diff --output=markdown >> pr-description.md |
| 302 | + |
| 303 | +# CI/CD pipeline check |
| 304 | +composer-diff --strict --output=json > changes.json |
| 305 | + |
| 306 | +# Compare major version upgrades |
| 307 | +composer-diff --source="tags/v1.0:composer.lock" --target="tags/v2.0:composer.lock" |
| 308 | +``` |
| 309 | + |
| 310 | +## Requirements |
| 311 | + |
| 312 | +- **PHP**: ^8.2 |
| 313 | +- **Extensions**: ext-json, ext-filter |
| 314 | +- **Composer**: ^2.0 (for development) |
| 315 | + |
| 316 | +## Architecture |
| 317 | + |
| 318 | +The tool is built with a clean, object-oriented architecture: |
| 319 | + |
| 320 | +- **`DiffAction`**: Main CLI command handler (Symfony Console) |
| 321 | +- **`Comparator`**: Orchestrates comparison between composer.lock files |
| 322 | +- **`ComposerLock`**: Parses and manages composer.lock data |
| 323 | +- **`Package`**: Represents individual packages with version handling |
| 324 | +- **`Diff`**: Compares package versions and determines change types |
| 325 | +- **`Url`**: Generates comparison URLs for Git hosting platforms |
| 326 | +- **Renderers**: Multiple output formats (Console, Markdown, JSON) |
| 327 | + |
| 328 | +### Change Detection Logic |
| 329 | + |
| 330 | +The tool intelligently categorizes changes: |
| 331 | + |
| 332 | +- **New**: Package added to dependencies |
| 333 | +- **Removed**: Package removed from dependencies |
| 334 | +- **Upgraded**: Semantic version increased (1.0.0 → 2.0.0) |
| 335 | +- **Downgraded**: Semantic version decreased (2.0.0 → 1.0.0) |
| 336 | +- **Changed**: Dev branches with different commit hashes |
| 337 | +- **Same**: No changes (filtered out by default) |
| 338 | + |
| 339 | +### Supported Git Platforms |
| 340 | + |
| 341 | +Automatically generates comparison URLs for: |
| 342 | + |
| 343 | +- **GitHub**: `github.com/user/repo/compare/v1.0.0...v2.0.0` |
| 344 | +- **GitLab**: `gitlab.com/user/repo/compare/v1.0.0...v2.0.0` |
| 345 | +- **Bitbucket**: `bitbucket.org/user/repo/branches/compare/v1.0.0%0Dv2.0.0` |
| 346 | + |
| 347 | +## Development |
| 348 | + |
| 349 | +### Setup |
| 350 | +```bash |
| 351 | +# Clone and install dependencies |
| 352 | +git clone https://github.com/JBZoo/Composer-Diff.git |
| 353 | +cd Composer-Diff |
| 354 | +make build |
| 355 | +``` |
| 356 | + |
| 357 | +### Testing |
| 358 | +```bash |
| 359 | +# Run all tests |
| 360 | +make test-all |
| 361 | + |
| 362 | +# Run specific test suites |
| 363 | +make test # PHPUnit tests |
| 364 | +make test-drupal # Real Drupal upgrade test |
| 365 | +make test-manual # Manual output examples |
| 366 | +make codestyle # Code quality checks |
| 367 | +``` |
| 368 | + |
| 369 | +### Building PHAR |
| 370 | +```bash |
| 371 | +# Build standalone PHAR executable |
| 372 | +make build-phar |
| 373 | + |
| 374 | +# Create symlink for local testing |
| 375 | +make create-symlink |
| 376 | +``` |
| 377 | + |
218 | 378 | ## Roadmap
|
219 | 379 |
|
220 | 380 | * [ ] Supporting Drupal repos. [For example](https://git.drupalcode.org/project/fast_404).
|
|
0 commit comments