Skip to content
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

Fix reinstall command not firing pre-install-cmd/post-install-cmd events #10514

Merged
merged 1 commit into from Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Composer/Command/ReinstallCommand.php
Expand Up @@ -21,6 +21,8 @@
use Composer\Pcre\Preg;
use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents;
use Composer\Script\ScriptEvents;
use Composer\Util\Platform;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -127,7 +129,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
});

$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'reinstall', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
$eventDispatcher = $composer->getEventDispatcher();
$eventDispatcher->dispatch($commandEvent->getName(), $commandEvent);

$config = $composer->getConfig();
list($preferSource, $preferDist) = $this->getPreferredInstallOptions($config, $input);
Expand All @@ -146,8 +149,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
$downloadManager->setPreferSource($preferSource);
$downloadManager->setPreferDist($preferDist);

$installationManager->execute($localRepo, $uninstallOperations, true);
$installationManager->execute($localRepo, $installOperations, true);
$devMode = $localRepo->getDevMode() !== null ? $localRepo->getDevMode() : true;

Platform::putEnv('COMPOSER_DEV_MODE', $devMode ? '1' : '0');
$eventDispatcher->dispatchScript(ScriptEvents::PRE_INSTALL_CMD, $devMode);

$installationManager->execute($localRepo, $uninstallOperations, $devMode);
$installationManager->execute($localRepo, $installOperations, $devMode);

if (!$input->getOption('no-autoloader')) {
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
Expand All @@ -162,6 +170,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
}

$eventDispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, $devMode);

return 0;
}
}
13 changes: 13 additions & 0 deletions src/Composer/Repository/FilesystemRepository.php
Expand Up @@ -36,6 +36,8 @@ class FilesystemRepository extends WritableArrayRepository
private $rootPackage;
/** @var Filesystem */
private $filesystem;
/** @var bool|null */
private $devMode = null;

/**
* Initializes filesystem repository.
Expand All @@ -56,6 +58,14 @@ public function __construct(JsonFile $repositoryFile, $dumpVersions = false, Roo
}
}

/**
* @return bool|null true if dev requirements were installed, false if --no-dev was used, null if yet unknown
*/
public function getDevMode()
{
return $this->devMode;
}

/**
* Initializes repository (reads file, or remote address).
*/
Expand All @@ -78,6 +88,9 @@ protected function initialize()
if (isset($data['dev-package-names'])) {
$this->setDevPackageNames($data['dev-package-names']);
}
if (isset($data['dev'])) {
$this->devMode = $data['dev'];
}

if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the repository');
Expand Down
5 changes: 5 additions & 0 deletions src/Composer/Repository/InstalledRepositoryInterface.php
Expand Up @@ -21,6 +21,11 @@
*/
interface InstalledRepositoryInterface extends WritableRepositoryInterface
{
/**
* @return bool|null true if dev requirements were installed, false if --no-dev was used, null if yet unknown
*/
public function getDevMode();

/**
* @return bool true if packages were never installed in this repository
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Composer/Repository/WritableArrayRepository.php
Expand Up @@ -27,6 +27,17 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit
*/
protected $devPackageNames = array();

/** @var bool|null */
private $devMode = null;

/**
* @return bool|null true if dev requirements were installed, false if --no-dev was used, null if yet unknown
*/
public function getDevMode()
{
return $this->devMode;
}

/**
* @inheritDoc
*/
Expand All @@ -48,13 +59,15 @@ public function getDevPackageNames()
*/
public function write($devMode, InstallationManager $installationManager)
{
$this->devMode = $devMode;
}

/**
* @inheritDoc
*/
public function reload()
{
$this->devMode = null;
}

/**
Expand Down