1
0
Fork 0

Show a warning if require key changes for dependency (#9542)

Fixes #9516

Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>
pull/9730/head
Julian 2021-02-25 10:24:09 +01:00 committed by GitHub
parent d806013091
commit c78850ab98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 59 additions and 0 deletions

View File

@ -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