Show a warning if require key changes for dependency (#9542)
Fixes #9516 Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>pull/9730/head
parent
d806013091
commit
c78850ab98
|
@ -211,6 +211,29 @@ EOT
|
||||||
$versionParser->parseConstraints($constraint);
|
$versionParser->parseConstraints($constraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$inconsistentRequireKeys = $this->getInconsistentRequireKeys($requirements, $requireKey);
|
||||||
|
if (count($inconsistentRequireKeys) > 0) {
|
||||||
|
foreach ($inconsistentRequireKeys as $package) {
|
||||||
|
$io->warning(sprintf(
|
||||||
|
'%s is currently present in the %s key and you ran the command %s the --dev flag, which would move it to the %s key.',
|
||||||
|
$package,
|
||||||
|
$removeKey,
|
||||||
|
$input->getOption('dev') ? 'with' : 'without',
|
||||||
|
$requireKey
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($io->isInteractive()) {
|
||||||
|
if (!$io->askConfirmation(sprintf('<info>Do you want to move %s?</info> [<comment>no</comment>]? ', count($inconsistentRequireKeys) > 1 ? 'these requirements' : 'this requirement'), false)) {
|
||||||
|
if (!$io->askConfirmation(sprintf('<info>Do you want to re-run the command %s --dev?</info> [<comment>yes</comment>]? ', $input->getOption('dev') ? 'without' : 'with'), true)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
list($requireKey, $removeKey) = array($removeKey, $requireKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$sortPackages = $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages');
|
$sortPackages = $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages');
|
||||||
|
|
||||||
$this->firstRequire = $this->newlyCreated;
|
$this->firstRequire = $this->newlyCreated;
|
||||||
|
@ -247,6 +270,42 @@ EOT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getInconsistentRequireKeys(array $newRequirements, $requireKey)
|
||||||
|
{
|
||||||
|
$requireKeys = $this->getPackagesByRequireKey();
|
||||||
|
$inconsistentRequirements = array();
|
||||||
|
foreach ($requireKeys as $package => $packageRequireKey) {
|
||||||
|
if (!isset($newRequirements[$package])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($requireKey !== $packageRequireKey) {
|
||||||
|
$inconsistentRequirements[] = $package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $inconsistentRequirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPackagesByRequireKey()
|
||||||
|
{
|
||||||
|
$composerDefinition = $this->json->read();
|
||||||
|
$require = array();
|
||||||
|
$requireDev = array();
|
||||||
|
|
||||||
|
if (isset($composerDefinition['require'])) {
|
||||||
|
$require = $composerDefinition['require'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($composerDefinition['require-dev'])) {
|
||||||
|
$requireDev = $composerDefinition['require-dev'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_merge(
|
||||||
|
array_fill_keys(array_keys($require), 'require'),
|
||||||
|
array_fill_keys(array_keys($requireDev), 'require-dev')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey)
|
private function doUpdate(InputInterface $input, OutputInterface $output, IOInterface $io, array $requirements, $requireKey, $removeKey)
|
||||||
{
|
{
|
||||||
// Update packages
|
// Update packages
|
||||||
|
|
Loading…
Reference in New Issue