Skip to content

Commit

Permalink
Fix cweagans#12: Respect composer.lock during initial vendor folder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscaner committed Nov 24, 2020
1 parent 2e6f72a commit 82cec38
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class Patches implements PluginInterface, EventSubscriberInterface {
* @var array $patches
*/
protected $patches;
/**
* @var array $packages
*/
protected $reExcutePackages = [];

/**
* Apply plugin modifications to composer
Expand Down Expand Up @@ -136,6 +140,7 @@ public function checkPatches(Event $event) {
$uninstallOperation = new UninstallOperation($package, 'Removing package so it can be re-installed and re-patched.');
$this->io->write('<info>Removing package ' . $package_name . ' so that it can be re-installed and re-patched.</info>');
$installationManager->uninstall($localRepository, $uninstallOperation);
$this->reExcutePackages[] = $package_name;
}
}
}
Expand Down Expand Up @@ -220,11 +225,33 @@ public function gatherPatches(PackageEvent $event) {
* @throws \Exception
*/
public function grabPatches() {
// First, try to get the patches from the root composer.json.
$local_repository = $this->composer->getRepositoryManager()->getLocalRepository();
$tmp_packages = array_map(function ($package) {
return $package->getName();
}, $local_repository->getPackages());
$tmp_packages = array_merge($tmp_packages, $this->reExcutePackages);

$locked_packages = $this->composer->getLocker()->getLockedRepository()->getPackages();

// First, try to get the patches from the root composer.json.
$extra = $this->composer->getPackage()->getExtra();
if (isset($extra['patches'])) {
$this->io->write('<info>Gathering patches for root package.</info>');
$patches = $extra['patches'];

// Merge patches from lock file, if the package is first install.
foreach ($locked_packages as $locked_package) {
if (in_array($locked_package->getName(), $tmp_packages)) {
continue;
}
$extra = $locked_package->getExtra();
if (isset($extra['patches_applied'])) {
$patches = $this->arrayMergeRecursiveDistinct([
$locked_package->getName() => $extra['patches_applied'],
], $patches);
}
}

return $patches;
}
// If it's not specified there, look for a patches-file definition.
Expand Down

0 comments on commit 82cec38

Please sign in to comment.