You are here

public function PackageManager::rebuildRootPackage in Composer Manager 8

Rebuilds the root package by merging in the extension requirements.

Overrides PackageManagerInterface::rebuildRootPackage

File

src/PackageManager.php, line 204

Class

PackageManager
Manages composer packages.

Namespace

Drupal\composer_manager

Code

public function rebuildRootPackage() {
  $root_package = JsonFile::read($this->root . '/composer.json');

  // Initialize known start values. These should match what's already in
  // the root composer.json shipped with Drupal.
  $core_requirement = $root_package['replace']['drupal/core'];
  $root_package['replace'] = [
    'drupal/core' => $core_requirement,
  ];
  $root_package['repositories'] = [];
  $root_package['extra']['merge-plugin']['include'] = [
    'core/composer.json',
  ];

  // Add the discovered extensions to the replace list so that they doesn't
  // get redownloaded if required by another package.
  foreach ($this
    ->getExtensionPackages() as $extension_package) {
    $version = '8.*';
    if (isset($extension_package['extra']['branch-alias']['dev-master'])) {
      $version = $extension_package['extra']['branch-alias']['dev-master'];
    }
    $root_package['replace'][$extension_package['name']] = $version;
  }

  // Ensure the presence of the Drupal Packagist repository.
  // @todo Remove once Drupal Packagist moves to d.o and gets added to
  // the root package by default.
  $root_package['repositories'][] = [
    'type' => 'composer',
    'url' => 'https://packagist.drupal-composer.org',
  ];

  // Add each discovered extension to the merge list.
  foreach ($this
    ->getExtensionPackages() as $extension_package) {
    $root_package['extra']['merge-plugin']['include'][] = $extension_package['extra']['path'];
  }
  JsonFile::write($this->root . '/composer.json', $root_package);
}