Skip to content

Commit

Permalink
Added composer files as default values for command, fixed constraint … (
Browse files Browse the repository at this point in the history
#5)

* Added composer files as default values for command, fixed constraint being quoted

* Updated readme

---------

Co-authored-by: Martins Rucevskis <[email protected]>
  • Loading branch information
MartinsRucevskis and Martins Rucevskis authored Nov 16, 2023
1 parent e79daaa commit e2137fc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Helps You automatically resolve composer conflicts

E.g Need to upgrade your framework to the newest version? Just run
E.g. Need to upgrade your framework to the newest version? Just run
```bash
composer major-update -C=composerPath --constraint=package/package:^10.0 --constraint=php:^8.1
composer major-update --composer-json=composerPath --constraint=package/package:^10.0 --constraint=php:^8.1
```
Want to upgrade minor versions and also update your compose.json file to the up-to-date versions? Run
```
composer minor-update -C=composerPath
composer minor-update --composer-json=composerPath
```

## Installation
Expand All @@ -22,19 +22,19 @@ composer require martinsr/constraint-updater
## How to use

- Add it to Your project
- Specify your composer location when running any of the commands
```
-C=composer/json/path
- Specify your composer json/lock location when running any of the commands if needed
```bash
--composer-json=composer/json/path --composer-lock=composer/lock/path
```
- Specify Your needed constraints when running `composer major-update`
```
```bash
--constraint=php:^8.1 --constraint=package/package:^10.0
```
- Run the either `composer major-update` or `composer minor-update` with your params.

## How it works

### update-major
### major-update

It will replace all your `composer.json` package versions with `*` except for packages You have added with `--constraint`.

Expand All @@ -43,12 +43,20 @@ Versions you add for the packages will be taken literally.
#### Examples:
`constraint=laravel/framework:^10.0` will set the version to `^10.0` `constraint=laravel/framework:10.0` will set it to `10.0`.

Would suggest to always add the `^` since composer will still keep the major version the same, while updating to newest minor version other packages support.
Would suggest to always add the `^` since composer will still keep the major version the same, while updating to the newest minor version other packages support.

This will make composer install the most up to date versions possible, taken the constraints and there won't be any conflicts.
This will make composer install the most up-to-date versions possible, taken the constraints and there won't be any conflicts as long as there is a supported version'.

After composer update has been run, it will fix your `composer.json` file from versions that were installed and specified in Your `composer.lock`

## update-minor
## minor-update

This will run `composer update` and after that fix the `composer.json` with the actual versions that were installed.

#### Examples:

Run
```bash
composer minor-update
```
Will run composer update command, and rebuild composer.json file to have up-to-date dependencies with the lock file
12 changes: 7 additions & 5 deletions src/MajorConstraintUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ protected function configure()
'composer-json',
null,
InputOption::VALUE_OPTIONAL,
'Composer json file location'
'Composer json file location',
Factory::getComposerFile()
),
new InputOption(
'composer-lock',
null,
InputOption::VALUE_OPTIONAL,
'Composer lock file location'
'Composer lock file location',
Factory::getLockFile(Factory::getComposerFile())
),
new InputOption(
'constraint',
Expand All @@ -51,8 +53,8 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output): int
{
$composerPath = $input->getOption('composer-json') ?? Factory::getComposerFile();
$composerLock = $input->getOption('composer-lock') ?? Factory::getLockFile($composerPath);
$composerPath = $input->getOption('composer-json');
$composerLock = $input->getOption('composer-lock');

$composerFileContents = file_get_contents($composerPath) ?: throw new \Exception('Couldn\'t open the composer json from ' . $composerPath);

Expand Down Expand Up @@ -94,7 +96,7 @@ function replaceVersions(string $composerContents, array $packageConstraints): s
foreach ($packageConstraints as $constraint => $version) {
$packages = preg_replace(
'@"' . preg_quote($constraint) . '"\s*:\s*"\*"@m',
'"' . preg_quote($constraint) . '": "' . $version . '"',
'"' . $constraint . '": "' . $version . '"',
$packages
);
}
Expand Down
10 changes: 6 additions & 4 deletions src/MinorConstraintUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ protected function configure()
'composer-json',
null,
InputOption::VALUE_OPTIONAL,
'Composer json file location'
'Composer json file location',
Factory::getComposerFile()
),
new InputOption(
'composer-lock',
null,
InputOption::VALUE_OPTIONAL,
'Composer lock file location'
'Composer lock file location',
Factory::getLockFile(Factory::getComposerFile())
),
])
->setHelp(<<<EOT
Expand All @@ -41,8 +43,8 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output): int
{
$composerPath = $input->getOption('composer-json') ?? Factory::getComposerFile();
$composerLock = $input->getOption('composer-lock') ?? Factory::getLockFile($composerPath);
$composerPath = $input->getOption('composer-json');
$composerLock = $input->getOption('composer-lock');

$output->writeln('Launching composer update');
$this->updateComposer();
Expand Down

0 comments on commit e2137fc

Please sign in to comment.