Move plugins with no dependencies to the front, followed by plugins with their dependencies
parent
4cda7e0a44
commit
06bb6c7530
|
@ -744,8 +744,10 @@ class Installer
|
||||||
*/
|
*/
|
||||||
private function movePluginsToFront(array $operations)
|
private function movePluginsToFront(array $operations)
|
||||||
{
|
{
|
||||||
$installerOps = array();
|
$pluginsNoDeps = array();
|
||||||
$installerRequires = array();
|
$pluginsWithDeps = array();
|
||||||
|
$pluginRequires = array();
|
||||||
|
|
||||||
foreach (array_reverse($operations, true) as $idx => $op) {
|
foreach (array_reverse($operations, true) as $idx => $op) {
|
||||||
if ($op instanceof InstallOperation) {
|
if ($op instanceof InstallOperation) {
|
||||||
$package = $op->getPackage();
|
$package = $op->getPackage();
|
||||||
|
@ -755,19 +757,32 @@ class Installer
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($package->getType() === 'composer-plugin'
|
// is this package a plugin?
|
||||||
|| $package->getType() === 'composer-installer'
|
$is_plugin = $package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer';
|
||||||
|| count(array_intersect($package->getNames(), $installerRequires))
|
|
||||||
) {
|
// is this a plugin or a dependency of a plugin?
|
||||||
// capture the requirements for this package so those packages will be moved up as well
|
if ($is_plugin || count(array_intersect($package->getNames(), $pluginRequires))) {
|
||||||
$installerRequires = array_merge($installerRequires, array_keys($package->getRequires()));
|
// get the package's requires, but filter out any platform requirements or 'composer-plugin-api'
|
||||||
// move the operation to the front
|
$requires = array_filter(array_keys($package->getRequires()), function($req) {
|
||||||
array_unshift($installerOps, $op);
|
return $req !== 'composer-plugin-api' && !preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req);
|
||||||
|
});
|
||||||
|
|
||||||
|
// is this a plugin with no meaningful dependencies?
|
||||||
|
if ($is_plugin && !count($requires)) {
|
||||||
|
// plugins with no dependencies go to the very front
|
||||||
|
array_unshift($pluginsNoDeps, $op);
|
||||||
|
} else {
|
||||||
|
// capture the requirements for this package so those packages will be moved up as well
|
||||||
|
$pluginRequires = array_merge($pluginRequires, $requires);
|
||||||
|
// move the operation to the front
|
||||||
|
array_unshift($pluginsWithDeps, $op);
|
||||||
|
}
|
||||||
|
|
||||||
unset($operations[$idx]);
|
unset($operations[$idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge($installerOps, $operations);
|
return array_merge($pluginsNoDeps, $pluginsWithDeps, $operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -25,7 +25,7 @@ Composer installers and their requirements are installed first
|
||||||
install
|
install
|
||||||
--EXPECT--
|
--EXPECT--
|
||||||
Installing inst (1.0.0)
|
Installing inst (1.0.0)
|
||||||
|
Installing inst-with-req (1.0.0)
|
||||||
Installing pkg2 (1.0.0)
|
Installing pkg2 (1.0.0)
|
||||||
Installing inst-with-req2 (1.0.0)
|
Installing inst-with-req2 (1.0.0)
|
||||||
Installing inst-with-req (1.0.0)
|
|
||||||
Installing pkg (1.0.0)
|
Installing pkg (1.0.0)
|
||||||
|
|
Loading…
Reference in New Issue