Commit 53e445bf 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
parent f75a4b42
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -884,10 +884,10 @@
            "dist": {
                "type": "path",
                "url": "composer/Plugin/ProjectMessage",
                "reference": "3b795f469441eb27854798f70cb38e717d80bbfc"
                "reference": "ed6afc20bfed583e5325ca86f78d07a653d6045c"
            },
            "require": {
                "composer-plugin-api": "^1.1",
                "composer-plugin-api": "^1.1 || ^2",
                "php": ">=7.0.8"
            },
            "type": "composer-plugin",
@@ -914,10 +914,10 @@
            "dist": {
                "type": "path",
                "url": "composer/Plugin/VendorHardening",
                "reference": "2db54f089065dedbe4a040b01f7b527f2bad68f6"
                "reference": "6773d713a655ec8a5ac8c29cd5df653cfec6d3cc"
            },
            "require": {
                "composer-plugin-api": "^1.1",
                "composer-plugin-api": "^1.1 || ^2",
                "php": ">=7.0.8"
            },
            "type": "composer-plugin",
+12 −0
Original line number Diff line number Diff line
@@ -45,6 +45,18 @@ public function activate(Composer $composer, IOInterface $io) {
    $this->io = $io;
  }

  /**
   * {@inheritdoc}
   */
  public function deactivate(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
  public function uninstall(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
+1 −1
Original line number Diff line number Diff line
@@ -15,6 +15,6 @@
  },
  "require": {
    "php": ">=7.0.8",
    "composer-plugin-api": "^1.1"
    "composer-plugin-api": "^1.1 || ^2"
  }
}
+27 −2
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\Composer\Plugin\Scaffold;

use Composer\Composer;
use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\Installer\PackageEvent;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
@@ -96,8 +97,12 @@ public function getAllowedPackages() {
   */
  public function event(PackageEvent $event) {
    $operation = $event->getOperation();
    // Determine the package.
    $package = $operation->getJobType() == 'update' ? $operation->getTargetPackage() : $operation->getPackage();
    // Determine the package. Later, in evaluateNewPackages(), we will report
    // 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())) {
      $this->newPackages[$package->getName()] = $package;
    }
@@ -176,6 +181,26 @@ protected function evaluateNewPackages(array $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.
   *
+12 −0
Original line number Diff line number Diff line
@@ -60,6 +60,18 @@ public function activate(Composer $composer, IOInterface $io) {
    $this->requireWasCalled = FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function deactivate(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
  public function uninstall(Composer $composer, IOInterface $io) {
  }

  /**
   * {@inheritdoc}
   */
Loading