1
0
Fork 0

Merge pull request #2893 from naderman/require-delete-duplicate

When requiring a package remove it from require-dev and vice versa
pull/2895/head
Nils Adermann 2014-04-09 20:13:34 -07:00
commit 8aac44d57d
1 changed files with 10 additions and 2 deletions

View File

@ -81,6 +81,7 @@ EOT
$requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'));
$requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
$removeKey = $input->getOption('dev') ? 'require' : 'require-dev';
$baseRequirements = array_key_exists($requireKey, $composer) ? $composer[$requireKey] : array();
$requirements = $this->formatRequirements($requirements);
@ -90,9 +91,13 @@ EOT
$versionParser->parseConstraints($constraint);
}
if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey)) {
if (!$this->updateFileCleanly($json, $baseRequirements, $requirements, $requireKey, $removeKey)) {
foreach ($requirements as $package => $version) {
$baseRequirements[$package] = $version;
if (isset($composer[$removeKey][$package])) {
unset($composer[$removeKey][$package]);
}
}
$composer[$requireKey] = $baseRequirements;
@ -134,7 +139,7 @@ EOT
return $status;
}
private function updateFileCleanly($json, array $base, array $new, $requireKey)
private function updateFileCleanly($json, array $base, array $new, $requireKey, $removeKey)
{
$contents = file_get_contents($json->getPath());
@ -144,6 +149,9 @@ EOT
if (!$manipulator->addLink($requireKey, $package, $constraint)) {
return false;
}
if (!$manipulator->removeSubNode($removeKey, $package)) {
return false;
}
}
file_put_contents($json->getPath(), $manipulator->getContents());