Switch to handrolled semver implementation
This commit is contained in:
parent
2b98b502d6
commit
06d2ae4a7f
8 changed files with 48 additions and 71 deletions
19
src/utils.js
19
src/utils.js
|
@ -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
|
||||
)
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue