1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 16:42:57 +00:00

Separate locked packages from fixed packages in request

Locked packages are basically like removable fixed packages, so we still
only load one version, but we do not require their installation unless
something the user needs requires their use. So they automatically get
removed if they are no longer needed on any update.
This commit is contained in:
Nils Adermann 2020-09-23 16:52:30 +02:00
parent 73e24ea9fb
commit 74fb313c39
11 changed files with 117 additions and 105 deletions

View file

@ -125,23 +125,25 @@ abstract class Rule
public function isCausedByLock(RepositorySet $repositorySet, Request $request, Pool $pool)
{
if ($this->getReason() === self::RULE_FIXED && $this->reasonData['lockable']) {
return true;
}
if ($this->getReason() === self::RULE_PACKAGE_REQUIRES) {
if (PlatformRepository::isPlatformPackage($this->reasonData->getTarget())) {
return false;
}
foreach ($request->getFixedPackages() as $package) {
if ($package->getName() === $this->reasonData->getTarget()) {
if ($pool->isUnacceptableFixedPackage($package)) {
return true;
if ($request->getLockedRepository()) {
foreach ($request->getLockedRepository()->getPackages() as $package) {
if ($package->getName() === $this->reasonData->getTarget()) {
if ($pool->isUnacceptableFixedOrLockedPackage($package)) {
return true;
}
if (!$this->reasonData->getConstraint()->matches(new Constraint('=', $package->getVersion()))) {
return true;
}
// required package was locked but has been unlocked and still matches
if (!$request->isLockedPackage($package)) {
return true;
}
break;
}
if (!$this->reasonData->getConstraint()->matches(new Constraint('=', $package->getVersion()))) {
return true;
}
break;
}
}
}
@ -150,15 +152,17 @@ abstract class Rule
if (PlatformRepository::isPlatformPackage($this->reasonData['packageName'])) {
return false;
}
foreach ($request->getFixedPackages() as $package) {
if ($package->getName() === $this->reasonData['packageName']) {
if ($pool->isUnacceptableFixedPackage($package)) {
return true;
if ($request->getLockedRepository()) {
foreach ($request->getLockedRepository()->getPackages() as $package) {
if ($package->getName() === $this->reasonData['packageName']) {
if ($pool->isUnacceptableFixedOrLockedPackage($package)) {
return true;
}
if (!$this->reasonData['constraint']->matches(new Constraint('=', $package->getVersion()))) {
return true;
}
break;
}
if (!$this->reasonData['constraint']->matches(new Constraint('=', $package->getVersion()))) {
return true;
}
break;
}
}
}
@ -180,13 +184,20 @@ abstract class Rule
return 'No package found to satisfy root composer.json require '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '');
}
$packagesNonAlias = array_values(array_filter($packages, function ($p) {
return !($p instanceof AliasPackage);
}));
if (count($packagesNonAlias) === 1) {
$package = $packagesNonAlias[0];
if (!($package instanceof AliasPackage) && $request->isLockedPackage($package)) {
return $package->getPrettyName().' is locked to version '.$package->getPrettyVersion()." and an update of this package was not requested.";
}
}
return 'Root composer.json requires '.$packageName.($constraint ? ' '.$constraint->getPrettyString() : '').' -> satisfiable by '.$this->formatPackagesUnique($pool, $packages, $isVerbose).'.';
case self::RULE_FIXED:
$package = $this->deduplicateDefaultBranchAlias($this->reasonData['package']);
if ($this->reasonData['lockable']) {
return $package->getPrettyName().' is locked to version '.$package->getPrettyVersion().' and an update of this package was not requested.';
}
return $package->getPrettyName().' is present at version '.$package->getPrettyVersion() . ' and cannot be modified by Composer';