From 4ae6f770d0d85a7f0823aea8563262deb121d817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Mon, 13 Mar 2023 13:55:07 +0100 Subject: [PATCH] refactor(plugin): inherit from topfloor/composer-cleanup-vcs-dirs --- composer.json | 21 ++++++++++++------- src/Handler.php | 39 +++++++++++++++++++++++++++++++++++ src/Plugin.php | 55 +++++++------------------------------------------ 3 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 src/Handler.php diff --git a/composer.json b/composer.json index 4218ad0..3dcb146 100644 --- a/composer.json +++ b/composer.json @@ -19,16 +19,23 @@ "source": "https://git.defis.info/SeaCMS/composer-plugin" }, "require": { - "composer-plugin-api": "^2.3" + "composer-plugin-api": "^2.3", + "topfloor/composer-cleanup-vcs-dirs": "^1.1" + }, + "replace": { + "symfony/finder": "*" }, "autoload": { - "psr-4": { - "Seacms\\ComposerInstaller\\": "src" - } + "psr-4": { + "Seacms\\ComposerInstaller\\": "src" + } }, "extra": { - "class": "Seacms\\ComposerInstaller\\Plugin", - "plugin-modifies-downloads": false, - "plugin-modifies-install-path": false + "class": "Seacms\\ComposerInstaller\\Plugin" + }, + "config": { + "allow-plugins": { + "topfloor/composer-cleanup-vcs-dirs": false + } } } diff --git a/src/Handler.php b/src/Handler.php new file mode 100644 index 0000000..64266f5 --- /dev/null +++ b/src/Handler.php @@ -0,0 +1,39 @@ +fs->removeDirectory($dir->getRealPath()); + } + } +} \ No newline at end of file diff --git a/src/Plugin.php b/src/Plugin.php index 6662ac6..608e9ca 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -9,19 +9,17 @@ namespace Seacms\ComposerInstaller; use Composer\Composer; use Composer\Config; -use Composer\EventDispatcher\EventSubscriberInterface; -use Composer\Installer\PackageEvent; -use Composer\Installer\PackageEvents; use Composer\Json\JsonFile; use Composer\IO\IOInterface; -use Composer\Plugin\PluginInterface; +use Seacms\ComposerInstaller\Handler; use Seacms\ComposerInstaller\NotFoundFileException; +use TopFloor\ComposerCleanupVcsDirs\Plugin as ParentPlugin; /** * Composer plugin to install or not packages from local path */ -class Plugin implements PluginInterface, EventSubscriberInterface +class Plugin extends ParentPlugin { /** * composer instance @@ -33,60 +31,23 @@ class Plugin implements PluginInterface, EventSubscriberInterface * @var IOInterface */ protected $io; - - /** - * Returns an array of event names this subscriber wants to listen to. - * @return array> The event names to listen to - */ - public static function getSubscribedEvents(){ - return [ - PackageEvents::PRE_PACKAGE_UPDATE => 'prePackageUpdate', - ]; - } - - public function prePackageUpdate(PackageEvent $event) - { - $event->getIO()->write("Test : {$event->getOperation()}"); - } - + /** * Apply plugin modifications to Composer * - * @return void + * @param Composer $composer + * @param IOInterface $io */ - public function activate(Composer $composer, IOInterface $io){ + public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; $this->io = $io; + $this->handler = new Handler($composer, $io); try { $this->updateConfig($this->getConfigJsonFile()); } catch (NotFoundFileException $ex){ // do nothing } } - - /** - * 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. - * - * @return void - */ - public function deactivate(Composer $composer, IOInterface $io){ - - } - - /** - * Prepare the plugin to be uninstalled - * - * This will be called after deactivate. - * - * @return void - */ - public function uninstall(Composer $composer, IOInterface $io){ - - } /** * get config.json File from root path