Skip to content

Commit

Permalink
Convert the option into a bool | string parameter and change a couple…
Browse files Browse the repository at this point in the history
… of texts
  • Loading branch information
carlos-granados committed Apr 29, 2024
1 parent 7328dec commit 1d13727
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
4 changes: 1 addition & 3 deletions doc/03-cli.md
Expand Up @@ -234,9 +234,7 @@ php composer.phar update vendor/package:2.0.1 vendor/package2:3.0.*
changes to transitive dependencies. Can also be set via the COMPOSER_MINIMAL_CHANGES=1 env var.
* **--interactive:** Interactive interface with autocompletion to select the packages to update.
* **--root-reqs:** Restricts the update to your first degree dependencies.
* **--bump-after-update:** Runs Bump after performing the update.
* **--bump-dev-only:** Used if "Bump after Update" option is selected. Only bump requirements in "require-dev".
* **--bump-no-dev-only:** Used if "Bump after Update" option is selected. Only bump requirements in "require".
* **--bump-after-update:** Runs Bump after performing the update. Set to `dev` or `no-dev` to only bump those dependencies.

Specifying one of the words `mirrors`, `lock`, or `nothing` as an argument has the same effect as specifying the option `--lock`, for example `composer update mirrors` is exactly the same as `composer update --lock`.

Expand Down
4 changes: 2 additions & 2 deletions doc/06-config.md
Expand Up @@ -478,7 +478,7 @@ altogether.

## bump-after-update

Defaults to false. If set to true, Composer will run the Bump command after running
the Update command.
Defaults to `false` and can be any of `true`, `false`, `"dev"` or `"no-dev"`. If set to true, Composer will run the Bump command after running
the Update command. If set to `"dev"` or `"no-dev"` then only the corresponding dependencies will be bumped.

← [Repositories](05-repositories.md) | [Runtime](07-runtime.md) →
4 changes: 2 additions & 2 deletions res/composer-schema.json
Expand Up @@ -658,8 +658,8 @@
"description": "Defaults to \"php-only\" which checks only the PHP version. Setting to true will also check the presence of required PHP extensions. If set to false, Composer will not create and require a platform_check.php file as part of the autoloader bootstrap."
},
"bump-after-update": {
"type": "boolean",
"description": "Defaults to false. If set to true, Composer will run the Bump command after running the Update command."
"type": ["string", "boolean"],
"description": "Defaults to false and can be any of true, false, \"dev\"` or \"no-dev\"`. If set to true, Composer will run the Bump command after running the Update command. If set to \"dev\" or \"no-dev\" then only the corresponding dependencies will be bumped."
}
}
},
Expand Down
7 changes: 2 additions & 5 deletions src/Composer/Command/BumpCommand.php
Expand Up @@ -91,8 +91,7 @@ public function doBump(
bool $devOnly,
bool $noDevOnly,
bool $dryRun,
array $packagesFilter,
bool $calledFromUpdate = false
array $packagesFilter
): int {
/** @readonly */
$composerJsonPath = Factory::getComposerFile();
Expand Down Expand Up @@ -139,9 +138,7 @@ public function doBump(
$contents = $composerJson->read();
if (!isset($contents['type'])) {
$io->writeError('<warning>If your package is not a library, you can explicitly specify the "type" by using "composer config type project".</warning>');
$io->writeError('<warning>Alternatively you can use --' .
($calledFromUpdate ? 'bump-' : '') .
'dev-only to only bump dependencies within "require-dev".</warning>');
$io->writeError('<warning>Alternatively you can use the dev-only option to only bump dependencies within "require-dev".</warning>');
}
unset($contents);
}
Expand Down
13 changes: 12 additions & 1 deletion src/Composer/Command/ConfigCommand.php
Expand Up @@ -469,7 +469,18 @@ static function ($val) {
'prepend-autoloader' => [$booleanValidator, $booleanNormalizer],
'disable-tls' => [$booleanValidator, $booleanNormalizer],
'secure-http' => [$booleanValidator, $booleanNormalizer],
'bump-after-update' => [$booleanValidator, $booleanNormalizer],
'bump-after-update' => [
static function ($val): bool {
return in_array($val, ['dev', 'no-dev', 'true', 'false', '1', '0'], true);
},
static function ($val) {
if ('dev' === $val || 'no-dev' === $val) {
return $val;
}

return $val !== 'false' && (bool) $val;
},
],
'cafile' => [
static function ($val): bool {
return file_exists($val) && Filesystem::isReadable($val);
Expand Down
22 changes: 10 additions & 12 deletions src/Composer/Command/UpdateCommand.php
Expand Up @@ -79,8 +79,6 @@ protected function configure()
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.'),
new InputOption('bump-after-update', null, InputOption::VALUE_NONE, 'Runs Bump after performing the update.'),
new InputOption('bump-dev-only', null, InputOption::VALUE_NONE, 'Used if "Bump after Update" option is selected. Only bump requirements in "require-dev".'),
new InputOption('bump-no-dev-only', null, InputOption::VALUE_NONE, 'Used if "Bump after Update" option is selected. Only bump requirements in "require".'),
])
->setHelp(
<<<EOT
Expand Down Expand Up @@ -252,23 +250,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$result = $install->run();
$bumpAfterUpdate = $input->getOption('bump-after-update') || $composer->getConfig()->get('bump-after-update');

if ($bumpAfterUpdate) {
if ($result === 0) {
$io->writeError('<info>Running Bump after Update.</info>');
if ($result === 0) {
$bumpAfterUpdate = (bool) $input->getOption('bump-after-update') || (bool) $composer->getConfig()->get('bump-after-update');

if ($bumpAfterUpdate) {
$io->writeError('<info>Bumping dependencies</info>');
$bumpCommand = new BumpCommand();
$bumpCommand->setComposer($composer);
$result = $bumpCommand->doBump(
$io,
$input->getOption('bump-dev-only'),
$input->getOption('bump-no-dev-only'),
$input->getOption('bump-after-update') === 'dev'
|| $composer->getConfig()->get('bump-after-update') === 'dev',
$input->getOption('bump-after-update') === 'no-dev'
|| $composer->getConfig()->get('bump-after-update') === 'no-dev',
$input->getOption('dry-run'),
$input->getArgument('packages'),
true
$input->getArgument('packages')
);
} else {
$io->writeError('<warning>Not running Bump after Update because the update command did not finish successfully.</warning>');
}
}
return $result;
Expand Down
10 changes: 4 additions & 6 deletions tests/Composer/Test/Command/UpdateCommandTest.php
Expand Up @@ -142,18 +142,18 @@ public static function provideUpdates(): \Generator
Package operations: 2 installs, 0 updates, 0 removals
- Installing dep/pkg (1.0.2)
- Installing root/req (1.0.0)
Running Bump after Update.
Bumping dependencies
<warning>Warning: Bumping dependency constraints is not recommended for libraries as it will narrow down your dependencies and may cause problems for your users.</warning>
<warning>If your package is not a library, you can explicitly specify the "type" by using "composer config type project".</warning>
<warning>Alternatively you can use --bump-dev-only to only bump dependencies within "require-dev".</warning>
<warning>Alternatively you can use the dev-only option to only bump dependencies within "require-dev".</warning>
No requirements to update in ./composer.json.
OUTPUT
, true
];

yield 'update & bump dev only' => [
$rootDepAndTransitiveDep,
['--bump-after-update' => true, '--bump-dev-only' => true],
['--bump-after-update' => 'dev'],
<<<OUTPUT
Loading composer repositories with package information
Updating dependencies
Expand All @@ -164,7 +164,7 @@ public static function provideUpdates(): \Generator
Package operations: 2 installs, 0 updates, 0 removals
- Installing dep/pkg (1.0.2)
- Installing root/req (1.0.0)
Running Bump after Update.
Bumping dependencies
No requirements to update in ./composer.json.
OUTPUT
, true
Expand All @@ -181,8 +181,6 @@ public static function provideUpdates(): \Generator
Problem 1
- Root composer.json requires root/req 1.* -> satisfiable by root/req[1.0.0].
- root/req 1.0.0 requires dep/pkg ^1 -> found dep/pkg[1.0.0, 1.0.1, 1.0.2] but it conflicts with your temporary update constraint (dep/pkg:^2).
<warning>Not running Bump after Update because the update command did not finish successfully.</warning>
OUTPUT
];

Expand Down

0 comments on commit 1d13727

Please sign in to comment.