diff --git a/composer.json b/composer.json index 1bf8ec6..33e1152 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require" : { "php" : ">=5.3.2", - "composer-plugin-api": "~1.1.0" + "composer-plugin-api": "^1.0 || ^2.0" }, "require-dev" : { "composer/composer" : "1.1.*@dev", diff --git a/package.json b/package.json index 335aaf2..3b25085 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version" : "0.2.0", + "version" : "0.2.1", "repository" : { "type": "git", "url" : "https://github.com/devaloka/mu-plugin-installer.git" diff --git a/src/Installer/MuPluginInstaller.php b/src/Installer/MuPluginInstaller.php index 5edb2fb..fbf252a 100644 --- a/src/Installer/MuPluginInstaller.php +++ b/src/Installer/MuPluginInstaller.php @@ -13,6 +13,7 @@ use Composer\Installer\LibraryInstaller; use Composer\Package\PackageInterface; use Composer\Repository\InstalledRepositoryInterface; +use React\Promise\PromiseInterface; /** * Class MuPluginInstaller @@ -238,9 +239,21 @@ protected function resolveInstallPath(array $paths, $name) */ protected function installCode(PackageInterface $package) { - parent::installCode($package); + $muPluginInstaller = $this; - $this->installLoader($package); + $installLoader = function () use ($muPluginInstaller, $package) { + $muPluginInstaller->installLoader($package); + }; + + $promise = parent::installCode($package); + + // Composer v2 might return a promise here + if ($promise instanceof PromiseInterface) { + return $promise->then($installLoader); + } + + // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async) + $installLoader(); } /** @@ -261,9 +274,21 @@ protected function installLoader(PackageInterface $package) */ protected function removeCode(PackageInterface $package) { - parent::removeCode($package); + $muPluginInstaller = $this; + + $removeLoader = function () use ($muPluginInstaller, $package) { + $muPluginInstaller->removeLoader($package); + }; + + $promise = parent::removeCode($package); + + // Composer v2 might return a promise here + if ($promise instanceof PromiseInterface) { + return $promise->then($removeLoader); + } - $this->removeLoader($package); + // If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async) + $removeLoader(); } /** diff --git a/src/Installer/MuPluginInstallerPlugin.php b/src/Installer/MuPluginInstallerPlugin.php index 6c70299..3a6d788 100644 --- a/src/Installer/MuPluginInstallerPlugin.php +++ b/src/Installer/MuPluginInstallerPlugin.php @@ -21,13 +21,23 @@ */ class MuPluginInstallerPlugin implements PluginInterface { + private $installer; + /** * {@inheritDoc} */ public function activate(Composer $composer, IOInterface $io) { - $installer = new MuPluginInstaller($io, $composer); + $this->installer = new MuPluginInstaller($io, $composer); + $composer->getInstallationManager()->addInstaller($this->installer); + } + + public function deactivate(Composer $composer, IOInterface $io) + { + $composer->getInstallationManager()->removeInstaller($this->installer); + } - $composer->getInstallationManager()->addInstaller($installer); + public function uninstall(Composer $composer, IOInterface $io) + { } }