Skip to content

Commit

Permalink
Add COMPOSER_PREFER_STABLE and COMPOSER_PREFER_LOWEST env vars, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Jul 20, 2022
1 parent 4182223 commit e43cae6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
24 changes: 19 additions & 5 deletions doc/03-cli.md
Expand Up @@ -218,9 +218,11 @@ and this feature is only available for your root package dependencies.
a `+` makes it only ignore the upper-bound of the requirements. For example, if a package
requires `php: ^7`, then the option `--ignore-platform-req=php+` would allow installing on PHP 8,
but installation on PHP 5.6 would still fail.
* **--prefer-stable:** Prefer stable versions of dependencies.
* **--prefer-stable:** Prefer stable versions of dependencies. Can also be set via the
COMPOSER_PREFER_STABLE=1 env var.
* **--prefer-lowest:** Prefer lowest versions of dependencies. Useful for testing minimal
versions of requirements, generally used with `--prefer-stable`.
versions of requirements, generally used with `--prefer-stable`. Can also be set via the
COMPOSER_PREFER_LOWEST=1 env var.
* **--interactive:** Interactive interface with autocompletion to select the packages to update.
* **--root-reqs:** Restricts the update to your first degree dependencies.

Expand Down Expand Up @@ -275,9 +277,11 @@ If you do not specify a package, Composer will prompt you to search for a packag
* **--ignore-platform-req:** ignore a specific platform requirement(`php`,
`hhvm`, `lib-*` and `ext-*`) and force the installation even if the local machine
does not fulfill it. Multiple requirements can be ignored via wildcard.
* **--prefer-stable:** Prefer stable versions of dependencies.
* **--prefer-stable:** Prefer stable versions of dependencies. Can also be set via the
COMPOSER_PREFER_STABLE=1 env var.
* **--prefer-lowest:** Prefer lowest versions of dependencies. Useful for testing minimal
versions of requirements, generally used with `--prefer-stable`.
versions of requirements, generally used with `--prefer-stable`. Can also be set via the
COMPOSER_PREFER_LOWEST=1 env var.
* **--sort-packages:** Keep packages sorted in `composer.json`.
* **--optimize-autoloader (-o):** Convert PSR-0/4 autoloading to classmap to
get a faster autoloader. This is recommended especially for production, but
Expand Down Expand Up @@ -1233,9 +1237,19 @@ useful for plugin authors to identify what is firing when exactly.
### COMPOSER_NO_DEV
If set to `1`, it is the equivalent of passing the `--no-dev` argument to `install` or
If set to `1`, it is the equivalent of passing the `--no-dev` option to `install` or
`update`. You can override this for a single command by setting `COMPOSER_NO_DEV=0`.
### COMPOSER_PREFER_STABLE
If set to `1`, it is the equivalent of passing the `--prefer-stable` option to
`update` or `require`.
### COMPOSER_PREFER_LOWEST
If set to `1`, it is the equivalent of passing the `--prefer-lowest` option to
`update` or `require`.
### COMPOSER_IGNORE_PLATFORM_REQ or COMPOSER_IGNORE_PLATFORM_REQS
If `COMPOSER_IGNORE_PLATFORM_REQS` set to `1`, it is the equivalent of passing the `--ignore-platform-reqs` argument.
Expand Down
13 changes: 10 additions & 3 deletions src/Composer/Command/BaseCommand.php
Expand Up @@ -243,9 +243,16 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$input->setOption('no-progress', true);
}

if (true === $input->hasOption('no-dev')) {
if (!$input->getOption('no-dev') && (bool) Platform::getEnv('COMPOSER_NO_DEV')) {
$input->setOption('no-dev', true);
$envOptions = [
'COMPOSER_NO_DEV' => 'no-dev',
'COMPOSER_PREFER_STABLE' => 'prefer-stable',
'COMPOSER_PREFER_LOWEST' => 'prefer-lowest',
];
foreach ($envOptions as $envName => $optionName) {
if (true === $input->hasOption($optionName)) {
if (false === $input->getOption($optionName) && (bool) Platform::getEnv($envName)) {
$input->setOption($optionName, true);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Command/RequireCommand.php
Expand Up @@ -90,8 +90,8 @@ protected function configure()
new InputOption('with-all-dependencies', null, InputOption::VALUE_NONE, 'Alias for --update-with-all-dependencies'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies.'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies.'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies (can also be set via the COMPOSER_PREFER_STABLE=1 env var).'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies (can also be set via the COMPOSER_PREFER_LOWEST=1 env var).'),
new InputOption('sort-packages', null, InputOption::VALUE_NONE, 'Sorts packages when adding/updating a new dependency'),
new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump'),
new InputOption('classmap-authoritative', 'a', InputOption::VALUE_NONE, 'Autoload classes from the classmap only. Implicitly enables `--optimize-autoloader`.'),
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Command/UpdateCommand.php
Expand Up @@ -75,8 +75,8 @@ protected function configure()
new InputOption('apcu-autoloader-prefix', null, InputOption::VALUE_REQUIRED, 'Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader'),
new InputOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Ignore a specific platform requirement (php & ext- packages).'),
new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore all platform requirements (php & ext- packages).'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies.'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies.'),
new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies (can also be set via the COMPOSER_PREFER_STABLE=1 env var).'),
new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies (can also be set via the COMPOSER_PREFER_LOWEST=1 env var).'),
new InputOption('interactive', 'i', InputOption::VALUE_NONE, 'Interactive interface with autocompletion to select the packages to update.'),
new InputOption('root-reqs', null, InputOption::VALUE_NONE, 'Restricts the update to your first degree dependencies.'),
))
Expand Down

0 comments on commit e43cae6

Please sign in to comment.