1
0
Fork 0

Support ignore-platform-reqs in `composer outdated` (#10293)

This allows users to also find libraries that require major platform
changes to unlock updates.
It addresses #10291.
pull/10307/head
Rafael Dohms 2021-11-23 17:16:58 +01:00 committed by GitHub
parent bac7b826f2
commit 78583ab678
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 4 deletions

View File

@ -485,6 +485,13 @@ php composer.phar show monolog/monolog 1.0.2
* **--direct (-D):** Restricts the list of packages to your direct dependencies. * **--direct (-D):** Restricts the list of packages to your direct dependencies.
* **--strict:** Return a non-zero exit code when there are outdated packages. * **--strict:** Return a non-zero exit code when there are outdated packages.
* **--format (-f):** Lets you pick between text (default) or json output format. * **--format (-f):** Lets you pick between text (default) or json output format.
* **--ignore-platform-reqs:** ignore all platform requirements (`php`, `hhvm`,
`lib-*` and `ext-*`) and force the installation even if the local machine does
not fulfill these. Use with the --outdated option.
* **--ignore-platform-req:** ignore a specific platform requirement(`php`,
`hhvm`, `lib-*` and `ext-*`) and force the installation even if the local machine
does not fulfill it. Multiple requirements can be ignored via wildcard. Use with
the --outdated option.
## outdated ## outdated
@ -508,6 +515,12 @@ The color coding is as such:
* **--format (-f):** Lets you pick between text (default) or json output format. * **--format (-f):** Lets you pick between text (default) or json output format.
* **--no-dev:** Do not show outdated dev dependencies. * **--no-dev:** Do not show outdated dev dependencies.
* **--locked:** Shows updates for packages from the lock file, regardless of what is currently in vendor dir. * **--locked:** Shows updates for packages from the lock file, regardless of what is currently in vendor dir.
* **--ignore-platform-reqs:** ignore all platform requirements (`php`, `hhvm`,
`lib-*` and `ext-*`) and force the installation even if the local machine does
not fulfill these.
* **--ignore-platform-req:** ignore a specific platform requirement(`php`,
`hhvm`, `lib-*` and `ext-*`) and force the installation even if the local machine
does not fulfill it. Multiple requirements can be ignored via wildcard.
## browse / home ## browse / home

View File

@ -42,6 +42,8 @@ class OutdatedCommand extends ShowCommand
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'), 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('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('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages). Use with the --outdated option'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages). Use with the --outdated option'),
)) ))
->setHelp( ->setHelp(
<<<EOT <<<EOT
@ -88,6 +90,12 @@ EOT
if ($input->getOption('no-dev')) { if ($input->getOption('no-dev')) {
$args['--no-dev'] = true; $args['--no-dev'] = true;
} }
if ($input->getOption('ignore-platform-req')) {
$args['--ignore-platform-req'] = $input->getOption('ignore-platform-req');
}
if ($input->getOption('ignore-platform-reqs')) {
$args['--ignore-platform-reqs'] = true;
}
$args['--format'] = $input->getOption('format'); $args['--format'] = $input->getOption('format');
$args['--ignore'] = $input->getOption('ignore'); $args['--ignore'] = $input->getOption('ignore');

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\DefaultPolicy; use Composer\DependencyResolver\DefaultPolicy;
use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\CompletePackageInterface; use Composer\Package\CompletePackageInterface;
@ -88,6 +89,8 @@ class ShowCommand extends BaseCommand
new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'), 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('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('no-dev', null, InputOption::VALUE_NONE, 'Disables search in require-dev packages.'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages). Use with the --outdated option'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages). Use with the --outdated option'),
)) ))
->setHelp( ->setHelp(
<<<EOT <<<EOT
@ -151,6 +154,8 @@ EOT
return 1; return 1;
} }
$ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false);
// init repos // init repos
$platformOverrides = array(); $platformOverrides = array();
if ($composer) { if ($composer) {
@ -267,7 +272,7 @@ EOT
} else { } else {
$latestPackage = null; $latestPackage = null;
if ($input->getOption('latest')) { if ($input->getOption('latest')) {
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $input->getOption('minor-only')); $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $input->getOption('minor-only'), $ignorePlatformReqs);
} }
if ( if (
$input->getOption('outdated') $input->getOption('outdated')
@ -387,7 +392,7 @@ EOT
if ($showLatest && $showVersion) { if ($showLatest && $showVersion) {
foreach ($packages[$type] as $package) { foreach ($packages[$type] as $package) {
if (is_object($package)) { if (is_object($package)) {
$latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly); $latestPackage = $this->findLatestPackage($package, $composer, $platformRepo, $showMinorOnly, $ignorePlatformReqs);
if ($latestPackage === false) { if ($latestPackage === false) {
continue; continue;
} }
@ -1248,10 +1253,11 @@ EOT
* Given a package, this finds the latest package matching it * Given a package, this finds the latest package matching it
* *
* @param bool $minorOnly * @param bool $minorOnly
* @param bool|string $ignorePlatformReqs
* *
* @return PackageInterface|false * @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 = false)
{ {
// find the latest version allowed in this repo set // find the latest version allowed in this repo set
$name = $package->getName(); $name = $package->getName();
@ -1276,7 +1282,7 @@ EOT
$targetVersion = '^' . $package->getVersion(); $targetVersion = '^' . $package->getVersion();
} }
$candidate = $versionSelector->findBestCandidate($name, $targetVersion, $bestStability); $candidate = $versionSelector->findBestCandidate($name, $targetVersion, $bestStability, PlatformRequirementFilterFactory::fromBoolOrList($ignorePlatformReqs));
while ($candidate instanceof AliasPackage) { while ($candidate instanceof AliasPackage) {
$candidate = $candidate->getAliasOf(); $candidate = $candidate->getAliasOf();
} }