| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
require_once __DIR__ . '/Maintenance.php'; |
| 5 |
|
| 6 |
|
| 7 |
use MediaWiki\Composer\LockFileChecker; |
| 8 |
use MediaWiki\Maintenance\Maintenance; |
| 9 |
use Wikimedia\Composer\ComposerJson; |
| 10 |
use Wikimedia\Composer\ComposerLock; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class CheckComposerLockUpToDate extends Maintenance { |
| 20 |
public function __construct() { |
| 21 |
parent::__construct(); |
| 22 |
$this->addDescription( |
| 23 |
'Checks whether your composer.lock file is up to date with the current composer.json' ); |
| 24 |
} |
| 25 |
|
| 26 |
public function canExecuteWithoutLocalSettings(): bool { |
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
protected function getMwInstallPath(): string { |
| 34 |
return MW_INSTALL_PATH; |
| 35 |
} |
| 36 |
|
| 37 |
public function execute() { |
| 38 |
$installPath = $this->getMwInstallPath(); |
| 39 |
$lockLocation = "$installPath/composer.lock"; |
| 40 |
$jsonLocation = "$installPath/composer.json"; |
| 41 |
if ( !file_exists( $lockLocation ) ) { |
| 42 |
|
| 43 |
$lockLocation = "$installPath/vendor/composer.lock"; |
| 44 |
if ( !file_exists( $lockLocation ) ) { |
| 45 |
$this->fatalError( |
| 46 |
'Could not find composer.lock file. Have you run "composer install --no-dev"?' |
| 47 |
); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
$lock = new ComposerLock( $lockLocation ); |
| 52 |
$json = new ComposerJson( $jsonLocation ); |
| 53 |
|
| 54 |
|
| 55 |
$checker = new LockFileChecker( $json, $lock ); |
| 56 |
$errors = $checker->check(); |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
if ( $errors ) { |
| 64 |
foreach ( $errors as $error ) { |
| 65 |
$this->error( $error . "\n" ); |
| 66 |
} |
| 67 |
$suggestedCommand = 'composer update'; |
| 68 |
if ( !defined( 'MW_PHPUNIT_TEST' ) ) { |
| 69 |
$suggestedCommand .= ' --no-dev'; |
| 70 |
} |
| 71 |
$this->fatalError( |
| 72 |
'Error: your composer.lock file is not up to date. ' . |
| 73 |
'Run "' . $suggestedCommand . '" to install newer dependencies' |
| 74 |
); |
| 75 |
} else { |
| 76 |
|
| 77 |
$this->output( "Your composer.lock file is up to date with current dependencies!\n" ); |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
$maintClass = CheckComposerLockUpToDate::class; |
| 84 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 85 |
|