Skip to content

Commit

Permalink
feat: use composer.json version if found instead of exact constructed…
Browse files Browse the repository at this point in the history
… match (#161)
  • Loading branch information
Vinai authored May 27, 2024
1 parent 02e1843 commit f5e39a1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions bin/find-composer-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/../';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f5e39a1

Please sign in to comment.