Uncertain Ordering of Pre‑Release Identifiers in sema Range Satisfaction
0 reputation · 17 Nov 2021, 18:29 UTC
0 reputation · 17 Nov 2021, 18:29 UTC
Clarify how the sema library orders pre‑release versions when evaluating a Range, particularly for constraints such as '>=1.2.3' or '>=1.2.3 <2.0.0'.
sema parses semantic version strings into major, minor, patch, prerelease, and build components. Build metadata is ignored per Semantic Versioning 2.0.0. The library treats pre‑release versions as lower than their corresponding release, but the ordering of multiple prerelease identifiers is not explicitly documented in the API. Wildcard '*' is unsupported and causes a parse error.
When a Range contains a lower bound that is a release version, it is unclear whether a pre‑release that precedes the bound satisfies the constraint. Additionally, the relative ordering of distinct pre‑release identifiers (e.g., alpha.1 vs alpha.2) is not defined in the current documentation.
35275 reputation · 17 Nov 2021, 20:46 UTC
1.2.3-alpha.1 does not satisfy >=1.2.3 because every pre‑release has lower precedence than its associated release per SemVer 2.0.0.1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-rc.1 < 1.0.0.+) is parsed but ignored for precedence.>=1.2.3 <2.0.0 matches 1.2.3, 1.2.4-beta.1, 1.9.0, but excludes 1.2.3-alpha.1.>=1.2.3-alpha.1), then 1.2.3-alpha.1 and higher pre‑releases of 1.2.3 satisfy the range; 1.2.3-alpha.0 does not.* in a version string throws a synchronous parse error.const sema = require('sema');
console.log(sema.satisfies('1.2.3-alpha.1', '>=1.2.3')); // false
console.log(sema.gt('1.0.0-alpha.1', '1.0.0-alpha')); // true
console.log(require('sema/package.json').version); // confirm ≥1.0.0
sema (ehmicky/sema) version ≥ 1.0.0. Older versions or differently named libraries (Go, Rust crates) may deviate.Alpha < alpha.Which exact sema version is installed in your project? Run npm ls sema or check package-lock.json. If it is below 1.0.0, the precedence rules may differ and the above guarantees do not apply.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.