Merge "composer: Remove localization from unlocalizable LockFileChecker"
This commit is contained in:
commit
9f8c62a20e
5 changed files with 33 additions and 61 deletions
|
|
@ -21,38 +21,29 @@
|
|||
namespace MediaWiki\Composer;
|
||||
|
||||
use Composer\Semver\Semver;
|
||||
use Status;
|
||||
use Wikimedia\Composer\ComposerJson;
|
||||
use Wikimedia\Composer\ComposerLock;
|
||||
|
||||
/**
|
||||
* Used to check whether composer-installed dependencies (no-dev) are up-to-date
|
||||
*
|
||||
* @internal For use by CheckComposerLockUpToDate and Installer
|
||||
* @since 1.42
|
||||
*/
|
||||
class LockFileChecker {
|
||||
/** @var ComposerJson */
|
||||
private $composerJson;
|
||||
private ComposerJson $composerJson;
|
||||
private ComposerLock $composerLock;
|
||||
|
||||
/** @var ComposerJson */
|
||||
private $composerLock;
|
||||
|
||||
/**
|
||||
* @param ComposerJson $composerJson
|
||||
* @param ComposerLock $composerLock
|
||||
*/
|
||||
public function __construct( ComposerJson $composerJson, ComposerLock $composerLock ) {
|
||||
$this->composerJson = $composerJson;
|
||||
$this->composerLock = $composerLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a {@link Status} instance,
|
||||
* you can use {@link Status::isGood()} to simply determine that
|
||||
* the composer-installed dependencies are up-to-date.
|
||||
* @return Status
|
||||
* @return string[]|null Array of error messages, or null when Composer-installed dependencies are up-to-date.
|
||||
*/
|
||||
public function check(): Status {
|
||||
$status = Status::newGood();
|
||||
public function check(): ?array {
|
||||
$errors = [];
|
||||
$requiredButOld = [];
|
||||
$requiredButMissing = [];
|
||||
|
||||
|
|
@ -79,26 +70,21 @@ class LockFileChecker {
|
|||
// We're happy; loop to the next dependency.
|
||||
}
|
||||
|
||||
if ( count( $requiredButOld ) === 0 && count( $requiredButMissing ) === 0 ) {
|
||||
// We couldn't find any out-of-date or missing dependencies, so assume everything is ok!
|
||||
return $status;
|
||||
}
|
||||
|
||||
foreach ( $requiredButOld as [
|
||||
"name" => $name,
|
||||
"suppliedVersion" => $suppliedVersion,
|
||||
"wantedVersion" => $wantedVersion
|
||||
] ) {
|
||||
$status->error( 'composer-deps-outdated', $name, $suppliedVersion, $wantedVersion );
|
||||
$errors[] = "$name: $suppliedVersion installed, $wantedVersion required.";
|
||||
}
|
||||
|
||||
foreach ( $requiredButMissing as [
|
||||
"name" => $name,
|
||||
"wantedVersion" => $wantedVersion
|
||||
] ) {
|
||||
$status->error( 'composer-deps-notinstalled', $name, $wantedVersion );
|
||||
$errors[] = "$name: not installed, $wantedVersion required.";
|
||||
}
|
||||
|
||||
return $status;
|
||||
return $errors ?: null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4475,7 +4475,5 @@
|
|||
"benefit-1-description": "Watchlists that allow you to keep track of pages that you’re interested in.",
|
||||
"benefit-2-description": "Permanent list of contributions you’ve made to the project.",
|
||||
"benefit-3-description": "Preferences that allow you to customize your experience.",
|
||||
"temp-user-unable-to-acquire": "Unable to acquire a temporary account username. Please try again.",
|
||||
"composer-deps-outdated": "$1: $2 installed, $3 required.",
|
||||
"composer-deps-notinstalled": "$1: not installed, $2 required."
|
||||
"temp-user-unable-to-acquire": "Unable to acquire a temporary account username. Please try again."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4734,7 +4734,5 @@
|
|||
"benefit-1-description": "The text for the first benefit shown on signup for temporary users.",
|
||||
"benefit-2-description": "The text for the second benefit shown on signup for temporary users.",
|
||||
"benefit-3-description": "The text for the third benefit shown on signup for temporary users.",
|
||||
"temp-user-unable-to-acquire": "The error message shown when the server was unable to acquire a temporary account username for the user.",
|
||||
"composer-deps-outdated": "Error in check composer-installed dependencies. Parameters:\n* $1 - Dependency name.\n* $2 - Installed version\n* $3 - Required version.",
|
||||
"composer-deps-notinstalled": "Error message if a composer dependency is not install. Parameters:\n* $1 - Dependency name.\n* $2 - Required version."
|
||||
"temp-user-unable-to-acquire": "The error message shown when the server was unable to acquire a temporary account username for the user."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,30 +43,24 @@ class CheckComposerLockUpToDate extends Maintenance {
|
|||
|
||||
// Check all the dependencies to see if any are old
|
||||
$checker = new LockFileChecker( $json, $lock );
|
||||
$result = $checker->check();
|
||||
if ( $result->isGood() ) {
|
||||
// We couldn't find any out-of-date dependencies, so assume everything is ok!
|
||||
$this->output( "Your composer.lock file is up to date with current dependencies!\n" );
|
||||
} else {
|
||||
// NOTE: wfMessage will fail if MediaWikiServices is not yet initialized.
|
||||
// This can happen when this class is called directly from bootstrap code,
|
||||
// e.g. by TestSetup. We get around this by having testSetup use quiet mode.
|
||||
if ( !$this->isQuiet() ) {
|
||||
foreach ( $result->getMessages() as $msg ) {
|
||||
$this->error(
|
||||
wfMessage( $msg )
|
||||
// Avoid fatal error from a cache miss in MessageCache when called
|
||||
// from maintenance/update.php
|
||||
->useDatabase( false )
|
||||
->inLanguage( 'en' )
|
||||
->plain() . "\n"
|
||||
);
|
||||
}
|
||||
$errors = $checker->check();
|
||||
|
||||
// NOTE: This is used by TestSetup before MediaWikiServices is initialized and thus
|
||||
// may not rely on global singletons.
|
||||
// NOTE: This is used by maintenance/update.php and thus may not rely on
|
||||
// database connections, including e.g. interface messages without useDatabase=false,
|
||||
// which would call MessageCache.
|
||||
if ( $errors ) {
|
||||
foreach ( $errors as $error ) {
|
||||
$this->error( $error . "\n" );
|
||||
}
|
||||
$this->fatalError(
|
||||
'Error: your composer.lock file is not up to date. ' .
|
||||
'Run "composer update --no-dev" to install newer dependencies'
|
||||
);
|
||||
} else {
|
||||
// We couldn't find any out-of-date dependencies, so assume everything is ok!
|
||||
$this->output( "Your composer.lock file is up to date with current dependencies!\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,32 +30,28 @@ class LockFileCheckerTest extends MediaWikiIntegrationTestCase {
|
|||
$json = new ComposerJson( __DIR__ . '/composer-testcase1.json' );
|
||||
$lock = new ComposerLock( __DIR__ . '/composer-testcase1.lock' );
|
||||
$checker = new LockFileChecker( $json, $lock );
|
||||
$status = $checker->check();
|
||||
$this->assertTrue( $status->isGood() );
|
||||
$errors = $checker->check();
|
||||
$this->assertNull( $errors );
|
||||
}
|
||||
|
||||
public function testOutdated() {
|
||||
$json = new ComposerJson( __DIR__ . '/composer-testcase2.json' );
|
||||
$lock = new ComposerLock( __DIR__ . '/composer-testcase2.lock' );
|
||||
$checker = new LockFileChecker( $json, $lock );
|
||||
$status = $checker->check();
|
||||
$this->assertFalse( $status->isGood() );
|
||||
$this->assertSame( 'wikimedia/relpath: 2.9.9 installed, 3.0.0 required.', $status->getMessage()->plain() );
|
||||
$errors = $checker->check();
|
||||
$this->assertArrayEquals( [
|
||||
'wikimedia/relpath: 2.9.9 installed, 3.0.0 required.',
|
||||
], $errors );
|
||||
}
|
||||
|
||||
public function testNotInstalled() {
|
||||
$json = new ComposerJson( __DIR__ . '/composer-testcase3.json' );
|
||||
$lock = new ComposerLock( __DIR__ . '/composer-testcase3.lock' );
|
||||
$checker = new LockFileChecker( $json, $lock );
|
||||
$status = $checker->check();
|
||||
$this->assertFalse( $status->isGood() );
|
||||
$msgs = [];
|
||||
foreach ( $status->getMessages() as $msg ) {
|
||||
$msgs[] = wfMessage( $msg )->plain();
|
||||
}
|
||||
$errors = $checker->check();
|
||||
$this->assertArrayEquals( [
|
||||
'wikimedia/relpath: 2.9.9 installed, 3.0.0 required.',
|
||||
'wikimedia/at-ease: not installed, 2.1.0 required.',
|
||||
], $msgs );
|
||||
], $errors );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue