Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for 📚 How to see what changed in Composer files
Ion Bazan
Ion Bazan

Posted on

📚 How to see what changed in Composer files

When reviewing a Pull Request that touchedcomposer.json andcomposer.lock files you might notice that the diffs are usually pretty huge and it's almost impossible to tell what exactly happened there - which packages got added, updated, downgraded or removed? Nobody knows.

That's becauseComposer stores information about all packages that should be installed incomposer.lock together with some of their metadata. This helps to manage the dependencies efficiently and browse most information offline but there is currently no built-in way to compare these files when changed.

How to live with that?

Don't worry, I got you. Simply installComposer-Diff plugin which allows you to easily compare any two versions of yourcomposer.lock files:

composer global req ion-bazan/composer-diff
Enter fullscreen modeExit fullscreen mode

To run it in your repository:

composer diff# Displays packages changed in current git tree compared with HEADcomposer diff--help# Display detailed usage instructions
Enter fullscreen modeExit fullscreen mode

By default, it compares current filesystem version with your last committed changes (to use it locally just before committing your new changes):

Image description

It produces a colourful, tabulated markdown output which can be copy-pasted into your PR description for reference 🤩

Besides of generating diff for your current filesystem changes, you can compare any 2 git refs or local copies of files using--base and--target options or arguments:

composer diff master# Compare current composer.lock with the one on master branchcomposer diff master:composer.lock develop:composer.lock-p# Compare master and develop branches, including platform dependenciescomposer diff--no-dev# ignore dev dependenciescomposer diff-p# include platform dependenciescomposer diff-f json# Output as JSON instead of table
Enter fullscreen modeExit fullscreen mode

Did I mention it works with all PHP versions from 5.3 all the way till 8.4+?

OK but I'm lazy

Me too! That's why I made things even easier with GitHub Actions - I'm addingComposer Diff Action to all my projects to enjoy an automated report in every PR.

Image description

Another day, another useful automation.

OK but I don't like you

No problem, you can check out a few other tools instead:

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Singapore
  • Joined

More fromIon Bazan

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp