diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index ab937e47e..7b6a8d9a1 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -459,6 +459,8 @@ class Installer $this->io->write('Nothing to install or update'); } + $operations = $this->moveComposerInstallerToFrontIfNeeded($operations); + foreach ($operations as $operation) { // collect suggestions if ('install' === $operation->getJobType()) { @@ -534,6 +536,39 @@ class Installer return true; } + + /** + * Workaround: if your packages depend on composer/installers, we must be sure + * that composer/installers is installed / updated at FIRST; else it would lead + * to packages being installed multiple times in different folders, when running + * composer twice. + * + * While this does not fix the root-causes of https://github.com/composer/composer/issues/1147, + * it at least fixes the symptoms and makes usage of composer possible (again) + * in such scenarios. + * + * @param array $operations + * @return array the modified + */ + private function moveComposerInstallerToFrontIfNeeded($operations) + { + $operationForComposerInstallers = NULL; + $operations = array_filter($operations, function($operation) use (&$operationForComposerInstallers) { + if ( ($operation instanceof DependencyResolver\Operation\InstallOperation && $operation->getPackage()->getName() === 'composer/installers') + || ($operation instanceof DependencyResolver\Operation\UpdateOperation && $operation->getInitialPackage()->getName() === 'composer/installers') + ) { + $operationForComposerInstallers = $operation; + return FALSE; + } + + return TRUE; + }); + if ($operationForComposerInstallers !== NULL) { + array_unshift($operations, $operationForComposerInstallers); + } + return $operations; + } + private function createPool() { $minimumStability = $this->package->getMinimumStability();