From de87a3c488a12f53a82d7e11d4e690c364b920e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 3 May 2024 11:25:14 +0200 Subject: [PATCH] Make sure "roundcube/roundcubemail" install path is always available --- composer.json | 4 ++-- src/ExtensionInstaller.php | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index f08d7df..54b491a 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,11 @@ ], "require": { "php": ">=7.3 <8.4", - "composer-plugin-api": "^1.0 || ^2.0", + "composer-plugin-api": "^2.1", "roundcube/roundcubemail": "*" }, "require-dev": { - "composer/composer": "^2.0", + "composer/composer": "^2.1", "ergebnis/composer-normalize": "^2.13", "friendsofphp/php-cs-fixer": "^3.0", "phpstan/extension-installer": "^1.1", diff --git a/src/ExtensionInstaller.php b/src/ExtensionInstaller.php index e24cd01..618b3e5 100644 --- a/src/ExtensionInstaller.php +++ b/src/ExtensionInstaller.php @@ -2,6 +2,7 @@ namespace Roundcube\Composer; +use Composer\Installer\InstallationManager; use Composer\Installer\LibraryInstaller; use Composer\Package\PackageInterface; use Composer\Package\Version\VersionParser; @@ -43,15 +44,26 @@ protected function setRoundcubemailInstallPath(InstalledRepositoryInterface $ins protected function getRoundcubemailInstallPath(): string { + // install path is not set at composer download phase + // never assume any path, but for this known composer behaviour get it from backtrace instead + if ($this->roundcubemailInstallPath === null) { + $backtrace = debug_backtrace(); + foreach ($backtrace as $frame) { + // relies on https://github.com/composer/composer/blob/2.7.4/src/Composer/Installer/InstallationManager.php#L243 + if (($frame['object'] ?? null) instanceof InstallationManager + && $frame['function'] === 'downloadAndExecuteBatch' + ) { + $this->setRoundcubemailInstallPath($frame['args'][0]); + } + } + } + return $this->roundcubemailInstallPath; } public function getInstallPath(PackageInterface $package) { - if ( - !$this->supports($package->getType()) - || $this->roundcubemailInstallPath === null // install path is not known at download phase - ) { + if (!$this->supports($package->getType())) { return parent::getInstallPath($package); }