Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions classes/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ class Range {
if (this.set.length === 0) {
this.set = [first]
} 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])) {
this.set = [c]
break
}
// A wildcard covers stable versions, but other sets may admit prereleases.
const any = this.set.findIndex(c => c.length === 1 && isAny(c[0]))
if (any !== -1) {
this.set = this.set.filter((c, i) => i === any || (
!this.includePrerelease && c.some(comp =>
!isAny(comp) && comp.semver.prerelease.length > 0)
))
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/range-exclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// [range, version, options]
// version should not be included by range
module.exports = [
['* || 1.2.3-alpha', '1.2.3-beta'],
['* || 1.2.3-alpha', '1.2.4-alpha'],
['* || >=1.2.3-alpha <1.2.3', '1.2.3-0'],
['* || >=1.2.3-alpha <1.2.3', '1.2.4-alpha'],
['1.0.0 - 2.0.0', '2.2.3'],
['1.2.3+asdf - 2.4.3+asdf', '1.2.3-pre.2'],
['1.2.3+asdf - 2.4.3+asdf', '2.4.3-alpha'],
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/range-include.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ module.exports = [
['', '1.0.0'],
['*', '1.2.3', {}],
['*', 'v1.2.3', { loose: 123 }],
['* || 1.2.3-alpha', '1.2.3-alpha'],
['1.2.3-alpha || *', '1.2.3-alpha'],
['* || 1.2.3-alpha || *', '1.2.3-alpha'],
['x || 1.2.3-alpha', '1.2.3-alpha'],
['>=0.0.0 || 1.2.3-alpha', '1.2.3-alpha'],
['* || >=1.2.3-alpha <1.2.3', '1.2.3-beta'],
['* || 1.2.3-alpha || 2.0.0-beta', '2.0.0-beta'],
['* || 1.2.3-alpha', '0.0.0'],
['* || 1.2.3-alpha', '2.0.0'],
['* || 1.2.3-alpha', '2.0.0-beta', { includePrerelease: true }],
['>=1.0.0', '1.0.0', /asdf/],
['>=1.0.0', '1.0.1', { loose: null }],
['>=1.0.0', '1.1.0', { loose: 0 }],
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/range-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ module.exports = [
['>=*', '*'],
['', '*'],
['*', '*'],
['* || 1.2.3-alpha', '||1.2.3-alpha'],
['1.2.3-alpha || *', '1.2.3-alpha||'],
['* || 1.2.3-alpha || *', '||1.2.3-alpha'],
['* || 1.2.3-alpha || 2.0.0-beta', '||1.2.3-alpha||2.0.0-beta'],
['* || 1.2.3-alpha || 2.0.0', '||1.2.3-alpha'],
['* || >=1.2.3-alpha <1.2.3', '||>=1.2.3-alpha <1.2.3'],
['* || 1.2.3-alpha', '*', { includePrerelease: true }],
['* || 1.2.3', '*'],
['>=1.0.0', '>=1.0.0'],
['>1.0.0', '>1.0.0'],
['<=2.0.0', '<=2.0.0'],
Expand Down