ocramius/package-versions
Fast, zero-I/O access to installed Composer package versions from composer.lock. Get dependency versions at runtime via PackageVersions\Versions::getVersion(), with versions compiled during install/update—ideal for building assets or artifacts based on dependency versions.
Dependency Versioning for Dynamic Asset Generation
Enable runtime access to installed package versions (e.g., for versioned API endpoints, changelog generation, or compliance metadata) without runtime composer show calls or filesystem reads. Critical for:
/version endpoints for APIs).Build vs. Buy: Avoid Custom Solutions
Replaces ad-hoc scripts parsing composer.lock or shelling out to composer show. Reduces technical debt by leveraging a battle-tested, zero-I/O library.
Roadmap: Scalable Dependency Tracking Foundation for future features like:
laravel/framework ≥ 10.0").monolog/monolog to v3.0").Use Cases in Laravel Ecosystem
/vendor metadata.--show-versions flags to commands (e.g., php artisan vendor:versions).Adopt When:
composer.lock manually or shelling out to composer show.Look Elsewhere If:
composer.lock at install time; use composer show for live updates).Composer\Semver for comparisons).*"This package lets us automatically embed dependency versions into our system—without slowing down performance. For example:
/version endpoints to show all installed package versions (critical for support and debugging).app-v1.2.3.css) during deployment, reducing cache conflicts.It’s free, MIT-licensed, and used by thousands of projects. We avoid reinventing the wheel while gaining reliability and speed."*
*"Problem: Accessing dependency versions at runtime (e.g., for logs, APIs, or builds) is slow if we parse composer.lock or shell out to composer show. This package solves it by:
composer install (zero I/O at runtime).optimize-autoloader).Use Cases:
ocramius/package-versions:2.12.0 in /version without filesystem reads.mix-manifest.json).getVersion() + CVE API).Trade-offs:
composer.lock at install time).composer show for live queries).Implementation:
composer require ocramius/package-versions
Add to composer.json:
"config": { "optimize-autoloader": true }
Then use:
$version = \PackageVersions\Versions::getVersion('laravel/framework');
// Returns '10.42.0' (or hash if needed).
Alternatives: Custom composer.lock parsing (slower) or shelling out (less secure). This is the de facto standard for this use case."*
How can I help you explore Laravel packages today?