1
0
Fork 0

Merge pull request #9942 from nicolas-grekas/fix-no-scripts

Fix --no-scripts disabling events for plugins
pull/9959/head
Jordi Boggiano 2021-06-05 16:26:01 +02:00 committed by GitHub
commit edf9951006
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 18 deletions

View File

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

View File

@ -52,6 +52,7 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
$composer = $this->getComposer();
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'dump-autoload', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@ -82,7 +83,6 @@ EOT
}
$generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix);
$generator->setRunScripts(!$input->getOption('no-scripts'));
$generator->setIgnorePlatformRequirements($ignorePlatformReqs);
$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->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
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>');
@ -123,7 +124,6 @@ EOT
->setPreferDist($preferDist)
->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix)

View File

@ -69,6 +69,7 @@ EOT
$io = $this->getIO();
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
$localRepo = $composer->getRepositoryManager()->getLocalRepository();
$packagesToReinstall = array();
@ -142,8 +143,8 @@ EOT
$downloadManager->setPreferSource($preferSource);
$downloadManager->setPreferDist($preferDist);
$installationManager->execute($localRepo, $uninstallOperations, true, !$input->getOption('no-scripts'));
$installationManager->execute($localRepo, $installOperations, true, !$input->getOption('no-scripts'));
$installationManager->execute($localRepo, $uninstallOperations, true);
$installationManager->execute($localRepo, $installOperations, true);
if (!$input->getOption('no-autoloader')) {
$optimize = $input->getOption('optimize-autoloader') || $config->get('optimize-autoloader');
@ -154,7 +155,6 @@ EOT
$generator = $composer->getAutoloadGenerator();
$generator->setClassMapAuthoritative($authoritative);
$generator->setApcu($apcu, $apcuPrefix);
$generator->setRunScripts(!$input->getOption('no-scripts'));
$generator->setIgnorePlatformRequirements($ignorePlatformReqs);
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', $optimize);
}

View File

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

View File

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

View File

@ -116,6 +116,7 @@ EOT
}
$composer = $this->getComposer(true, $input->getOption('no-plugins'));
$composer->getEventDispatcher()->setRunScripts(!$input->getOption('no-scripts'));
if (!HttpDownloader::isCurlEnabled()) {
$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)
->setDevMode(!$input->getOption('no-dev'))
->setDumpAutoloader(!$input->getOption('no-autoloader'))
->setRunScripts(!$input->getOption('no-scripts'))
->setOptimizeAutoloader($optimize)
->setClassMapAuthoritative($authoritative)
->setApcuAutoloader($apcu, $apcuPrefix)

View File

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

View File

@ -1131,6 +1131,7 @@ class Installer
*
* @param bool $runScripts
* @return Installer
* @deprecated Use setRunScripts(false) on the EventDispatcher instance being injected instead
*/
public function setRunScripts($runScripts = true)
{