From 94076c0bb980af15e29a72328f7bc1a41e46776f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 12 Jan 2021 13:47:36 +0100 Subject: [PATCH] Make sure if plugins depend on the root package that the root package is also autoloaded correctly, refs #9530 --- src/Composer/Plugin/PluginManager.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 8aad71b8e..d16f364e4 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -21,6 +21,7 @@ use Composer\Package\RootPackage; use Composer\Package\Version\VersionParser; use Composer\Repository\RepositoryInterface; use Composer\Repository\InstalledRepository; +use Composer\Repository\RootPackageRepository; use Composer\Package\PackageInterface; use Composer\Package\Link; use Composer\Semver\Constraint\Constraint; @@ -174,7 +175,8 @@ class PluginManager $localRepo = $this->composer->getRepositoryManager()->getLocalRepository(); $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; - $installedRepo = new InstalledRepository(array($localRepo)); + $rootPackageRepo = new RootPackageRepository($this->composer->getPackage()); + $installedRepo = new InstalledRepository(array($localRepo, $rootPackageRepo)); if ($globalRepo) { $installedRepo->addRepository($globalRepo); } @@ -185,11 +187,15 @@ class PluginManager $generator = $this->composer->getAutoloadGenerator(); $autoloads = array(); foreach ($autoloadPackages as $autoloadPackage) { - $downloadPath = $this->getInstallPath($autoloadPackage, $globalRepo && $globalRepo->hasPackage($autoloadPackage)); + if ($autoloadPackage === $this->composer->getPackage()) { + $downloadPath = ''; + } else { + $downloadPath = $this->getInstallPath($autoloadPackage, $globalRepo && $globalRepo->hasPackage($autoloadPackage)); + } $autoloads[] = array($autoloadPackage, $downloadPath); } - $map = $generator->parseAutoloads($autoloads, new RootPackage('dummy/root-package', '1.0.0.0', '1.0.0')); + $map = $generator->parseAutoloads($autoloads, $this->composer->getPackage()); $classLoader = $generator->createLoader($map); $classLoader->register();