1
0
Fork 0

Move duplicate key parsing from bootstrap to validate/diagnose to reduce bootstrap time a bit

pull/10701/head
Jordi Boggiano 2022-04-01 11:34:03 +02:00
parent 9a42f69a99
commit 27a449eaf7
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 10 additions and 7 deletions

View File

@ -316,13 +316,6 @@ class Factory
$message = $e->getMessage() . ':' . PHP_EOL . $errors;
throw new JsonValidationException($message);
}
$jsonParser = new JsonParser;
try {
$jsonParser->parse(file_get_contents($localConfig), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
$details = $e->getDetails();
$io->writeError('<warning>Key '.$details['key'].' is a duplicate in '.$localConfig.' at line '.$details['line'].'</warning>');
}
$localConfig = $file->read();
$localConfigSource = $file->getPath();

View File

@ -20,6 +20,8 @@ use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Pcre\Preg;
use Composer\Spdx\SpdxLicenses;
use Seld\JsonLint\DuplicateKeyException;
use Seld\JsonLint\JsonParser;
/**
* Validates a composer configuration.
@ -77,6 +79,14 @@ class ConfigValidator
return array($errors, $publishErrors, $warnings);
}
$jsonParser = new JsonParser();
try {
$jsonParser->parse(file_get_contents($file), JsonParser::DETECT_KEY_CONFLICTS);
} catch (DuplicateKeyException $e) {
$details = $e->getDetails();
$warnings[] = 'Key '.$details['key'].' is a duplicate in '.$file.' at line '.$details['line'];
}
// validate actual data
if (empty($manifest['license'])) {
$warnings[] = 'No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.';