1
0
Fork 0

Fix --no-scripts disabling events for plugins

pull/9942/head
Nicolas Grekas 2021-06-04 09:56:28 +02:00 committed by Jordi Boggiano
parent 288e19153d
commit eac069bf36
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
7 changed files with 25 additions and 15 deletions

View File

@ -183,6 +183,7 @@ EOT
} }
$composer = Factory::create($io, null, $disablePlugins); $composer = Factory::create($io, null, $disablePlugins);
$composer->getEventDispatcher()->setRunScripts(!$noScripts);
// add the repository to the composer.json and use it for the install run later // add the repository to the composer.json and use it for the install run later
if ($repositories !== null && $addRepository) { if ($repositories !== null && $addRepository) {
@ -208,10 +209,8 @@ EOT
$process = new ProcessExecutor($io); $process = new ProcessExecutor($io);
$fs = new Filesystem($process); $fs = new Filesystem($process);
if ($noScripts === false) {
// dispatch event // dispatch event
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages); $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_ROOT_PACKAGE_INSTALL, $installDevPackages);
}
// use the new config including the newly installed project // use the new config including the newly installed project
$config = $composer->getConfig(); $config = $composer->getConfig();
@ -225,7 +224,6 @@ EOT
$installer->setPreferSource($preferSource) $installer->setPreferSource($preferSource)
->setPreferDist($preferDist) ->setPreferDist($preferDist)
->setDevMode($installDevPackages) ->setDevMode($installDevPackages)
->setRunScripts(!$noScripts)
->setIgnorePlatformRequirements($ignorePlatformReqs) ->setIgnorePlatformRequirements($ignorePlatformReqs)
->setSuggestedPackagesReporter($this->suggestedPackagesReporter) ->setSuggestedPackagesReporter($this->suggestedPackagesReporter)
->setOptimizeAutoloader($config->get('optimize-autoloader')) ->setOptimizeAutoloader($config->get('optimize-autoloader'))
@ -290,10 +288,8 @@ EOT
} }
} }
if ($noScripts === false) {
// dispatch event // dispatch event
$composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages); $composer->getEventDispatcher()->dispatchScript(ScriptEvents::POST_CREATE_PROJECT_CMD, $installDevPackages);
}
chdir($oldCwd); chdir($oldCwd);
$vendorComposerDir = $config->get('vendor-dir').'/composer'; $vendorComposerDir = $config->get('vendor-dir').'/composer';

View File

@ -52,6 +52,7 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$composer = $this->getComposer(); $composer = $this->getComposer();
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@ -82,7 +83,6 @@ EOT
} }
$generator->setClassMapAuthoritative($authoritative); $generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix); $generator->setApcu($apcu, $apcuPrefix);
$generator->setRunScripts(!$input->getOption('no-scripts'));
$generator->setIgnorePlatformRequirements($ignorePlatformReqs); $generator->setIgnorePlatformRequirements($ignorePlatformReqs);
$numberOfClasses = $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize); $numberOfClasses = $generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);

View File

@ -94,6 +94,7 @@ EOT
} }
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ((!$composer->getLocker() || !$composer->getLocker()->isLocked()) && !HttpDownloader::isCurlEnabled()) { if ((!$composer->getLocker() || !$composer->getLocker()->isLocked()) && !HttpDownloader::isCurlEnabled()) {
$io->writeError('<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>'); $io->writeError('<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>');
@ -123,7 +124,6 @@ EOT
->setPreferDist($preferDist) ->setPreferDist($preferDist)
->setDevMode(!$input->getOption('no-dev')) ->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader')) ->setDumpAutoloader(!$input->getOption('no-autoloader'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize) ->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative) ->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix) ->setApcuAutoloader($apcu, $apcuPrefix)

View File

@ -202,6 +202,7 @@ EOT
// Update packages // Update packages
$this->resetComposer(); $this->resetComposer();
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ($dryRun) { if ($dryRun) {
$rootPackage = $composer->getPackage(); $rootPackage = $composer->getPackage();
@ -255,7 +256,6 @@ EOT
->setInstall(!$input->getOption('no-install')) ->setInstall(!$input->getOption('no-install'))
->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies) ->setUpdateAllowTransitiveDependencies($updateAllowTransitiveDependencies)
->setIgnorePlatformRequirements($ignorePlatformReqs) ->setIgnorePlatformRequirements($ignorePlatformReqs)
->setRunScripts(!$input->getOption('no-scripts'))
->setDryRun($dryRun) ->setDryRun($dryRun)
; ;

View File

@ -311,6 +311,7 @@ EOT
// Update packages // Update packages
$this->resetComposer(); $this->resetComposer();
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if ($input->getOption('dry-run')) { if ($input->getOption('dry-run')) {
$rootPackage = $composer->getPackage(); $rootPackage = $composer->getPackage();
@ -362,7 +363,6 @@ EOT
->setPreferSource($preferSource) ->setPreferSource($preferSource)
->setPreferDist($preferDist) ->setPreferDist($preferDist)
->setDevMode($updateDevMode) ->setDevMode($updateDevMode)
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize) ->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative) ->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix) ->setApcuAutoloader($apcu, $apcuPrefix)

View File

@ -116,6 +116,7 @@ EOT
} }
$composer = $this->getComposer(true, $input->getOption('no-plugins')); $composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if (!HttpDownloader::isCurlEnabled()) { if (!HttpDownloader::isCurlEnabled()) {
$io->writeError('<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>'); $io->writeError('<warning>Composer is operating significantly slower than normal because you do not have the PHP curl extension enabled.</warning>');
@ -220,7 +221,6 @@ EOT
->setPreferDist($preferDist) ->setPreferDist($preferDist)
->setDevMode(!$input->getOption('no-dev')) ->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader')) ->setDumpAutoloader(!$input->getOption('no-autoloader'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize) ->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative) ->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix) ->setApcuAutoloader($apcu, $apcuPrefix)

View File

@ -53,6 +53,8 @@ class EventDispatcher
protected $process; protected $process;
/** @var array<string, array<int, array<callable|string>>> */ /** @var array<string, array<int, array<callable|string>>> */
protected $listeners = array(); protected $listeners = array();
/** @var bool */
protected $runScripts = true;
/** @var list<string> */ /** @var list<string> */
private $eventStack; private $eventStack;
@ -71,6 +73,18 @@ class EventDispatcher
$this->eventStack = array(); $this->eventStack = array();
} }
/**
* Set whether to run scripts or not
*
* @param bool $runScripts
*/
public function setRunScripts($runScripts = true)
{
$this->runScripts = (bool) $runScripts;
return $this;
}
/** /**
* Dispatch an event * Dispatch an event
* *
@ -421,7 +435,7 @@ class EventDispatcher
*/ */
protected function getListeners(Event $event) protected function getListeners(Event $event)
{ {
$scriptListeners = $this->getScriptListeners($event); $scriptListeners = $this->runScripts ? $this->getScriptListeners($event) : array();
if (!isset($this->listeners[$event->getName()][0])) { if (!isset($this->listeners[$event->getName()][0])) {
$this->listeners[$event->getName()][0] = array(); $this->listeners[$event->getName()][0] = array();