Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 6, 2022
1 parent 38029ed commit e57353c
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 517 deletions.
25 changes: 17 additions & 8 deletions node_modules/semver/bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const semver = require('../')

let reverse = false

const options = {}
let options = {}

const main = () => {
if (!argv.length) return help()
if (!argv.length) {
return help()
}
while (argv.length) {
let a = argv.shift()
const indexOfEqualSign = a.indexOf('=')
Expand Down Expand Up @@ -85,26 +87,31 @@ const main = () => {
}
}

const options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }

versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
}).filter((v) => {
return semver.valid(v)
})
if (!versions.length) return fail()
if (inc && (versions.length !== 1 || range.length)) { return failInc() }
if (!versions.length) {
return fail()
}
if (inc && (versions.length !== 1 || range.length)) {
return failInc()
}

for (let i = 0, l = range.length; i < l; i++) {
versions = versions.filter((v) => {
return semver.satisfies(v, range[i], options)
})
if (!versions.length) return fail()
if (!versions.length) {
return fail()
}
}
return success(versions)
}


const failInc = () => {
console.error('--inc can only be used on a single version with no range')
fail()
Expand All @@ -120,7 +127,9 @@ const success = () => {
return semver.clean(v, options)
}).map((v) => {
return inc ? semver.inc(v, inc, options, identifier) : v
}).forEach((v, i, _) => { console.log(v) })
}).forEach((v, i, _) => {
console.log(v)
})
}

const help = () => console.log(
Expand Down
5 changes: 3 additions & 2 deletions node_modules/semver/classes/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Comparator {
static get ANY () {
return ANY
}

constructor (comp, options) {
options = parseOptions(options)

Expand Down Expand Up @@ -80,7 +81,7 @@ class Comparator {
if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false
includePrerelease: false,
}
}

Expand Down Expand Up @@ -128,7 +129,7 @@ class Comparator {
module.exports = Comparator

const parseOptions = require('../internal/parse-options')
const {re, t} = require('../internal/re')
const { re, t } = require('../internal/re')
const cmp = require('../functions/cmp')
const debug = require('../internal/debug')
const SemVer = require('./semver')
Expand Down
2 changes: 1 addition & 1 deletion node_modules/semver/classes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
SemVer: require('./semver.js'),
Range: require('./range.js'),
Comparator: require('./comparator.js')
Comparator: require('./comparator.js'),
}
53 changes: 31 additions & 22 deletions node_modules/semver/classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Range {
// First, split based on boolean or ||
this.raw = range
this.set = range
.split(/\s*\|\|\s*/)
.split('||')
// map the range to a 2d array of comparators
.map(range => this.parseRange(range.trim()))
.map(r => this.parseRange(r.trim()))
// throw out any comparator lists that are empty
// this generally means that it was not a valid range, which is allowed
// in loose mode, but will still throw if the WHOLE range is invalid.
Expand All @@ -46,9 +46,9 @@ class Range {
// keep the first one, in case they're all null sets
const first = this.set[0]
this.set = this.set.filter(c => !isNullSet(c[0]))
if (this.set.length === 0)
if (this.set.length === 0) {
this.set = [first]
else if (this.set.length > 1) {
} else if (this.set.length > 1) {
// if we have any that are *, then the range is just *
for (const c of this.set) {
if (c.length === 1 && isAny(c[0])) {
Expand Down Expand Up @@ -84,8 +84,9 @@ class Range {
const memoOpts = Object.keys(this.options).join(',')
const memoKey = `parseRange:${memoOpts}:${range}`
const cached = cache.get(memoKey)
if (cached)
if (cached) {
return cached
}

const loose = this.options.loose
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
Expand All @@ -94,7 +95,7 @@ class Range {
debug('hyphen replace', range)
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
debug('comparator trim', range, re[t.COMPARATORTRIM])
debug('comparator trim', range)

// `~ 1.2.3` => `~1.2.3`
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
Expand All @@ -108,30 +109,37 @@ class Range {
// At this point, the range is completely trimmed and
// ready to be split into comparators.

const compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR]
const rangeList = range
let rangeList = range
.split(' ')
.map(comp => parseComparator(comp, this.options))
.join(' ')
.split(/\s+/)
// >=0.0.0 is equivalent to *
.map(comp => replaceGTE0(comp, this.options))

if (loose) {
// in loose mode, throw out any that are not valid comparators
.filter(this.options.loose ? comp => !!comp.match(compRe) : () => true)
.map(comp => new Comparator(comp, this.options))
rangeList = rangeList.filter(comp => {
debug('loose invalid filter', comp, this.options)
return !!comp.match(re[t.COMPARATORLOOSE])
})
}
debug('range list', rangeList)

// if any comparators are the null set, then replace with JUST null set
// if more than one comparator, remove any * comparators
// also, don't include the same comparator more than once
const l = rangeList.length
const rangeMap = new Map()
for (const comp of rangeList) {
if (isNullSet(comp))
const comparators = rangeList.map(comp => new Comparator(comp, this.options))
for (const comp of comparators) {
if (isNullSet(comp)) {
return [comp]
}
rangeMap.set(comp.value, comp)
}
if (rangeMap.size > 1 && rangeMap.has(''))
if (rangeMap.size > 1 && rangeMap.has('')) {
rangeMap.delete('')
}

const result = [...rangeMap.values()]
cache.set(memoKey, result)
Expand Down Expand Up @@ -196,7 +204,7 @@ const {
t,
comparatorTrimReplace,
tildeTrimReplace,
caretTrimReplace
caretTrimReplace,
} = require('../internal/re')

const isNullSet = c => c.value === '<0.0.0-0'
Expand Down Expand Up @@ -245,8 +253,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
const replaceTildes = (comp, options) =>
comp.trim().split(/\s+/).map((comp) => {
return replaceTilde(comp, options)
comp.trim().split(/\s+/).map((c) => {
return replaceTilde(c, options)
}).join(' ')

const replaceTilde = (comp, options) => {
Expand Down Expand Up @@ -284,8 +292,8 @@ const replaceTilde = (comp, options) => {
// ^1.2.3 --> >=1.2.3 <2.0.0-0
// ^1.2.0 --> >=1.2.0 <2.0.0-0
const replaceCarets = (comp, options) =>
comp.trim().split(/\s+/).map((comp) => {
return replaceCaret(comp, options)
comp.trim().split(/\s+/).map((c) => {
return replaceCaret(c, options)
}).join(' ')

const replaceCaret = (comp, options) => {
Expand Down Expand Up @@ -343,8 +351,8 @@ const replaceCaret = (comp, options) => {

const replaceXRanges = (comp, options) => {
debug('replaceXRanges', comp, options)
return comp.split(/\s+/).map((comp) => {
return replaceXRange(comp, options)
return comp.split(/\s+/).map((c) => {
return replaceXRange(c, options)
}).join(' ')
}

Expand Down Expand Up @@ -405,8 +413,9 @@ const replaceXRange = (comp, options) => {
}
}

if (gtlt === '<')
if (gtlt === '<') {
pr = '-0'
}

ret = `${gtlt + M}.${m}.${p}${pr}`
} else if (xm) {
Expand Down
12 changes: 8 additions & 4 deletions node_modules/semver/functions/cmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ const lte = require('./lte')
const cmp = (a, op, b, loose) => {
switch (op) {
case '===':
if (typeof a === 'object')
if (typeof a === 'object') {
a = a.version
if (typeof b === 'object')
}
if (typeof b === 'object') {
b = b.version
}
return a === b

case '!==':
if (typeof a === 'object')
if (typeof a === 'object') {
a = a.version
if (typeof b === 'object')
}
if (typeof b === 'object') {
b = b.version
}
return a !== b

case '':
Expand Down
5 changes: 3 additions & 2 deletions node_modules/semver/functions/coerce.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const SemVer = require('../classes/semver')
const parse = require('./parse')
const {re, t} = require('../internal/re')
const { re, t } = require('../internal/re')

const coerce = (version, options) => {
if (version instanceof SemVer) {
Expand Down Expand Up @@ -43,8 +43,9 @@ const coerce = (version, options) => {
re[t.COERCERTL].lastIndex = -1
}

if (match === null)
if (match === null) {
return null
}

return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
}
Expand Down
2 changes: 1 addition & 1 deletion node_modules/semver/functions/parse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {MAX_LENGTH} = require('../internal/constants')
const { MAX_LENGTH } = require('../internal/constants')
const { re, t } = require('../internal/re')
const SemVer = require('../classes/semver')

Expand Down
4 changes: 2 additions & 2 deletions node_modules/semver/internal/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const SEMVER_SPEC_VERSION = '2.0.0'

const MAX_LENGTH = 256
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
/* istanbul ignore next */ 9007199254740991
/* istanbul ignore next */ 9007199254740991

// Max safe segment length for coercion.
const MAX_SAFE_COMPONENT_LENGTH = 16
Expand All @@ -13,5 +13,5 @@ module.exports = {
SEMVER_SPEC_VERSION,
MAX_LENGTH,
MAX_SAFE_INTEGER,
MAX_SAFE_COMPONENT_LENGTH
MAX_SAFE_COMPONENT_LENGTH,
}
2 changes: 1 addition & 1 deletion node_modules/semver/internal/identifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a)

module.exports = {
compareIdentifiers,
rcompareIdentifiers
rcompareIdentifiers,
}
6 changes: 3 additions & 3 deletions node_modules/semver/internal/parse-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const opts = ['includePrerelease', 'loose', 'rtl']
const parseOptions = options =>
!options ? {}
: typeof options !== 'object' ? { loose: true }
: opts.filter(k => options[k]).reduce((options, k) => {
options[k] = true
return options
: opts.filter(k => options[k]).reduce((o, k) => {
o[k] = true
return o
}, {})
module.exports = parseOptions
6 changes: 3 additions & 3 deletions node_modules/semver/internal/re.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let R = 0

const createToken = (name, value, isGlobal) => {
const index = R++
debug(index, value)
debug(name, index, value)
t[name] = index
src[index] = value
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
Expand Down Expand Up @@ -178,5 +178,5 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
// Star ranges basically just allow anything at all.
createToken('STAR', '(<|>)?=?\\s*\\*')
// >=0.0.0 is like a star
createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$')
createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$')
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$')
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$')
15 changes: 0 additions & 15 deletions node_modules/semver/node_modules/lru-cache/LICENSE

This file was deleted.

Loading

0 comments on commit e57353c

Please sign in to comment.