Skip to content

Commit

Permalink
Fix reinstall command not firing pre-install-cmd/post-install-cmd eve…
Browse files Browse the repository at this point in the history
…nts, fixes #10508 (#10514)
  • Loading branch information
Seldaek committed Feb 4, 2022
1 parent 88171e4 commit 8053d79
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
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

0 comments on commit 8053d79

Please sign in to comment.