1
0
Fork 0

Merge remote-tracking branch 'PrinsFrank/detect-missing-packages-on-validate'

pull/9928/head
Jordi Boggiano 2021-05-31 17:29:40 +02:00
commit 69dc607408
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 20 additions and 0 deletions

View File

@ -16,6 +16,7 @@ use Composer\Factory;
use Composer\Package\Loader\ValidatingArrayLoader;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Repository\PlatformRepository;
use Composer\Util\ConfigValidator;
use Composer\Util\Filesystem;
use Symfony\Component\Console\Input\InputArgument;
@ -99,6 +100,25 @@ EOT
$lockErrors[] = 'The lock file is not up to date with the latest changes in composer.json, it is recommended that you run `composer update` or `composer update <package name>`.';
}
$lockData = $locker->getLockData();
$lockPackageNames = array_map(function($lockPackage) {return $lockPackage['name'];}, $lockData['packages']);
$devLockPackageNames = array_map(function($devLockPackage) {return $devLockPackage['name'];}, $lockData['packages-dev']);
$requiredPackages = array_filter(array_keys($composer->getPackage()->getRequires()), function($requiredPackageName) {return PlatformRepository::isPlatformPackage($requiredPackageName) === false;});
$devRequiredPackages = array_filter(array_keys($composer->getPackage()->getDevRequires()), function($devRequiredPackageName) {return PlatformRepository::isPlatformPackage($devRequiredPackageName) === false;});
$missingRequiredPackages = array_diff($requiredPackages, $lockPackageNames);
$missingDevRequiredPackages = array_diff($devRequiredPackages, $devLockPackageNames);
if (count(array_merge($missingRequiredPackages, $missingDevRequiredPackages)) > 0) {
if (count($missingRequiredPackages) > 0) {
$lockErrors[] = '- Required package "' . implode('", "', $missingRequiredPackages) . '" is not present in the lock file.';
}
if (count($missingDevRequiredPackages) > 0) {
$lockErrors[] = '- Dev-required package "' . implode('", "', $missingDevRequiredPackages) . '" is not present in the lock file.';
}
$lockErrors[] = 'This usually happens when composer files are incorrectly merged or the composer.json file is manually edited.';
$lockErrors[] = 'Read more about correctly resolving merge conflicts -> https://getcomposer.org/doc/articles/resolving-merge-conflicts.md';
$lockErrors[] = 'and make sure to not edit the composer.json file directly but to use the "require" command (https://getcomposer.org/doc/03-cli.md#require).';
}
$this->outputResult($io, $file, $errors, $warnings, $checkPublish, $publishErrors, $checkLock, $lockErrors, true);
// $errors include publish and lock errors when exists