Skip to content

Commit 5006d0c

Browse files
committed
Add handling for LibraryInstaller returning PromiseInterface
1 parent 8669edf commit 5006d0c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Composer/Installers/Installer.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Composer\Package\PackageInterface;
1010
use Composer\Repository\InstalledRepositoryInterface;
1111
use Composer\Util\Filesystem;
12+
use React\Promise\PromiseInterface;
1213

1314
class Installer extends LibraryInstaller
1415
{
@@ -160,9 +161,21 @@ public function getInstallPath(PackageInterface $package)
160161

161162
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
162163
{
163-
parent::uninstall($repo, $package);
164164
$installPath = $this->getPackageBasePath($package);
165-
$this->io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
165+
$io = $this->io;
166+
$outputStatus = function () use ($io, $installPath) {
167+
$io->write(sprintf('Deleting %s - %s', $installPath, !file_exists($installPath) ? '<comment>deleted</comment>' : '<error>not deleted</error>'));
168+
};
169+
170+
$promise = parent::uninstall($repo, $package);
171+
172+
// Composer v2 might return a promise here
173+
if ($promise instanceof PromiseInterface) {
174+
return $promise->then($outputStatus);
175+
}
176+
177+
// If not, execute the code right away as parent::uninstall executed synchronously (composer v1, or v2 without async)
178+
$outputStatus();
166179
}
167180

168181
/**

0 commit comments

Comments
 (0)