diff options
Diffstat (limited to 'node_modules/semver')
-rw-r--r-- | node_modules/semver/README.md | 90 | ||||
-rw-r--r-- | node_modules/semver/package.json | 6 | ||||
-rw-r--r-- | node_modules/semver/semver.js | 119 |
3 files changed, 162 insertions, 53 deletions
diff --git a/node_modules/semver/README.md b/node_modules/semver/README.md index cbd956549..fd5151ab3 100644 --- a/node_modules/semver/README.md +++ b/node_modules/semver/README.md @@ -1,55 +1,65 @@ semver(1) -- The semantic versioner for npm =========================================== +## Install + +```bash +npm install --save semver +```` + ## Usage - $ npm install semver - $ node - var semver = require('semver') +As a node module: - semver.valid('1.2.3') // '1.2.3' - semver.valid('a.b.c') // null - semver.clean(' =v1.2.3 ') // '1.2.3' - semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true - semver.gt('1.2.3', '9.8.7') // false - semver.lt('1.2.3', '9.8.7') // true +```js +const semver = require('semver') + +semver.valid('1.2.3') // '1.2.3' +semver.valid('a.b.c') // null +semver.clean(' =v1.2.3 ') // '1.2.3' +semver.satisfies('1.2.3', '1.x || >=2.5.0 || 5.0.0 - 7.2.3') // true +semver.gt('1.2.3', '9.8.7') // false +semver.lt('1.2.3', '9.8.7') // true +``` As a command-line utility: - $ semver -h +``` +$ semver -h - SemVer 5.1.0 +SemVer 5.3.0 - A JavaScript implementation of the http://semver.org/ specification - Copyright Isaac Z. Schlueter +A JavaScript implementation of the http://semver.org/ specification +Copyright Isaac Z. Schlueter - Usage: semver [options] <version> [<version> [...]] - Prints valid versions sorted by SemVer precedence +Usage: semver [options] <version> [<version> [...]] +Prints valid versions sorted by SemVer precedence - Options: - -r --range <range> - Print versions that match the specified range. +Options: +-r --range <range> + Print versions that match the specified range. - -i --increment [<level>] - Increment a version by the specified level. Level can - be one of: major, minor, patch, premajor, preminor, - prepatch, or prerelease. Default level is 'patch'. - Only one version may be specified. +-i --increment [<level>] + Increment a version by the specified level. Level can + be one of: major, minor, patch, premajor, preminor, + prepatch, or prerelease. Default level is 'patch'. + Only one version may be specified. - --preid <identifier> - Identifier to be used to prefix premajor, preminor, - prepatch or prerelease version increments. +--preid <identifier> + Identifier to be used to prefix premajor, preminor, + prepatch or prerelease version increments. - -l --loose - Interpret versions and ranges loosely +-l --loose + Interpret versions and ranges loosely - Program exits successfully if any valid version satisfies - all supplied ranges, and prints all satisfying versions. +Program exits successfully if any valid version satisfies +all supplied ranges, and prints all satisfying versions. - If no satisfying versions are found, then exits failure. +If no satisfying versions are found, then exits failure. - Versions are printed in ascending order, so supplying - multiple versions to the utility will just sort them. +Versions are printed in ascending order, so supplying +multiple versions to the utility will just sort them. +``` ## Versions @@ -126,20 +136,20 @@ The method `.inc` takes an additional `identifier` string argument that will append the value of the string as a prerelease identifier: ```javascript -> semver.inc('1.2.3', 'prerelease', 'beta') -'1.2.4-beta.0' +semver.inc('1.2.3', 'prerelease', 'beta') +// '1.2.4-beta.0' ``` command-line example: -```shell +```bash $ semver 1.2.3 -i prerelease --preid beta 1.2.4-beta.0 ``` Which then can be used to increment further: -```shell +```bash $ semver 1.2.4-beta.0 -i prerelease 1.2.4-beta.1 ``` @@ -296,6 +306,8 @@ strings that they parse. * `major(v)`: Return the major version number. * `minor(v)`: Return the minor version number. * `patch(v)`: Return the patch version number. +* `intersects(r1, r2, loose)`: Return true if the two supplied ranges + or comparators intersect. ### Comparison @@ -319,6 +331,9 @@ strings that they parse. (`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`), or null if the versions are the same. +### Comparators + +* `intersects(comparator)`: Return true if the comparators intersect ### Ranges @@ -337,6 +352,7 @@ strings that they parse. the bounds of the range in either the high or low direction. The `hilo` argument must be either the string `'>'` or `'<'`. (This is the function called by `gtr` and `ltr`.) +* `intersects(range)`: Return true if any of the ranges comparators intersect Note that, since ranges may be non-contiguous, a version might not be greater than a range, less than a range, *or* satisfy a range! For diff --git a/node_modules/semver/package.json b/node_modules/semver/package.json index ec9b01643..ca7e4b416 100644 --- a/node_modules/semver/package.json +++ b/node_modules/semver/package.json @@ -1,13 +1,13 @@ { "name": "semver", - "version": "5.3.0", + "version": "5.4.1", "description": "The semantic version parser used by npm.", "main": "semver.js", "scripts": { - "test": "tap test/*.js" + "test": "tap test/*.js --cov -J" }, "devDependencies": { - "tap": "^2.0.0" + "tap": "^10.7.0" }, "license": "ISC", "repository": "https://github.com/npm/node-semver", diff --git a/node_modules/semver/semver.js b/node_modules/semver/semver.js index 5f1a3c5c9..389cb4467 100644 --- a/node_modules/semver/semver.js +++ b/node_modules/semver/semver.js @@ -563,7 +563,7 @@ function patch(a, loose) { exports.compare = compare; function compare(a, b, loose) { - return new SemVer(a, loose).compare(b); + return new SemVer(a, loose).compare(new SemVer(b, loose)); } exports.compareLoose = compareLoose; @@ -704,11 +704,59 @@ Comparator.prototype.test = function(version) { return cmp(version, this.operator, this.semver, this.loose); }; +Comparator.prototype.intersects = function(comp, loose) { + if (!(comp instanceof Comparator)) { + throw new TypeError('a Comparator is required'); + } + + var rangeTmp; + + if (this.operator === '') { + rangeTmp = new Range(comp.value, loose); + return satisfies(this.value, rangeTmp, loose); + } else if (comp.operator === '') { + rangeTmp = new Range(this.value, loose); + return satisfies(comp.semver, rangeTmp, loose); + } + + var sameDirectionIncreasing = + (this.operator === '>=' || this.operator === '>') && + (comp.operator === '>=' || comp.operator === '>'); + var sameDirectionDecreasing = + (this.operator === '<=' || this.operator === '<') && + (comp.operator === '<=' || comp.operator === '<'); + var sameSemVer = this.semver.version === comp.semver.version; + var differentDirectionsInclusive = + (this.operator === '>=' || this.operator === '<=') && + (comp.operator === '>=' || comp.operator === '<='); + var oppositeDirectionsLessThan = + cmp(this.semver, '<', comp.semver, loose) && + ((this.operator === '>=' || this.operator === '>') && + (comp.operator === '<=' || comp.operator === '<')); + var oppositeDirectionsGreaterThan = + cmp(this.semver, '>', comp.semver, loose) && + ((this.operator === '<=' || this.operator === '<') && + (comp.operator === '>=' || comp.operator === '>')); + + return sameDirectionIncreasing || sameDirectionDecreasing || + (sameSemVer && differentDirectionsInclusive) || + oppositeDirectionsLessThan || oppositeDirectionsGreaterThan; +}; + exports.Range = Range; function Range(range, loose) { - if ((range instanceof Range) && range.loose === loose) - return range; + if (range instanceof Range) { + if (range.loose === loose) { + return range; + } else { + return new Range(range.raw, loose); + } + } + + if (range instanceof Comparator) { + return new Range(range.value, loose); + } if (!(this instanceof Range)) return new Range(range, loose); @@ -783,6 +831,22 @@ Range.prototype.parseRange = function(range) { return set; }; +Range.prototype.intersects = function(range, loose) { + if (!(range instanceof Range)) { + throw new TypeError('a Range is required'); + } + + return this.set.some(function(thisComparators) { + return thisComparators.every(function(thisComparator) { + return range.set.some(function(rangeComparators) { + return rangeComparators.every(function(rangeComparator) { + return thisComparator.intersects(rangeComparator, loose); + }); + }); + }); + }); +}; + // Mostly just for testing and legacy API reasons exports.toComparators = toComparators; function toComparators(range, loose) { @@ -1087,20 +1151,42 @@ function satisfies(version, range, loose) { exports.maxSatisfying = maxSatisfying; function maxSatisfying(versions, range, loose) { - return versions.filter(function(version) { - return satisfies(version, range, loose); - }).sort(function(a, b) { - return rcompare(a, b, loose); - })[0] || null; + var max = null; + var maxSV = null; + try { + var rangeObj = new Range(range, loose); + } catch (er) { + return null; + } + versions.forEach(function (v) { + if (rangeObj.test(v)) { // satisfies(v, range, loose) + if (!max || maxSV.compare(v) === -1) { // compare(max, v, true) + max = v; + maxSV = new SemVer(max, loose); + } + } + }) + return max; } exports.minSatisfying = minSatisfying; function minSatisfying(versions, range, loose) { - return versions.filter(function(version) { - return satisfies(version, range, loose); - }).sort(function(a, b) { - return compare(a, b, loose); - })[0] || null; + var min = null; + var minSV = null; + try { + var rangeObj = new Range(range, loose); + } catch (er) { + return null; + } + versions.forEach(function (v) { + if (rangeObj.test(v)) { // satisfies(v, range, loose) + if (!min || minSV.compare(v) === 1) { // compare(min, v, true) + min = v; + minSV = new SemVer(min, loose); + } + } + }) + return min; } exports.validRange = validRange; @@ -1201,3 +1287,10 @@ function prerelease(version, loose) { var parsed = parse(version, loose); return (parsed && parsed.prerelease.length) ? parsed.prerelease : null; } + +exports.intersects = intersects; +function intersects(r1, r2, loose) { + r1 = new Range(r1, loose) + r2 = new Range(r2, loose) + return r1.intersects(r2) +} |