Static linked CLI wrapper for composer/semver
.
Parsing and validating versions exactly like Composer does without installing PHP.
Built with ♥ by Typist Tech
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.
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.
$ composer-semver --version
For shell completions, follow the instructions from:
$ composer-semver completion --help
If you installed Composer SemVer
via Homebrew, completion scripts are managed by
Homebrew. Read more at https://docs.brew.sh/Shell-Completion
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/
Which version numbering system does Composer itself use?
Composer uses Semantic Versioning (aka SemVer) 2.0.0.
-- Composer FAQ
Under the hood, Composer uses composer/semver
to parse and validate
versions.
Despite the lie
on Composer FAQ,
the fragmentary documentation, and the deceitful package name
composer/semver
, 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/
brew tap typisttech/tap
brew install typisttech/tap/composer-semver
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.
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
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
- ComVer
A failed attempt to re-implementcomposer/semver
in Go. It only supports a subset of Composer versioning.
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.
This project is a free software distributed under the terms of the MIT license. For the full license, see LICENSE.
Feedbacks / bug reports / pull requests are welcome.