Home

Awesome

composer-lock-diff

See what packages have changed after you run composer update by comparing composer.lock to the the git HEAD.

Requires:

There are no other dependencies.

Install

composer global require davidrjonas/composer-lock-diff:^1.0

# With zsh, run `rehash` to make it known to the shell.

# try it
composer-lock-diff --help

If composer-lock-diff is not found, make sure ~/.composer/vendor/bin is in your $PATH env variable. For more information on how to do that see this question on Stack Overflow.

Usage

composer update
# don't commit yet!
composer-lock-diff

Or from vim, to insert the output into the commit message, type :r!composer-lock-diff.

Options

^ File includes anything available as a protocol stream wrapper such as URLs.

Example Plain Text Table Output

+--------------------+-------+--------+------------------------------------------------------------------+
| Production Changes | From  | To     | Compare                                                          |
+--------------------+-------+--------+------------------------------------------------------------------+
| guzzlehttp/guzzle  | 6.2.0 | 6.3.0  | https://github.com/guzzle/guzzle/compare/6.2.0...6.3.0           |
| hashids/hashids    | 2.0.0 | 2.0.4  | https://github.com/ivanakimov/hashids.php/compare/2.0.0...2.0.4  |
| league/flysystem   | 1.0.0 | 1.0.42 | https://github.com/thephpleague/flysystem/compare/1.0.0...1.0.42 |
| monolog/monolog    | NEW   | 1.21.0 |                                                                  |
+--------------------+-------+--------+------------------------------------------------------------------+

+------------------+--------+---------+---------+
| Dev Changes      | From   | To      | Compare |
+------------------+--------+---------+---------+
| phpspec/php-diff | v1.0.2 | REMOVED |         |
+------------------+--------+---------+---------+

Markdown Table

Raw

| Production Changes | From  | To     | Compare                                                                 |
|--------------------|-------|--------|-------------------------------------------------------------------------|
| guzzlehttp/guzzle  | 6.2.0 | 6.3.0  | [...](https://github.com/guzzle/guzzle/compare/6.2.0...6.3.0)           |
| hashids/hashids    | 2.0.0 | 2.0.4  | [...](https://github.com/ivanakimov/hashids.php/compare/2.0.0...2.0.4)  |
| league/flysystem   | 1.0.0 | 1.0.42 | [...](https://github.com/thephpleague/flysystem/compare/1.0.0...1.0.42) |
| monolog/monolog    | NEW   | 1.21.0 |                                                                         |

| Dev Changes      | From   | To      | Compare |
|------------------|--------|---------|---------|
| phpspec/php-diff | v1.0.2 | REMOVED |         |

Rendered

Production ChangesFromToCompare
guzzlehttp/guzzle6.2.06.3.0...
hashids/hashids2.0.02.0.4...
league/flysystem1.0.01.0.42...
monolog/monologNEW1.21.0
Dev ChangesFromToCompare
phpspec/php-diffv1.0.2REMOVED

Development

New features are always welcome! Follow these guidelines

The Makefile has some test cases. Run make | less and inspect the output. If you need specific versions or more information, continue reading.

To run using the test data manually simply point the --to and --from args at the lock files,

php ./composer-lock-diff --from ./test-data/composer.from.lock --to ./test-data/composer.to.lock

Docker is very helpful for targeting a specific version of php and/or composer,

docker run --rm -it -v "$PWD":/src -w /src php:7.4.2 \
  php ./composer-lock-diff --from ./test-data/composer.from.lock --to ./test-data/composer.to.lock

Sometimes you want to test the git related functions. To do that first I make a temporary repo. Then I copy into it test-data/composer.from.lock as composer.lock to set the previous state and test-data/composer.to.json as composer.json for the future state. I commit those then run composer-lock-diff with the options I want to test and visually inspect the results.

mkdir tmp && cd tmp
git init
cp ../test-data/composer.to.json composer.json
cp ../test-data/composer.from.lock composer.lock
git add .
git commit -m "initial"

composer update
# or
docker run --rm -it -v "$PWD":/src -w /src composer:latest php composer update

php ../composer-lock-diff

# or, if you want to use docker, you'll need git
cd ..
docker run --rm -it -v "$PWD":/src -w /src php:7.4.2 bash
apt-get update && apt-get install -y git
# You may want composer as well,
curl -OL https://getcomposer.org/download/1.9.3/composer.phar
cd tmp
php ../composer.phar update
php ../composer-lock-diff

Add a test case to test-data/

Test Cases

See Makefile.

If anyone can help test with Windows that would be very much appreciated!

Contributors

Thanks to everyone who has shared ideas and code! In particular,