diff --git a/classes/range.js b/classes/range.js index a7d6556f..baf64012 100644 --- a/classes/range.js +++ b/classes/range.js @@ -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) + )) } } } diff --git a/test/fixtures/range-exclude.js b/test/fixtures/range-exclude.js index a4b92d1d..13fb7352 100644 --- a/test/fixtures/range-exclude.js +++ b/test/fixtures/range-exclude.js @@ -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'], diff --git a/test/fixtures/range-include.js b/test/fixtures/range-include.js index 3df851b8..0b12374d 100644 --- a/test/fixtures/range-include.js +++ b/test/fixtures/range-include.js @@ -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 }], diff --git a/test/fixtures/range-parse.js b/test/fixtures/range-parse.js index 1c69c96d..c7728ea9 100644 --- a/test/fixtures/range-parse.js +++ b/test/fixtures/range-parse.js @@ -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'],