diff --git a/dist/redolent-testing.js b/dist/redolent-testing.js new file mode 100644 index 0000000..127b144 --- /dev/null +++ b/dist/redolent-testing.js @@ -0,0 +1,137 @@ +'use strict'; + +var arrify = require('arrify'); +var sliced = require('sliced'); +var extend = require('extend-shallow'); +var register = require('native-or-another/register'); +var Promize = require('native-or-another'); +var isAsync = require('is-async-function'); + +/*! + * redolent + * + * Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online) + * Released under the MIT license. + */ + +/** + * > Will try to promisify `fn` with native Promise, + * otherwise you can give different promise module + * to `opts.Promise`, for example [pinkie][] or [bluebird][]. + * If `fn` [is-async-function][] it will be passed with `done` callback + * as last argument - always concatenated with the other provided args + * through `opts.args`. + * + * **Note:** Uses [native-or-another][] for detection, so it will always will use the + * native Promise, otherwise will try to load some of the common promise libraries + * and as last resort if can't find one of them installed, then throws an Error! + * + * **Example** + * + * ```js + * const fs = require('fs') + * const request = require('request') + * const redolent = require('redolent') + * + * redolent(fs.readFile)('package.json', 'utf-8').then(data => { + * console.log(JSON.parse(data).name) + * }) + * + * // handles multiple arguments by default + * redolent(request)('http://www.tunnckocore.tk/').then(result => { + * const [httpResponse, body] = result + * }) + * + * // `a` and `b` arguments comes from `opts.args` + * // `c` and `d` comes from the call of the promisified function + * const fn = redolent((a, b, c, d, done) => { + * console.log(typeof done) // => 'function' + * done(null, a + b + c + d) + * }, { + * args: [1, 2] + * }) + * + * fn(3, 5).then((res) => { + * console.log(res) // => 11 + * }) + * ``` + * + * @name redolent + * @param {Function} `` a function to be promisified + * @param {Object} `[opts]` optional options, also passed to [native-or-another][] + * @param {Array} `[opts.args]` additional arguments to be passed to `fn`, + * all args from `opts.args` and these that are + * passed to promisifed function are concatenated + * @param {Object} `[opts.context]` what context to be applied to `fn`, + * by default it is smart enough and applies + * the `this` context of redolent call or the call + * of the promisified function + * @param {Function} `[opts.Promise]` custom Promise constructor for versions `< v0.12`, + * like [bluebird][] for example, by default + * it **always** uses the native Promise in newer + * node versions + * @param {Boolean} `[opts.global]` defaults to `true`, pass false if you don't + * want to attach/add/register the given promise + * to the `global` scope, when node `< v0.12` + * @return {Function} promisified function + * @throws {TypeError} If `fn` is not a function + * @throws {TypeError} If no promise is found + * @api public + */ + +function redolent (fn, opts) { + if (typeof fn !== 'function') { + throw new TypeError('redolent: expect `fn` to be a function') + } + + opts = extend({ context: this, Promise: Promize }, opts); + opts.Promise = register(opts); + + // we can't test that here, because some + // of our devDeps has some Promise library, + // so it's loaded by `native-or-another` automatically + /* istanbul ignore next */ + if (typeof opts.Promise !== 'function') { + var msg = 'no native Promise support nor other promise were found'; + throw new TypeError('redolent: ' + msg) + } + + return function () { + opts.context = this || opts.context; + opts.args = arrify(opts.args).concat(sliced(arguments)); + + var promise = new opts.Promise(function (resolve, reject) { + var called = false; + + function done (er, res) { + called = true; + if (er) { + return reject(er) + } + if (arguments.length > 2) { + res = sliced(arguments, 1); + } + return resolve(res) + } + + var isAsyncFn = isAsync(fn); + + opts.args = isAsyncFn ? opts.args.concat(done) : opts.args; + var syncResult = fn.apply(opts.context, opts.args); + + if (!isAsyncFn && !called) { + resolve(syncResult); + } + }); + + return normalize(promise, opts.Promise) + } +} + +function normalize (promise, Ctor) { + promise.___nativePromise = Boolean(Ctor.___nativePromise); + promise.___customPromise = Boolean(Ctor.___customPromise); + return promise +} + +module.exports = redolent; diff --git a/dist/redolent.common.js b/dist/redolent.common.js index b95fb99..01e3996 100644 --- a/dist/redolent.common.js +++ b/dist/redolent.common.js @@ -1,6 +1,11 @@ 'use strict'; -var index$2 = function (val) { +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var register = _interopDefault(require('native-or-another/register')); +var Promize = _interopDefault(require('native-or-another')); + +var index = function (val) { if (val === null || val === undefined) { return []; } @@ -17,7 +22,7 @@ var index$2 = function (val) { * @api public */ -var index$4 = function (args, slice, sliceEnd) { +var index$1 = function (args, slice, sliceEnd) { var ret = []; var len = args.length; @@ -47,21 +52,21 @@ var index$4 = function (args, slice, sliceEnd) { * Licensed under the MIT License. */ -var index$8 = function isExtendable(val) { +var index$3 = function isExtendable(val) { return typeof val !== 'undefined' && val !== null && (typeof val === 'object' || typeof val === 'function'); }; -var index$6 = function extend(o/*, objects*/) { +var index$2 = function extend(o/*, objects*/) { var arguments$1 = arguments; - if (!index$8(o)) { o = {}; } + if (!index$3(o)) { o = {}; } var len = arguments.length; for (var i = 1; i < len; i++) { var obj = arguments$1[i]; - if (index$8(obj)) { + if (index$3(obj)) { assign(o, obj); } } @@ -84,1385 +89,6 @@ function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } -var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - -function commonjsRequire () { - throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); -} - - - -function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; -} - -var semver = createCommonjsModule(function (module, 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'; - -var MAX_LENGTH = 256; -var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; - -// 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] + ')?' + - src[BUILD] + '?' + - ')?)?'; - -var XRANGEPLAINLOOSE = R++; -src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:' + src[PRERELEASELOOSE] + ')?' + - src[BUILD] + '?' + - ')?)?'; - -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) { - if (version instanceof SemVer) - { return version; } - - if (typeof version !== 'string') - { return null; } - - if (version.length > MAX_LENGTH) - { return null; } - - var r = loose ? re[LOOSE] : re[FULL]; - if (!r.test(version)) - { return null; } - - try { - return new SemVer(version, loose); - } catch (er) { - return 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.trim().replace(/^[=v]+/, ''), 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; } - } else if (typeof version !== 'string') { - throw new TypeError('Invalid Version: ' + version); - } - - if (version.length > MAX_LENGTH) - { throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters') } - - 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]; - - if (this.major > MAX_SAFE_INTEGER || this.major < 0) - { throw new TypeError('Invalid major version') } - - if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) - { throw new TypeError('Invalid minor version') } - - if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) - { throw new TypeError('Invalid patch version') } - - // numberify any prerelease numeric ids - if (!m[4]) - { this.prerelease = []; } - else - { this.prerelease = m[4].split('.').map(function(id) { - if (/^[0-9]+$/.test(id)) { - var num = +id; - if (num >= 0 && num < MAX_SAFE_INTEGER) - { return num; } - } - return 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.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) { - var this$1 = this; - - 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.length && !other.prerelease.length) - { return 0; } - - var i = 0; - do { - var a = this$1.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); -}; - -// preminor will bump the version up to the next minor release, and immediately -// down to pre-release. premajor and prepatch work the same way. -SemVer.prototype.inc = function(release, identifier) { - var this$1 = this; - - switch (release) { - case 'premajor': - this.prerelease.length = 0; - this.patch = 0; - this.minor = 0; - this.major++; - this.inc('pre', identifier); - break; - case 'preminor': - this.prerelease.length = 0; - this.patch = 0; - this.minor++; - this.inc('pre', identifier); - break; - case 'prepatch': - // If this is already a prerelease, it will bump to the next version - // drop any prereleases that might already exist, since they are not - // relevant at this point. - this.prerelease.length = 0; - this.inc('patch', identifier); - this.inc('pre', identifier); - break; - // If the input is a non-prerelease version, this acts the same as - // prepatch. - case 'prerelease': - if (this.prerelease.length === 0) - { this.inc('patch', identifier); } - this.inc('pre', identifier); - break; - - case 'major': - // If this is a pre-major version, bump up to the same major version. - // Otherwise increment major. - // 1.0.0-5 bumps to 1.0.0 - // 1.1.0 bumps to 2.0.0 - if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) - { this.major++; } - this.minor = 0; - this.patch = 0; - this.prerelease = []; - break; - case 'minor': - // If this is a pre-minor version, bump up to the same minor version. - // Otherwise increment minor. - // 1.2.0-5 bumps to 1.2.0 - // 1.2.1 bumps to 1.3.0 - if (this.patch !== 0 || this.prerelease.length === 0) - { this.minor++; } - this.patch = 0; - this.prerelease = []; - break; - case 'patch': - // If this is not a pre-release version, it will increment the patch. - // If it is a pre-release it will bump up to the same patch version. - // 1.2.0-5 patches to 1.2.0 - // 1.2.0 patches to 1.2.1 - if (this.prerelease.length === 0) - { this.patch++; } - this.prerelease = []; - break; - // This probably shouldn't be used publicly. - // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction. - case 'pre': - if (this.prerelease.length === 0) - { this.prerelease = [0]; } - else { - var i = this.prerelease.length; - while (--i >= 0) { - if (typeof this$1.prerelease[i] === 'number') { - this$1.prerelease[i]++; - i = -2; - } - } - if (i === -1) // didn't increment anything - { this.prerelease.push(0); } - } - if (identifier) { - // 1.2.0-beta.1 bumps to 1.2.0-beta.2, - // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0 - if (this.prerelease[0] === identifier) { - if (isNaN(this.prerelease[1])) - { this.prerelease = [identifier, 0]; } - } else - { this.prerelease = [identifier, 0]; } - } - break; - - default: - throw new Error('invalid increment argument: ' + release); - } - this.format(); - this.raw = this.version; - return this; -}; - -exports.inc = inc; -function inc(version, release, loose, identifier) { - if (typeof(loose) === 'string') { - identifier = loose; - loose = undefined; - } - - try { - return new SemVer(version, loose).inc(release, identifier).version; - } catch (er) { - return null; - } -} - -exports.diff = diff; -function diff(version1, version2) { - if (eq(version1, version2)) { - return null; - } else { - var v1 = parse(version1); - var v2 = parse(version2); - if (v1.prerelease.length || v2.prerelease.length) { - for (var key in v1) { - if (key === 'major' || key === 'minor' || key === 'patch') { - if (v1[key] !== v2[key]) { - return 'pre'+key; - } - } - } - return 'prerelease'; - } - for (var key in v1) { - if (key === 'major' || key === 'minor' || key === 'patch') { - if (v1[key] !== v2[key]) { - return key; - } - } - } - } -} - -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.major = major; -function major(a, loose) { - return new SemVer(a, loose).major; -} - -exports.minor = minor; -function minor(a, loose) { - return new SemVer(a, loose).minor; -} - -exports.patch = patch; -function patch(a, loose) { - return new SemVer(a, loose).patch; -} - -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 '===': - if (typeof a === 'object') { a = a.version; } - if (typeof b === 'object') { b = b.version; } - ret = a === b; - break; - case '!==': - if (typeof a === 'object') { a = a.version; } - if (typeof b === 'object') { b = b.version; } - 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; } - - debug('comp', this); -} - -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 (this.operator === '=') - { this.operator = ''; } - - // if it literally is just '>' or '' then allow anything. - if (!m[2]) - { this.semver = ANY; } - else - { this.semver = new SemVer(m[2], this.loose); } -}; - -Comparator.prototype.toString = function() { - return this.value; -}; - -Comparator.prototype.test = function(version) { - debug('Comparator.test', version, this.loose); - - if (this.semver === ANY) - { return true; } - - if (typeof version === 'string') - { version = new SemVer(version, this.loose); } - - return 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.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 <' + (+M + 1) + '.0.0'; } - else if (isX(p)) - // ~1.2 == >=1.2.0 <1.3.0 - { ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; } - else if (pr) { - debug('replaceTilde pr', pr); - if (pr.charAt(0) !== '-') - { pr = '-' + pr; } - ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + M + '.' + (+m + 1) + '.0'; - } else - // ~1.2.3 == >=1.2.3 <1.3.0 - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + (+m + 1) + '.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) { - debug('caret', 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 <' + (+M + 1) + '.0.0'; } - else if (isX(p)) { - if (M === '0') - { ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; } - else - { ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.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 + - ' <' + M + '.' + m + '.' + (+p + 1); } - else - { ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + M + '.' + (+m + 1) + '.0'; } - } else - { ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + (+M + 1) + '.0.0'; } - } else { - debug('no pr'); - if (M === '0') { - if (m === '0') - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + m + '.' + (+p + 1); } - else - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + (+m + 1) + '.0'; } - } else - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + (+M + 1) + '.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 (xM) { - if (gtlt === '>' || gtlt === '<') { - // nothing is allowed - ret = '<0.0.0'; - } else { - // nothing is forbidden - ret = '*'; - } - } else if (gtlt && anyX) { - // replace X with 0 - if (xm) - { m = 0; } - if (xp) - { p = 0; } - - if (gtlt === '>') { - // >1 => >=2.0.0 - // >1.2 => >=1.3.0 - // >1.2.3 => >= 1.2.4 - gtlt = '>='; - if (xm) { - M = +M + 1; - m = 0; - p = 0; - } else if (xp) { - m = +m + 1; - p = 0; - } - } else if (gtlt === '<=') { - // <=0.7.x is actually <0.8.0, since any 0.7.x should - // pass. Similarly, <=7.x is actually <8.0.0, etc. - gtlt = '<'; - if (xm) - { M = +M + 1; } - else - { m = +m + 1; } - } - - ret = gtlt + M + '.' + m + '.' + p; - } else if (xm) { - ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'; - } else if (xp) { - ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.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 <=3.4.5 -// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do -// 1.2 - 3.4 => >=1.2.0 <3.5.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'; } - else if (isX(fp)) - { from = '>=' + fM + '.' + fm + '.0'; } - else - { from = '>=' + from; } - - if (isX(tM)) - { to = ''; } - else if (isX(tm)) - { to = '<' + (+tM + 1) + '.0.0'; } - else if (isX(tp)) - { to = '<' + tM + '.' + (+tm + 1) + '.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) { - var this$1 = this; - - if (!version) - { return false; } - - if (typeof version === 'string') - { version = new SemVer(version, this.loose); } - - for (var i = 0; i < this.set.length; i++) { - if (testSet(this$1.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; } - } - - if (version.prerelease.length) { - // Find the set of versions that are allowed to have prereleases - // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0 - // That should allow `1.2.3-pr.2` to pass. - // However, `1.2.4-alpha.notready` should NOT be allowed, - // even though it's within the range set by the comparators. - for (var i = 0; i < set.length; i++) { - debug(set[i].semver); - if (set[i].semver === ANY) - { continue; } - - if (set[i].semver.prerelease.length > 0) { - var allowed = set[i].semver; - if (allowed.major === version.major && - allowed.minor === version.minor && - allowed.patch === version.patch) - { return true; } - } - } - - // Version has a -pre, but it's not one of the ones we like. - 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.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; -} - -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; - } -} - -// Determine if version is less than all the versions possible in the range -exports.ltr = ltr; -function ltr(version, range, loose) { - return outside(version, range, '<', loose); -} - -// Determine if version is greater than all the versions possible in the range. -exports.gtr = gtr; -function gtr(version, range, loose) { - return outside(version, range, '>', loose); -} - -exports.outside = outside; -function outside(version, range, hilo, loose) { - version = new SemVer(version, loose); - range = new Range(range, loose); - - var gtfn, ltefn, ltfn, comp, ecomp; - switch (hilo) { - case '>': - gtfn = gt; - ltefn = lte; - ltfn = lt; - comp = '>'; - ecomp = '>='; - break; - case '<': - gtfn = lt; - ltefn = gte; - ltfn = gt; - comp = '<'; - ecomp = '<='; - break; - default: - throw new TypeError('Must provide a hilo val of "<" or ">"'); - } - - // If it satisifes the range it is not outside - if (satisfies(version, range, loose)) { - return false; - } - - // From now on, variable terms are as if we're in "gtr" mode. - // but note that everything is flipped for the "ltr" function. - - for (var i = 0; i < range.set.length; ++i) { - var comparators = range.set[i]; - - var high = null; - var low = null; - - comparators.forEach(function(comparator) { - if (comparator.semver === ANY) { - comparator = new Comparator('>=0.0.0'); - } - high = high || comparator; - low = low || comparator; - if (gtfn(comparator.semver, high.semver, loose)) { - high = comparator; - } else if (ltfn(comparator.semver, low.semver, loose)) { - low = comparator; - } - }); - - // If the edge version comparator has a operator then our version - // isn't outside it - if (high.operator === comp || high.operator === ecomp) { - return false; - } - - // If the lowest version comparator has an operator and our version - // is less than it then it isn't higher than the range - if ((!low.operator || low.operator === comp) && - ltefn(version, low.semver)) { - return false; - } else if (low.operator === ecomp && ltfn(version, low.semver)) { - return false; - } - } - return true; -} - -exports.prerelease = prerelease; -function prerelease(version, loose) { - var parsed = parse(version, loose); - return (parsed && parsed.prerelease.length) ? parsed.prerelease : null; -} -}); - -var index$10 = typeof commonjsGlobal === 'object' && commonjsGlobal.Promise || - typeof window === 'object' && window.Promise || - typeof Promise !== 'undefined' && Promise || - false; - -/** - * > Pass a synchronous `fn` that returns some - * result and handle completion or errors in `cb` - * if given, otherwise it returns thunk which accepts - * that `cb`. It's possible to not work in "async mode", - * if that's the case try to use [try-catch-core][] for - * your case, which guarantees that `cb` is called only - * once and always in next tick, using [dezalgo][] and [once][]. - * - * **Example** - * - * ```js - * var tryCatch = require('try-catch-callback') - * - * tryCatch(function () { - * return 'fox qux' - * }, function done (err, res) { - * if (err) return console.error(err) - * console.log(res) // => 'fox qux' - * }) - * ``` - * - * @param {Function} `` function to be called. - * @param {Object} `[opts]` optional options, such as `context` and `args` - * @param {Object} `[opts.context]` context to be passed to `fn` - * @param {Array} `[opts.args]` custom argument(s) to be pass to `fn`, given value is arrayified - * @param {Boolean} `[opts.passCallback]` pass `true` if you want `cb` to be passed to `fn` args - * @param {Boolean} `[opts.return]` if `true` returns error/value and does not calls `cb` - * @param {Function} `[cb]` callback with `cb(err, res)` signature. - * @return {Function} `thunk` if `cb` not given. - * @throws {TypError} if `fn` not a function. - * @throws {TypError} if no function is passed to `thunk`. - * @api public - */ - -var index$12 = function tryCatchCallback (fn, opts, cb) { - if (typeof fn !== 'function') { - throw new TypeError('try-catch-callback: expect `fn` to be a function') - } - if (typeof opts === 'function') { - cb = opts; - opts = false; - } - opts = index$6({}, opts); - - if (opts.return || typeof cb === 'function') { - return tryCatch.call(this, fn, opts, cb) - } - return function thunk (done) { - opts.thunk = true; - tryCatch.call(this, fn, opts, done); - } -}; - -function tryCatch (fn, opts, cb) { - if (opts.thunk && typeof cb !== 'function') { - throw new TypeError('try-catch-callback: expect `cb` to be a function') - } - var args = arrayify(opts.args); - var ctx = opts.context || this; - var ret = null; - - try { - ret = fn.apply(ctx, opts.passCallback ? args.concat(cb) : args); - } catch (err) { - return opts.return ? err : cb(err) - } - - if (opts.return) { return ret } - if (!opts.passCallback) { cb(null, ret); } -} - -function arrayify (val) { - if (!val) { return [] } - if (Array.isArray(val)) { return val } - return [val] -} - -var commonPromiseLibs = [ - 'es6-promise', - 'promise', - 'native-promise-only', - 'bluebird', - 'rsvp', - 'when', - 'q', - 'pinkie', - 'lie', - 'vow' -]; - -var register = function register (opts) { - // won't load native Promise if < v0.12, since it is buggy - /* istanbul ignore next */ - if (index$10 && semver.gte(process.version, '0.12.0')) { - index$10.___nativePromise = true; - return index$10 - } - if (typeof opts === 'function') { - opts = { Promise: opts, global: opts.global }; - } - - var options = index$6({ global: true }, opts); - var PromiseCtor = options.Promise || tryLoadCommon(); - PromiseCtor.___customPromise = true; - - if (options.global === false) { - return PromiseCtor - } - - commonjsGlobal.Promise = PromiseCtor; - return commonjsGlobal.Promise -}; - -function tryLoadCommon () { - var len = commonPromiseLibs.length; - var i = -1; - - while (i++ < len) { - var lib = commonPromiseLibs[i]; - var ret = index$12(function () { - var ret = commonjsRequire(lib); - return ret.Promise || ret - }, { return: true }); - - if (ret instanceof Error) { - if ((i + 1) < len) { - continue - } else { - var msg = [ - 'No native Promise support nor other promise were found.', - 'These promise libraries are supported by default: ' + commonPromiseLibs.join(', ') + '.', - 'This means that if one of them is installed it will be loaded automatically.', - 'Otherwise you should give a promise implementation through opts.Promise!' - ].join(' '); - - throw new Error(msg) - } - } else { - return ret - } - } -} - -var commonPromiseLibs_1 = commonPromiseLibs; - -register.commonPromiseLibs = commonPromiseLibs_1; - -var index$14 = register({ global: false }); - /** * > Check any of `values` exists on `arr`. * @@ -1500,7 +126,7 @@ var index$14 = register({ global: false }); * @api public */ -var index$18 = function arrIncludes (arr, values) { +var index$6 = function arrIncludes (arr, values) { if (!Array.isArray(values)) { return inArray(arr, values) } var len = values.length; var i = -1; @@ -1516,7 +142,7 @@ var index$18 = function arrIncludes (arr, values) { }; function inArray (arr, val) { - arr = index$2(arr); + arr = index(arr); var len = arr.length; var i = null; @@ -1535,7 +161,7 @@ function inArray (arr, val) { * Released under the MIT license. */ -var index$20 = [ +var index$8 = [ 'callback', 'callback_', 'cb', @@ -1574,7 +200,7 @@ var index$20 = [ * @api public */ -var index$22 = function functionArguments (fn) { +var index$10 = function functionArguments (fn) { if (typeof fn !== 'function') { throw new TypeError('function-arguments expect a function') } @@ -1639,7 +265,7 @@ var index$22 = function functionArguments (fn) { * @api public */ -var index$16 = function isAsyncFunction (fn, names, strict) { +var index$5 = function isAsyncFunction (fn, names, strict) { if (typeof fn !== 'function') { throw new TypeError('is-async-function expect a function') } @@ -1648,13 +274,20 @@ var index$16 = function isAsyncFunction (fn, names, strict) { strict = typeof strict === 'boolean' ? strict : true; names = typeof names === 'boolean' ? null : names; - names = Array.isArray(names) ? names : index$2(names); - names = names.length ? names : index$20; + names = Array.isArray(names) ? names : index(names); + names = names.length ? names : index$8; - var idx = index$18(names, index$22(fn)); + var idx = index$6(names, index$10(fn)); return strict ? Boolean(idx) : idx }; +/*! + * redolent + * + * Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online) + * Released under the MIT license. + */ + /** * > Will try to promisify `fn` with native Promise, * otherwise you can give different promise module @@ -1720,12 +353,12 @@ var index$16 = function isAsyncFunction (fn, names, strict) { * @api public */ -var index = function redolent (fn, opts) { +function redolent (fn, opts) { if (typeof fn !== 'function') { throw new TypeError('redolent: expect `fn` to be a function') } - opts = index$6({ context: this, Promise: index$14 }, opts); + opts = index$2({ context: this, Promise: Promize }, opts); opts.Promise = register(opts); // we can't test that here, because some @@ -1739,7 +372,7 @@ var index = function redolent (fn, opts) { return function () { opts.context = this || opts.context; - opts.args = index$2(opts.args).concat(index$4(arguments)); + opts.args = index(opts.args).concat(index$1(arguments)); var promise = new opts.Promise(function (resolve, reject) { var called = false; @@ -1750,12 +383,12 @@ var index = function redolent (fn, opts) { return reject(er) } if (arguments.length > 2) { - res = index$4(arguments, 1); + res = index$1(arguments, 1); } return resolve(res) } - var isAsyncFn = index$16(fn); + var isAsyncFn = index$5(fn); opts.args = isAsyncFn ? opts.args.concat(done) : opts.args; var syncResult = fn.apply(opts.context, opts.args); @@ -1767,7 +400,7 @@ var index = function redolent (fn, opts) { return normalize(promise, opts.Promise) } -}; +} function normalize (promise, Ctor) { promise.___nativePromise = Boolean(Ctor.___nativePromise); @@ -1775,4 +408,4 @@ function normalize (promise, Ctor) { return promise } -module.exports = index; +module.exports = redolent; diff --git a/dist/redolent.es.js b/dist/redolent.es.js index e4f7322..61c8318 100644 --- a/dist/redolent.es.js +++ b/dist/redolent.es.js @@ -1,4 +1,7 @@ -var index$2 = function (val) { +import register from 'native-or-another/register'; +import Promize from 'native-or-another'; + +var index = function (val) { if (val === null || val === undefined) { return []; } @@ -15,7 +18,7 @@ var index$2 = function (val) { * @api public */ -var index$4 = function (args, slice, sliceEnd) { +var index$1 = function (args, slice, sliceEnd) { var ret = []; var len = args.length; @@ -45,21 +48,21 @@ var index$4 = function (args, slice, sliceEnd) { * Licensed under the MIT License. */ -var index$8 = function isExtendable(val) { +var index$3 = function isExtendable(val) { return typeof val !== 'undefined' && val !== null && (typeof val === 'object' || typeof val === 'function'); }; -var index$6 = function extend(o/*, objects*/) { +var index$2 = function extend(o/*, objects*/) { var arguments$1 = arguments; - if (!index$8(o)) { o = {}; } + if (!index$3(o)) { o = {}; } var len = arguments.length; for (var i = 1; i < len; i++) { var obj = arguments$1[i]; - if (index$8(obj)) { + if (index$3(obj)) { assign(o, obj); } } @@ -82,1385 +85,6 @@ function hasOwn(obj, key) { return Object.prototype.hasOwnProperty.call(obj, key); } -var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - -function commonjsRequire () { - throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); -} - - - -function createCommonjsModule(fn, module) { - return module = { exports: {} }, fn(module, module.exports), module.exports; -} - -var semver = createCommonjsModule(function (module, 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'; - -var MAX_LENGTH = 256; -var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; - -// 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] + ')?' + - src[BUILD] + '?' + - ')?)?'; - -var XRANGEPLAINLOOSE = R++; -src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' + - '(?:' + src[PRERELEASELOOSE] + ')?' + - src[BUILD] + '?' + - ')?)?'; - -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) { - if (version instanceof SemVer) - { return version; } - - if (typeof version !== 'string') - { return null; } - - if (version.length > MAX_LENGTH) - { return null; } - - var r = loose ? re[LOOSE] : re[FULL]; - if (!r.test(version)) - { return null; } - - try { - return new SemVer(version, loose); - } catch (er) { - return 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.trim().replace(/^[=v]+/, ''), 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; } - } else if (typeof version !== 'string') { - throw new TypeError('Invalid Version: ' + version); - } - - if (version.length > MAX_LENGTH) - { throw new TypeError('version is longer than ' + MAX_LENGTH + ' characters') } - - 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]; - - if (this.major > MAX_SAFE_INTEGER || this.major < 0) - { throw new TypeError('Invalid major version') } - - if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) - { throw new TypeError('Invalid minor version') } - - if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) - { throw new TypeError('Invalid patch version') } - - // numberify any prerelease numeric ids - if (!m[4]) - { this.prerelease = []; } - else - { this.prerelease = m[4].split('.').map(function(id) { - if (/^[0-9]+$/.test(id)) { - var num = +id; - if (num >= 0 && num < MAX_SAFE_INTEGER) - { return num; } - } - return 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.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) { - var this$1 = this; - - 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.length && !other.prerelease.length) - { return 0; } - - var i = 0; - do { - var a = this$1.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); -}; - -// preminor will bump the version up to the next minor release, and immediately -// down to pre-release. premajor and prepatch work the same way. -SemVer.prototype.inc = function(release, identifier) { - var this$1 = this; - - switch (release) { - case 'premajor': - this.prerelease.length = 0; - this.patch = 0; - this.minor = 0; - this.major++; - this.inc('pre', identifier); - break; - case 'preminor': - this.prerelease.length = 0; - this.patch = 0; - this.minor++; - this.inc('pre', identifier); - break; - case 'prepatch': - // If this is already a prerelease, it will bump to the next version - // drop any prereleases that might already exist, since they are not - // relevant at this point. - this.prerelease.length = 0; - this.inc('patch', identifier); - this.inc('pre', identifier); - break; - // If the input is a non-prerelease version, this acts the same as - // prepatch. - case 'prerelease': - if (this.prerelease.length === 0) - { this.inc('patch', identifier); } - this.inc('pre', identifier); - break; - - case 'major': - // If this is a pre-major version, bump up to the same major version. - // Otherwise increment major. - // 1.0.0-5 bumps to 1.0.0 - // 1.1.0 bumps to 2.0.0 - if (this.minor !== 0 || this.patch !== 0 || this.prerelease.length === 0) - { this.major++; } - this.minor = 0; - this.patch = 0; - this.prerelease = []; - break; - case 'minor': - // If this is a pre-minor version, bump up to the same minor version. - // Otherwise increment minor. - // 1.2.0-5 bumps to 1.2.0 - // 1.2.1 bumps to 1.3.0 - if (this.patch !== 0 || this.prerelease.length === 0) - { this.minor++; } - this.patch = 0; - this.prerelease = []; - break; - case 'patch': - // If this is not a pre-release version, it will increment the patch. - // If it is a pre-release it will bump up to the same patch version. - // 1.2.0-5 patches to 1.2.0 - // 1.2.0 patches to 1.2.1 - if (this.prerelease.length === 0) - { this.patch++; } - this.prerelease = []; - break; - // This probably shouldn't be used publicly. - // 1.0.0 "pre" would become 1.0.0-0 which is the wrong direction. - case 'pre': - if (this.prerelease.length === 0) - { this.prerelease = [0]; } - else { - var i = this.prerelease.length; - while (--i >= 0) { - if (typeof this$1.prerelease[i] === 'number') { - this$1.prerelease[i]++; - i = -2; - } - } - if (i === -1) // didn't increment anything - { this.prerelease.push(0); } - } - if (identifier) { - // 1.2.0-beta.1 bumps to 1.2.0-beta.2, - // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0 - if (this.prerelease[0] === identifier) { - if (isNaN(this.prerelease[1])) - { this.prerelease = [identifier, 0]; } - } else - { this.prerelease = [identifier, 0]; } - } - break; - - default: - throw new Error('invalid increment argument: ' + release); - } - this.format(); - this.raw = this.version; - return this; -}; - -exports.inc = inc; -function inc(version, release, loose, identifier) { - if (typeof(loose) === 'string') { - identifier = loose; - loose = undefined; - } - - try { - return new SemVer(version, loose).inc(release, identifier).version; - } catch (er) { - return null; - } -} - -exports.diff = diff; -function diff(version1, version2) { - if (eq(version1, version2)) { - return null; - } else { - var v1 = parse(version1); - var v2 = parse(version2); - if (v1.prerelease.length || v2.prerelease.length) { - for (var key in v1) { - if (key === 'major' || key === 'minor' || key === 'patch') { - if (v1[key] !== v2[key]) { - return 'pre'+key; - } - } - } - return 'prerelease'; - } - for (var key in v1) { - if (key === 'major' || key === 'minor' || key === 'patch') { - if (v1[key] !== v2[key]) { - return key; - } - } - } - } -} - -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.major = major; -function major(a, loose) { - return new SemVer(a, loose).major; -} - -exports.minor = minor; -function minor(a, loose) { - return new SemVer(a, loose).minor; -} - -exports.patch = patch; -function patch(a, loose) { - return new SemVer(a, loose).patch; -} - -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 '===': - if (typeof a === 'object') { a = a.version; } - if (typeof b === 'object') { b = b.version; } - ret = a === b; - break; - case '!==': - if (typeof a === 'object') { a = a.version; } - if (typeof b === 'object') { b = b.version; } - 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; } - - debug('comp', this); -} - -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 (this.operator === '=') - { this.operator = ''; } - - // if it literally is just '>' or '' then allow anything. - if (!m[2]) - { this.semver = ANY; } - else - { this.semver = new SemVer(m[2], this.loose); } -}; - -Comparator.prototype.toString = function() { - return this.value; -}; - -Comparator.prototype.test = function(version) { - debug('Comparator.test', version, this.loose); - - if (this.semver === ANY) - { return true; } - - if (typeof version === 'string') - { version = new SemVer(version, this.loose); } - - return 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.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 <' + (+M + 1) + '.0.0'; } - else if (isX(p)) - // ~1.2 == >=1.2.0 <1.3.0 - { ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; } - else if (pr) { - debug('replaceTilde pr', pr); - if (pr.charAt(0) !== '-') - { pr = '-' + pr; } - ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + M + '.' + (+m + 1) + '.0'; - } else - // ~1.2.3 == >=1.2.3 <1.3.0 - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + (+m + 1) + '.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) { - debug('caret', 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 <' + (+M + 1) + '.0.0'; } - else if (isX(p)) { - if (M === '0') - { ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'; } - else - { ret = '>=' + M + '.' + m + '.0 <' + (+M + 1) + '.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 + - ' <' + M + '.' + m + '.' + (+p + 1); } - else - { ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + M + '.' + (+m + 1) + '.0'; } - } else - { ret = '>=' + M + '.' + m + '.' + p + pr + - ' <' + (+M + 1) + '.0.0'; } - } else { - debug('no pr'); - if (M === '0') { - if (m === '0') - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + m + '.' + (+p + 1); } - else - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + M + '.' + (+m + 1) + '.0'; } - } else - { ret = '>=' + M + '.' + m + '.' + p + - ' <' + (+M + 1) + '.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 (xM) { - if (gtlt === '>' || gtlt === '<') { - // nothing is allowed - ret = '<0.0.0'; - } else { - // nothing is forbidden - ret = '*'; - } - } else if (gtlt && anyX) { - // replace X with 0 - if (xm) - { m = 0; } - if (xp) - { p = 0; } - - if (gtlt === '>') { - // >1 => >=2.0.0 - // >1.2 => >=1.3.0 - // >1.2.3 => >= 1.2.4 - gtlt = '>='; - if (xm) { - M = +M + 1; - m = 0; - p = 0; - } else if (xp) { - m = +m + 1; - p = 0; - } - } else if (gtlt === '<=') { - // <=0.7.x is actually <0.8.0, since any 0.7.x should - // pass. Similarly, <=7.x is actually <8.0.0, etc. - gtlt = '<'; - if (xm) - { M = +M + 1; } - else - { m = +m + 1; } - } - - ret = gtlt + M + '.' + m + '.' + p; - } else if (xm) { - ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'; - } else if (xp) { - ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.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 <=3.4.5 -// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do -// 1.2 - 3.4 => >=1.2.0 <3.5.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'; } - else if (isX(fp)) - { from = '>=' + fM + '.' + fm + '.0'; } - else - { from = '>=' + from; } - - if (isX(tM)) - { to = ''; } - else if (isX(tm)) - { to = '<' + (+tM + 1) + '.0.0'; } - else if (isX(tp)) - { to = '<' + tM + '.' + (+tm + 1) + '.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) { - var this$1 = this; - - if (!version) - { return false; } - - if (typeof version === 'string') - { version = new SemVer(version, this.loose); } - - for (var i = 0; i < this.set.length; i++) { - if (testSet(this$1.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; } - } - - if (version.prerelease.length) { - // Find the set of versions that are allowed to have prereleases - // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0 - // That should allow `1.2.3-pr.2` to pass. - // However, `1.2.4-alpha.notready` should NOT be allowed, - // even though it's within the range set by the comparators. - for (var i = 0; i < set.length; i++) { - debug(set[i].semver); - if (set[i].semver === ANY) - { continue; } - - if (set[i].semver.prerelease.length > 0) { - var allowed = set[i].semver; - if (allowed.major === version.major && - allowed.minor === version.minor && - allowed.patch === version.patch) - { return true; } - } - } - - // Version has a -pre, but it's not one of the ones we like. - 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.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; -} - -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; - } -} - -// Determine if version is less than all the versions possible in the range -exports.ltr = ltr; -function ltr(version, range, loose) { - return outside(version, range, '<', loose); -} - -// Determine if version is greater than all the versions possible in the range. -exports.gtr = gtr; -function gtr(version, range, loose) { - return outside(version, range, '>', loose); -} - -exports.outside = outside; -function outside(version, range, hilo, loose) { - version = new SemVer(version, loose); - range = new Range(range, loose); - - var gtfn, ltefn, ltfn, comp, ecomp; - switch (hilo) { - case '>': - gtfn = gt; - ltefn = lte; - ltfn = lt; - comp = '>'; - ecomp = '>='; - break; - case '<': - gtfn = lt; - ltefn = gte; - ltfn = gt; - comp = '<'; - ecomp = '<='; - break; - default: - throw new TypeError('Must provide a hilo val of "<" or ">"'); - } - - // If it satisifes the range it is not outside - if (satisfies(version, range, loose)) { - return false; - } - - // From now on, variable terms are as if we're in "gtr" mode. - // but note that everything is flipped for the "ltr" function. - - for (var i = 0; i < range.set.length; ++i) { - var comparators = range.set[i]; - - var high = null; - var low = null; - - comparators.forEach(function(comparator) { - if (comparator.semver === ANY) { - comparator = new Comparator('>=0.0.0'); - } - high = high || comparator; - low = low || comparator; - if (gtfn(comparator.semver, high.semver, loose)) { - high = comparator; - } else if (ltfn(comparator.semver, low.semver, loose)) { - low = comparator; - } - }); - - // If the edge version comparator has a operator then our version - // isn't outside it - if (high.operator === comp || high.operator === ecomp) { - return false; - } - - // If the lowest version comparator has an operator and our version - // is less than it then it isn't higher than the range - if ((!low.operator || low.operator === comp) && - ltefn(version, low.semver)) { - return false; - } else if (low.operator === ecomp && ltfn(version, low.semver)) { - return false; - } - } - return true; -} - -exports.prerelease = prerelease; -function prerelease(version, loose) { - var parsed = parse(version, loose); - return (parsed && parsed.prerelease.length) ? parsed.prerelease : null; -} -}); - -var index$10 = typeof commonjsGlobal === 'object' && commonjsGlobal.Promise || - typeof window === 'object' && window.Promise || - typeof Promise !== 'undefined' && Promise || - false; - -/** - * > Pass a synchronous `fn` that returns some - * result and handle completion or errors in `cb` - * if given, otherwise it returns thunk which accepts - * that `cb`. It's possible to not work in "async mode", - * if that's the case try to use [try-catch-core][] for - * your case, which guarantees that `cb` is called only - * once and always in next tick, using [dezalgo][] and [once][]. - * - * **Example** - * - * ```js - * var tryCatch = require('try-catch-callback') - * - * tryCatch(function () { - * return 'fox qux' - * }, function done (err, res) { - * if (err) return console.error(err) - * console.log(res) // => 'fox qux' - * }) - * ``` - * - * @param {Function} `` function to be called. - * @param {Object} `[opts]` optional options, such as `context` and `args` - * @param {Object} `[opts.context]` context to be passed to `fn` - * @param {Array} `[opts.args]` custom argument(s) to be pass to `fn`, given value is arrayified - * @param {Boolean} `[opts.passCallback]` pass `true` if you want `cb` to be passed to `fn` args - * @param {Boolean} `[opts.return]` if `true` returns error/value and does not calls `cb` - * @param {Function} `[cb]` callback with `cb(err, res)` signature. - * @return {Function} `thunk` if `cb` not given. - * @throws {TypError} if `fn` not a function. - * @throws {TypError} if no function is passed to `thunk`. - * @api public - */ - -var index$12 = function tryCatchCallback (fn, opts, cb) { - if (typeof fn !== 'function') { - throw new TypeError('try-catch-callback: expect `fn` to be a function') - } - if (typeof opts === 'function') { - cb = opts; - opts = false; - } - opts = index$6({}, opts); - - if (opts.return || typeof cb === 'function') { - return tryCatch.call(this, fn, opts, cb) - } - return function thunk (done) { - opts.thunk = true; - tryCatch.call(this, fn, opts, done); - } -}; - -function tryCatch (fn, opts, cb) { - if (opts.thunk && typeof cb !== 'function') { - throw new TypeError('try-catch-callback: expect `cb` to be a function') - } - var args = arrayify(opts.args); - var ctx = opts.context || this; - var ret = null; - - try { - ret = fn.apply(ctx, opts.passCallback ? args.concat(cb) : args); - } catch (err) { - return opts.return ? err : cb(err) - } - - if (opts.return) { return ret } - if (!opts.passCallback) { cb(null, ret); } -} - -function arrayify (val) { - if (!val) { return [] } - if (Array.isArray(val)) { return val } - return [val] -} - -var commonPromiseLibs = [ - 'es6-promise', - 'promise', - 'native-promise-only', - 'bluebird', - 'rsvp', - 'when', - 'q', - 'pinkie', - 'lie', - 'vow' -]; - -var register = function register (opts) { - // won't load native Promise if < v0.12, since it is buggy - /* istanbul ignore next */ - if (index$10 && semver.gte(process.version, '0.12.0')) { - index$10.___nativePromise = true; - return index$10 - } - if (typeof opts === 'function') { - opts = { Promise: opts, global: opts.global }; - } - - var options = index$6({ global: true }, opts); - var PromiseCtor = options.Promise || tryLoadCommon(); - PromiseCtor.___customPromise = true; - - if (options.global === false) { - return PromiseCtor - } - - commonjsGlobal.Promise = PromiseCtor; - return commonjsGlobal.Promise -}; - -function tryLoadCommon () { - var len = commonPromiseLibs.length; - var i = -1; - - while (i++ < len) { - var lib = commonPromiseLibs[i]; - var ret = index$12(function () { - var ret = commonjsRequire(lib); - return ret.Promise || ret - }, { return: true }); - - if (ret instanceof Error) { - if ((i + 1) < len) { - continue - } else { - var msg = [ - 'No native Promise support nor other promise were found.', - 'These promise libraries are supported by default: ' + commonPromiseLibs.join(', ') + '.', - 'This means that if one of them is installed it will be loaded automatically.', - 'Otherwise you should give a promise implementation through opts.Promise!' - ].join(' '); - - throw new Error(msg) - } - } else { - return ret - } - } -} - -var commonPromiseLibs_1 = commonPromiseLibs; - -register.commonPromiseLibs = commonPromiseLibs_1; - -var index$14 = register({ global: false }); - /** * > Check any of `values` exists on `arr`. * @@ -1498,7 +122,7 @@ var index$14 = register({ global: false }); * @api public */ -var index$18 = function arrIncludes (arr, values) { +var index$6 = function arrIncludes (arr, values) { if (!Array.isArray(values)) { return inArray(arr, values) } var len = values.length; var i = -1; @@ -1514,7 +138,7 @@ var index$18 = function arrIncludes (arr, values) { }; function inArray (arr, val) { - arr = index$2(arr); + arr = index(arr); var len = arr.length; var i = null; @@ -1533,7 +157,7 @@ function inArray (arr, val) { * Released under the MIT license. */ -var index$20 = [ +var index$8 = [ 'callback', 'callback_', 'cb', @@ -1572,7 +196,7 @@ var index$20 = [ * @api public */ -var index$22 = function functionArguments (fn) { +var index$10 = function functionArguments (fn) { if (typeof fn !== 'function') { throw new TypeError('function-arguments expect a function') } @@ -1637,7 +261,7 @@ var index$22 = function functionArguments (fn) { * @api public */ -var index$16 = function isAsyncFunction (fn, names, strict) { +var index$5 = function isAsyncFunction (fn, names, strict) { if (typeof fn !== 'function') { throw new TypeError('is-async-function expect a function') } @@ -1646,13 +270,20 @@ var index$16 = function isAsyncFunction (fn, names, strict) { strict = typeof strict === 'boolean' ? strict : true; names = typeof names === 'boolean' ? null : names; - names = Array.isArray(names) ? names : index$2(names); - names = names.length ? names : index$20; + names = Array.isArray(names) ? names : index(names); + names = names.length ? names : index$8; - var idx = index$18(names, index$22(fn)); + var idx = index$6(names, index$10(fn)); return strict ? Boolean(idx) : idx }; +/*! + * redolent + * + * Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online) + * Released under the MIT license. + */ + /** * > Will try to promisify `fn` with native Promise, * otherwise you can give different promise module @@ -1718,12 +349,12 @@ var index$16 = function isAsyncFunction (fn, names, strict) { * @api public */ -var index = function redolent (fn, opts) { +function redolent (fn, opts) { if (typeof fn !== 'function') { throw new TypeError('redolent: expect `fn` to be a function') } - opts = index$6({ context: this, Promise: index$14 }, opts); + opts = index$2({ context: this, Promise: Promize }, opts); opts.Promise = register(opts); // we can't test that here, because some @@ -1737,7 +368,7 @@ var index = function redolent (fn, opts) { return function () { opts.context = this || opts.context; - opts.args = index$2(opts.args).concat(index$4(arguments)); + opts.args = index(opts.args).concat(index$1(arguments)); var promise = new opts.Promise(function (resolve, reject) { var called = false; @@ -1748,12 +379,12 @@ var index = function redolent (fn, opts) { return reject(er) } if (arguments.length > 2) { - res = index$4(arguments, 1); + res = index$1(arguments, 1); } return resolve(res) } - var isAsyncFn = index$16(fn); + var isAsyncFn = index$5(fn); opts.args = isAsyncFn ? opts.args.concat(done) : opts.args; var syncResult = fn.apply(opts.context, opts.args); @@ -1765,7 +396,7 @@ var index = function redolent (fn, opts) { return normalize(promise, opts.Promise) } -}; +} function normalize (promise, Ctor) { promise.___nativePromise = Boolean(Ctor.___nativePromise); @@ -1773,4 +404,4 @@ function normalize (promise, Ctor) { return promise } -export default index; +export default redolent; diff --git a/index.js b/index.js index db5f5dd..954a4f6 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,12 @@ 'use strict' -var arrify = require('arrify') -var sliced = require('sliced') -var extend = require('extend-shallow') -var register = require('native-or-another/register') -var Promize = require('native-or-another') -var isAsync = require('is-async-function') +import arrify from 'arrify' +import sliced from 'sliced' +import extend from 'extend-shallow' +import register from 'native-or-another/register' +import Promize from 'native-or-another' +import isAsync from 'is-async-function' /** * > Will try to promisify `fn` with native Promise, @@ -79,7 +79,7 @@ var isAsync = require('is-async-function') * @api public */ -module.exports = function redolent (fn, opts) { +export default function redolent (fn, opts) { if (typeof fn !== 'function') { throw new TypeError('redolent: expect `fn` to be a function') } diff --git a/package.json b/package.json index b4215f6..7865e9a 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,13 @@ "commit": "npm-run-all -s build test git", "build": "npm-run-all -s build:*", "build:clean": "rimraf dist", - "build:bundle": "rollup -c", + "build:dist": "rollup -c", + "build:testing": "rollup -c --environment NODE_TESTING", "build:show": "ls -al dist" }, - "dependencies": {}, + "dependencies": { + "native-or-another": "^5.0.1" + }, "devDependencies": { "arrify": "^1.0.1", "commitizen": "~2.7.0", @@ -33,7 +36,6 @@ "extend-shallow": "^2.0.1", "is-async-function": "^1.2.3", "mukla": "^0.4.9", - "native-or-another": "^5.0.1", "npm-run-all": "~3.1.2", "nyc": "^10.1.2", "pinkie": "^2.0.4", diff --git a/rollup.config.js b/rollup.config.js index 43c6cb3..0f8c1e1 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,15 +4,49 @@ var buble = require('rollup-plugin-buble') var resolve = require('rollup-plugin-node-resolve') var commonjs = require('rollup-plugin-commonjs') -module.exports = { - entry: 'index.js', - plugins: [ - resolve({ jsnext: true }), - commonjs(), - buble() - ], - targets: [ - { dest: 'dist/redolent.es.js', format: 'es' }, - { dest: 'dist/redolent.common.js', format: 'cjs' } - ] +if (process.env.NODE_TESTING) { + module.exports = { + entry: 'index.js', + dest: 'dist/redolent-testing.js', + format: 'cjs', + interop: false, + plugins: [ + buble() + ], + external: [ + 'native-or-another/register', + 'native-or-another', + 'is-async-function', + 'extend-shallow', + 'sliced', + 'arrify' + ] + } +} else { + module.exports = { + entry: 'index.js', + plugins: [ + commonjs({ + include: [ + 'node_modules/**', + ], + exclude: [ + 'node_modules/native-or-another/register.js', + 'node_modules/native-or-another/index.js' + ] + }), + resolve({ + jsnext: true + }), + buble() + ], + external: [ + 'native-or-another', + 'native-or-another/register' + ], + targets: [ + { dest: 'dist/redolent.es.js', format: 'es' }, + { dest: 'dist/redolent.common.js', format: 'cjs' } + ] + } } diff --git a/test.js b/test.js index fd5fd8e..c8823e8 100644 --- a/test.js +++ b/test.js @@ -12,7 +12,7 @@ var fs = require('fs') var test = require('mukla') var semver = require('semver') -var redolent = require('./index') +var redolent = require('./dist/redolent-testing.js') var extend = require('extend-shallow') var Pinkie = require('pinkie') diff --git a/yarn.lock b/yarn.lock index d2e0d0d..223c386 100644 --- a/yarn.lock +++ b/yarn.lock @@ -366,16 +366,13 @@ circular-json@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/circular-json/-/circular-json-0.3.1.tgz#be8b36aefccde8b3ca7aa2d6afc07a37242c0d2d" -clean-stacktrace-metadata@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/clean-stacktrace-metadata/-/clean-stacktrace-metadata-1.0.2.tgz#49cc35ebac153e630d42c5bb89e349653029a0ca" - dependencies: - normalize-path "^2.0.1" - parse-filepath "^1.0.1" +clean-stacktrace-metadata@^1.0.6: + version "1.0.6" + resolved "https://registry.yarnpkg.com/clean-stacktrace-metadata/-/clean-stacktrace-metadata-1.0.6.tgz#e0fc7b59be42820ba39c46b45280bb445b412a96" -clean-stacktrace-relative-paths@^1.0.1, clean-stacktrace-relative-paths@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/clean-stacktrace-relative-paths/-/clean-stacktrace-relative-paths-1.0.2.tgz#4a6a4b883522e15cad02a9e82b5751d07c6e33f5" +clean-stacktrace-relative-paths@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/clean-stacktrace-relative-paths/-/clean-stacktrace-relative-paths-1.0.4.tgz#b318ce059abab31f3ce58aa702575d205bf3b9f4" clean-stacktrace@^1.1.0: version "1.1.0" @@ -468,7 +465,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream@^1.4.10, concat-stream@^1.4.6, concat-stream@^1.4.7: +concat-stream@^1.4.10, concat-stream@^1.4.7, concat-stream@^1.5.2: version "1.6.0" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7" dependencies: @@ -664,12 +661,6 @@ d@1: dependencies: es5-ext "^0.10.9" -d@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309" - dependencies: - es5-ext "~0.10.2" - dargs@^4.0.1: version "4.1.0" resolved "https://registry.yarnpkg.com/dargs/-/dargs-4.1.0.tgz#03a9dbb4b5c2f139bf14ae53f0b8a2a6a86f4e17" @@ -781,6 +772,13 @@ doctrine@^1.2.2: esutils "^2.0.2" isarray "^1.0.0" +doctrine@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" + dependencies: + esutils "^2.0.2" + isarray "^1.0.0" + dot-prop@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-3.0.0.tgz#1b708af094a49c9a0e7dbcad790aba539dac1177" @@ -830,7 +828,7 @@ es-to-primitive@^1.1.1: is-date-object "^1.0.1" is-symbol "^1.0.1" -es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.11, es5-ext@~0.10.14, es5-ext@~0.10.2: +es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: version "0.10.14" resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.14.tgz#625bc9ab9cac0f6fb9dc271525823d1800b3d360" dependencies: @@ -846,17 +844,17 @@ es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1: es6-symbol "^3.1" es6-map@^0.1.3: - version "0.1.4" - resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.4.tgz#a34b147be224773a4d7da8072794cefa3632b897" + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.5.tgz#9136e0503dcc06a301690f0bb14ff4e364e949f0" dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - es6-iterator "2" - es6-set "~0.1.3" - es6-symbol "~3.1.0" - event-emitter "~0.3.4" + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-set "~0.1.5" + es6-symbol "~3.1.1" + event-emitter "~0.3.5" -es6-set@~0.1.3: +es6-set@~0.1.5: version "0.1.5" resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1" dependencies: @@ -866,7 +864,7 @@ es6-set@~0.1.3: es6-symbol "3.1.1" event-emitter "~0.3.5" -es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbol@~3.1.0: +es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbol@~3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77" dependencies: @@ -899,9 +897,9 @@ eslint-config-standard-jsx@3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-3.3.0.tgz#cab0801a15a360bf63facb97ab22fbdd88d8a5e0" -eslint-config-standard@7.0.1: - version "7.0.1" - resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-7.0.1.tgz#6cec96084de9ac862c33ccb953d13a7c59872342" +eslint-config-standard@7.1.0: + version "7.1.0" + resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-7.1.0.tgz#47e769ea0739f5b2d5693b1a501c21c9650fafcf" eslint-plugin-promise@~3.4.0: version "3.4.2" @@ -919,17 +917,18 @@ eslint-plugin-standard@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/eslint-plugin-standard/-/eslint-plugin-standard-2.0.1.tgz#3589699ff9c917f2c25f76a916687f641c369ff3" -eslint@~3.15.0: - version "3.15.0" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.15.0.tgz#bdcc6a6c5ffe08160e7b93c066695362a91e30f2" +eslint@~3.18.0: + version "3.18.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.18.0.tgz#647e985c4ae71502d20ac62c109f66d5104c8a4b" dependencies: babel-code-frame "^6.16.0" chalk "^1.1.3" - concat-stream "^1.4.6" + concat-stream "^1.5.2" debug "^2.1.1" - doctrine "^1.2.2" + doctrine "^2.0.0" escope "^3.6.0" espree "^3.4.0" + esquery "^1.0.0" estraverse "^4.2.0" esutils "^2.0.2" file-entry-cache "^2.0.0" @@ -969,6 +968,12 @@ esprima@^3.1.1: version "3.1.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" +esquery@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.0.tgz#cfba8b57d7fba93f17298a8a006a04cda13d80fa" + dependencies: + estraverse "^4.0.0" + esrecurse@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.1.0.tgz#4713b6536adf7f2ac4f327d559e7756bff648220" @@ -976,7 +981,7 @@ esrecurse@^4.1.0: estraverse "~4.1.0" object-assign "^4.0.1" -estraverse@^4.1.1, estraverse@^4.2.0: +estraverse@^4.0.0, estraverse@^4.1.1, estraverse@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" @@ -996,7 +1001,7 @@ esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" -event-emitter@~0.3.4, event-emitter@~0.3.5: +event-emitter@~0.3.5: version "0.3.5" resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" dependencies: @@ -1100,11 +1105,11 @@ find-cache-dir@^0.1.1: mkdirp "^0.5.1" pkg-dir "^1.0.0" -find-callsite@^1.1.2: - version "1.1.2" - resolved "https://registry.yarnpkg.com/find-callsite/-/find-callsite-1.1.2.tgz#cbdca0803572027432affd3727a29ddd090d8273" +find-callsite@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/find-callsite/-/find-callsite-1.1.3.tgz#894e8736ba89b6504bb03f64063d927b5f640aa0" dependencies: - clean-stacktrace-relative-paths "^1.0.1" + clean-stacktrace-relative-paths "^1.0.3" extend-shallow "^2.0.1" find-index@^0.1.1: @@ -1550,8 +1555,8 @@ homedir-polyfill@^1.0.0: parse-passwd "^1.0.0" hosted-git-info@^2.1.4: - version "2.2.0" - resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.2.0.tgz#7a0d097863d886c0fabbdcd37bf1758d8becf8a5" + version "2.3.1" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.3.1.tgz#ac439421605f0beb0ea1349de7d8bb28e50be1dd" ignore@^3.0.9, ignore@^3.2.0: version "3.2.6" @@ -2176,6 +2181,12 @@ magic-string@^0.14.0: dependencies: vlq "^0.2.1" +magic-string@^0.15.2: + version "0.15.2" + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.15.2.tgz#0681d7388741bbc3addaa65060992624c6c09e9c" + dependencies: + vlq "^0.2.1" + magic-string@^0.19.0: version "0.19.0" resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.19.0.tgz#198948217254e3e0b93080e01146b7c73b2a06b2" @@ -2851,6 +2862,14 @@ rollup-plugin-node-resolve@^2.0.0: builtin-modules "^1.1.0" resolve "^1.1.6" +rollup-plugin-replace@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/rollup-plugin-replace/-/rollup-plugin-replace-1.1.1.tgz#396315ded050a6ce43b9518a886a3f60efb1ea33" + dependencies: + magic-string "^0.15.2" + minimatch "^3.0.2" + rollup-pluginutils "^1.5.0" + rollup-pluginutils@^1.5.0: version "1.5.2" resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-1.5.2.tgz#1e156e778f94b7255bfa1b3d0178be8f5c552408" @@ -2963,8 +2982,8 @@ slide@^1.1.5: resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707" source-map-support@^0.4.0: - version "0.4.13" - resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.13.tgz#9782e6f7deb424d5f173327a1879eb46453bdcd4" + version "0.4.14" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.14.tgz#9d4463772598b86271b4f523f6c1f4e02a7d6aef" dependencies: source-map "^0.5.6" @@ -3041,14 +3060,14 @@ stack-utils-node-internals@^1.0.1: resolved "https://registry.yarnpkg.com/stack-utils-node-internals/-/stack-utils-node-internals-1.0.1.tgz#ab4a8a469b6cbec72b0bfb589df5e28b1d12281f" stacktrace-metadata@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/stacktrace-metadata/-/stacktrace-metadata-2.0.1.tgz#737e47d61bb800743dbd32ecc33e01ac611ebb85" + version "2.0.4" + resolved "https://registry.yarnpkg.com/stacktrace-metadata/-/stacktrace-metadata-2.0.4.tgz#fd126eec712e998165dfc9ed848a92ba5d4b11db" dependencies: clean-stacktrace "^1.1.0" - clean-stacktrace-metadata "^1.0.2" - clean-stacktrace-relative-paths "^1.0.2" + clean-stacktrace-metadata "^1.0.6" + clean-stacktrace-relative-paths "^1.0.3" extend-shallow "^2.0.1" - find-callsite "^1.1.2" + find-callsite "^1.1.3" standard-engine@~5.4.0: version "5.4.0" @@ -3074,11 +3093,11 @@ standard-version@^4.0.0: yargs "^6.0.0" standard@^9.0.0: - version "9.0.1" - resolved "https://registry.yarnpkg.com/standard/-/standard-9.0.1.tgz#c053e9009bb1a8b4c6b03bf12df4784185bb5899" + version "9.0.2" + resolved "https://registry.yarnpkg.com/standard/-/standard-9.0.2.tgz#9bd3b9467492e212b1914d78553943ff9b48fd99" dependencies: - eslint "~3.15.0" - eslint-config-standard "7.0.1" + eslint "~3.18.0" + eslint-config-standard "7.1.0" eslint-config-standard-jsx "3.3.0" eslint-plugin-promise "~3.4.0" eslint-plugin-react "~6.9.0"