Skip to content

Commit 80d6c43

Browse files
authored
Merge pull request #3 from wireframe-framework/dev
Release 1.1.0
2 parents c63afc7 + 12f2bae commit 80d6c43

File tree

4 files changed

+55
-12
lines changed

4 files changed

+55
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.1.0] - 2020-12-09
11+
12+
### Added
13+
- Support for Composer 2.0.
14+
1015
## [1.0.4] - 2020-10-20
1116

1217
### Changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"composer-plugin-api": "^1.0",
16+
"composer-plugin-api": "^1.0 || ^2.0",
1717
"hari/pw-module": "^1.0.0"
1818
},
1919
"autoload": {

src/ComposerInstaller/Plugin.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,30 @@ public static function prePackageInstall(PackageEvent $event)
6565
$installationManager->removeInstaller($moduleInstaller);
6666
}
6767
}
68+
69+
/**
70+
* Remove any hooks from Composer
71+
*
72+
* This will be called when a plugin is deactivated before being uninstalled, but also before it
73+
* gets upgraded to a new version so the old one can be deactivated and the new one activated.
74+
*
75+
* @param Composer $composer
76+
* @param IOInterface $io
77+
*/
78+
public function deactivate(Composer $composer, IOInterface $io)
79+
{
80+
}
81+
82+
/**
83+
* Prepare the plugin to be uninstalled
84+
*
85+
* This will be called after deactivate.
86+
*
87+
* @param Composer $composer
88+
* @param IOInterface $io
89+
*/
90+
public function uninstall(Composer $composer, IOInterface $io)
91+
{
92+
}
93+
6894
}

src/ComposerInstaller/SiteProfileInstaller.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Composer\Repository\InstalledRepositoryInterface;
66
use Composer\Package\PackageInterface;
77
use Composer\Util\Filesystem;
8+
use React\Promise\PromiseInterface;
89

910
/**
1011
* SiteProfileInstaller class
@@ -35,21 +36,32 @@ public function supports($packageType)
3536
*/
3637
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
3738
{
38-
parent::install($repo, $package);
39-
4039
// check if there's a nested site- prefixed directory, in which case we
4140
// must assume that it's the real site profile directory and move it up
4241
// one level
43-
$path = $this->getInstallPath($package);
44-
$site = $this->getNestedSiteDirectoryName($path);
45-
if ($site) {
46-
$basePath = $this->getBasePath(static::BASE_PATH);
47-
$tempPath = $basePath . 'temp-' . \basename($path);
48-
$filesystem = new Filesystem();
49-
$filesystem->rename($path, $tempPath);
50-
$filesystem->rename($tempPath . '/' . $site, $basePath . $site);
51-
$filesystem->remove($tempPath);
42+
$adjustProfilePath = function() use ($package) {
43+
$path = $this->getInstallPath($package);
44+
$site = $this->getNestedSiteDirectoryName($path);
45+
if ($site) {
46+
$basePath = $this->getBasePath(static::BASE_PATH);
47+
$tempPath = $basePath . 'temp-' . \basename($path);
48+
$filesystem = new Filesystem();
49+
$filesystem->rename($path, $tempPath);
50+
$filesystem->rename($tempPath . '/' . $site, $basePath . $site);
51+
$filesystem->remove($tempPath);
52+
}
53+
};
54+
55+
$promise = parent::install($repo, $package);
56+
57+
// Composer v2 might return a promise here
58+
if ($promise instanceof PromiseInterface) {
59+
return $promise->then($adjustProfilePath);
5260
}
61+
62+
// if not, execute the code right away as parent::install executed synchronously
63+
// (composer v1, or v2 without async)
64+
$adjustProfilePath();
5365
}
5466

5567
/**

0 commit comments

Comments
 (0)