Switch to handrolled semver implementation

This commit is contained in:
Bán Dénes 2022-01-23 21:45:09 +01:00
parent 2b98b502d6
commit 06d2ae4a7f
8 changed files with 48 additions and 71 deletions

View file

@ -108,4 +108,23 @@ exports.stack = (a, b) => {
a, b
}
}
}
const semver = exports.semver = (str, name='') => {
const main = str.split('-')[0]
if (/^\d+\.\d+\.\d+$/.test(main)) {
const parts = main.split('.').map(v => parseInt(v))
return {major: parts[0], minor: parts[1], patch: parts[2]}
} else throw new Error(`Invalid semver "${str}" at ${name}!`)
}
const satisfies = exports.satisfies = (current, expected) => {
if (current.major === undefined) current = semver(current)
if (expected.major === undefined) expected = semver(expected)
return current.major === expected.major && (
current.minor > expected.minor || (
current.minor === expected.minor &&
current.patch >= expected.patch
)
)
}