From e0f800c0ebeed4d15a1305f4e82285c88a91e9f1 Mon Sep 17 00:00:00 2001 From: teppokoivula Date: Wed, 9 Dec 2020 20:51:16 +0200 Subject: [PATCH 1/3] Composer 2.0 support --- CHANGELOG.md | 5 +++++ composer.json | 5 +++-- src/ComposerInstaller/Plugin.php | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45882ef..803ed4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.1.0] - 2020-12-09 + +### Added +- Support for Composer 2.0. + ## [1.0.4] - 2020-10-20 ### Changed diff --git a/composer.json b/composer.json index 63ed62a..a22ab54 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "composer-plugin-api": "^1.0", + "composer-plugin-api": "^1.0 || ^2.0", "hari/pw-module": "^1.0.0" }, "autoload": { @@ -22,6 +22,7 @@ } }, "extra": { - "class": "wireframe\\ComposerInstaller\\Plugin" + "class": "wireframe\\ComposerInstaller\\Plugin", + "branch-version": "1.1.0" } } diff --git a/src/ComposerInstaller/Plugin.php b/src/ComposerInstaller/Plugin.php index 0a66701..0a8b6c9 100644 --- a/src/ComposerInstaller/Plugin.php +++ b/src/ComposerInstaller/Plugin.php @@ -65,4 +65,30 @@ public static function prePackageInstall(PackageEvent $event) $installationManager->removeInstaller($moduleInstaller); } } + + /** + * Remove any hooks from Composer + * + * This will be called when a plugin is deactivated before being uninstalled, but also before it + * gets upgraded to a new version so the old one can be deactivated and the new one activated. + * + * @param Composer $composer + * @param IOInterface $io + */ + public function deactivate(Composer $composer, IOInterface $io) + { + } + + /** + * Prepare the plugin to be uninstalled + * + * This will be called after deactivate. + * + * @param Composer $composer + * @param IOInterface $io + */ + public function uninstall(Composer $composer, IOInterface $io) + { + } + } From d20c10c97c05c46c8a5f320edb195b0631f03c20 Mon Sep 17 00:00:00 2001 From: teppokoivula Date: Wed, 9 Dec 2020 21:08:10 +0200 Subject: [PATCH 2/3] Remove temporary branch-version param --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a22ab54..90631f2 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ } }, "extra": { - "class": "wireframe\\ComposerInstaller\\Plugin", - "branch-version": "1.1.0" + "class": "wireframe\\ComposerInstaller\\Plugin" } } From 12f2baec9941b1124af23d420e610ab9bcaeb551 Mon Sep 17 00:00:00 2001 From: teppokoivula Date: Wed, 9 Dec 2020 21:28:29 +0200 Subject: [PATCH 3/3] Add support for Composer v2 promises --- .../SiteProfileInstaller.php | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ComposerInstaller/SiteProfileInstaller.php b/src/ComposerInstaller/SiteProfileInstaller.php index c9c182b..b2bcefb 100644 --- a/src/ComposerInstaller/SiteProfileInstaller.php +++ b/src/ComposerInstaller/SiteProfileInstaller.php @@ -5,6 +5,7 @@ use Composer\Repository\InstalledRepositoryInterface; use Composer\Package\PackageInterface; use Composer\Util\Filesystem; +use React\Promise\PromiseInterface; /** * SiteProfileInstaller class @@ -35,21 +36,32 @@ public function supports($packageType) */ public function install(InstalledRepositoryInterface $repo, PackageInterface $package) { - parent::install($repo, $package); - // check if there's a nested site- prefixed directory, in which case we // must assume that it's the real site profile directory and move it up // one level - $path = $this->getInstallPath($package); - $site = $this->getNestedSiteDirectoryName($path); - if ($site) { - $basePath = $this->getBasePath(static::BASE_PATH); - $tempPath = $basePath . 'temp-' . \basename($path); - $filesystem = new Filesystem(); - $filesystem->rename($path, $tempPath); - $filesystem->rename($tempPath . '/' . $site, $basePath . $site); - $filesystem->remove($tempPath); + $adjustProfilePath = function() use ($package) { + $path = $this->getInstallPath($package); + $site = $this->getNestedSiteDirectoryName($path); + if ($site) { + $basePath = $this->getBasePath(static::BASE_PATH); + $tempPath = $basePath . 'temp-' . \basename($path); + $filesystem = new Filesystem(); + $filesystem->rename($path, $tempPath); + $filesystem->rename($tempPath . '/' . $site, $basePath . $site); + $filesystem->remove($tempPath); + } + }; + + $promise = parent::install($repo, $package); + + // Composer v2 might return a promise here + if ($promise instanceof PromiseInterface) { + return $promise->then($adjustProfilePath); } + + // if not, execute the code right away as parent::install executed synchronously + // (composer v1, or v2 without async) + $adjustProfilePath(); } /**