Skip to content

Commit

Permalink
Unified processing of new packages
Browse files Browse the repository at this point in the history
  • Loading branch information
macrini committed Nov 23, 2020
1 parent 441e71a commit c971a53
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions src/Packman.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
25 changes: 10 additions & 15 deletions src/PluginLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,39 @@ 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');

$parser = new VersionParser();

$parsed = $parser->parseNameVersionPairs($packages);
$require = [];

foreach ($parsed as $pkg) {
// Note: there might be multiple ones with the same name
// and different version
$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)
Expand Down

0 comments on commit c971a53

Please sign in to comment.