Get the list of outdated Composer packages
When you run composer update, Composer resolves dependencies against your composer.json constraints and then attempts to fetch the latest compatible versions from Packagist. However, this process is opaque by default; it often updates packages silently or prompts for confirmation without clearly listing exactly which packages are changing before the lock file is rewritten. If you need a precise inventory of outdated packages prior to execution, Composer does not provide a dedicated flag like composer outdated in its core CLI. Fortunately, there are reliable ways to achieve this using built-in tools or external utilities.
The most straightforward approach involves leveraging the composer update --dry-run command. This flag instructs Composer to perform a dry run of the update process. It resolves dependencies against the latest versions available on Packagist without actually downloading or installing anything, and it explicitly lists which packages would be updated. This is particularly useful for identifying major version jumps that might introduce breaking changes before you commit the resulting composer.lock file.
composer update --dry-run
The output will display a list of packages alongside their current versions and the versions they would be upgraded to. For example, you might see entries like:
Problem 1
- lock is not consistent with package.php
Package root requires: ^2.0
- don't install symfony/console v3.4.x (conflict with symfony/... ^2.0)
- don't install symfony/console v2.8.x (conflict with symfony/... ^2.0)
While the --dry-run output is informative, it can sometimes be verbose or cluttered with conflict resolution details if your dependencies are tightly constrained. In such cases, filtering the output to focus solely on the package names and version changes adds clarity. You can pipe the output through grep to isolate specific patterns, though this requires careful regex construction to avoid false positives.
Another method involves using Composer's plugin ecosystem. The composer-plugin package allows you to extend Composer's functionality. While no official "outdated" plugin exists in the core repository, third-party tools often fill this gap. One notable utility is the outdated command provided by various community plugins or scripts that analyze the lock file against Packagist metadata.
If you are working within a Laravel ecosystem, understanding dependency drift is crucial for maintaining security patches and performance improvements. Tools like those developed by LaravelCompany often integrate seamlessly with Composer workflows to streamline maintenance tasks, though always verify compatibility with your specific project version. The core principle remains: inspect the lock file before committing changes.
A common pitfall when using --dry-run is ignoring minor updates that are strictly security patches. These updates might not trigger a major version bump but still require attention. Always review the changelog for the specific packages listed in the dry run output. Additionally, be cautious of dependency conflicts that appear during the dry run; they indicate that updating one package might break another unless you adjust your constraints in composer.json.
For large monorepos or complex dependency trees, the dry run output can become unwieldy. In these scenarios, consider scripting the analysis to parse the JSON output directly rather than relying on terminal text processing. Composer emits structured data that can be queried programmatically, allowing for automated alerts when critical dependencies reach end-of-life status.
Ultimately, while composer update handles the actual installation, taking a moment to inspect the proposed changes ensures you are not introducing unexpected breaking changes into your codebase. This proactive approach saves significant time during the development cycle and prevents production incidents caused by unvetted dependency updates.