kubawerlos / composer-require-better
Provides a command to require package with constraint having patch version
Installs: 97
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:composer-plugin
Requires
- php: ^7.4 || ^8.0
- composer-plugin-api: ^2.0.0
Requires (Dev)
- composer/composer: ^2.0.0
- phpunit/phpunit: ^9.5.20
This package is auto-updated.
Last update: 2023-05-05 22:06:52 UTC
README
This repository is abandoned,
use composer bump
instead.
Plugin for Composer to require package with constraint having patch version.
Installation
composer global require kubawerlos/composer-require-better
Usage
composer rb vendor/package
All Composer's require options (except prefer-lowest
and prefer-stable
) can be used.
Motivation
Let's assume we want to install package acme-corporation/adding-machine
for our project and it has versions 1.0.0
and 1.0.1
released. Usually, we run:
composer require acme-corporation/adding-machine
We will have the latest version installed (1.0.1
) and constraint ^1.0
added to composer.json
. The constraint means all version from 1.0.0
, but lower than 2.0.0
are allowed.
This can result in some problems in the future:
- If we would want to install another package, that allows
acme-corporation/adding-machine
only in version1.0.0
(or has a conflict withacme-corporation/adding-machine
version1.0.1
) it would result withacme-corporation/adding-machine
being downgraded to version1.0.0
- we can easily miss that downgrade (as it will be one line in the console) - what if1.0.1
fixes critical bug for us? - If we run
composer update --prefer-lowest
(quite often practice when developing a library) we would end up withacme-corporation/adding-machine
in version1.0.0
. - Command
composer update
could take a long time to run when having many packages with many allowed versions (e.g. Symfony 3 LTS has current version3.4.38
, so constraint^3.4
is allowing 39 versions - from3.4.0
to3.4.38
).
So instead we can run:
composer rb acme-corporation/adding-machine
We will have the latest version installed - the same as with require
command, but the constraint added to composer.json
will be ^1.0.1
- it would mean all version from 1.0.0
, but lower than 2.0.0
are allowed.
What would that change?
- If we would want to install the package that previously downgraded
acme-corporation/adding-machine
we would see an error and would have to make a decision - is this acceptable to us or we cannot allow it? - Running
composer update --prefer-lowest
would do nothing for the package as now installed version is the lowest allowed with the constraint. - Command
composer update
would work faster - mentioned Symfony 3 LST constraint would be^3.4.38
, so it would allow only single version, not 39 versions. - In
composer.json
we now have the installed version as the constraint, so we don't have to check withcomposer show
or incomposer.lock
(if we even have it in the repository) which version is used in the project.