Skip to content

Commit

Permalink
DX-3021: Fix #4292: Check for Composer 2 instead of prestissimo (#4296)
Browse files Browse the repository at this point in the history
* DX-3021: Fix #4292: Check for Composer 2 instead of prestissimo

* Fix tests
  • Loading branch information
danepowell authored Dec 14, 2020
1 parent 9fedc00 commit 9b9a627
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/Robo/Doctor/ComposerCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ class ComposerCheck extends DoctorCheck {

/**
* DoctorCheck constructor.
*
* @param \Robo\Config\Config $config
* Robo config.
* @param \Acquia\Blt\Robo\Inspector\Inspector $inspector
* BLT inspector.
* @param \Acquia\Blt\Robo\Common\Executor $executor
* BLT executor.
* @param array $drush_status
* Drush status.
*/
public function __construct(Config $config, Inspector $inspector, Executor $executor, array $drush_status) {
parent::__construct($config, $inspector, $executor, $drush_status);
Expand Down Expand Up @@ -73,8 +82,7 @@ protected function setComposerLock() {
*/
public function performAllChecks() {
$this->checkRequire();
$this->checkPrestissimo();
$this->checkDrupalCore();
$this->checkVersion();

return $this->problems;
}
Expand All @@ -93,27 +101,13 @@ protected function checkRequire() {
}

/**
* Check prestissimo.
*/
protected function checkPrestissimo() {
$prestissimo_intalled = $this->getExecutor()->execute("composer global show | grep hirak/prestissimo")->run()->wasSuccessful();
if (!$prestissimo_intalled) {
$this->logProblem(__FUNCTION__ . ":plugins", [
"hirak/prestissimo plugin for composer is not installed.",
" Run <comment>composer global require hirak/prestissimo</comment> to install it.",
" This will improve composer install/update performance by parallelizing the download of dependency information.",
], 'comment');
}
}

/**
* Check Drupal core.
* Check Composer version.
*/
protected function checkDrupalCore() {
if (empty($this->composerJson['require']['drupal/core']) && empty($this->composerJson['require']['drupal/core-recommended'])) {
$this->logProblem(__FUNCTION__ . ":plugins", [
"drupal/core or drupal/core-recommended are not required by the root composer.json.",
" This impairs performance by preventing zaporylie/composer-drupal-optimizations from taking effect.",
protected function checkVersion() {
if (!$this->getInspector()->isComposerMinimumVersionSatisfied('2')) {
$this->logProblem(__FUNCTION__, [
"Composer 1 detected.",
" Composer 1 is end of life, and Composer 2 includes significant performance improvements. Upgrade to Composer 2 as soon as possible.",
], 'comment');
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/Robo/Inspector/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,24 @@ public function getComposerVersion() {
return $version;
}

/**
* Verifies that installed minimum Composer version is met.
*
* @param string $minimum_version
* The minimum Composer version that is required.
*
* @return bool
* TRUE if minimum version is satisfied.
*/
public function isComposerMinimumVersionSatisfied($minimum_version) {
// phpcs:ignore
exec("composer --version | cut -d' ' -f3", $output, $exit_code);
if (version_compare($output[0], $minimum_version, '>=')) {
return TRUE;
}
return FALSE;
}

/**
* Checks to see if BLT alias is installed on CLI.
*
Expand Down

0 comments on commit 9b9a627

Please sign in to comment.