composer-semver

module
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2025 License: MIT

README

Composer SemVer

GitHub Release CI License Hire Typist Tech

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.
  This is a wrapper of the Composer\Semver\VersionParser::normalize() method.

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
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

$ bin/composer-semver parse --help
Description:
  Parses a constraint string and strip its ignorable parts.
  This is a wrapper of the Composer\Semver\VersionParser::parseConstraints() method.

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

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.

Installation

brew tap typisttech/tap
brew install typisttech/composer-semver
apt (Debian based distributions, for example: Ubuntu)
# TODO!
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. Alternatively, you can download it 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'

Then, 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

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. Alternatively, you can download it 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'

Then, 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

Alternatives

  • ComVer
    A failed attempt to re-implement composer/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.

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.

Directories

Path Synopsis
normalize/fail command
parse/fail command
parse/success command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL