Skip to content

Commit

Permalink
deps: semver@7.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Apr 17, 2023
1 parent e49844e commit 3fa9542
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 119 deletions.
18 changes: 16 additions & 2 deletions node_modules/semver/bin/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ let rtl = false

let identifier

let identifierBase

const semver = require('../')
const parseOptions = require('../internal/parse-options')

let reverse = false

Expand Down Expand Up @@ -71,6 +74,12 @@ const main = () => {
case '-r': case '--range':
range.push(argv.shift())
break
case '-n':
identifierBase = argv.shift()
if (identifierBase === 'false') {
identifierBase = false
}
break
case '-c': case '--coerce':
coerce = true
break
Expand All @@ -88,7 +97,7 @@ const main = () => {
}
}

options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
options = parseOptions({ loose, includePrerelease, rtl })

versions = versions.map((v) => {
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
Expand Down Expand Up @@ -127,7 +136,7 @@ const success = () => {
}).map((v) => {
return semver.clean(v, options)
}).map((v) => {
return inc ? semver.inc(v, inc, options, identifier) : v
return inc ? semver.inc(v, inc, options, identifier, identifierBase) : v
}).forEach((v, i, _) => {
console.log(v)
})
Expand Down Expand Up @@ -172,6 +181,11 @@ Options:
--ltr
Coerce version strings left to right (default)
-n <base>
Base number to be used for the prerelease identifier.
Can be either 0 or 1, or false to omit the number altogether.
Defaults to 0.
Program exits successfully if any valid version satisfies
all supplied ranges, and prints all satisfying versions.
Expand Down
70 changes: 37 additions & 33 deletions node_modules/semver/classes/comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ class Comparator {
throw new TypeError('a Comparator is required')
}

if (!options || typeof options !== 'object') {
options = {
loose: !!options,
includePrerelease: false,
}
}

if (this.operator === '') {
if (this.value === '') {
return true
Expand All @@ -97,32 +90,43 @@ class Comparator {
return new Range(this.value, options).test(comp.semver)
}

const sameDirectionIncreasing =
(this.operator === '>=' || this.operator === '>') &&
(comp.operator === '>=' || comp.operator === '>')
const sameDirectionDecreasing =
(this.operator === '<=' || this.operator === '<') &&
(comp.operator === '<=' || comp.operator === '<')
const sameSemVer = this.semver.version === comp.semver.version
const differentDirectionsInclusive =
(this.operator === '>=' || this.operator === '<=') &&
(comp.operator === '>=' || comp.operator === '<=')
const oppositeDirectionsLessThan =
cmp(this.semver, '<', comp.semver, options) &&
(this.operator === '>=' || this.operator === '>') &&
(comp.operator === '<=' || comp.operator === '<')
const oppositeDirectionsGreaterThan =
cmp(this.semver, '>', comp.semver, options) &&
(this.operator === '<=' || this.operator === '<') &&
(comp.operator === '>=' || comp.operator === '>')

return (
sameDirectionIncreasing ||
sameDirectionDecreasing ||
(sameSemVer && differentDirectionsInclusive) ||
oppositeDirectionsLessThan ||
oppositeDirectionsGreaterThan
)
options = parseOptions(options)

// Special cases where nothing can possibly be lower
if (options.includePrerelease &&
(this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
return false
}
if (!options.includePrerelease &&
(this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
return false
}

// Same direction increasing (> or >=)
if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
return true
}
// Same direction decreasing (< or <=)
if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
return true
}
// same SemVer and both sides are inclusive (<= or >=)
if (
(this.semver.version === comp.semver.version) &&
this.operator.includes('=') && comp.operator.includes('=')) {
return true
}
// opposite directions less than
if (cmp(this.semver, '<', comp.semver, options) &&
this.operator.startsWith('>') && comp.operator.startsWith('<')) {
return true
}
// opposite directions greater than
if (cmp(this.semver, '>', comp.semver, options) &&
this.operator.startsWith('<') && comp.operator.startsWith('>')) {
return true
}
return false
}
}

Expand Down
8 changes: 6 additions & 2 deletions node_modules/semver/classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class Range {

// memoize range parsing for performance.
// this is a very hot path, and fully deterministic.
const memoOpts = Object.keys(this.options).join(',')
const memoKey = `parseRange:${memoOpts}:${range}`
const memoOpts =
(this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
(this.options.loose && FLAG_LOOSE)
const memoKey = memoOpts + ':' + range
const cached = cache.get(memoKey)
if (cached) {
return cached
Expand Down Expand Up @@ -190,6 +192,7 @@ class Range {
return false
}
}

module.exports = Range

const LRU = require('lru-cache')
Expand All @@ -206,6 +209,7 @@ const {
tildeTrimReplace,
caretTrimReplace,
} = require('../internal/re')
const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = require('../internal/constants')

const isNullSet = c => c.value === '<0.0.0-0'
const isAny = c => c.value === ''
Expand Down
41 changes: 27 additions & 14 deletions node_modules/semver/classes/semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SemVer {
version = version.version
}
} else if (typeof version !== 'string') {
throw new TypeError(`Invalid Version: ${version}`)
throw new TypeError(`Invalid Version: ${require('util').inspect(version)}`)
}

if (version.length > MAX_LENGTH) {
Expand Down Expand Up @@ -175,36 +175,36 @@ class SemVer {

// preminor will bump the version up to the next minor release, and immediately
// down to pre-release. premajor and prepatch work the same way.
inc (release, identifier) {
inc (release, identifier, identifierBase) {
switch (release) {
case 'premajor':
this.prerelease.length = 0
this.patch = 0
this.minor = 0
this.major++
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break
case 'preminor':
this.prerelease.length = 0
this.patch = 0
this.minor++
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break
case 'prepatch':
// If this is already a prerelease, it will bump to the next version
// drop any prereleases that might already exist, since they are not
// relevant at this point.
this.prerelease.length = 0
this.inc('patch', identifier)
this.inc('pre', identifier)
this.inc('patch', identifier, identifierBase)
this.inc('pre', identifier, identifierBase)
break
// If the input is a non-prerelease version, this acts the same as
// prepatch.
case 'prerelease':
if (this.prerelease.length === 0) {
this.inc('patch', identifier)
this.inc('patch', identifier, identifierBase)
}
this.inc('pre', identifier)
this.inc('pre', identifier, identifierBase)
break

case 'major':
Expand Down Expand Up @@ -246,9 +246,15 @@ class SemVer {
break
// This probably shouldn't be used publicly.
// 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
case 'pre':
case 'pre': {
const base = Number(identifierBase) ? 1 : 0

if (!identifier && identifierBase === false) {
throw new Error('invalid increment argument: identifier is empty')
}

if (this.prerelease.length === 0) {
this.prerelease = [0]
this.prerelease = [base]
} else {
let i = this.prerelease.length
while (--i >= 0) {
Expand All @@ -259,22 +265,29 @@ class SemVer {
}
if (i === -1) {
// didn't increment anything
this.prerelease.push(0)
if (identifier === this.prerelease.join('.') && identifierBase === false) {
throw new Error('invalid increment argument: identifier already exists')
}
this.prerelease.push(base)
}
}
if (identifier) {
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
let prerelease = [identifier, base]
if (identifierBase === false) {
prerelease = [identifier]
}
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
if (isNaN(this.prerelease[1])) {
this.prerelease = [identifier, 0]
this.prerelease = prerelease
}
} else {
this.prerelease = [identifier, 0]
this.prerelease = prerelease
}
}
break

}
default:
throw new Error(`invalid increment argument: ${release}`)
}
Expand Down
65 changes: 48 additions & 17 deletions node_modules/semver/functions/diff.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
const parse = require('./parse')
const eq = require('./eq')
const parse = require('./parse.js')

const diff = (version1, version2) => {
if (eq(version1, version2)) {
const v1 = parse(version1, null, true)
const v2 = parse(version2, null, true)
const comparison = v1.compare(v2)

if (comparison === 0) {
return null
} else {
const v1 = parse(version1)
const v2 = parse(version2)
const hasPre = v1.prerelease.length || v2.prerelease.length
const prefix = hasPre ? 'pre' : ''
const defaultResult = hasPre ? 'prerelease' : ''
for (const key in v1) {
if (key === 'major' || key === 'minor' || key === 'patch') {
if (v1[key] !== v2[key]) {
return prefix + key
}
}
}
return defaultResult // may be undefined
}

const v1Higher = comparison > 0
const highVersion = v1Higher ? v1 : v2
const lowVersion = v1Higher ? v2 : v1
const highHasPre = !!highVersion.prerelease.length

// add the `pre` prefix if we are going to a prerelease version
const prefix = highHasPre ? 'pre' : ''

if (v1.major !== v2.major) {
return prefix + 'major'
}

if (v1.minor !== v2.minor) {
return prefix + 'minor'
}

if (v1.patch !== v2.patch) {
return prefix + 'patch'
}

// at this point we know stable versions match but overall versions are not equal,
// so either they are both prereleases, or the lower version is a prerelease

if (highHasPre) {
// high and low are preleases
return 'prerelease'
}

if (lowVersion.patch) {
// anything higher than a patch bump would result in the wrong version
return 'patch'
}

if (lowVersion.minor) {
// anything higher than a minor bump would result in the wrong version
return 'minor'
}

// bumping major/minor/patch all have same result
return 'major'
}

module.exports = diff
5 changes: 3 additions & 2 deletions node_modules/semver/functions/inc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const SemVer = require('../classes/semver')

const inc = (version, release, options, identifier) => {
const inc = (version, release, options, identifier, identifierBase) => {
if (typeof (options) === 'string') {
identifierBase = identifier
identifier = options
options = undefined
}
Expand All @@ -10,7 +11,7 @@ const inc = (version, release, options, identifier) => {
return new SemVer(
version instanceof SemVer ? version.version : version,
options
).inc(release, identifier).version
).inc(release, identifier, identifierBase).version
} catch (er) {
return null
}
Expand Down
Loading

0 comments on commit 3fa9542

Please sign in to comment.