fix(composer): detect if TopFloor is installed

This commit is contained in:
Jérémy Dufraisse 2023-03-16 22:25:46 +01:00
parent 3a1a8da810
commit 0de838a4df
3 changed files with 59 additions and 1 deletions

View File

@ -20,6 +20,7 @@
}, },
"require": { "require": {
"composer-plugin-api": "^2.3", "composer-plugin-api": "^2.3",
"picocms/pico": "*",
"topfloor/composer-cleanup-vcs-dirs": "^1.1" "topfloor/composer-cleanup-vcs-dirs": "^1.1"
}, },
"replace": { "replace": {

52
src/ParentPlugin.php Normal file
View File

@ -0,0 +1,52 @@
<?php
/**
* SPDX-License-Identifier: EUPL-1.2
* Authors: see /README.md
*/
namespace Seacms\ComposerInstaller;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
use TopFloor\ComposerCleanupVcsDirs\Plugin as TopFloorPlugin;
if (class_exists(TopFloorPlugin::class,false)){
abstract class ParentPlugin extends TopFloorPlugin
{
/**
* const to test if TopFloorPlugin
* @var bool
*/
protected const IS_TOP_FLOOR_PLUGIN = true;
}
} else {
abstract class ParentPlugin implements PluginInterface
{
/**
* const to test if TopFloorPlugin
* @var bool
*/
protected const IS_TOP_FLOOR_PLUGIN = false;
/**
* Deactivation hook.
*
* @param Composer $composer
* @param IOInterface $io
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* Uninstall hook.
*
* @param Composer $composer
* @param IOInterface $io
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
}
}

View File

@ -17,7 +17,7 @@ use Composer\Repository\VcsRepository;
use Exception; use Exception;
use Seacms\ComposerInstaller\Handler; use Seacms\ComposerInstaller\Handler;
use Seacms\ComposerInstaller\NotFoundFileException; use Seacms\ComposerInstaller\NotFoundFileException;
use TopFloor\ComposerCleanupVcsDirs\Plugin as ParentPlugin; use Seacms\ComposerInstaller\ParentPlugin;
/** /**
* Composer plugin to install or not packages from local path * Composer plugin to install or not packages from local path
@ -35,6 +35,7 @@ class Plugin extends ParentPlugin
* @var IOInterface * @var IOInterface
*/ */
protected $io; protected $io;
protected $handler;
/** /**
* Apply plugin modifications to Composer * Apply plugin modifications to Composer
@ -45,6 +46,10 @@ class Plugin extends ParentPlugin
public function activate(Composer $composer, IOInterface $io) { public function activate(Composer $composer, IOInterface $io) {
$this->composer = $composer; $this->composer = $composer;
$this->io = $io; $this->io = $io;
if (!self::IS_TOP_FLOOR_PLUGIN){
// do nothing
return ;
}
$this->handler = new Handler($composer, $io); $this->handler = new Handler($composer, $io);
try { try {
list('config' => $config,'path' => $path) = $this->getConfigJsonFile(); list('config' => $config,'path' => $path) = $this->getConfigJsonFile();