From c971a5360b1ff3329ee7aa01555303e0d1b45ac0 Mon Sep 17 00:00:00 2001 From: Diego Macrini Date: Mon, 23 Nov 2020 12:33:12 -0500 Subject: [PATCH] Unified processing of new packages --- README.md | 2 +- src/Packman.php | 9 --------- src/PluginLoader.php | 25 ++++++++++--------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 6b41734..0523fac 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ In Composer terminology, a **repository** is a set of packages, and a **package* A **private repository** is a set of **private packages**. Packages can be required by other packages in relative terms based on their [semantic version](#semantic-versioning). That is, instead of specifying a commit hash, one can request the newest package that matches a version pattern, such as `1.1.*`. -After running `composer install` or `composer update`, the `require` pattern of each package is **locked** to the specific **commit hash** that **satisfies** the requirement. +After running composer `install`, `update` or `require`, the resulting `require` pattern of each package is **locked** to the specific **commit hash** that **satisfies** the requirement. ## How Packman works diff --git a/src/Packman.php b/src/Packman.php index 6111f3a..3b1aece 100644 --- a/src/Packman.php +++ b/src/Packman.php @@ -142,15 +142,6 @@ public function start(array $options = []) // $this->log(array_keys($this->getRepositories()), 'Active repos'); } - public function addPackages(array $options) - { - // The start() method was supposedly already called, so only - // call it again if there are new packages - if ($packages = $options['packages'] ?? false) { - $this->start($packages); - } - } - public function listSatisRepos() { // print_r($this->getDeclaredRepos()); diff --git a/src/PluginLoader.php b/src/PluginLoader.php index 75f2600..ea43545 100644 --- a/src/PluginLoader.php +++ b/src/PluginLoader.php @@ -119,22 +119,18 @@ public static function getSubscribedEvents() ]; } - public static function needsWebServer($event): bool + public function preCommandRun(PreCommandRunEvent $event) { - $commands = ['install', 'update', 'require']; + $commands = ['install', 'update', 'require', 'require-dev']; $cmd = $event->getCommand(); - return in_array($cmd, $commands); - } - - public function preCommandRun(PreCommandRunEvent $event) - { - if (!self::needsWebServer($event)) { + if (!in_array($cmd, $commands)) { return; } $input = $event->getInput(); - $require = []; + + $options = []; if ($input->hasArgument('packages')) { $packages = $input->getArgument('packages'); @@ -142,6 +138,7 @@ public function preCommandRun(PreCommandRunEvent $event) $parser = new VersionParser(); $parsed = $parser->parseNameVersionPairs($packages); + $require = []; foreach ($parsed as $pkg) { // Note: there might be multiple ones with the same name @@ -149,14 +146,12 @@ public function preCommandRun(PreCommandRunEvent $event) $require[$pkg['name']] = $pkg['version'] ?? 0; } - $options = [ - 'packages' => $require - ]; - - $this->packman->addPackages($options); + $options['packages'] = $require; } - // $this->packman->start($require); + // Packman::log($options, $event->getCommand()); + + $this->packman->start($options); } // public function initCommand($event)