Reputation: 4193
Is there an easy way to show a diff between two different versions of one Composer package? Of course, I could manually or semi-automatically download the two versions and then manually run a diff on them. However, it would be quite handy to have a command like
composer diff namespace/module 1.0.0 1.0.1
This would show a diff between the versions 1.0.0 and 1.0.1 of package namespace/module
, so that I can easily review what has changed.
Is there any smart way to do that?
It would even be nicer if I could see the diff in PhpStorm.
Upvotes: 3
Views: 1303
Reputation: 838
You can check out this Composer plugin I created to compare differences between 2 composer.lock
versions which generates the diff links to GitHub/BitBucket.
Simply install it using Composer:
composer global require ion-bazan/composer-diff
After updating your packages, run:
composer diff -l
which prints a summary of package changes and provides clickable links to each package's diff:
You can experiment with different options and flags, as explained in README.
Upvotes: 1
Reputation: 34978
Assuming you are in the project directory, JQ must be installed.
It installs both package versions in temp folders and compares them.
Usage: ./composer-diff.sh foo/bar 1.0.0 2.0.0
#!/bin/bash
PACKAGE=$1 # namespace/module
OLD=$2
NEW=$3
PROJECT=`pwd`
TMPBASE=/tmp/$$
mkdir -p $TMPBASE/$OLD
mkdir -p $TMPBASE/$NEW
jq '{repositories}' composer.json > $TMPBASE/$OLD/composer.json
jq '{repositories}' composer.json > $TMPBASE/$NEW/composer.json
cp auth.json $TMPBASE/$OLD
cp auth.json $TMPBASE/$NEW
cd $TMPBASE/$OLD
composer require $PACKAGE $OLD
cd $TMPBASE/$NEW
composer require $PACKAGE $NEW
set +x
diff -ur $TMPBASE/$OLD/vendor/$PACKAGE $TMPBASE/$NEW/vendor/$PACKAGE > $PROJECT/composer-package.diff
Now the resulting composer-package.diff
file can be openend in any editor.
Upvotes: 2
Reputation: 1114
I stumbled upon this while documenting myself about the existence of such a command for my other question. A similar feature was suggested in the Composer issue tracker previously. The author of that proposal made it into a separate tool, available here (looks old, working status unknown). I'm not sure it covers your exact case, tough.
Upvotes: 1