1
0
Fork 0

Fix handling of inline-update-constraints with refs or stability flags, fixes #9847

pull/9873/head
Jordi Boggiano 2021-05-04 14:14:57 +02:00
parent a677d3e9a4
commit a844fce23e
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 18 additions and 8 deletions

View File

@ -16,6 +16,7 @@ use Composer\Composer;
use Composer\DependencyResolver\Request;
use Composer\Installer;
use Composer\IO\IOInterface;
use Composer\Package\Loader\RootPackageLoader;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Package\Version\VersionParser;
@ -139,8 +140,9 @@ EOT
}
}
$rootRequires = $composer->getPackage()->getRequires();
$rootDevRequires = $composer->getPackage()->getDevRequires();
$rootPackage = $composer->getPackage();
$rootRequires = $rootPackage->getRequires();
$rootDevRequires = $rootPackage->getDevRequires();
foreach ($reqs as $package => $constraint) {
if (isset($rootRequires[$package])) {
$rootRequires[$package] = $this->appendConstraintToLink($rootRequires[$package], $constraint);
@ -150,8 +152,10 @@ EOT
throw new \UnexpectedValueException('Only root package requirements can receive temporary constraints and '.$package.' is not one');
}
}
$composer->getPackage()->setRequires($rootRequires);
$composer->getPackage()->setDevRequires($rootDevRequires);
$rootPackage->setRequires($rootRequires);
$rootPackage->setDevRequires($rootDevRequires);
$rootPackage->setReferences(RootPackageLoader::extractReferences($reqs, $rootPackage->getReferences()));
$rootPackage->setStabilityFlags(RootPackageLoader::extractStabilityFlags($reqs, $rootPackage->getMinimumStability(), $rootPackage->getStabilityFlags()));
if ($input->getOption('interactive')) {
$packages = $this->getPackagesInteractively($io, $input, $output, $composer, $packages);

View File

@ -130,8 +130,8 @@ class RootPackageLoader extends ArrayLoader
$links[$link->getTarget()] = $link->getConstraint()->getPrettyString();
}
$aliases = $this->extractAliases($links, $aliases);
$stabilityFlags = $this->extractStabilityFlags($links, $stabilityFlags, $realPackage->getMinimumStability());
$references = $this->extractReferences($links, $references);
$stabilityFlags = self::extractStabilityFlags($links, $realPackage->getMinimumStability(), $stabilityFlags);
$references = self::extractReferences($links, $references);
if (isset($links[$config['name']])) {
throw new \RuntimeException(sprintf('Root package \'%s\' cannot require itself in its composer.json' . PHP_EOL .
@ -189,7 +189,10 @@ class RootPackageLoader extends ArrayLoader
return $aliases;
}
private function extractStabilityFlags(array $requires, array $stabilityFlags, $minimumStability)
/**
* @internal
*/
public static function extractStabilityFlags(array $requires, $minimumStability, array $stabilityFlags)
{
$stabilities = BasePackage::$stabilities;
$minimumStability = $stabilities[$minimumStability];
@ -242,7 +245,10 @@ class RootPackageLoader extends ArrayLoader
return $stabilityFlags;
}
private function extractReferences(array $requires, array $references)
/**
* @internal
*/
public static function extractReferences(array $requires, array $references)
{
foreach ($requires as $reqName => $reqVersion) {
$reqVersion = preg_replace('{^([^,\s@]+) as .+$}', '$1', $reqVersion);