1
0
Fork 0

Make sure the first require does not fail due to a missing lock file

pull/8561/head
Jordi Boggiano 2020-01-28 15:13:35 +01:00
parent 7e6fe585bc
commit 173b96de2d
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 10 additions and 1 deletions

View File

@ -35,6 +35,7 @@ use Composer\Util\Silencer;
class RequireCommand extends InitCommand class RequireCommand extends InitCommand
{ {
private $newlyCreated; private $newlyCreated;
private $firstRequire;
private $json; private $json;
private $file; private $file;
private $composerBackup; private $composerBackup;
@ -186,6 +187,14 @@ EOT
$sortPackages = $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages'); $sortPackages = $input->getOption('sort-packages') || $composer->getConfig()->get('sort-packages');
$this->firstRequire = $this->newlyCreated;
if (!$this->firstRequire) {
$composerDefinition = $this->json->read();
if (empty($composerDefinition['require']) && empty($composerDefinition['require-dev'])) {
$this->firstRequire = true;
}
}
if (!$this->updateFileCleanly($this->json, $requirements, $requireKey, $removeKey, $sortPackages)) { if (!$this->updateFileCleanly($this->json, $requirements, $requireKey, $removeKey, $sortPackages)) {
$composerDefinition = $this->json->read(); $composerDefinition = $this->json->read();
foreach ($requirements as $package => $version) { foreach ($requirements as $package => $version) {
@ -245,7 +254,7 @@ EOT
// if no lock is present, or the file is brand new, we do not do a // if no lock is present, or the file is brand new, we do not do a
// partial update as this is not supported by the Installer // partial update as this is not supported by the Installer
if (!$this->newlyCreated && $composer->getConfig()->get('lock')) { if (!$this->firstRequire && $composer->getConfig()->get('lock')) {
$install->setUpdateWhitelist(array_keys($requirements)); $install->setUpdateWhitelist(array_keys($requirements));
} }