Skip to content

Commit

Permalink
Merge pull request #3 from wireframe-framework/dev
Browse files Browse the repository at this point in the history
Release 1.1.0
  • Loading branch information
teppokoivula authored Dec 9, 2020
2 parents c63afc7 + 12f2bae commit 80d6c43
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"composer-plugin-api": "^1.0",
"composer-plugin-api": "^1.0 || ^2.0",
"hari/pw-module": "^1.0.0"
},
"autoload": {
Expand Down
26 changes: 26 additions & 0 deletions src/ComposerInstaller/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

}
34 changes: 23 additions & 11 deletions src/ComposerInstaller/SiteProfileInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Package\PackageInterface;
use Composer\Util\Filesystem;
use React\Promise\PromiseInterface;

/**
* SiteProfileInstaller class
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 80d6c43

Please sign in to comment.