Skip to content

Commit 60ff5ba

Browse files
authored
Merge pull request #396 from asgrim/add-no-cache-option
Added --no-cache option to avoid using Composer cache
2 parents 6769906 + 5709823 commit 60ff5ba

12 files changed

+36
-0
lines changed

src/Command/BuildCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
6262
}
6363

6464
$forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input);
65+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
6566

6667
$composer = PieComposerFactory::createPieComposer(
6768
$this->container,

src/Command/CommandHelper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ final class CommandHelper
6060
private const OPTION_MAKE_PARALLEL_JOBS = 'make-parallel-jobs';
6161
private const OPTION_SKIP_ENABLE_EXTENSION = 'skip-enable-extension';
6262
private const OPTION_FORCE = 'force';
63+
private const OPTION_NO_CACHE = 'no-cache';
6364

6465
private function __construct()
6566
{
@@ -85,6 +86,12 @@ public static function configurePhpConfigOptions(Command $command): void
8586
InputOption::VALUE_REQUIRED,
8687
'The path to the `phpize` binary to use as the target PHP platform, e.g. --' . self::OPTION_WITH_PHPIZE_PATH . '=/usr/bin/phpize7.4',
8788
);
89+
$command->addOption(
90+
self::OPTION_NO_CACHE,
91+
null,
92+
InputOption::VALUE_NONE,
93+
'Prevent the use of the Composer cache.',
94+
);
8895
}
8996

9097
public static function configureDownloadBuildInstallOptions(Command $command, bool $withRequestedPackageAndVersion = true): void
@@ -432,4 +439,14 @@ static function (array $match) use ($io): void {
432439

433440
return 1;
434441
}
442+
443+
public static function applyNoCacheOptionIfSet(InputInterface $input, IOInterface $io): void
444+
{
445+
if (! $input->hasOption(self::OPTION_NO_CACHE) || ! $input->getOption(self::OPTION_NO_CACHE)) {
446+
return;
447+
}
448+
449+
$io->writeError('Disabling cache usage', verbosity: IOInterface::DEBUG);
450+
Platform::putEnv('COMPOSER_CACHE_DIR', Platform::isWindows() ? 'nul' : '/dev/null');
451+
}
435452
}

src/Command/DownloadCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
6464
}
6565

6666
$forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input);
67+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
6768

6869
$composer = PieComposerFactory::createPieComposer(
6970
$this->container,

src/Command/InfoCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
6969
);
7070
}
7171

72+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
73+
7274
$composer = PieComposerFactory::createPieComposer(
7375
$this->container,
7476
new PieComposerRequest(

src/Command/InstallCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
7676
}
7777

7878
$forceInstallPackageVersion = CommandHelper::determineForceInstallingPackageVersion($input);
79+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
7980

8081
$composer = PieComposerFactory::createPieComposer(
8182
$this->container,

src/Command/InstallExtensionsForProjectCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
9696
);
9797
}
9898

99+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
100+
99101
$rootPackage = $this->composerFactoryForProject->rootPackage($this->io);
100102

101103
if (ExtensionType::isValid($rootPackage->getType())) {

src/Command/RepositoryAddCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
8383
->addRepository($type, $url);
8484
}
8585

86+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
87+
8688
CommandHelper::listRepositories(
8789
PieComposerFactory::createPieComposer(
8890
$this->container,

src/Command/RepositoryListCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public function configure(): void
3636

3737
public function execute(InputInterface $input, OutputInterface $output): int
3838
{
39+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
40+
3941
CommandHelper::listRepositories(
4042
PieComposerFactory::createPieComposer(
4143
$this->container,

src/Command/RepositoryRemoveCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
6666
->removeRepository($url);
6767
}
6868

69+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
70+
6971
CommandHelper::listRepositories(
7072
PieComposerFactory::createPieComposer(
7173
$this->container,

src/Command/SelfUpdateCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function execute(InputInterface $input, OutputInterface $output): int
107107

108108
$targetPlatform = CommandHelper::determineTargetPlatformFromInputs($input, $this->io);
109109

110+
CommandHelper::applyNoCacheOptionIfSet($input, $this->io);
111+
110112
$composer = PieComposerFactory::createPieComposer(
111113
$this->container,
112114
PieComposerRequest::noOperation(

0 commit comments

Comments
 (0)