Skip to content

Commit

Permalink
Convert > to >=. Fixes #957.
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Oct 20, 2021
1 parent 26ceb1e commit f773263
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/version-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,17 @@ function upgradeDependencyDeclaration(declaration, latestVersion, options = {})
const operator = uniqueOperators[0] || ''

const hasWildCard = WILDCARDS.some(wildcard => newSemverString.includes(wildcard))
const isLessThan = uniqueOperators[0] === '<' || uniqueOperators[0] === '<='
const isLessThanOrEqual = uniqueOperators[0] === '<' || uniqueOperators[0] === '<='
const isGreaterThan = uniqueOperators[0] === '>'
const isMixed = uniqueOperators.length > 1

// convert versions with </<= or mixed operators into the preferred wildcard
// only do so if the new version does not already contain a wildcard
return !hasWildCard && (isLessThan || isMixed) ?
return !hasWildCard && (isLessThanOrEqual || isMixed) ?
addWildCard(version, options.wildcard) :
operator + version
// convert > to >= since there are likely no available versions > latest
// https://github.com/raineorshine/npm-check-updates/issues/957
(isGreaterThan ? '>=' : operator) + version
}

/**
Expand Down
7 changes: 5 additions & 2 deletions test/version-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ describe('version-util', () => {
versionUtil.upgradeDependencyDeclaration('<1.0', '1.1.0').should.equal('^1.1')
})

it('preserve > and >=', () => {
versionUtil.upgradeDependencyDeclaration('>1.0', '2.0.0').should.equal('>2.0')
it('preserve >=', () => {
versionUtil.upgradeDependencyDeclaration('>=1.0', '2.0.0').should.equal('>=2.0')
})

it('convert > to >=', () => {
versionUtil.upgradeDependencyDeclaration('>1.0.0', '2.0.0').should.equal('>=2.0.0')
})

it('preserve ^ and ~', () => {
versionUtil.upgradeDependencyDeclaration('^1.2.3', '1.2.4').should.equal('^1.2.4')
versionUtil.upgradeDependencyDeclaration('~1.2.3', '1.2.4').should.equal('~1.2.4')
Expand Down

0 comments on commit f773263

Please sign in to comment.