diff --git a/bin/find-composer-packages.php b/bin/find-composer-packages.php index 4fcef83..a6a71a3 100755 --- a/bin/find-composer-packages.php +++ b/bin/find-composer-packages.php @@ -24,6 +24,15 @@ } $loader = require($argv[1]); +$rootComposerFile = realpath(dirname($argv[1]) . '/../composer.json'); + +if (! file_exists($rootComposerFile)) { + fwrite(STDERR, sprintf("ERROR: Unable to find root composer.json file \"%s\"\n", $rootComposerFile)); + exit(2); +} + +$rootComposerConfig = json_decode(file_get_contents($rootComposerFile), true); + // Get length of file path (returned by $loader) up to package dir inside composer $needle = 'vendor/composer/../'; @@ -62,9 +71,14 @@ function getPackageForClass(ClassLoader $loader, string $class) continue; } try { - $version = \Composer\InstalledVersions::getVersion($package); + $depVersion = $rootComposerConfig['require'][$package] + ?? $rootComposerConfig['require-dev'][$package] + ?? null; + if ($depVersion === null) { + $version = \Composer\InstalledVersions::getVersion($package); + $depVersion = substr($version, 0, strrpos($version, '.')); + } $done[$package] = true; - $depVersion = substr($version, 0, strrpos($version, '.')); echo "\"$package\": \"^$depVersion\"\n"; } catch (OutOfBoundsException $exception) { // ignore package