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

Skip to content

Commit d9a158d

Browse files
authored
Merge pull request composer#12268 from Seldaek/suppress_dev_hint_on_global
Suppress require-dev hint when requiring things globally
2 parents 34c16ad + c1256a2 commit d9a158d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/Composer/Command/RequireCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
231231

232232
$requirements = $this->formatRequirements($requirements);
233233

234-
if (!$input->getOption('dev') && $io->isInteractive()) {
234+
if (!$input->getOption('dev') && $io->isInteractive() && !$composer->isGlobal()) {
235235
$devPackages = [];
236236
$devTags = ['dev', 'testing', 'static analysis'];
237237
$currentRequiresByKey = $this->getPackagesByRequireKey();

src/Composer/Factory.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
324324

325325
// Load config and override with local config/auth config
326326
$config = static::createConfig($io, $cwd);
327+
$isGlobal = $localConfigSource !== Config::SOURCE_UNKNOWN && realpath($config->get('home')) === realpath(dirname($localConfigSource));
327328
$config->merge($localConfig, $localConfigSource);
329+
328330
if (isset($composerFile)) {
329331
$io->writeError('Loading config file ' . $composerFile .' ('.realpath($composerFile).')', true, IOInterface::DEBUG);
330332
$config->setConfigSource(new JsonConfigSource(new JsonFile(realpath($composerFile), null, $io)));
@@ -346,6 +348,9 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
346348
// initialize composer
347349
$composer = $fullLoad ? new Composer() : new PartialComposer();
348350
$composer->setConfig($config);
351+
if ($isGlobal) {
352+
$composer->setGlobal();
353+
}
349354

350355
if ($fullLoad) {
351356
// load auth configs into the IO instance
@@ -429,14 +434,14 @@ public function createComposer(IOInterface $io, $localConfig = null, $disablePlu
429434

430435
if ($composer instanceof Composer) {
431436
$globalComposer = null;
432-
if (realpath($config->get('home')) !== $cwd) {
437+
if (!$composer->isGlobal()) {
433438
$globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins, $disableScripts);
434439
}
435440

436441
$pm = $this->createPluginManager($io, $composer, $globalComposer, $disablePlugins);
437442
$composer->setPluginManager($pm);
438443

439-
if (realpath($config->get('home')) === $cwd) {
444+
if ($composer->isGlobal()) {
440445
$pm->setRunningInGlobalDir(true);
441446
}
442447

src/Composer/PartialComposer.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
*/
2424
class PartialComposer
2525
{
26+
/**
27+
* @var bool
28+
*/
29+
private $global = false;
30+
2631
/**
2732
* @var RootPackageInterface
2833
*/
@@ -112,4 +117,14 @@ public function getEventDispatcher(): EventDispatcher
112117
{
113118
return $this->eventDispatcher;
114119
}
120+
121+
public function isGlobal(): bool
122+
{
123+
return $this->global;
124+
}
125+
126+
public function setGlobal(): void
127+
{
128+
$this->global = true;
129+
}
115130
}

0 commit comments

Comments
 (0)