Skip to content
Snippets Groups Projects
Commit 6c767cd3 authored by catch's avatar catch
Browse files

Issue #3126566 by greg.1.anderson, jungle, tedbow, hussainweb, Kristen Pol,...

Issue #3126566 by greg.1.anderson, jungle, tedbow, hussainweb, Kristen Pol, alexpott: Allow Drupal to work with Composer 2

(cherry picked from commit 6b939e7b858afaa409d0d97e56084e2c8f209bc7)
parent 97744c09
No related branches found
No related tags found
No related merge requests found
Showing
with 89 additions and 13 deletions
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
"chat": "https://www.drupal.org/node/314178" "chat": "https://www.drupal.org/node/314178"
}, },
"require": { "require": {
"composer/installers": "^1.0.24", "composer/installers": "^1.9",
"drupal/core": "self.version", "drupal/core": "self.version",
"drupal/core-project-message": "self.version", "drupal/core-project-message": "self.version",
"drupal/core-vendor-hardening": "self.version" "drupal/core-vendor-hardening": "self.version"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "966c0ed90c2996cad45b441c58d01aa2", "content-hash": "bf3f5b1c0d2f35255e03825589a1ee4f",
"packages": [ "packages": [
{ {
"name": "asm89/stack-cors", "name": "asm89/stack-cors",
...@@ -705,10 +705,10 @@ ...@@ -705,10 +705,10 @@
"dist": { "dist": {
"type": "path", "type": "path",
"url": "composer/Plugin/ProjectMessage", "url": "composer/Plugin/ProjectMessage",
"reference": "0691ca6beba657e6da57a893b1c6da757d16afc8" "reference": "b4efdbe26634b41a1b89e4f3770a8074769088a6"
}, },
"require": { "require": {
"composer-plugin-api": "^1.1", "composer-plugin-api": "^1.1 || ^2",
"php": ">=7.3.0" "php": ">=7.3.0"
}, },
"type": "composer-plugin", "type": "composer-plugin",
...@@ -735,10 +735,10 @@ ...@@ -735,10 +735,10 @@
"dist": { "dist": {
"type": "path", "type": "path",
"url": "composer/Plugin/VendorHardening", "url": "composer/Plugin/VendorHardening",
"reference": "0b015340af38f90df46923a934d0b22026134f18" "reference": "d54f0b3cc8b4237f3a41a0860a808db242f9da9e"
}, },
"require": { "require": {
"composer-plugin-api": "^1.1", "composer-plugin-api": "^1.1 || ^2",
"php": ">=7.3.0" "php": ">=7.3.0"
}, },
"type": "composer-plugin", "type": "composer-plugin",
......
...@@ -45,6 +45,18 @@ public function activate(Composer $composer, IOInterface $io) { ...@@ -45,6 +45,18 @@ public function activate(Composer $composer, IOInterface $io) {
$this->io = $io; $this->io = $io;
} }
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
}, },
"require": { "require": {
"php": ">=7.3.0", "php": ">=7.3.0",
"composer-plugin-api": "^1.1" "composer-plugin-api": "^1.1 || ^2"
} }
} }
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Drupal\Composer\Plugin\Scaffold; namespace Drupal\Composer\Plugin\Scaffold;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\Installer\PackageEvent; use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
...@@ -96,8 +97,12 @@ public function getAllowedPackages() { ...@@ -96,8 +97,12 @@ public function getAllowedPackages() {
*/ */
public function event(PackageEvent $event) { public function event(PackageEvent $event) {
$operation = $event->getOperation(); $operation = $event->getOperation();
// Determine the package. // Determine the package. Later, in evaluateNewPackages(), we will report
$package = $operation->getJobType() == 'update' ? $operation->getTargetPackage() : $operation->getPackage(); // which of the newly-installed packages have scaffold operations, and
// whether or not they are allowed to scaffold by the allowed-packages
// option in the root-level composer.json file.
$operationType = $this->getOperationType($operation);
$package = $operationType === 'update' ? $operation->getTargetPackage() : $operation->getPackage();
if (ScaffoldOptions::hasOptions($package->getExtra())) { if (ScaffoldOptions::hasOptions($package->getExtra())) {
$this->newPackages[$package->getName()] = $package; $this->newPackages[$package->getName()] = $package;
} }
...@@ -176,6 +181,26 @@ protected function evaluateNewPackages(array $allowed_packages) { ...@@ -176,6 +181,26 @@ protected function evaluateNewPackages(array $allowed_packages) {
return $allowed_packages; return $allowed_packages;
} }
/**
* Determine the type of the provided operation.
*
* Adjusts API used for Composer 1 or Composer 2.
*
* @param \Composer\DependencyResolver\Operation\OperationInterface $operation
* The operation object.
*
* @return string
* The operation type.
*/
protected function getOperationType(OperationInterface $operation) {
// Use Composer 2 method.
if (method_exists($operation, 'getOperationType')) {
return $operation->getOperationType();
}
// Fallback to Composer 1 method.
return $operation->getJobType();
}
/** /**
* Retrieves a package from the current composer process. * Retrieves a package from the current composer process.
* *
......
...@@ -60,6 +60,18 @@ public function activate(Composer $composer, IOInterface $io) { ...@@ -60,6 +60,18 @@ public function activate(Composer $composer, IOInterface $io) {
$this->requireWasCalled = FALSE; $this->requireWasCalled = FALSE;
} }
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"homepage": "https://www.drupal.org/project/drupal", "homepage": "https://www.drupal.org/project/drupal",
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",
"require": { "require": {
"composer-plugin-api": "^1.0.0", "composer-plugin-api": "^1 || ^2",
"php": ">=7.3.0" "php": ">=7.3.0"
}, },
"conflict": { "conflict": {
......
...@@ -65,6 +65,18 @@ public function activate(Composer $composer, IOInterface $io) { ...@@ -65,6 +65,18 @@ public function activate(Composer $composer, IOInterface $io) {
$this->config = new Config($this->composer->getPackage()); $this->config = new Config($this->composer->getPackage());
} }
/**
* {@inheritdoc}
*/
public function deactivate(Composer $composer, IOInterface $io) {
}
/**
* {@inheritdoc}
*/
public function uninstall(Composer $composer, IOInterface $io) {
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -15,6 +15,6 @@ ...@@ -15,6 +15,6 @@
}, },
"require": { "require": {
"php": ">=7.3.0", "php": ">=7.3.0",
"composer-plugin-api": "^1.1" "composer-plugin-api": "^1.1 || ^2"
} }
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
} }
], ],
"require": { "require": {
"composer/installers": "^1.2", "composer/installers": "^1.9",
"drupal/core-composer-scaffold": "^9", "drupal/core-composer-scaffold": "^9",
"drupal/core-project-message": "^9", "drupal/core-project-message": "^9",
"drupal/core-recommended": "^9", "drupal/core-recommended": "^9",
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
} }
], ],
"require": { "require": {
"composer/installers": "^1.2", "composer/installers": "^1.9",
"drupal/core-composer-scaffold": "^9", "drupal/core-composer-scaffold": "^9",
"drupal/core-project-message": "^9", "drupal/core-project-message": "^9",
"drupal/core-recommended": "^9" "drupal/core-recommended": "^9"
......
...@@ -50,3 +50,9 @@ build: ...@@ -50,3 +50,9 @@ build:
# Run nightwatch testing. # Run nightwatch testing.
# @see https://www.drupal.org/project/drupal/issues/2869825 # @see https://www.drupal.org/project/drupal/issues/2869825
nightwatchjs: nightwatchjs:
# Re-run Composer plugin tests after installing Composer 2
container_command.composer-upgrade:
commands:
- "sudo composer self-update --snapshot"
- "./vendor/bin/phpunit -c core --group VendorHardening,ProjectMessage,Scaffold"
halt-on-fail: true
...@@ -105,6 +105,11 @@ public function testVerifyTemplateTestProviderIsAccurate() { ...@@ -105,6 +105,11 @@ public function testVerifyTemplateTestProviderIsAccurate() {
* @dataProvider provideTemplateCreateProject * @dataProvider provideTemplateCreateProject
*/ */
public function testTemplateCreateProject($project, $package_dir, $docroot_dir) { public function testTemplateCreateProject($project, $package_dir, $docroot_dir) {
$composerVersionLine = exec('composer --version');
if (strpos($composerVersionLine, 'Composer version 2') !== FALSE) {
$this->markTestSkipped('We cannot run the template create project test with Composer 2 until we have a stable version of composer/semver 2.x. The create project test installs drupal/core-recommended and the Drupal Composer plugins from Packagist, so these must also be compatible with Composer 2.x in order for this test to work.');
}
$this->copyCodebase(); $this->copyCodebase();
// Get the Drupal core version branch. For instance, this should be // Get the Drupal core version branch. For instance, this should be
......
...@@ -44,6 +44,10 @@ protected function setUp(): void { ...@@ -44,6 +44,10 @@ protected function setUp(): void {
* Test upgrading the Composer Scaffold plugin. * Test upgrading the Composer Scaffold plugin.
*/ */
public function testScaffoldUpgrade() { public function testScaffoldUpgrade() {
$composerVersionLine = exec('composer --version');
if (strpos($composerVersionLine, 'Composer version 2') !== FALSE) {
$this->markTestSkipped('We cannot run the scaffold upgrade test with Composer 2 until we have a stable version of drupal/core-composer-scaffold to start from that we can install with Composer 2.x.');
}
$this->fixturesDir = $this->fixtures->tmpDir($this->getName()); $this->fixturesDir = $this->fixtures->tmpDir($this->getName());
$replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()]; $replacements = ['SYMLINK' => 'false', 'PROJECT_ROOT' => $this->fixtures->projectRoot()];
$this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements); $this->fixtures->cloneFixtureProjects($this->fixturesDir, $replacements);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment