Skip to content

#118 | Use syncHelper to ensure package install complete #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/Compatibility/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
namespace Vaimo\ComposerPatches\Compatibility;

use Composer\Composer;
use Composer\Util\SyncHelper;
use React\Promise\Promise;
use Vaimo\ComposerPatches\Exceptions\OperationFailure;
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
use Composer\Repository\WritableRepositoryInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
Expand Down Expand Up @@ -76,21 +80,28 @@ public function processReinstallOperation(
WritableRepositoryInterface $repository,
InstallationManager $installationManager,
InstallOperation $installOperation,
UninstallOperation $uninstallOperation
UninstallOperation $uninstallOperation,
Composer $composer
) {
if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
return $installationManager->install($repository, $installOperation);
}

return $installationManager
->uninstall($repository, $uninstallOperation)
->then(function () use ($installationManager, $installOperation, $repository) {
$package = $installOperation->getPackage();
$installationManager->getInstaller($package->getType())
->download($package)
->then(function () use ($installationManager, $installOperation, $repository) {
$installationManager->install($repository, $installOperation);
});
});
$package = $installOperation->getPackage();
$installer = $installationManager->getInstaller($package->getType());

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

return $promise->then(static function () use ($composer, $installer, $package) {
return SyncHelper::downloadAndInstallPackageSync(
$composer->getLoop(),
$composer->getDownloadManager(),
$installer->getInstallPath($package),
$package
);
});
}
}
12 changes: 8 additions & 4 deletions src/Managers/RepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Vaimo\ComposerPatches\Managers;

use Composer\Composer;
use Composer\Repository\WritableRepositoryInterface;
use Composer\Package\PackageInterface;
use Composer\DependencyResolver\Operation\UninstallOperation;
Expand Down Expand Up @@ -56,8 +57,11 @@ public function __construct(
* @param PackageInterface $package
* @throws \Vaimo\ComposerPatches\Exceptions\PackageResetException
*/
public function resetPackage(WritableRepositoryInterface $repository, PackageInterface $package)
{
public function resetPackage(
WritableRepositoryInterface $repository,
PackageInterface $package,
Composer $composer
) {
$resetOperation = new ResetOperation($package, 'Package reset due to changes in patches configuration');
$uninstallOperation = new UninstallOperation($package);

Expand All @@ -70,8 +74,8 @@ public function resetPackage(WritableRepositoryInterface $repository, PackageInt
$compExecutor = $this->compExecutor;
$installationManager = $this->installationManager;
return $this->consoleSilencer->applyToCallback(
function () use ($compExecutor, $installationManager, $repository, $resetOperation, $uninstallOperation) {
return $compExecutor->processReinstallOperation($repository, $installationManager, $resetOperation, $uninstallOperation);
function () use ($compExecutor, $installationManager, $repository, $resetOperation, $uninstallOperation, $composer) {
return $compExecutor->processReinstallOperation($repository, $installationManager, $resetOperation, $uninstallOperation, $composer);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/PatchesApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function apply(Repository $repository, array $patches)
);
}

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

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