Use policy rule instead of stacking up another repo to prioritize aliased packages
parent
59d2b1145c
commit
956b54e516
|
@ -106,7 +106,6 @@ EOT
|
|||
}
|
||||
|
||||
// prepare aliased packages
|
||||
$aliasRepo = new ArrayRepository;
|
||||
if (!$update && $composer->getLocker()->isLocked()) {
|
||||
$aliases = $composer->getLocker()->getAliases();
|
||||
} else {
|
||||
|
@ -114,14 +113,13 @@ EOT
|
|||
}
|
||||
foreach ($aliases as $alias) {
|
||||
foreach ($repoManager->findPackages($alias['package'], $alias['version']) as $package) {
|
||||
$aliasRepo->addPackage(new AliasPackage($package, $alias['alias']));
|
||||
$package->getRepository()->addPackage(new AliasPackage($package, $alias['alias']));
|
||||
}
|
||||
foreach ($repoManager->getLocalRepository()->findPackages($alias['package'], $alias['version']) as $package) {
|
||||
$repoManager->getLocalRepository()->addPackage(new AliasPackage($package, $alias['alias']));
|
||||
$repoManager->getLocalRepository()->removePackage($package);
|
||||
}
|
||||
}
|
||||
$repoManager->addRepository($aliasRepo);
|
||||
|
||||
// creating repository pool
|
||||
$pool = new Pool;
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Composer\DependencyResolver;
|
|||
|
||||
use Composer\Repository\RepositoryInterface;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\AliasPackage;
|
||||
use Composer\Package\LinkConstraint\VersionConstraint;
|
||||
|
||||
/**
|
||||
|
@ -103,6 +104,16 @@ class DefaultPolicy implements PolicyInterface
|
|||
public function compareByPriorityPreferInstalled(Pool $pool, array $installedMap, PackageInterface $a, PackageInterface $b, $ignoreReplace = false)
|
||||
{
|
||||
if ($a->getRepository() === $b->getRepository()) {
|
||||
if ($a->getName() === $b->getName()) {
|
||||
$aAliased = $a instanceof AliasPackage;
|
||||
$bAliased = $b instanceof AliasPackage;
|
||||
if ($aAliased && !$bAliased) {
|
||||
return -1; // use a
|
||||
}
|
||||
if (!$aAliased && $bAliased) {
|
||||
return 1; // use b
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ignoreReplace) {
|
||||
// return original, not replaced
|
||||
|
|
Loading…
Reference in New Issue