typisttech / composer-semver
Static linked CLI wrapper for composer/semver. Parsing and validating versions exactly like Composer does without installing PHP.
Fund package maintenance!
tangrufus
typist.tech/donation
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Go
Type:project
pkg:composer/typisttech/composer-semver
Requires
- php: ~8.4.13
- composer-runtime-api: ^2.2
- composer/semver: ^3.4
- symfony/console: ^7.3
- symfony/polyfill-iconv: ^1.33
Requires (Dev)
README
Composer SemVer
Static linked CLI wrapper for composer/semver
.
Parsing and validating versions exactly like Composer
does without installing PHP.
Built with ♥ by Typist Tech
Usage
Normalize Versions
Normalizes a version string to be able to perform comparisons on it.
This is a wrapper of the Composer\Semver\VersionParser::normalize()
method.
$ composer-semver normalize '1.2-p.5+foo' 1.2.0.0-patch5 # Status code 0 means valid versions $ echo $? 0 $ composer-semver normalize 'not-a-version' [ERROR] Invalid version string "not-a-version" # Non-zero status codes mean invalid versions $ echo $? 1 $ composer-semver normalize --help Description: Normalizes a version string to be able to perform comparisons on it Usage: normalize [options] [--] <version> Arguments: version Options: --full-version=FULL-VERSION Complete version string to give more context. -h, --help Display help for the given command. When no command is given display help for the list command --silent Do not output any message -q, --quiet Only errors are displayed. All other output is suppressed -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: This is a wrapper of the Composer\Semver\VersionParser::normalize() method.
Parse Constraints
Parses a constraint string and strip its ignorable parts.
This is a wrapper of the Composer\Semver\VersionParser::parseConstraints()
method.
$ composer-semver parse '>=1.2 <2.0 || ~3.4.5 || ^6.7' [[>= 1.2.0.0-dev < 2.0.0.0-dev] || [>= 3.4.5.0-dev < 3.5.0.0-dev] || [>= 6.7.0.0-dev < 7.0.0.0-dev]] # Status code 0 means valid constraints $ echo $? 0 $ composer-semver parse '~>1.2' [ERROR] Could not parse version constraint ~>1.2: Invalid operator "~>", you probably meant to use the "~" operator # Non-zero status codes mean invalid constraints $ echo $? 1 $ composer-semver parse --help Description: Parses a constraint string and strip its ignorable parts Usage: parse <constraints> Arguments: constraints Options: -h, --help Display help for the given command. When no command is given display help for the list command --silent Do not output any message -q, --quiet Only errors are displayed. All other output is suppressed -V, --version Display this application version --ansi|--no-ansi Force (or disable --no-ansi) ANSI output -n, --no-interaction Do not ask any interactive question -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: This is a wrapper of the Composer\Semver\VersionParser::parseConstraints() method.
Print Bundled PHP and composer/semver
Versions
$ composer-semver --version
Tip
Hire Tang Rufus!
I am looking for my next role, freelance or full-time. If you find this tool useful, I can build you more weird stuffs like this. Let's talk if you are hiring PHP / Ruby / Go developers.
Contact me at https://typist.tech/contact/
Why
Under the hood, Composer uses
composer/semver
package to parse and validate versions.
Despite the name composer/semver
and
the incompleted documentation, Composer implements only a subset
of Semantic Versioning specification while supports some uncommon versioning schemes.
Working with Composer packages versions without composer/semver
is a bit tricky.
"A bit tricky" is an understatement.
Version | Validity |
---|---|
1.2.3 |
✅ Valid. |
1.2.3.4 |
✅ Valid. But not SemVer compliant. |
1.0.0-a |
✅ Valid. |
1.0.0-b |
✅ Valid. |
1.0.0-c |
❌ Invalid. But SemVer compliant. Composer only accepts a limited sets of pre-release versions. |
99999 |
✅ Valid. Composer normalize it to 99999.0.0.0 . |
100000.0.0 |
✅ Valid |
100000.0.0.0 |
❌ Invalid. Starting from 100000 , Composer treats it as CalVer which cannot have 4 bits. |
2010-01-02 |
✅ Valid. |
2010-01-02-10-20-30.5 |
✅ Valid. |
20100102-203040 |
✅ Valid. |
20100102.0.3.4 |
❌ Invalid. CalVer cannot have 4 bits. |
2023013.0.0 |
❌ Invalid. YYYYMMD is a bad CalVer major version. |
202301311.0.0 |
❌ Invalid. YYYYMMDDh is a bad CalVer major version. |
20230131000.0.0 |
❌ Invalid.YYYYMMDDhhm is a bad CalVer major version. |
2023013100000.0.0 |
❌ Invalid. YYYYMMDDhhmmX is a bad CalVer major version. |
000.001.003.004 |
✅ Valid. Composer normalizes it to 000.001.003.004 . The leading zeros are significant and cannot be ignored. |
0700 |
✅ Valid. Composer normalizes it to 0700.0.0.0 . The leading zero is significant and cannot be ignored. |
1.00.000 |
✅ Valid. Composer normalizes it to 1.00.000.0 . All the zeroes are significant and cannot be ignored. |
Composer SemVer
wraps composer/semver
and the PHP runtime as a static linked CLI tool,
so you can work with the package versions exactly like Composer does without installing PHP.
Tip
Hire Tang Rufus!
There is no need to understand any of these quirks. Let me handle them for you. I am seeking my next job, freelance or full-time.
If you are hiring PHP / Ruby / Go developers, contact me at https://typist.tech/contact/
Installation
Homebrew (macOS / Linux) (Recommended)
brew tap typisttech/tap brew install typisttech/tap/composer-semver
apt-get
(Debian based distributions, for example: Ubuntu)
curl -1sLf 'https://dl.cloudsmith.io/public/typisttech/oss/setup.deb.sh' | sudo -E bash sudo apt-get install composer-version
Instead of the automatic setup script, you can manually configure the repository with the instructsions on Cloudsmith.
Manual .deb
(Debian based distributions, for example: Ubuntu)
Warning
If you install the .deb
file manually, you have to take care of updating it by yourself.
Download the latest .deb
file from GitHub Releases, or via gh
:
# Both arm64 (aarch64) and amd64 (x86_64) architectures are available. gh release download --repo 'typisttech/composer-semver' --pattern 'composer-semver_Linux_arm64.deb'
Optionally, verify the .deb
file:
gh attestation verify --repo 'typisttech/composer-semver' 'composer-semver_Linux_arm64.deb'
Finally, install the package:
sudo dpkg -i composer-semver_Linux_arm64.deb
For shell completions, follow the instructions from:
composer-semver completion --help
Manual Binary
Warning
If you install the binary manually, you have to take care of updating it by yourself.
Download the latest .tar.gz
file from GitHub Releases, or via gh
:
# Both Darwin (macOS) and Linux operating systems are available. # Both arm64 (aarch64) and amd64 (x86_64) architectures are available. gh release download --repo 'typisttech/composer-semver' --pattern 'composer-semver_Darwin_arm64.tar.gz'
Optionally, verify the .tar.gz
file:
gh attestation verify --repo 'typisttech/composer-semver' 'composer-semver_Darwin_arm64.tar.gz'
Finally, unarchive and move the binary into $PATH
:
tar -xvf 'composer-semver_Darwin_arm64.tar.gz' # Or, move it to any directory under `$PATH` mv composer-semver /usr/local/bin
For shell completions, follow the instructions from:
composer-semver completion --help
Alternatives
- ComVer
A failed attempt to re-implementcomposer/semver
in Go. It only supports a subset of Composer versioning.
Credits
Composer SemVer
is a Typist Tech
project and maintained by Tang Rufus, freelance
developer for hire.
Full list of contributors can be found on GitHub.
Copyright and License
This project is a free software distributed under the terms of the MIT license. For the full license, see LICENSE.
Contribute
Feedbacks / bug reports / pull requests are welcome.