Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 690fe71

Browse files
authored
Output more warnings about plugins being disabled to hint that it may cause problems, fixes #11839 (#11842)
1 parent 33335fd commit 690fe71

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/Composer/Console/Application.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function doRun(InputInterface $input, OutputInterface $output): int
220220

221221
// Clobber sudo credentials if COMPOSER_ALLOW_SUPERUSER is not set before loading plugins
222222
if ($needsSudoCheck) {
223-
$isNonAllowedRoot = function_exists('posix_getuid') && posix_getuid() === 0;
223+
$isNonAllowedRoot = $this->isRunningAsRoot();
224224

225225
if ($isNonAllowedRoot) {
226226
if ($uid = (int) Platform::getEnv('SUDO_UID')) {
@@ -476,6 +476,12 @@ private function hintCommonErrors(\Throwable $exception, OutputInterface $output
476476
$io->writeError('<error>Check https://getcomposer.org/doc/06-config.md#process-timeout for details</error>', true, IOInterface::QUIET);
477477
}
478478

479+
if ($this->getDisablePluginsByDefault() && $this->isRunningAsRoot() && !$this->io->isInteractive()) {
480+
$io->writeError('<error>Plugins have been disabled automatically as you are running as root, this may be the cause of the following exception. See also https://getcomposer.org/root</error>', true, IOInterface::QUIET);
481+
} elseif ($exception instanceof CommandNotFoundException && $this->getDisablePluginsByDefault()) {
482+
$io->writeError('<error>Plugins have been disabled, which may be why some commands are missing, unless you made a typo</error>', true, IOInterface::QUIET);
483+
}
484+
479485
$hints = HttpDownloader::getExceptionHints($exception);
480486
if (null !== $hints && count($hints) > 0) {
481487
foreach ($hints as $hint) {
@@ -678,4 +684,9 @@ private function getUseParentDirConfigValue()
678684

679685
return $config->get('use-parent-dir');
680686
}
687+
688+
private function isRunningAsRoot(): bool
689+
{
690+
return function_exists('posix_getuid') && posix_getuid() === 0;
691+
}
681692
}

src/Composer/Installer/InstallationManager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ public function removeInstaller(InstallerInterface $installer): void
9494
/**
9595
* Disables plugins.
9696
*
97-
* We prevent any plugins from being instantiated by simply
98-
* deactivating the installer for them. This ensure that no third-party
97+
* We prevent any plugins from being instantiated by
98+
* disabling the PluginManager. This ensures that no third-party
9999
* code is ever executed.
100100
*/
101101
public function disablePlugins(): void
@@ -105,7 +105,7 @@ public function disablePlugins(): void
105105
continue;
106106
}
107107

108-
unset($this->installers[$i]);
108+
$installer->disablePlugins();
109109
}
110110
}
111111

src/Composer/Installer/PluginInstaller.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function supports(string $packageType)
4343
return $packageType === 'composer-plugin' || $packageType === 'composer-installer';
4444
}
4545

46+
public function disablePlugins(): void
47+
{
48+
$this->getPluginManager()->disablePlugins();
49+
}
50+
4651
/**
4752
* @inheritDoc
4853
*/

src/Composer/Plugin/PluginManager.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function getGlobalComposer(): ?PartialComposer
153153
public function registerPackage(PackageInterface $package, bool $failOnMissingClasses = false, bool $isGlobalPlugin = false): void
154154
{
155155
if ($this->arePluginsDisabled($isGlobalPlugin ? 'global' : 'local')) {
156+
$this->io->writeError('<warning>The "'.$package->getName().'" plugin was not loaded as plugins are disabled.</warning>');
156157
return;
157158
}
158159

@@ -656,6 +657,14 @@ public function arePluginsDisabled($type)
656657
return $this->disablePlugins === true || $this->disablePlugins === $type;
657658
}
658659

660+
/**
661+
* @internal
662+
*/
663+
public function disablePlugins(): void
664+
{
665+
$this->disablePlugins = true;
666+
}
667+
659668
/**
660669
* @internal
661670
*/

0 commit comments

Comments
 (0)