|
8 | 8 | namespace DrupalProject\composer;
|
9 | 9 |
|
10 | 10 | use Composer\Script\Event;
|
| 11 | +use Composer\Semver\Comparator; |
11 | 12 | use Symfony\Component\Filesystem\Filesystem;
|
12 | 13 |
|
13 | 14 | class ScriptHandler {
|
@@ -57,4 +58,35 @@ public static function createRequiredFiles(Event $event) {
|
57 | 58 | }
|
58 | 59 | }
|
59 | 60 |
|
| 61 | + /** |
| 62 | + * Checks if the installed version of Composer is compatible. |
| 63 | + * |
| 64 | + * Composer 1.0.0 and higher consider a `composer install` without having a |
| 65 | + * lock file present as equal to `composer update`. We do not ship with a lock |
| 66 | + * file to avoid merge conflicts downstream, meaning that if a project is |
| 67 | + * installed with an older version of Composer the scaffolding of Drupal will |
| 68 | + * not be triggered. We check this here instead of in drupal-scaffold to be |
| 69 | + * able to give immediate feedback to the end user, rather than failing the |
| 70 | + * installation after going through the lengthy process of compiling and |
| 71 | + * downloading the Composer dependencies. |
| 72 | + * |
| 73 | + * @see https://github.com/composer/composer/pull/5035 |
| 74 | + */ |
| 75 | + public static function checkComposerVersion(Event $event) { |
| 76 | + $composer = $event->getComposer(); |
| 77 | + $io = $event->getIO(); |
| 78 | + |
| 79 | + $version = $composer::VERSION; |
| 80 | + |
| 81 | + // If Composer is installed through git we have no easy way to determine if |
| 82 | + // it is new enough, just display a warning. |
| 83 | + if ($version === '@package_version@') { |
| 84 | + $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>'); |
| 85 | + } |
| 86 | + elseif (Comparator::lessThan($version, '1.0.0')) { |
| 87 | + $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.'); |
| 88 | + exit(1); |
| 89 | + } |
| 90 | + } |
| 91 | + |
60 | 92 | }
|
0 commit comments