Switch to handrolled semver implementation
This commit is contained in:
parent
2b98b502d6
commit
06d2ae4a7f
8 changed files with 48 additions and 71 deletions
|
@ -7,7 +7,6 @@ const outlines_lib = require('./outlines')
|
|||
const cases_lib = require('./cases')
|
||||
const pcbs_lib = require('./pcbs')
|
||||
|
||||
const semver = require('semver')
|
||||
const version = require('../package.json').version
|
||||
|
||||
const process = async (raw, debug=false, logger=()=>{}) => {
|
||||
|
@ -34,12 +33,9 @@ const process = async (raw, debug=false, logger=()=>{}) => {
|
|||
|
||||
if (config.meta && config.meta.engine) {
|
||||
logger('Checking compatibility...')
|
||||
const engine = semver.validRange(config.meta.engine)
|
||||
if (!engine) {
|
||||
throw new Error('Invalid config engine declaration!')
|
||||
}
|
||||
if (!semver.satisfies(version, engine)) {
|
||||
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${engine})!`)
|
||||
const engine = u.semver(config.meta.engine, 'config.meta.engine')
|
||||
if (!u.satisfies(version, engine)) {
|
||||
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${config.meta.engine})!`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
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