Skip to content

Commit

Permalink
Support ignore-platform-reqs in composer outdated
Browse files Browse the repository at this point in the history
This allows users to also find libraries that require major platform
changes to unlock updates.
It addresses #10291.
  • Loading branch information
rdohms committed Nov 19, 2021
1 parent 8386264 commit a1922d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/Composer/Command/OutdatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected function configure()
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
new InputOption('ignore', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore specified package(s). Use it with the --outdated option if you don\'t want to be informed about new versions of some packages.'),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages). Use with the --outdated option'),
))
->setHelp(
<<<EOT
Expand Down Expand Up @@ -88,6 +89,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($input->getOption('no-dev')) {
$args['--no-dev'] = true;
}
if ($input->getOption('ignore-platform-reqs')) {
$args['--ignore-platform-reqs'] = true;
}
$args['--format'] = $input->getOption('format');
$args['--ignore'] = $input->getOption('ignore');

Expand Down
15 changes: 11 additions & 4 deletions src/Composer/Command/ShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Composer\Composer;
use Composer\DependencyResolver\DefaultPolicy;
use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory;
use Composer\Json\JsonFile;
use Composer\Package\BasePackage;
use Composer\Package\CompletePackageInterface;
Expand Down Expand Up @@ -88,6 +89,7 @@ protected function configure()
new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages). Use with the --outdated option'),
))
->setHelp(
<<<EOT
Expand Down Expand Up @@ -267,7 +269,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} else {
$latestPackage = null;
if ($input->getOption('latest')) {
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $input->getOption('minor-only'));
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $input->getOption('minor-only'), $input->getOption('ignore-platform-reqs'));
}
if (
$input->getOption('outdated')
Expand Down Expand Up @@ -371,6 +373,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$showAllTypes = $input->getOption('all');
$showLatest = $input->getOption('latest');
$showMinorOnly = $input->getOption('minor-only');
$ignorePlatformReqs = $input->getOption('ignore-platform-reqs');
$ignoredPackages = array_map('strtolower', $input->getOption('ignore'));
$indent = $showAllTypes ? ' ' : '';
/** @var PackageInterface[] $latestPackages */
Expand All @@ -387,7 +390,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($showLatest && $showVersion) {
foreach ($packages[$type] as $package) {
if (is_object($package)) {
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly);
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly, $ignorePlatformReqs);
if ($latestPackage === false) {
continue;
}
Expand Down Expand Up @@ -1251,7 +1254,7 @@ private function writeTreeLine($line)
*
* @return PackageInterface|false
*/
private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, $minorOnly = false)
private function findLatestPackage(PackageInterface $package, Composer $composer, PlatformRepository $platformRepo, $minorOnly = false, $ignorePlatformReqs = null)
{
// find the latest version allowed in this repo set
$name = $package->getName();
Expand All @@ -1276,7 +1279,11 @@ private function findLatestPackage(PackageInterface $package, Composer $composer
$targetVersion = '^' . $package->getVersion();
}

$candidate = $versionSelector->findBestCandidate($name, $targetVersion, $bestStability);
if ($ignorePlatformReqs !== null) {
$ignorePlatformReqs = PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs);
}

$candidate = $versionSelector->findBestCandidate($name, $targetVersion, $bestStability, $ignorePlatformReqs);
while ($candidate instanceof AliasPackage) {
$candidate = $candidate->getAliasOf();
}
Expand Down

0 comments on commit a1922d7

Please sign in to comment.