function Unpacker::updateComposerLockContent

Updates the composer.lock content and keeps the local repo in sync.

This method will remove the package itself from the composer.lock content in the root composer.

1 call to Unpacker::updateComposerLockContent()
Unpacker::unpackDependencies in composer/Plugin/RecipeUnpack/Unpacker.php
Unpacks the package's dependencies to the root composer.json and lock file.

File

composer/Plugin/RecipeUnpack/Unpacker.php, line 166

Class

Unpacker
Handles the details of unpacking a specific recipe.

Namespace

Drupal\Composer\Plugin\RecipeUnpack

Code

private function updateComposerLockContent() : void {
  $composer_locker_content = $this->rootComposer
    ->getComposerLockedContent();
  $root_package = $this->composer
    ->getPackage();
  $root_requires = $root_package->getRequires();
  $root_dev_requires = $root_package->getDevRequires();
  $local_repo = $this->composer
    ->getRepositoryManager()
    ->getLocalRepository();
  if (isset($root_requires[$this->package
    ->getName()])) {
    unset($root_requires[$this->package
      ->getName()]);
    $root_package->setRequires($root_requires);
  }
  foreach ($composer_locker_content['packages'] as $key => $lock_data) {
    // Find the package being unpacked in the composer.lock content and
    // remove it.
    if ($lock_data['name'] === $this->package
      ->getName()) {
      $this->rootComposer
        ->removeFromComposerLock('packages', $key);
      // If the package is in require-dev we need to move the lock data.
      if (isset($root_dev_requires[$lock_data['name']])) {
        $this->rootComposer
          ->addToComposerLock('packages-dev', $lock_data);
        $dev_package_names = $local_repo->getDevPackageNames();
        $dev_package_names[] = $lock_data['name'];
        $local_repo->setDevPackageNames($dev_package_names);
        return;
      }
      break;

    }
  }
  $local_repo->setDevPackageNames(array_diff($local_repo->getDevPackageNames(), [
    $this->package
      ->getName(),
  ]));
  $local_repo->removePackage($this->package);
  if (isset($root_dev_requires[$this->package
    ->getName()])) {
    unset($root_dev_requires[$this->package
      ->getName()]);
    $root_package->setDevRequires($root_dev_requires);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.