Skip to content

Commit c05f786

Browse files
author
Leander Huysse
committed
#118 | Use syncHelper to ensure package install complete
1 parent 60e9ee0 commit c05f786

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/Compatibility/Executor.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66
namespace Vaimo\ComposerPatches\Compatibility;
77

8+
use Composer\Composer;
9+
use Composer\Util\SyncHelper;
10+
use React\Promise\Promise;
11+
use Vaimo\ComposerPatches\Exceptions\OperationFailure;
812
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
913
use Composer\Repository\WritableRepositoryInterface;
1014
use Composer\DependencyResolver\Operation\InstallOperation;
@@ -76,7 +80,8 @@ public function processReinstallOperation(
7680
WritableRepositoryInterface $repository,
7781
InstallationManager $installationManager,
7882
InstallOperation $installOperation,
79-
UninstallOperation $uninstallOperation
83+
UninstallOperation $uninstallOperation,
84+
Composer $composer
8085
) {
8186
if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
8287
return $installationManager->install($repository, $installOperation);
@@ -85,12 +90,18 @@ public function processReinstallOperation(
8590
$package = $installOperation->getPackage();
8691
$installer = $installationManager->getInstaller($package->getType());
8792

88-
$installationManager->uninstall($repository, $uninstallOperation);
93+
$promise = $installationManager->uninstall($repository, $uninstallOperation);
94+
if (!$promise instanceof Promise) {
95+
throw new OperationFailure("Uninstallation of {$package->getName()} failed");
96+
}
8997

90-
return $installer
91-
->download($package)
92-
->then(function () use ($installationManager, $installOperation, $repository) {
93-
$installationManager->install($repository, $installOperation);
94-
});
98+
return $promise->then(static function () use ($composer, $installer, $package) {
99+
return SyncHelper::downloadAndInstallPackageSync(
100+
$composer->getLoop(),
101+
$composer->getDownloadManager(),
102+
$installer->getInstallPath($package),
103+
$package
104+
);
105+
});
95106
}
96107
}

src/Managers/RepositoryManager.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Vaimo\ComposerPatches\Managers;
77

8+
use Composer\Composer;
89
use Composer\Repository\WritableRepositoryInterface;
910
use Composer\Package\PackageInterface;
1011
use Composer\DependencyResolver\Operation\UninstallOperation;
@@ -56,8 +57,11 @@ public function __construct(
5657
* @param PackageInterface $package
5758
* @throws \Vaimo\ComposerPatches\Exceptions\PackageResetException
5859
*/
59-
public function resetPackage(WritableRepositoryInterface $repository, PackageInterface $package)
60-
{
60+
public function resetPackage(
61+
WritableRepositoryInterface $repository,
62+
PackageInterface $package,
63+
Composer $composer
64+
) {
6165
$resetOperation = new ResetOperation($package, 'Package reset due to changes in patches configuration');
6266
$uninstallOperation = new UninstallOperation($package);
6367

@@ -70,8 +74,8 @@ public function resetPackage(WritableRepositoryInterface $repository, PackageInt
7074
$compExecutor = $this->compExecutor;
7175
$installationManager = $this->installationManager;
7276
return $this->consoleSilencer->applyToCallback(
73-
function () use ($compExecutor, $installationManager, $repository, $resetOperation, $uninstallOperation) {
74-
return $compExecutor->processReinstallOperation($repository, $installationManager, $resetOperation, $uninstallOperation);
77+
function () use ($compExecutor, $installationManager, $repository, $resetOperation, $uninstallOperation, $composer) {
78+
return $compExecutor->processReinstallOperation($repository, $installationManager, $resetOperation, $uninstallOperation, $composer);
7579
}
7680
);
7781
}

src/Repository/PatchesApplier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function apply(Repository $repository, array $patches)
195195
);
196196
}
197197

198-
$resets[] = $this->repositoryManager->resetPackage($repository, $resetTarget);
198+
$resets[] = $this->repositoryManager->resetPackage($repository, $resetTarget, $this->composer);
199199
}
200200

201201
$this->compExecutor->waitForCompletion($this->composer, $resets);

0 commit comments

Comments
 (0)