From 4c8149a33d9da7dd2bc3dbf90ebed2a2a8f68a8b Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 11 Feb 2021 14:55:03 +0100 Subject: [PATCH] Only load dev requirements for the root package when collecting autoload dependencies during plugin activation, fixes #9683 --- src/Composer/Plugin/PluginManager.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index d89db97f7..058c03ecd 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -23,6 +23,7 @@ use Composer\Repository\RepositoryInterface; use Composer\Repository\InstalledRepository; use Composer\Repository\RootPackageRepository; use Composer\Package\PackageInterface; +use Composer\Package\RootPackageInterface; use Composer\Package\Link; use Composer\Semver\Constraint\Constraint; use Composer\Plugin\Capability\Capability; @@ -183,7 +184,7 @@ class PluginManager } $autoloadPackages = array($package->getName() => $package); - $autoloadPackages = $this->collectDependencies($installedRepo, $autoloadPackages, $package); + $autoloadPackages = $this->collectDependencies($installedRepo, $autoloadPackages, $package, $rootPackage); $generator = $this->composer->getAutoloadGenerator(); $autoloads = array(array($rootPackage, '')); @@ -408,18 +409,18 @@ class PluginManager * * @return array Map of package names to packages */ - private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package) + private function collectDependencies(InstalledRepository $installedRepo, array $collected, PackageInterface $package, RootPackageInterface $rootPackage) { - $requires = array_merge( - $package->getRequires(), - $package->getDevRequires() - ); + $requires = $package->getRequires(); + if ($rootPackage->getName() === $package->getName()) { + $requires = array_merge($requires, $package->getDevRequires()); + } foreach ($requires as $requireLink) { foreach ($installedRepo->findPackagesWithReplacersAndProviders($requireLink->getTarget()) as $requiredPackage) { if (!isset($collected[$requiredPackage->getName()])) { $collected[$requiredPackage->getName()] = $requiredPackage; - $collected = $this->collectDependencies($installedRepo, $collected, $requiredPackage); + $collected = $this->collectDependencies($installedRepo, $collected, $requiredPackage, $rootPackage); } } }