Skip to content

Commit c589828

Browse files
authored
docs: Enhance project documentation and add Claude guide (#40)
- Introduce CLAUDE.md to provide detailed context and instructions for AI assistants like Claude Code. - Revamp README.md for better clarity and comprehensiveness. - Add new sections to README.md, including Features, Advanced Usage, Requirements, Architecture, and Development. - Improve existing sections like Installation and Basic Usage. - Update .gitignore to exclude .claude files.
1 parent 0b2c1c1 commit c589828

File tree

3 files changed

+321
-16
lines changed

3 files changed

+321
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ build
1616
vendor
1717
phpunit.xml
1818
*.cache
19+
.claude

CLAUDE.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
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.
8+
9+
## Core Architecture
10+
11+
### Command-Line Interface
12+
- Built on **Symfony Console** and **JBZoo CLI** framework
13+
- Single command application with `DiffAction` as the main command (`src/Commands/DiffAction.php`)
14+
- Executable binary: `composer-diff` (defined in composer.json bin section)
15+
- Entry point through the binary file `/composer-diff`
16+
17+
### Core Classes
18+
- **`Diff`** (`src/Diff.php`) - Main comparison logic with version change detection (New, Removed, Changed, Upgraded, Downgraded)
19+
- **`Comparator`** (`src/Comparator.php`) - Orchestrates the comparison process between composer.lock files
20+
- **`ComposerLock`** (`src/ComposerLock.php`) - Parses and extracts package data from composer.lock files
21+
- **`Package`** (`src/Package.php`) - Represents individual package with version and URL information
22+
- **`Url`** (`src/Url.php`) - Generates comparison URLs for different Git hosting platforms
23+
24+
### Output Renderers (`src/Renders/`)
25+
- **`Console`** - Default colored table output for terminal
26+
- **`Markdown`** - Generates markdown tables for PRs/documentation
27+
- **`JsonOutput`** - Machine-readable JSON format
28+
- **`AbstractRender`** - Base class for all output formats
29+
30+
## Common Commands
31+
32+
### Development Setup
33+
```bash
34+
make build # Install dependencies and build phar
35+
make update # Install/update dependencies and build phar
36+
```
37+
38+
### Testing
39+
```bash
40+
make test # Run PHPUnit tests
41+
make test-all # Run all tests and code quality checks
42+
make test-drupal # Test with real Drupal upgrade scenario
43+
make test-manual # Run manual test examples with sample data
44+
```
45+
46+
### Code Quality (via JBZoo Toolbox)
47+
```bash
48+
make codestyle # Run all linters and code style checks
49+
```
50+
51+
### Build Process
52+
```bash
53+
make build-phar # Build composer-diff.phar executable
54+
make create-symlink # Create symlink vendor/bin/composer-diff → build/composer-diff.phar
55+
```
56+
57+
### Usage Examples
58+
```bash
59+
# Basic usage (compares HEAD:composer.lock with ./composer.lock)
60+
php ./vendor/bin/composer-diff
61+
62+
# Compare specific files
63+
php ./composer-diff --source="old/composer.lock" --target="new/composer.lock"
64+
65+
# Different output formats
66+
php ./composer-diff --output=markdown
67+
php ./composer-diff --output=json
68+
69+
# Filter environments
70+
php ./composer-diff --env=require # Production dependencies only
71+
php ./composer-diff --env=require-dev # Development dependencies only
72+
```
73+
74+
## Package Detection Logic
75+
76+
The tool identifies changes by:
77+
1. **Version Comparison**: Uses Composer's semantic versioning via `composer/semver`
78+
2. **Hash Detection**: Recognizes dev packages with commit hashes (40-character strings without dots)
79+
3. **URL Generation**: Creates compare links for GitHub, GitLab, and Bitbucket repositories
80+
4. **Change Classification**: Categorizes as New, Removed, Upgraded, Downgraded, Changed, or Same
81+
82+
## Testing Strategy
83+
84+
### Test Structure
85+
- **Unit Tests**: `tests/` directory with comprehensive coverage of all classes
86+
- **Fixture Data**: `tests/fixtures/` contains realistic composer.lock samples for various scenarios
87+
- **Integration Tests**: Real-world examples like Drupal version comparisons
88+
- **Manual Testing**: Built-in examples in Makefile for output verification
89+
90+
### Test Scenarios Covered
91+
- New package installation
92+
- Package removal
93+
- Version upgrades/downgrades
94+
- Dev branch changes (hash-based versions)
95+
- Complex dependency matrices
96+
- Different environment filtering (require vs require-dev)
97+
98+
## Build System
99+
100+
### JBZoo Toolbox Integration
101+
Uses JBZoo's standardized development toolchain:
102+
- Inherits comprehensive Makefile targets from `vendor/jbzoo/codestyle/src/init.Makefile`
103+
- Automated code style, static analysis, and testing via `jbzoo/toolbox-dev`
104+
- Consistent development experience across JBZoo ecosystem
105+
106+
### PHAR Distribution
107+
- Builds standalone `build/composer-diff.phar` executable
108+
- Supports global installation via `composer global require jbzoo/composer-diff`
109+
- GitHub releases provide downloadable phar files
110+
111+
## Dependencies
112+
113+
### Production
114+
- `php: ^8.2` with `ext-json` and `ext-filter`
115+
- `jbzoo/cli: ^7.2.4` - Enhanced Symfony Console wrapper
116+
- `jbzoo/data: ^7.2` - Data manipulation utilities
117+
- `jbzoo/markdown: ^7.0.2` - Markdown generation
118+
- `symfony/console: >=6.4`, `symfony/process: >=6.4`
119+
- `composer/semver: >=1.0` - Version comparison logic
120+
121+
### Development
122+
- `jbzoo/toolbox-dev: ^7.3` - Complete development toolchain
123+
- `composer/composer: >=2.0` - For testing with real composer.lock files
124+
125+
## File Structure Patterns
126+
127+
```
128+
src/
129+
├── Commands/DiffAction.php # Main CLI command
130+
├── Renders/ # Output format implementations
131+
├── Diff.php # Core comparison logic
132+
├── Comparator.php # Comparison orchestration
133+
├── ComposerLock.php # Lock file parsing
134+
├── Package.php # Package representation
135+
├── Url.php # URL generation
136+
└── Exception.php # Custom exceptions
137+
138+
tests/
139+
├── fixtures/ # Test composer.lock files
140+
│ ├── testComparingComplex/ # Complex change scenarios
141+
│ ├── testDrupal/ # Real Drupal upgrade data
142+
│ └── [scenario-name]/ # Various test cases
143+
└── *Test.php # Unit tests for each class
144+
```

README.md

Lines changed: 176 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,87 @@
1212
[![GitHub License](https://img.shields.io/github/license/jbzoo/composer-diff)](https://github.com/JBZoo/Composer-Diff/blob/master/LICENSE)
1313

1414

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+
1519
<!--ts-->
16-
* [Why?](#why)
20+
* [Features](#features)
1721
* [Installation](#installation)
18-
* [Usage](#usage)
22+
* [Via Composer (Recommended)](#via-composer-recommended)
23+
* [Standalone PHAR](#standalone-phar)
24+
* [Basic Usage](#basic-usage)
1925
* [Help Description](#help-description)
2026
* [Output Examples](#output-examples)
2127
* [Default view (--output=console)](#default-view---outputconsole)
2228
* [Markdown Output (--output=markdown)](#markdown-output---outputmarkdown)
2329
* [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)
2443
* [Roadmap](#roadmap)
25-
* [Unit tests and check code style](#unit-tests-and-check-code-style)
2644
* [License](#license)
2745
* [See Also](#see-also)
2846
<!--te-->
2947

3048

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
3450

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
3560

3661
## Installation
3762

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
4174

42-
# OR use phar file.
75+
```bash
76+
# Download latest release
4377
wget https://github.com/JBZoo/Composer-Diff/releases/latest/download/composer-diff.phar
78+
79+
# Make it executable
80+
chmod +x composer-diff.phar
4481
```
4582

46-
## Usage
83+
## Basic Usage
4784

4885
```bash
86+
# Update your dependencies first
4987
composer update
5088

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)
5590
composer-diff
5691

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
5896
php composer-diff.phar
5997
```
6098

@@ -215,6 +253,128 @@ Rendered in your readme or PR/MR description:
215253
```
216254

217255

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+
218378
## Roadmap
219379

220380
* [ ] Supporting Drupal repos. [For example](https://git.drupalcode.org/project/fast_404).

0 commit comments

Comments
 (0)