pax_global_header00006660000000000000000000000064121756161100014512gustar00rootroot0000000000000052 comment=9109e22e9ab2269a7fae1444ca7094df4e22f977 node-semver-2.1.0/000077500000000000000000000000001217561611000137365ustar00rootroot00000000000000node-semver-2.1.0/.gitignore000066400000000000000000000001061217561611000157230ustar00rootroot00000000000000semver.min.js semver.min.js.gz semver.browser.js semver.browser.js.gz node-semver-2.1.0/.npmignore000066400000000000000000000000071217561611000157320ustar00rootroot00000000000000# nada node-semver-2.1.0/LICENSE000066400000000000000000000024361217561611000147500ustar00rootroot00000000000000Copyright (c) Isaac Z. Schlueter ("Author") All rights reserved. The BSD License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. node-semver-2.1.0/Makefile000066400000000000000000000007311217561611000153770ustar00rootroot00000000000000files = semver.browser.js \ semver.min.js \ semver.browser.js.gz \ semver.min.js.gz all: $(files) clean: rm $(files) semver.browser.js: head.js semver.js foot.js ( cat head.js; \ cat semver.js | \ egrep -v '^ *\/\* nomin \*\/' | \ perl -pi -e 's/debug\([^\)]+\)//g'; \ cat foot.js ) > semver.browser.js semver.min.js: semver.browser.js uglifyjs -m semver.min.js %.gz: % gzip --stdout -9 <$< >$@ .PHONY: all clean node-semver-2.1.0/README.md000066400000000000000000000120071217561611000152150ustar00rootroot00000000000000semver(1) -- The semantic versioner for npm =========================================== ## Usage $ npm install 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 Usage: semver [ [...]] [-r | -i | -d ] Test if version(s) satisfy the supplied range(s), and sort them. Multiple versions or ranges may be supplied, unless increment or decrement options are specified. In that case, only a single version may be used, and it is incremented by the specified level Program exits successfully if any valid version satisfies all supplied ranges, and prints all satisfying versions. If no versions are valid, or ranges are not satisfied, then exits failure. Versions are printed in ascending order, so supplying multiple versions to the utility will just sort them. ## Versions A "version" is described by the v2.0.0 specification found at . A leading `"="` or `"v"` character is stripped off and ignored. ## Ranges The following range styles are supported: * `1.2.3` A specific version. When nothing else will do. Note that build metadata is still ignored, so `1.2.3+build2012` will satisfy this range. * `>1.2.3` Greater than a specific version. * `<1.2.3` Less than a specific version. If there is no prerelease tag on the version range, then no prerelease version will be allowed either, even though these are technically "less than". * `>=1.2.3` Greater than or equal to. Note that prerelease versions are NOT equal to their "normal" equivalents, so `1.2.3-beta` will not satisfy this range, but `2.3.0-beta` will. * `<=1.2.3` Less than or equal to. In this case, prerelease versions ARE allowed, so `1.2.3-beta` would satisfy. * `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4` * `~1.2.3` := `>=1.2.3-0 <1.3.0-0` "Reasonably close to 1.2.3". When using tilde operators, prerelease versions are supported as well, but a prerelease of the next significant digit will NOT be satisfactory, so `1.3.0-beta` will not satisfy `~1.2.3`. * `^1.2.3` := `>=1.2.3-0 <2.0.0-0` "Compatible with 1.2.3". When using caret operators, anything from the specified version (including prerelease) will be supported up to, but not including, the next major version (or its prereleases). `1.5.1` will satisfy `^1.2.3`, while `1.2.2` and `2.0.0-beta` will not. * `^0.1.3` := `>=0.1.3-0 <0.2.0-0` "Compatible with 0.1.3". 0.x.x versions are special: the first non-zero component indicates potentially breaking changes, meaning the caret operator matches any version with the same first non-zero component starting at the specified version. * `^0.0.2` := `=0.0.2` "Only the version 0.0.2 is considered compatible" * `~1.2` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2" * `^1.2` := `>=1.2.0-0 <2.0.0-0` "Any version compatible with 1.2" * `1.2.x` := `>=1.2.0-0 <1.3.0-0` "Any version starting with 1.2" * `~1` := `>=1.0.0-0 <2.0.0-0` "Any version starting with 1" * `^1` := `>=1.0.0-0 <2.0.0-0` "Any version compatible with 1" * `1.x` := `>=1.0.0-0 <2.0.0-0` "Any version starting with 1" Ranges can be joined with either a space (which implies "and") or a `||` (which implies "or"). ## Functions All methods and classes take a final `loose` boolean argument that, if true, will be more forgiving about not-quite-valid semver strings. The resulting output will always be 100% strict, of course. Strict-mode Comparators and Ranges will be strict about the SemVer strings that they parse. * valid(v): Return the parsed version, or null if it's not valid. * inc(v, release): Return the version incremented by the release type (major, minor, patch, or prerelease), or null if it's not valid. ### Comparison * gt(v1, v2): `v1 > v2` * gte(v1, v2): `v1 >= v2` * lt(v1, v2): `v1 < v2` * lte(v1, v2): `v1 <= v2` * eq(v1, v2): `v1 == v2` This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings. * neq(v1, v2): `v1 != v2` The opposite of eq. * cmp(v1, comparator, v2): Pass in a comparison string, and it'll call the corresponding function above. `"==="` and `"!=="` do simple string comparison, but are included for completeness. Throws if an invalid comparison string is provided. * compare(v1, v2): Return 0 if v1 == v2, or 1 if v1 is greater, or -1 if v2 is greater. Sorts in ascending order if passed to Array.sort(). * rcompare(v1, v2): The reverse of compare. Sorts an array of versions in descending order when passed to Array.sort(). ### Ranges * validRange(range): Return the valid range or null if it's not valid * satisfies(version, range): Return true if the version satisfies the range. * maxSatisfying(versions, range): Return the highest version in the list that satisfies the range, or null if none of them do. node-semver-2.1.0/bin/000077500000000000000000000000001217561611000145065ustar00rootroot00000000000000node-semver-2.1.0/bin/semver000077500000000000000000000066771217561611000157550ustar00rootroot00000000000000#!/usr/bin/env node // Standalone semver comparison program. // Exits successfully and prints matching version(s) if // any supplied version is valid and passes all tests. var argv = process.argv.slice(2) , versions = [] , range = [] , gt = [] , lt = [] , eq = [] , inc = null , version = require("../package.json").version , loose = false , semver = require("../semver") main() function main () { if (!argv.length) return help() while (argv.length) { var a = argv.shift() var i = a.indexOf('=') if (i !== -1) { a = a.slice(0, i) argv.unshift(a.slice(i + 1)) } switch (a) { case "-l": case "--loose": loose = true break case "-v": case "--version": versions.push(argv.shift()) break case "-i": case "--inc": case "--increment": switch (argv[0]) { case "major": case "minor": case "patch": case "prerelease": inc = argv.shift() break default: inc = "patch" break } break case "-r": case "--range": range.push(argv.shift()) break case "-h": case "--help": case "-?": return help() default: versions.push(a) break } } versions = versions.filter(function (v) { return semver.valid(v, loose) }) if (!versions.length) return fail() if (inc && (versions.length !== 1 || range.length)) return failInc() for (var i = 0, l = range.length; i < l ; i ++) { versions = versions.filter(function (v) { return semver.satisfies(v, range[i], loose) }) if (!versions.length) return fail() } return success(versions) } function failInc () { console.error("--inc can only be used on a single version with no range") fail() } function fail () { process.exit(1) } function success () { versions.sort(function (a, b) { return semver.compare(a, b, loose) }).map(function (v) { return semver.clean(v, loose) }).map(function (v) { return inc ? semver.inc(v, inc, loose) : v }).forEach(function (v,i,_) { console.log(v) }) } function help () { console.log(["SemVer " + version ,"" ,"A JavaScript implementation of the http://semver.org/ specification" ,"Copyright Isaac Z. Schlueter" ,"" ,"Usage: semver [options] [ [...]]" ,"Prints valid versions sorted by SemVer precedence" ,"" ,"Options:" ,"-r --range " ," Print versions that match the specified range." ,"" ,"-i --increment []" ," Increment a version by the specified level. Level can" ," be one of: major, minor, patch, or prerelease" ," Default level is 'patch'." ," Only one version may be specified." ,"" ,"-l --loose" ," Interpret versions and ranges loosely" ,"" ,"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." ,"" ,"Versions are printed in ascending order, so supplying" ,"multiple versions to the utility will just sort them." ].join("\n")) } node-semver-2.1.0/foot.js000066400000000000000000000001641217561611000152440ustar00rootroot00000000000000 })( typeof exports === 'object' ? exports : typeof define === 'function' && define.amd ? {} : semver = {} ); node-semver-2.1.0/head.js000066400000000000000000000000271217561611000151740ustar00rootroot00000000000000;(function(exports) { node-semver-2.1.0/package.json000066400000000000000000000007231217561611000162260ustar00rootroot00000000000000{ "name": "semver", "version": "2.1.0", "description": "The semantic version parser used by npm.", "main": "semver.js", "browser": "semver.browser.js", "min": "semver.min.js", "scripts": { "test": "tap test/*.js", "prepublish": "make" }, "devDependencies": { "tap": "0.x >=0.0.4", "uglify-js": "~2.3.6" }, "license": "BSD", "repository": "git://github.com/isaacs/node-semver.git", "bin": { "semver": "./bin/semver" } } node-semver-2.1.0/semver.js000066400000000000000000000615041217561611000156030ustar00rootroot00000000000000// export the class if we are in a Node-like system. if (typeof module === 'object' && module.exports === exports) exports = module.exports = SemVer; // The debug function is excluded entirely from the minified version. /* nomin */ var debug; /* nomin */ if (typeof process === 'object' && /* nomin */ process.env && /* nomin */ process.env.NODE_DEBUG && /* nomin */ /\bsemver\b/i.test(process.env.NODE_DEBUG)) /* nomin */ debug = function() { /* nomin */ var args = Array.prototype.slice.call(arguments, 0); /* nomin */ args.unshift('SEMVER'); /* nomin */ console.log.apply(console, args); /* nomin */ }; /* nomin */ else /* nomin */ debug = function() {}; // Note: this is the semver.org version of the spec that it implements // Not necessarily the package version of this code. exports.SEMVER_SPEC_VERSION = '2.0.0'; // The actual regexps go on exports.re var re = exports.re = []; var src = exports.src = []; var R = 0; // The following Regular Expressions can be used for tokenizing, // validating, and parsing SemVer version strings. // ## Numeric Identifier // A single `0`, or a non-zero digit followed by zero or more digits. var NUMERICIDENTIFIER = R++; src[NUMERICIDENTIFIER] = '0|[1-9]\\d*'; var NUMERICIDENTIFIERLOOSE = R++; src[NUMERICIDENTIFIERLOOSE] = '[0-9]+'; // ## Non-numeric Identifier // Zero or more digits, followed by a letter or hyphen, and then zero or // more letters, digits, or hyphens. var NONNUMERICIDENTIFIER = R++; src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*'; // ## Main Version // Three dot-separated numeric identifiers. var MAINVERSION = R++; src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')\\.' + '(' + src[NUMERICIDENTIFIER] + ')'; var MAINVERSIONLOOSE = R++; src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' + '(' + src[NUMERICIDENTIFIERLOOSE] + ')'; // ## Pre-release Version Identifier // A numeric identifier, or a non-numeric identifier. var PRERELEASEIDENTIFIER = R++; src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] + '|' + src[NONNUMERICIDENTIFIER] + ')'; var PRERELEASEIDENTIFIERLOOSE = R++; src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] + '|' + src[NONNUMERICIDENTIFIER] + ')'; // ## Pre-release Version // Hyphen, followed by one or more dot-separated pre-release version // identifiers. var PRERELEASE = R++; src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] + '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))'; var PRERELEASELOOSE = R++; src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] + '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))'; // ## Build Metadata Identifier // Any combination of digits, letters, or hyphens. var BUILDIDENTIFIER = R++; src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+'; // ## Build Metadata // Plus sign, followed by one or more period-separated build metadata // identifiers. var BUILD = R++; src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] + '(?:\\.' + src[BUILDIDENTIFIER] + ')*))'; // ## Full Version String // A main version, followed optionally by a pre-release version and // build metadata. // Note that the only major, minor, patch, and pre-release sections of // the version string are capturing groups. The build metadata is not a // capturing group, because it should not ever be used in version // comparison. var FULL = R++; var FULLPLAIN = 'v?' + src[MAINVERSION] + src[PRERELEASE] + '?' + src[BUILD] + '?'; src[FULL] = '^' + FULLPLAIN + '$'; // like full, but allows v1.2.3 and =1.2.3, which people do sometimes. // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty // common in the npm registry. var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] + src[PRERELEASELOOSE] + '?' + src[BUILD] + '?'; var LOOSE = R++; src[LOOSE] = '^' + LOOSEPLAIN + '$'; var GTLT = R++; src[GTLT] = '((?:<|>)?=?)'; // Something like "2.*" or "1.2.x". // Note that "x.x" is a valid xRange identifer, meaning "any version" // Only the first item is strictly required. var XRANGEIDENTIFIERLOOSE = R++; src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*'; var XRANGEIDENTIFIER = R++; src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*'; var XRANGEPLAIN = R++; src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' + '(?:(' + src[PRERELEASE] + ')' + ')?)?)?'; var XRANGEPLAINLOOSE = R++; src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + '(?:(' + src[PRERELEASELOOSE] + ')' + ')?)?)?'; // >=2.x, for example, means >=2.0.0-0 // <1.x would be the same as "<1.0.0-0", though. var XRANGE = R++; src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$'; var XRANGELOOSE = R++; src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$'; // Tilde ranges. // Meaning is "reasonably at or greater than" var LONETILDE = R++; src[LONETILDE] = '(?:~>?)'; var TILDETRIM = R++; src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+'; re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g'); var tildeTrimReplace = '$1~'; var TILDE = R++; src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$'; var TILDELOOSE = R++; src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$'; // Caret ranges. // Meaning is "at least and backwards compatible with" var LONECARET = R++; src[LONECARET] = '(?:\\^)'; var CARETTRIM = R++; src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+'; re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g'); var caretTrimReplace = '$1^'; var CARET = R++; src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$'; var CARETLOOSE = R++; src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$'; // A simple gt/lt/eq thing, or just "" to indicate "any version" var COMPARATORLOOSE = R++; src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$'; var COMPARATOR = R++; src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$'; // An expression to strip any whitespace between the gtlt and the thing // it modifies, so that `> 1.2.3` ==> `>1.2.3` var COMPARATORTRIM = R++; src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] + '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')'; // this one has to use the /g flag re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g'); var comparatorTrimReplace = '$1$2$3'; // Something like `1.2.3 - 1.2.4` // Note that these all use the loose form, because they'll be // checked against either the strict or loose comparator form // later. var HYPHENRANGE = R++; src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAIN] + ')' + '\\s*$'; var HYPHENRANGELOOSE = R++; src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' + '\\s+-\\s+' + '(' + src[XRANGEPLAINLOOSE] + ')' + '\\s*$'; // Star ranges basically just allow anything at all. var STAR = R++; src[STAR] = '(<|>)?=?\\s*\\*'; // Compile to actual regexp objects. // All are flag-free, unless they were created above with a flag. for (var i = 0; i < R; i++) { debug(i, src[i]); if (!re[i]) re[i] = new RegExp(src[i]); } exports.parse = parse; function parse(version, loose) { var r = loose ? re[LOOSE] : re[FULL]; return (r.test(version)) ? new SemVer(version, loose) : null; } exports.valid = valid; function valid(version, loose) { var v = parse(version, loose); return v ? v.version : null; } exports.clean = clean; function clean(version, loose) { var s = parse(version, loose); return s ? s.version : null; } exports.SemVer = SemVer; function SemVer(version, loose) { if (version instanceof SemVer) { if (version.loose === loose) return version; else version = version.version; } if (!(this instanceof SemVer)) return new SemVer(version, loose); debug('SemVer', version, loose); this.loose = loose; var m = version.trim().match(loose ? re[LOOSE] : re[FULL]); if (!m) throw new TypeError('Invalid Version: ' + version); this.raw = version; // these are actually numbers this.major = +m[1]; this.minor = +m[2]; this.patch = +m[3]; // numberify any prerelease numeric ids if (!m[4]) this.prerelease = []; else this.prerelease = m[4].split('.').map(function(id) { return (/^[0-9]+$/.test(id)) ? +id : id; }); this.build = m[5] ? m[5].split('.') : []; this.format(); } SemVer.prototype.format = function() { this.version = this.major + '.' + this.minor + '.' + this.patch; if (this.prerelease.length) this.version += '-' + this.prerelease.join('.'); return this.version; }; SemVer.prototype.inspect = function() { return ''; }; SemVer.prototype.toString = function() { return this.version; }; SemVer.prototype.compare = function(other) { debug('SemVer.compare', this.version, this.loose, other); if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); return this.compareMain(other) || this.comparePre(other); }; SemVer.prototype.compareMain = function(other) { if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); return compareIdentifiers(this.major, other.major) || compareIdentifiers(this.minor, other.minor) || compareIdentifiers(this.patch, other.patch); }; SemVer.prototype.comparePre = function(other) { if (!(other instanceof SemVer)) other = new SemVer(other, this.loose); // NOT having a prerelease is > having one if (this.prerelease.length && !other.prerelease.length) return -1; else if (!this.prerelease.length && other.prerelease.length) return 1; else if (!this.prerelease.lenth && !other.prerelease.length) return 0; var i = 0; do { var a = this.prerelease[i]; var b = other.prerelease[i]; debug('prerelease compare', i, a, b); if (a === undefined && b === undefined) return 0; else if (b === undefined) return 1; else if (a === undefined) return -1; else if (a === b) continue; else return compareIdentifiers(a, b); } while (++i); }; SemVer.prototype.inc = function(release) { switch (release) { case 'major': this.major++; this.minor = -1; case 'minor': this.minor++; this.patch = -1; case 'patch': this.patch++; this.prerelease = []; break; case 'prerelease': if (this.prerelease.length === 0) this.prerelease = [0]; else { var i = this.prerelease.length; while (--i >= 0) { if (typeof this.prerelease[i] === 'number') { this.prerelease[i]++; i = -2; } } if (i === -1) // didn't increment anything this.prerelease.push(0); } break; default: throw new Error('invalid increment argument: ' + release); } this.format(); return this; }; exports.inc = inc; function inc(version, release, loose) { try { return new SemVer(version, loose).inc(release).version; } catch (er) { return null; } } exports.compareIdentifiers = compareIdentifiers; var numeric = /^[0-9]+$/; function compareIdentifiers(a, b) { var anum = numeric.test(a); var bnum = numeric.test(b); if (anum && bnum) { a = +a; b = +b; } return (anum && !bnum) ? -1 : (bnum && !anum) ? 1 : a < b ? -1 : a > b ? 1 : 0; } exports.rcompareIdentifiers = rcompareIdentifiers; function rcompareIdentifiers(a, b) { return compareIdentifiers(b, a); } exports.compare = compare; function compare(a, b, loose) { return new SemVer(a, loose).compare(b); } exports.compareLoose = compareLoose; function compareLoose(a, b) { return compare(a, b, true); } exports.rcompare = rcompare; function rcompare(a, b, loose) { return compare(b, a, loose); } exports.sort = sort; function sort(list, loose) { return list.sort(function(a, b) { return exports.compare(a, b, loose); }); } exports.rsort = rsort; function rsort(list, loose) { return list.sort(function(a, b) { return exports.rcompare(a, b, loose); }); } exports.gt = gt; function gt(a, b, loose) { return compare(a, b, loose) > 0; } exports.lt = lt; function lt(a, b, loose) { return compare(a, b, loose) < 0; } exports.eq = eq; function eq(a, b, loose) { return compare(a, b, loose) === 0; } exports.neq = neq; function neq(a, b, loose) { return compare(a, b, loose) !== 0; } exports.gte = gte; function gte(a, b, loose) { return compare(a, b, loose) >= 0; } exports.lte = lte; function lte(a, b, loose) { return compare(a, b, loose) <= 0; } exports.cmp = cmp; function cmp(a, op, b, loose) { var ret; switch (op) { case '===': ret = a === b; break; case '!==': ret = a !== b; break; case '': case '=': case '==': ret = eq(a, b, loose); break; case '!=': ret = neq(a, b, loose); break; case '>': ret = gt(a, b, loose); break; case '>=': ret = gte(a, b, loose); break; case '<': ret = lt(a, b, loose); break; case '<=': ret = lte(a, b, loose); break; default: throw new TypeError('Invalid operator: ' + op); } return ret; } exports.Comparator = Comparator; function Comparator(comp, loose) { if (comp instanceof Comparator) { if (comp.loose === loose) return comp; else comp = comp.value; } if (!(this instanceof Comparator)) return new Comparator(comp, loose); debug('comparator', comp, loose); this.loose = loose; this.parse(comp); if (this.semver === ANY) this.value = ''; else this.value = this.operator + this.semver.version; } var ANY = {}; Comparator.prototype.parse = function(comp) { var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR]; var m = comp.match(r); if (!m) throw new TypeError('Invalid comparator: ' + comp); this.operator = m[1]; // if it literally is just '>' or '' then allow anything. if (!m[2]) this.semver = ANY; else { this.semver = new SemVer(m[2], this.loose); // <1.2.3-rc DOES allow 1.2.3-beta (has prerelease) // >=1.2.3 DOES NOT allow 1.2.3-beta // <=1.2.3 DOES allow 1.2.3-beta // However, <1.2.3 does NOT allow 1.2.3-beta, // even though `1.2.3-beta < 1.2.3` // The assumption is that the 1.2.3 version has something you // *don't* want, so we push the prerelease down to the minimum. if (this.operator === '<' && !this.semver.prerelease.length) { this.semver.prerelease = ['0']; this.semver.format(); } } }; Comparator.prototype.inspect = function() { return ''; }; Comparator.prototype.toString = function() { return this.value; }; Comparator.prototype.test = function(version) { debug('Comparator.test', version, this.loose); return (this.semver === ANY) ? true : cmp(version, this.operator, this.semver, this.loose); }; exports.Range = Range; function Range(range, loose) { if ((range instanceof Range) && range.loose === loose) return range; if (!(this instanceof Range)) return new Range(range, loose); this.loose = loose; // First, split based on boolean or || this.raw = range; this.set = range.split(/\s*\|\|\s*/).map(function(range) { return this.parseRange(range.trim()); }, this).filter(function(c) { // throw out any that are not relevant for whatever reason return c.length; }); if (!this.set.length) { throw new TypeError('Invalid SemVer Range: ' + range); } this.format(); } Range.prototype.inspect = function() { return ''; }; Range.prototype.format = function() { this.range = this.set.map(function(comps) { return comps.join(' ').trim(); }).join('||').trim(); return this.range; }; Range.prototype.toString = function() { return this.range; }; Range.prototype.parseRange = function(range) { var loose = this.loose; range = range.trim(); debug('range', range, loose); // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE]; range = range.replace(hr, hyphenReplace); debug('hyphen replace', range); // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace); debug('comparator trim', range, re[COMPARATORTRIM]); // `~ 1.2.3` => `~1.2.3` range = range.replace(re[TILDETRIM], tildeTrimReplace); // `^ 1.2.3` => `^1.2.3` range = range.replace(re[CARETTRIM], caretTrimReplace); // normalize spaces range = range.split(/\s+/).join(' '); // At this point, the range is completely trimmed and // ready to be split into comparators. var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR]; var set = range.split(' ').map(function(comp) { return parseComparator(comp, loose); }).join(' ').split(/\s+/); if (this.loose) { // in loose mode, throw out any that are not valid comparators set = set.filter(function(comp) { return !!comp.match(compRe); }); } set = set.map(function(comp) { return new Comparator(comp, loose); }); return set; }; // Mostly just for testing and legacy API reasons exports.toComparators = toComparators; function toComparators(range, loose) { return new Range(range, loose).set.map(function(comp) { return comp.map(function(c) { return c.value; }).join(' ').trim().split(' '); }); } // comprised of xranges, tildes, stars, and gtlt's at this point. // already replaced the hyphen ranges // turn into a set of JUST comparators. function parseComparator(comp, loose) { debug('comp', comp); comp = replaceCarets(comp, loose); debug('caret', comp); comp = replaceTildes(comp, loose); debug('tildes', comp); comp = replaceXRanges(comp, loose); debug('xrange', comp); comp = replaceStars(comp, loose); debug('stars', comp); return comp; } function isX(id) { return !id || id.toLowerCase() === 'x' || id === '*'; } // ~, ~> --> * (any, kinda silly) // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0 // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0 // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0 // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0 // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0 function replaceTildes(comp, loose) { return comp.trim().split(/\s+/).map(function(comp) { return replaceTilde(comp, loose); }).join(' '); } function replaceTilde(comp, loose) { var r = loose ? re[TILDELOOSE] : re[TILDE]; return comp.replace(r, function(_, M, m, p, pr) { debug('tilde', comp, _, M, m, p, pr); var ret; if (isX(M)) ret = ''; else if (isX(m)) ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0'; else if (isX(p)) // ~1.2 == >=1.2.0- <1.3.0- ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0'; else if (pr) { debug('replaceTilde pr', pr); if (pr.charAt(0) !== '-') pr = '-' + pr; ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0-0'; } else // ~1.2.3 == >=1.2.3-0 <1.3.0-0 ret = '>=' + M + '.' + m + '.' + p + '-0' + ' <' + M + '.' + (+m + 1) + '.0-0'; debug('tilde return', ret); return ret; }); } // ^ --> * (any, kinda silly) // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0 // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0 // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0 // ^1.2.3 --> >=1.2.3 <2.0.0 // ^1.2.0 --> >=1.2.0 <2.0.0 function replaceCarets(comp, loose) { return comp.trim().split(/\s+/).map(function(comp) { return replaceCaret(comp, loose); }).join(' '); } function replaceCaret(comp, loose) { var r = loose ? re[CARETLOOSE] : re[CARET]; return comp.replace(r, function(_, M, m, p, pr) { debug('caret', comp, _, M, m, p, pr); var ret; if (isX(M)) ret = ''; else if (isX(m)) ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0'; else if (isX(p)) if (M === '0') ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0'; else ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0'; else if (pr) { debug('replaceCaret pr', pr); if (pr.charAt(0) !== '-') pr = '-' + pr; if (M === '0') if (m === '0') ret = '=' + M + '.' + m + '.' + p + pr; else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + M + '.' + (+m + 1) + '.0-0'; else ret = '>=' + M + '.' + m + '.' + p + pr + ' <' + (+M + 1) + '.0.0-0'; } else if (M === '0') if (m === '0') ret = '=' + M + '.' + m + '.' + p; else ret = '>=' + M + '.' + m + '.' + p + '-0' + ' <' + M + '.' + (+m + 1) + '.0-0'; else ret = '>=' + M + '.' + m + '.' + p + '-0' + ' <' + (+M + 1) + '.0.0-0'; debug('caret return', ret); return ret; }); } function replaceXRanges(comp, loose) { debug('replaceXRanges', comp, loose); return comp.split(/\s+/).map(function(comp) { return replaceXRange(comp, loose); }).join(' '); } function replaceXRange(comp, loose) { comp = comp.trim(); var r = loose ? re[XRANGELOOSE] : re[XRANGE]; return comp.replace(r, function(ret, gtlt, M, m, p, pr) { debug('xRange', comp, ret, gtlt, M, m, p, pr); var xM = isX(M); var xm = xM || isX(m); var xp = xm || isX(p); var anyX = xp; if (gtlt === '=' && anyX) gtlt = ''; if (gtlt && anyX) { // replace X with 0, and then append the -0 min-prerelease if (xM) M = 0; if (xm) m = 0; if (xp) p = 0; if (gtlt === '>') { // >1 => >=2.0.0-0 // >1.2 => >=1.3.0-0 // >1.2.3 => >= 1.2.4-0 gtlt = '>='; if (xM) { // no change } else if (xm) { M = +M + 1; m = 0; p = 0; } else if (xp) { m = +m + 1; p = 0; } } ret = gtlt + M + '.' + m + '.' + p + '-0'; } else if (xM) { // allow any ret = '*'; } else if (xm) { // append '-0' onto the version, otherwise // '1.x.x' matches '2.0.0-beta', since the tag // *lowers* the version value ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0'; } else if (xp) { ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0'; } debug('xRange return', ret); return ret; }); } // Because * is AND-ed with everything else in the comparator, // and '' means "any version", just remove the *s entirely. function replaceStars(comp, loose) { debug('replaceStars', comp, loose); // Looseness is ignored here. star is always as loose as it gets! return comp.trim().replace(re[STAR], ''); } // This function is passed to string.replace(re[HYPHENRANGE]) // M, m, patch, prerelease, build // 1.2 - 3.4.5 => >=1.2.0-0 <=3.4.5 // 1.2.3 - 3.4 => >=1.2.0-0 <3.5.0-0 Any 3.4.x will do // 1.2 - 3.4 => >=1.2.0-0 <3.5.0-0 function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) { if (isX(fM)) from = ''; else if (isX(fm)) from = '>=' + fM + '.0.0-0'; else if (isX(fp)) from = '>=' + fM + '.' + fm + '.0-0'; else from = '>=' + from; if (isX(tM)) to = ''; else if (isX(tm)) to = '<' + (+tM + 1) + '.0.0-0'; else if (isX(tp)) to = '<' + tM + '.' + (+tm + 1) + '.0-0'; else if (tpr) to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr; else to = '<=' + to; return (from + ' ' + to).trim(); } // if ANY of the sets match ALL of its comparators, then pass Range.prototype.test = function(version) { if (!version) return false; for (var i = 0; i < this.set.length; i++) { if (testSet(this.set[i], version)) return true; } return false; }; function testSet(set, version) { for (var i = 0; i < set.length; i++) { if (!set[i].test(version)) return false; } return true; } exports.satisfies = satisfies; function satisfies(version, range, loose) { try { range = new Range(range, loose); } catch (er) { return false; } return range.test(version); } 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; } exports.validRange = validRange; function validRange(range, loose) { try { // Return '*' instead of '' so that truthiness works. // This will throw if it's invalid anyway return new Range(range, loose).range || '*'; } catch (er) { return null; } } // Use the define() function if we're in AMD land if (typeof define === 'function' && define.amd) define(exports); node-semver-2.1.0/test/000077500000000000000000000000001217561611000147155ustar00rootroot00000000000000node-semver-2.1.0/test/amd.js000066400000000000000000000005421217561611000160150ustar00rootroot00000000000000var tap = require('tap'); var test = tap.test; test('amd', function(t) { global.define = define; define.amd = true; var defined = null; function define(stuff) { defined = stuff; } var fromRequire = require('../'); t.ok(defined, 'amd function called'); t.equal(fromRequire, defined, 'amd stuff same as require stuff'); t.end(); }); node-semver-2.1.0/test/index.js000066400000000000000000000433311217561611000163660ustar00rootroot00000000000000var tap = require('tap'); var test = tap.test; var semver = require('../semver.js'); var eq = semver.eq; var gt = semver.gt; var lt = semver.lt; var neq = semver.neq; var cmp = semver.cmp; var gte = semver.gte; var lte = semver.lte; var satisfies = semver.satisfies; var validRange = semver.validRange; var inc = semver.inc; var replaceStars = semver.replaceStars; var toComparators = semver.toComparators; var SemVer = semver.SemVer; var Range = semver.Range; test('\ncomparison tests', function(t) { // [version1, version2] // version1 should be greater than version2 [['0.0.0', '0.0.0-foo'], ['0.0.1', '0.0.0'], ['1.0.0', '0.9.9'], ['0.10.0', '0.9.0'], ['0.99.0', '0.10.0'], ['2.0.0', '1.2.3'], ['v0.0.0', '0.0.0-foo', true], ['v0.0.1', '0.0.0', true], ['v1.0.0', '0.9.9', true], ['v0.10.0', '0.9.0', true], ['v0.99.0', '0.10.0', true], ['v2.0.0', '1.2.3', true], ['0.0.0', 'v0.0.0-foo', true], ['0.0.1', 'v0.0.0', true], ['1.0.0', 'v0.9.9', true], ['0.10.0', 'v0.9.0', true], ['0.99.0', 'v0.10.0', true], ['2.0.0', 'v1.2.3', true], ['1.2.3', '1.2.3-asdf'], ['1.2.3', '1.2.3-4'], ['1.2.3', '1.2.3-4-foo'], ['1.2.3-5-foo', '1.2.3-5'], ['1.2.3-5', '1.2.3-4'], ['1.2.3-5-foo', '1.2.3-5-Foo'], ['3.0.0', '2.7.2+asdf'], ['1.2.3-a.10', '1.2.3-a.5'], ['1.2.3-a.b', '1.2.3-a.5'], ['1.2.3-a.b', '1.2.3-a'], ['1.2.3-a.b.c.10.d.5', '1.2.3-a.b.c.5.d.100'] ].forEach(function(v) { var v0 = v[0]; var v1 = v[1]; var loose = v[2]; t.ok(gt(v0, v1, loose), "gt('" + v0 + "', '" + v1 + "')"); t.ok(lt(v1, v0, loose), "lt('" + v1 + "', '" + v0 + "')"); t.ok(!gt(v1, v0, loose), "!gt('" + v1 + "', '" + v0 + "')"); t.ok(!lt(v0, v1, loose), "!lt('" + v0 + "', '" + v1 + "')"); t.ok(eq(v0, v0, loose), "eq('" + v0 + "', '" + v0 + "')"); t.ok(eq(v1, v1, loose), "eq('" + v1 + "', '" + v1 + "')"); t.ok(neq(v0, v1, loose), "neq('" + v0 + "', '" + v1 + "')"); t.ok(cmp(v1, '==', v1, loose), "cmp('" + v1 + "' == '" + v1 + "')"); t.ok(cmp(v0, '>=', v1, loose), "cmp('" + v0 + "' >= '" + v1 + "')"); t.ok(cmp(v1, '<=', v0, loose), "cmp('" + v1 + "' <= '" + v0 + "')"); t.ok(cmp(v0, '!=', v1, loose), "cmp('" + v0 + "' != '" + v1 + "')"); }); t.end(); }); test('\nequality tests', function(t) { // [version1, version2] // version1 should be equivalent to version2 [['1.2.3', 'v1.2.3', true], ['1.2.3', '=1.2.3', true], ['1.2.3', 'v 1.2.3', true], ['1.2.3', '= 1.2.3', true], ['1.2.3', ' v1.2.3', true], ['1.2.3', ' =1.2.3', true], ['1.2.3', ' v 1.2.3', true], ['1.2.3', ' = 1.2.3', true], ['1.2.3-0', 'v1.2.3-0', true], ['1.2.3-0', '=1.2.3-0', true], ['1.2.3-0', 'v 1.2.3-0', true], ['1.2.3-0', '= 1.2.3-0', true], ['1.2.3-0', ' v1.2.3-0', true], ['1.2.3-0', ' =1.2.3-0', true], ['1.2.3-0', ' v 1.2.3-0', true], ['1.2.3-0', ' = 1.2.3-0', true], ['1.2.3-1', 'v1.2.3-1', true], ['1.2.3-1', '=1.2.3-1', true], ['1.2.3-1', 'v 1.2.3-1', true], ['1.2.3-1', '= 1.2.3-1', true], ['1.2.3-1', ' v1.2.3-1', true], ['1.2.3-1', ' =1.2.3-1', true], ['1.2.3-1', ' v 1.2.3-1', true], ['1.2.3-1', ' = 1.2.3-1', true], ['1.2.3-beta', 'v1.2.3-beta', true], ['1.2.3-beta', '=1.2.3-beta', true], ['1.2.3-beta', 'v 1.2.3-beta', true], ['1.2.3-beta', '= 1.2.3-beta', true], ['1.2.3-beta', ' v1.2.3-beta', true], ['1.2.3-beta', ' =1.2.3-beta', true], ['1.2.3-beta', ' v 1.2.3-beta', true], ['1.2.3-beta', ' = 1.2.3-beta', true], ['1.2.3-beta+build', ' = 1.2.3-beta+otherbuild', true], ['1.2.3+build', ' = 1.2.3+otherbuild', true], ['1.2.3-beta+build', '1.2.3-beta+otherbuild'], ['1.2.3+build', '1.2.3+otherbuild'], [' v1.2.3+build', '1.2.3+otherbuild'] ].forEach(function(v) { var v0 = v[0]; var v1 = v[1]; var loose = v[2]; t.ok(eq(v0, v1, loose), "eq('" + v0 + "', '" + v1 + "')"); t.ok(!neq(v0, v1, loose), "!neq('" + v0 + "', '" + v1 + "')"); t.ok(cmp(v0, '==', v1, loose), 'cmp(' + v0 + '==' + v1 + ')'); t.ok(!cmp(v0, '!=', v1, loose), '!cmp(' + v0 + '!=' + v1 + ')'); t.ok(!cmp(v0, '===', v1, loose), '!cmp(' + v0 + '===' + v1 + ')'); t.ok(cmp(v0, '!==', v1, loose), 'cmp(' + v0 + '!==' + v1 + ')'); t.ok(!gt(v0, v1, loose), "!gt('" + v0 + "', '" + v1 + "')"); t.ok(gte(v0, v1, loose), "gte('" + v0 + "', '" + v1 + "')"); t.ok(!lt(v0, v1, loose), "!lt('" + v0 + "', '" + v1 + "')"); t.ok(lte(v0, v1, loose), "lte('" + v0 + "', '" + v1 + "')"); }); t.end(); }); test('\nrange tests', function(t) { // [range, version] // version should be included by range [['1.0.0 - 2.0.0', '1.2.3'], ['1.0.0', '1.0.0'], ['>=*', '0.2.4'], ['', '1.0.0'], ['*', '1.2.3'], ['*', 'v1.2.3-foo', true], ['>=1.0.0', '1.0.0'], ['>=1.0.0', '1.0.1'], ['>=1.0.0', '1.1.0'], ['>1.0.0', '1.0.1'], ['>1.0.0', '1.1.0'], ['<=2.0.0', '2.0.0'], ['<=2.0.0', '1.9999.9999'], ['<=2.0.0', '0.2.9'], ['<2.0.0', '1.9999.9999'], ['<2.0.0', '0.2.9'], ['>= 1.0.0', '1.0.0'], ['>= 1.0.0', '1.0.1'], ['>= 1.0.0', '1.1.0'], ['> 1.0.0', '1.0.1'], ['> 1.0.0', '1.1.0'], ['<= 2.0.0', '2.0.0'], ['<= 2.0.0', '1.9999.9999'], ['<= 2.0.0', '0.2.9'], ['< 2.0.0', '1.9999.9999'], ['<\t2.0.0', '0.2.9'], ['>=0.1.97', 'v0.1.97', true], ['>=0.1.97', '0.1.97'], ['0.1.20 || 1.2.4', '1.2.4'], ['>=0.2.3 || <0.0.1', '0.0.0'], ['>=0.2.3 || <0.0.1', '0.2.3'], ['>=0.2.3 || <0.0.1', '0.2.4'], ['||', '1.3.4'], ['2.x.x', '2.1.3'], ['1.2.x', '1.2.3'], ['1.2.x || 2.x', '2.1.3'], ['1.2.x || 2.x', '1.2.3'], ['x', '1.2.3'], ['2.*.*', '2.1.3'], ['1.2.*', '1.2.3'], ['1.2.* || 2.*', '2.1.3'], ['1.2.* || 2.*', '1.2.3'], ['*', '1.2.3'], ['2', '2.1.2'], ['2.3', '2.3.1'], ['~2.4', '2.4.0'], // >=2.4.0 <2.5.0 ['~2.4', '2.4.5'], ['~>3.2.1', '3.2.2'], // >=3.2.1 <3.3.0, ['~1', '1.2.3'], // >=1.0.0 <2.0.0 ['~>1', '1.2.3'], ['~> 1', '1.2.3'], ['~1.0', '1.0.2'], // >=1.0.0 <1.1.0, ['~ 1.0', '1.0.2'], ['~ 1.0.3', '1.0.12'], ['>=1', '1.0.0'], ['>= 1', '1.0.0'], ['<1.2', '1.1.1'], ['< 1.2', '1.1.1'], ['1', '1.0.0beta', true], ['~v0.5.4-pre', '0.5.5'], ['~v0.5.4-pre', '0.5.4'], ['=0.7.x', '0.7.2'], ['>=0.7.x', '0.7.2'], ['=0.7.x', '0.7.0-asdf'], ['>=0.7.x', '0.7.0-asdf'], ['<=0.7.x', '0.6.2'], ['~1.2.1 >=1.2.3', '1.2.3'], ['~1.2.1 =1.2.3', '1.2.3'], ['~1.2.1 1.2.3', '1.2.3'], ['~1.2.1 >=1.2.3 1.2.3', '1.2.3'], ['~1.2.1 1.2.3 >=1.2.3', '1.2.3'], ['~1.2.1 1.2.3', '1.2.3'], ['>=1.2.1 1.2.3', '1.2.3'], ['1.2.3 >=1.2.1', '1.2.3'], ['>=1.2.3 >=1.2.1', '1.2.3'], ['>=1.2.1 >=1.2.3', '1.2.3'], ['<=1.2.3', '1.2.3-beta'], ['>1.2', '1.3.0-beta'], ['>=1.2', '1.2.8'], ['^1.2.3', '1.8.1'], ['^1.2.3', '1.2.3-beta'], ['^0.1.2', '0.1.2'], ['^0.1', '0.1.2'], ['^1.2', '1.4.2'], ['^1.2 ^1', '1.4.2'], ['^1.2', '1.2.0-pre'], ['^1.2.3', '1.2.3-pre'] ].forEach(function(v) { var range = v[0]; var ver = v[1]; var loose = v[2]; t.ok(satisfies(ver, range, loose), range + ' satisfied by ' + ver); }); t.end(); }); test('\nnegative range tests', function(t) { // [range, version] // version should not be included by range [['1.0.0 - 2.0.0', '2.2.3'], ['1.0.0', '1.0.1'], ['>=1.0.0', '0.0.0'], ['>=1.0.0', '0.0.1'], ['>=1.0.0', '0.1.0'], ['>1.0.0', '0.0.1'], ['>1.0.0', '0.1.0'], ['<=2.0.0', '3.0.0'], ['<=2.0.0', '2.9999.9999'], ['<=2.0.0', '2.2.9'], ['<2.0.0', '2.9999.9999'], ['<2.0.0', '2.2.9'], ['>=0.1.97', 'v0.1.93', true], ['>=0.1.97', '0.1.93'], ['0.1.20 || 1.2.4', '1.2.3'], ['>=0.2.3 || <0.0.1', '0.0.3'], ['>=0.2.3 || <0.0.1', '0.2.2'], ['2.x.x', '1.1.3'], ['2.x.x', '3.1.3'], ['1.2.x', '1.3.3'], ['1.2.x || 2.x', '3.1.3'], ['1.2.x || 2.x', '1.1.3'], ['2.*.*', '1.1.3'], ['2.*.*', '3.1.3'], ['1.2.*', '1.3.3'], ['1.2.* || 2.*', '3.1.3'], ['1.2.* || 2.*', '1.1.3'], ['2', '1.1.2'], ['2.3', '2.4.1'], ['~2.4', '2.5.0'], // >=2.4.0 <2.5.0 ['~2.4', '2.3.9'], ['~>3.2.1', '3.3.2'], // >=3.2.1 <3.3.0 ['~>3.2.1', '3.2.0'], // >=3.2.1 <3.3.0 ['~1', '0.2.3'], // >=1.0.0 <2.0.0 ['~>1', '2.2.3'], ['~1.0', '1.1.0'], // >=1.0.0 <1.1.0 ['<1', '1.0.0'], ['>=1.2', '1.1.1'], ['1', '2.0.0beta', true], ['~v0.5.4-beta', '0.5.4-alpha'], ['<1', '1.0.0beta', true], ['< 1', '1.0.0beta', true], ['=0.7.x', '0.8.2'], ['>=0.7.x', '0.6.2'], ['<=0.7.x', '0.7.2'], ['<1.2.3', '1.2.3-beta'], ['=1.2.3', '1.2.3-beta'], ['>1.2', '1.2.8'], ['^1.2.3', '2.0.0-alpha'], ['^1.2.3', '1.2.2'], ['^1.2', '1.1.9'], // invalid ranges never satisfied! ['blerg', '1.2.3'], ['git+https://user:password0123@github.com/foo', '123.0.0', true], ['^1.2.3', '2.0.0-pre'] ].forEach(function(v) { var range = v[0]; var ver = v[1]; var loose = v[2]; var found = satisfies(ver, range, loose); t.ok(!found, ver + ' not satisfied by ' + range); }); t.end(); }); test('\nincrement versions test', function(t) { // [version, inc, result] // inc(version, inc) -> result [['1.2.3', 'major', '2.0.0'], ['1.2.3', 'minor', '1.3.0'], ['1.2.3', 'patch', '1.2.4'], ['1.2.3tag', 'major', '2.0.0', true], ['1.2.3-tag', 'major', '2.0.0'], ['1.2.3', 'fake', null], ['fake', 'major', null], ['1.2.3', 'prerelease', '1.2.3-0'], ['1.2.3-0', 'prerelease', '1.2.3-1'], ['1.2.3-alpha.0', 'prerelease', '1.2.3-alpha.1'], ['1.2.3-alpha.1', 'prerelease', '1.2.3-alpha.2'], ['1.2.3-alpha.2', 'prerelease', '1.2.3-alpha.3'], ['1.2.3-alpha.0.beta', 'prerelease', '1.2.3-alpha.1.beta'], ['1.2.3-alpha.1.beta', 'prerelease', '1.2.3-alpha.2.beta'], ['1.2.3-alpha.2.beta', 'prerelease', '1.2.3-alpha.3.beta'], ['1.2.3-alpha.10.0.beta', 'prerelease', '1.2.3-alpha.10.1.beta'], ['1.2.3-alpha.10.1.beta', 'prerelease', '1.2.3-alpha.10.2.beta'], ['1.2.3-alpha.10.2.beta', 'prerelease', '1.2.3-alpha.10.3.beta'], ['1.2.3-alpha.10.beta.0', 'prerelease', '1.2.3-alpha.10.beta.1'], ['1.2.3-alpha.10.beta.1', 'prerelease', '1.2.3-alpha.10.beta.2'], ['1.2.3-alpha.10.beta.2', 'prerelease', '1.2.3-alpha.10.beta.3'], ['1.2.3-alpha.9.beta', 'prerelease', '1.2.3-alpha.10.beta'], ['1.2.3-alpha.10.beta', 'prerelease', '1.2.3-alpha.11.beta'], ['1.2.3-alpha.11.beta', 'prerelease', '1.2.3-alpha.12.beta'] ].forEach(function(v) { var pre = v[0]; var what = v[1]; var wanted = v[2]; var loose = v[3]; var found = inc(pre, what, loose); t.equal(found, wanted, 'inc(' + pre + ', ' + what + ') === ' + wanted); }); t.end(); }); test('\nvalid range test', function(t) { // [range, result] // validRange(range) -> result // translate ranges into their canonical form [['1.0.0 - 2.0.0', '>=1.0.0 <=2.0.0'], ['1.0.0', '1.0.0'], ['>=*', '>=0.0.0-0'], ['', '*'], ['*', '*'], ['*', '*'], ['>=1.0.0', '>=1.0.0'], ['>1.0.0', '>1.0.0'], ['<=2.0.0', '<=2.0.0'], ['1', '>=1.0.0-0 <2.0.0-0'], ['<=2.0.0', '<=2.0.0'], ['<=2.0.0', '<=2.0.0'], ['<2.0.0', '<2.0.0-0'], ['<2.0.0', '<2.0.0-0'], ['>= 1.0.0', '>=1.0.0'], ['>= 1.0.0', '>=1.0.0'], ['>= 1.0.0', '>=1.0.0'], ['> 1.0.0', '>1.0.0'], ['> 1.0.0', '>1.0.0'], ['<= 2.0.0', '<=2.0.0'], ['<= 2.0.0', '<=2.0.0'], ['<= 2.0.0', '<=2.0.0'], ['< 2.0.0', '<2.0.0-0'], ['< 2.0.0', '<2.0.0-0'], ['>=0.1.97', '>=0.1.97'], ['>=0.1.97', '>=0.1.97'], ['0.1.20 || 1.2.4', '0.1.20||1.2.4'], ['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'], ['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'], ['>=0.2.3 || <0.0.1', '>=0.2.3||<0.0.1-0'], ['||', '||'], ['2.x.x', '>=2.0.0-0 <3.0.0-0'], ['1.2.x', '>=1.2.0-0 <1.3.0-0'], ['1.2.x || 2.x', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'], ['1.2.x || 2.x', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'], ['x', '*'], ['2.*.*', '>=2.0.0-0 <3.0.0-0'], ['1.2.*', '>=1.2.0-0 <1.3.0-0'], ['1.2.* || 2.*', '>=1.2.0-0 <1.3.0-0||>=2.0.0-0 <3.0.0-0'], ['*', '*'], ['2', '>=2.0.0-0 <3.0.0-0'], ['2.3', '>=2.3.0-0 <2.4.0-0'], ['~2.4', '>=2.4.0-0 <2.5.0-0'], ['~2.4', '>=2.4.0-0 <2.5.0-0'], ['~>3.2.1', '>=3.2.1-0 <3.3.0-0'], ['~1', '>=1.0.0-0 <2.0.0-0'], ['~>1', '>=1.0.0-0 <2.0.0-0'], ['~> 1', '>=1.0.0-0 <2.0.0-0'], ['~1.0', '>=1.0.0-0 <1.1.0-0'], ['~ 1.0', '>=1.0.0-0 <1.1.0-0'], ['^0', '>=0.0.0-0 <1.0.0-0'], ['^ 1', '>=1.0.0-0 <2.0.0-0'], ['^0.1', '>=0.1.0-0 <0.2.0-0'], ['^1.0', '>=1.0.0-0 <2.0.0-0'], ['^1.2', '>=1.2.0-0 <2.0.0-0'], ['^0.0.1', '=0.0.1'], ['^0.0.1-beta', '=0.0.1-beta'], ['^0.1.2', '>=0.1.2-0 <0.2.0-0'], ['^1.2.3', '>=1.2.3-0 <2.0.0-0'], ['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'], ['<1', '<1.0.0-0'], ['< 1', '<1.0.0-0'], ['>=1', '>=1.0.0-0'], ['>= 1', '>=1.0.0-0'], ['<1.2', '<1.2.0-0'], ['< 1.2', '<1.2.0-0'], ['1', '>=1.0.0-0 <2.0.0-0'], ['>01.02.03', '>1.2.3', true], ['>01.02.03', null], ['~1.2.3beta', '>=1.2.3-beta <1.3.0-0', true], ['~1.2.3beta', null], ['^ 1.2 ^ 1', '>=1.2.0-0 <2.0.0-0 >=1.0.0-0 <2.0.0-0'] ].forEach(function(v) { var pre = v[0]; var wanted = v[1]; var loose = v[2]; var found = validRange(pre, loose); t.equal(found, wanted, 'validRange(' + pre + ') === ' + wanted); }); t.end(); }); test('\ncomparators test', function(t) { // [range, comparators] // turn range into a set of individual comparators [['1.0.0 - 2.0.0', [['>=1.0.0', '<=2.0.0']]], ['1.0.0', [['1.0.0']]], ['>=*', [['>=0.0.0-0']]], ['', [['']]], ['*', [['']]], ['*', [['']]], ['>=1.0.0', [['>=1.0.0']]], ['>=1.0.0', [['>=1.0.0']]], ['>=1.0.0', [['>=1.0.0']]], ['>1.0.0', [['>1.0.0']]], ['>1.0.0', [['>1.0.0']]], ['<=2.0.0', [['<=2.0.0']]], ['1', [['>=1.0.0-0', '<2.0.0-0']]], ['<=2.0.0', [['<=2.0.0']]], ['<=2.0.0', [['<=2.0.0']]], ['<2.0.0', [['<2.0.0-0']]], ['<2.0.0', [['<2.0.0-0']]], ['>= 1.0.0', [['>=1.0.0']]], ['>= 1.0.0', [['>=1.0.0']]], ['>= 1.0.0', [['>=1.0.0']]], ['> 1.0.0', [['>1.0.0']]], ['> 1.0.0', [['>1.0.0']]], ['<= 2.0.0', [['<=2.0.0']]], ['<= 2.0.0', [['<=2.0.0']]], ['<= 2.0.0', [['<=2.0.0']]], ['< 2.0.0', [['<2.0.0-0']]], ['<\t2.0.0', [['<2.0.0-0']]], ['>=0.1.97', [['>=0.1.97']]], ['>=0.1.97', [['>=0.1.97']]], ['0.1.20 || 1.2.4', [['0.1.20'], ['1.2.4']]], ['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1-0']]], ['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1-0']]], ['>=0.2.3 || <0.0.1', [['>=0.2.3'], ['<0.0.1-0']]], ['||', [[''], ['']]], ['2.x.x', [['>=2.0.0-0', '<3.0.0-0']]], ['1.2.x', [['>=1.2.0-0', '<1.3.0-0']]], ['1.2.x || 2.x', [['>=1.2.0-0', '<1.3.0-0'], ['>=2.0.0-0', '<3.0.0-0']]], ['1.2.x || 2.x', [['>=1.2.0-0', '<1.3.0-0'], ['>=2.0.0-0', '<3.0.0-0']]], ['x', [['']]], ['2.*.*', [['>=2.0.0-0', '<3.0.0-0']]], ['1.2.*', [['>=1.2.0-0', '<1.3.0-0']]], ['1.2.* || 2.*', [['>=1.2.0-0', '<1.3.0-0'], ['>=2.0.0-0', '<3.0.0-0']]], ['1.2.* || 2.*', [['>=1.2.0-0', '<1.3.0-0'], ['>=2.0.0-0', '<3.0.0-0']]], ['*', [['']]], ['2', [['>=2.0.0-0', '<3.0.0-0']]], ['2.3', [['>=2.3.0-0', '<2.4.0-0']]], ['~2.4', [['>=2.4.0-0', '<2.5.0-0']]], ['~2.4', [['>=2.4.0-0', '<2.5.0-0']]], ['~>3.2.1', [['>=3.2.1-0', '<3.3.0-0']]], ['~1', [['>=1.0.0-0', '<2.0.0-0']]], ['~>1', [['>=1.0.0-0', '<2.0.0-0']]], ['~> 1', [['>=1.0.0-0', '<2.0.0-0']]], ['~1.0', [['>=1.0.0-0', '<1.1.0-0']]], ['~ 1.0', [['>=1.0.0-0', '<1.1.0-0']]], ['~ 1.0.3', [['>=1.0.3-0', '<1.1.0-0']]], ['~> 1.0.3', [['>=1.0.3-0', '<1.1.0-0']]], ['<1', [['<1.0.0-0']]], ['< 1', [['<1.0.0-0']]], ['>=1', [['>=1.0.0-0']]], ['>= 1', [['>=1.0.0-0']]], ['<1.2', [['<1.2.0-0']]], ['< 1.2', [['<1.2.0-0']]], ['1', [['>=1.0.0-0', '<2.0.0-0']]], ['1 2', [['>=1.0.0-0', '<2.0.0-0', '>=2.0.0-0', '<3.0.0-0']]], ['1.2 - 3.4.5', [['>=1.2.0-0', '<=3.4.5']]], ['1.2.3 - 3.4', [['>=1.2.3', '<3.5.0-0']]] ].forEach(function(v) { var pre = v[0]; var wanted = v[1]; var found = toComparators(v[0]); var jw = JSON.stringify(wanted); t.equivalent(found, wanted, 'toComparators(' + pre + ') === ' + jw); }); t.end(); }); test('\nstrict vs loose version numbers', function(t) { [['=1.2.3', '1.2.3'], ['01.02.03', '1.2.3'], ['1.2.3-beta.01', '1.2.3-beta.1'], [' =1.2.3', '1.2.3'], ['1.2.3foo', '1.2.3-foo'] ].forEach(function(v) { var loose = v[0]; var strict = v[1]; t.throws(function() { new SemVer(loose); }); var lv = new SemVer(loose, true); t.equal(lv.version, strict); t.ok(eq(loose, strict, true)); t.throws(function() { eq(loose, strict); }); t.throws(function() { new SemVer(strict).compare(loose); }); }); t.end(); }); test('\nstrict vs loose ranges', function(t) { [['>=01.02.03', '>=1.2.3'], ['~1.02.03beta', '>=1.2.3-beta <1.3.0-0'] ].forEach(function(v) { var loose = v[0]; var comps = v[1]; t.throws(function() { new Range(loose); }); t.equal(new Range(loose, true).range, comps); }); t.end(); }); test('\nmax satisfying', function(t) { [[['1.2.3', '1.2.4'], '1.2', '1.2.4'], [['1.2.4', '1.2.3'], '1.2', '1.2.4'], [['1.2.3','1.2.4','1.2.5','1.2.6'], '~1.2.3', '1.2.6'], [['1.1.0', '1.2.0', '1.2.1', '1.3.0', '2.0.0b1', '2.0.0b2', '2.0.0b3', '2.0.0', '2.1.0'], '~2.0.0', '2.0.0', true] ].forEach(function(v) { var versions = v[0]; var range = v[1]; var expect = v[2]; var loose = v[3]; var actual = semver.maxSatisfying(versions, range, loose); t.equal(actual, expect); }); t.end(); }); node-semver-2.1.0/test/no-module.js000066400000000000000000000011751217561611000171560ustar00rootroot00000000000000var tap = require('tap'); var test = tap.test; test('no module system', function(t) { var fs = require('fs'); var vm = require('vm'); var head = fs.readFileSync(require.resolve('../head.js'), 'utf8'); var src = fs.readFileSync(require.resolve('../'), 'utf8'); var foot = fs.readFileSync(require.resolve('../foot.js'), 'utf8'); vm.runInThisContext(head + src + foot, 'semver.js'); // just some basic poking to see if it did some stuff t.type(global.semver, 'object'); t.type(global.semver.SemVer, 'function'); t.type(global.semver.Range, 'function'); t.ok(global.semver.satisfies('1.2.3', '1.2')); t.end(); });