From 439ff4c9aa508ea6f38364859109267d8f26fcf1 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Thu, 13 Jan 2022 19:04:24 +0100 Subject: [PATCH] refactor: clean up setup action (#146) * refactor: replace cache with opinionated tool cacher * refactor: replace install with packager * refactor: replace various tools with worker BEARKING CHANGE: Dropping username and password authentication in favor of token authentication only. * refactor: update setup action with latest refactors * chore: rebuild project * chore: remove semver and rebuild project * refactor: update tests for new components * chore: fix linting issues and rebuild project --- build/setup/index.js | 3946 ++++------------------------------- build/setup/license.txt | 38 - package.json | 4 +- src/actions/setup.ts | 114 +- src/cache.ts | 94 - src/cacher.ts | 61 + src/install.ts | 60 - src/packager.ts | 22 +- src/tools.ts | 132 -- src/worker.ts | 92 + tests/actions/setup.test.ts | 205 +- tests/cache.test.ts | 153 -- tests/cacher.test.ts | 70 + tests/install.test.ts | 95 - tests/packager.test.ts | 21 +- tests/tools.test.ts | 328 --- tests/utils.ts | 22 +- tests/worker.test.ts | 133 ++ yarn.lock | 5 - 19 files changed, 918 insertions(+), 4677 deletions(-) delete mode 100644 src/cache.ts create mode 100644 src/cacher.ts delete mode 100644 src/install.ts delete mode 100644 src/tools.ts create mode 100644 src/worker.ts delete mode 100644 tests/cache.test.ts create mode 100644 tests/cacher.test.ts delete mode 100644 tests/install.test.ts delete mode 100644 tests/tools.test.ts create mode 100644 tests/worker.test.ts diff --git a/build/setup/index.js b/build/setup/index.js index 8bed45c2..22e37df1 100644 --- a/build/setup/index.js +++ b/build/setup/index.js @@ -51869,348 +51869,6 @@ module.exports = function(dst, src) { }; -/***/ }), - -/***/ 7129: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -"use strict"; - - -// A linked list to keep track of recently-used-ness -const Yallist = __nccwpck_require__(665) - -const MAX = Symbol('max') -const LENGTH = Symbol('length') -const LENGTH_CALCULATOR = Symbol('lengthCalculator') -const ALLOW_STALE = Symbol('allowStale') -const MAX_AGE = Symbol('maxAge') -const DISPOSE = Symbol('dispose') -const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet') -const LRU_LIST = Symbol('lruList') -const CACHE = Symbol('cache') -const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet') - -const naiveLength = () => 1 - -// lruList is a yallist where the head is the youngest -// item, and the tail is the oldest. the list contains the Hit -// objects as the entries. -// Each Hit object has a reference to its Yallist.Node. This -// never changes. -// -// cache is a Map (or PseudoMap) that matches the keys to -// the Yallist.Node object. -class LRUCache { - constructor (options) { - if (typeof options === 'number') - options = { max: options } - - if (!options) - options = {} - - if (options.max && (typeof options.max !== 'number' || options.max < 0)) - throw new TypeError('max must be a non-negative number') - // Kind of weird to have a default max of Infinity, but oh well. - const max = this[MAX] = options.max || Infinity - - const lc = options.length || naiveLength - this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc - this[ALLOW_STALE] = options.stale || false - if (options.maxAge && typeof options.maxAge !== 'number') - throw new TypeError('maxAge must be a number') - this[MAX_AGE] = options.maxAge || 0 - this[DISPOSE] = options.dispose - this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false - this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false - this.reset() - } - - // resize the cache when the max changes. - set max (mL) { - if (typeof mL !== 'number' || mL < 0) - throw new TypeError('max must be a non-negative number') - - this[MAX] = mL || Infinity - trim(this) - } - get max () { - return this[MAX] - } - - set allowStale (allowStale) { - this[ALLOW_STALE] = !!allowStale - } - get allowStale () { - return this[ALLOW_STALE] - } - - set maxAge (mA) { - if (typeof mA !== 'number') - throw new TypeError('maxAge must be a non-negative number') - - this[MAX_AGE] = mA - trim(this) - } - get maxAge () { - return this[MAX_AGE] - } - - // resize the cache when the lengthCalculator changes. - set lengthCalculator (lC) { - if (typeof lC !== 'function') - lC = naiveLength - - if (lC !== this[LENGTH_CALCULATOR]) { - this[LENGTH_CALCULATOR] = lC - this[LENGTH] = 0 - this[LRU_LIST].forEach(hit => { - hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key) - this[LENGTH] += hit.length - }) - } - trim(this) - } - get lengthCalculator () { return this[LENGTH_CALCULATOR] } - - get length () { return this[LENGTH] } - get itemCount () { return this[LRU_LIST].length } - - rforEach (fn, thisp) { - thisp = thisp || this - for (let walker = this[LRU_LIST].tail; walker !== null;) { - const prev = walker.prev - forEachStep(this, fn, walker, thisp) - walker = prev - } - } - - forEach (fn, thisp) { - thisp = thisp || this - for (let walker = this[LRU_LIST].head; walker !== null;) { - const next = walker.next - forEachStep(this, fn, walker, thisp) - walker = next - } - } - - keys () { - return this[LRU_LIST].toArray().map(k => k.key) - } - - values () { - return this[LRU_LIST].toArray().map(k => k.value) - } - - reset () { - if (this[DISPOSE] && - this[LRU_LIST] && - this[LRU_LIST].length) { - this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value)) - } - - this[CACHE] = new Map() // hash of items by key - this[LRU_LIST] = new Yallist() // list of items in order of use recency - this[LENGTH] = 0 // length of items in the list - } - - dump () { - return this[LRU_LIST].map(hit => - isStale(this, hit) ? false : { - k: hit.key, - v: hit.value, - e: hit.now + (hit.maxAge || 0) - }).toArray().filter(h => h) - } - - dumpLru () { - return this[LRU_LIST] - } - - set (key, value, maxAge) { - maxAge = maxAge || this[MAX_AGE] - - if (maxAge && typeof maxAge !== 'number') - throw new TypeError('maxAge must be a number') - - const now = maxAge ? Date.now() : 0 - const len = this[LENGTH_CALCULATOR](value, key) - - if (this[CACHE].has(key)) { - if (len > this[MAX]) { - del(this, this[CACHE].get(key)) - return false - } - - const node = this[CACHE].get(key) - const item = node.value - - // dispose of the old one before overwriting - // split out into 2 ifs for better coverage tracking - if (this[DISPOSE]) { - if (!this[NO_DISPOSE_ON_SET]) - this[DISPOSE](key, item.value) - } - - item.now = now - item.maxAge = maxAge - item.value = value - this[LENGTH] += len - item.length - item.length = len - this.get(key) - trim(this) - return true - } - - const hit = new Entry(key, value, len, now, maxAge) - - // oversized objects fall out of cache automatically. - if (hit.length > this[MAX]) { - if (this[DISPOSE]) - this[DISPOSE](key, value) - - return false - } - - this[LENGTH] += hit.length - this[LRU_LIST].unshift(hit) - this[CACHE].set(key, this[LRU_LIST].head) - trim(this) - return true - } - - has (key) { - if (!this[CACHE].has(key)) return false - const hit = this[CACHE].get(key).value - return !isStale(this, hit) - } - - get (key) { - return get(this, key, true) - } - - peek (key) { - return get(this, key, false) - } - - pop () { - const node = this[LRU_LIST].tail - if (!node) - return null - - del(this, node) - return node.value - } - - del (key) { - del(this, this[CACHE].get(key)) - } - - load (arr) { - // reset the cache - this.reset() - - const now = Date.now() - // A previous serialized cache has the most recent items first - for (let l = arr.length - 1; l >= 0; l--) { - const hit = arr[l] - const expiresAt = hit.e || 0 - if (expiresAt === 0) - // the item was created without expiration in a non aged cache - this.set(hit.k, hit.v) - else { - const maxAge = expiresAt - now - // dont add already expired items - if (maxAge > 0) { - this.set(hit.k, hit.v, maxAge) - } - } - } - } - - prune () { - this[CACHE].forEach((value, key) => get(this, key, false)) - } -} - -const get = (self, key, doUse) => { - const node = self[CACHE].get(key) - if (node) { - const hit = node.value - if (isStale(self, hit)) { - del(self, node) - if (!self[ALLOW_STALE]) - return undefined - } else { - if (doUse) { - if (self[UPDATE_AGE_ON_GET]) - node.value.now = Date.now() - self[LRU_LIST].unshiftNode(node) - } - } - return hit.value - } -} - -const isStale = (self, hit) => { - if (!hit || (!hit.maxAge && !self[MAX_AGE])) - return false - - const diff = Date.now() - hit.now - return hit.maxAge ? diff > hit.maxAge - : self[MAX_AGE] && (diff > self[MAX_AGE]) -} - -const trim = self => { - if (self[LENGTH] > self[MAX]) { - for (let walker = self[LRU_LIST].tail; - self[LENGTH] > self[MAX] && walker !== null;) { - // We know that we're about to delete this one, and also - // what the next least recently used key will be, so just - // go ahead and set it now. - const prev = walker.prev - del(self, walker) - walker = prev - } - } -} - -const del = (self, node) => { - if (node) { - const hit = node.value - if (self[DISPOSE]) - self[DISPOSE](hit.key, hit.value) - - self[LENGTH] -= hit.length - self[CACHE].delete(hit.key) - self[LRU_LIST].removeNode(node) - } -} - -class Entry { - constructor (key, value, length, now, maxAge) { - this.key = key - this.value = value - this.length = length - this.now = now - this.maxAge = maxAge || 0 - } -} - -const forEachStep = (self, fn, node, thisp) => { - let hit = node.value - if (isStale(self, hit)) { - del(self, node) - if (!self[ALLOW_STALE]) - hit = undefined - } - if (hit) - fn.call(thisp, hit.value, hit.key, self) -} - -module.exports = LRUCache - - /***/ }), /***/ 7426: @@ -56948,2411 +56606,143 @@ module.exports = safer /***/ }), -/***/ 1532: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { +/***/ 7372: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { -const ANY = Symbol('SemVer ANY') -// hoisted class for cyclic dependency -class Comparator { - static get ANY () { - return ANY - } - constructor (comp, options) { - options = parseOptions(options) +"use strict"; +/*! + * Copyright (c) 2015, Salesforce.com, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of Salesforce.com nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ - if (comp instanceof Comparator) { - if (comp.loose === !!options.loose) { - return comp - } else { - comp = comp.value - } - } +const punycode = __nccwpck_require__(5477); +const urlParse = (__nccwpck_require__(7310).parse); +const util = __nccwpck_require__(3837); +const pubsuffix = __nccwpck_require__(4401); +const Store = (__nccwpck_require__(460)/* .Store */ .y); +const MemoryCookieStore = (__nccwpck_require__(2640)/* .MemoryCookieStore */ .m); +const pathMatch = (__nccwpck_require__(4336)/* .pathMatch */ .U); +const VERSION = __nccwpck_require__(3199); +const { fromCallback } = __nccwpck_require__(260); - debug('comparator', comp, options) - this.options = options - this.loose = !!options.loose - this.parse(comp) +// From RFC6265 S4.1.1 +// note that it excludes \x3B ";" +const COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/; - if (this.semver === ANY) { - this.value = '' - } else { - this.value = this.operator + this.semver.version - } +const CONTROL_CHARS = /[\x00-\x1F]/; - debug('comp', this) - } +// From Chromium // '\r', '\n' and '\0' should be treated as a terminator in +// the "relaxed" mode, see: +// https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60 +const TERMINATORS = ["\n", "\r", "\0"]; - parse (comp) { - const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] - const m = comp.match(r) +// RFC6265 S4.1.1 defines path value as 'any CHAR except CTLs or ";"' +// Note ';' is \x3B +const PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/; - if (!m) { - throw new TypeError(`Invalid comparator: ${comp}`) - } +// date-time parsing constants (RFC6265 S5.1.1) - this.operator = m[1] !== undefined ? m[1] : '' - if (this.operator === '=') { - this.operator = '' - } +const DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/; - // if it literally is just '>' or '' then allow anything. - if (!m[2]) { - this.semver = ANY - } else { - this.semver = new SemVer(m[2], this.options.loose) - } - } +const MONTH_TO_NUM = { + jan: 0, + feb: 1, + mar: 2, + apr: 3, + may: 4, + jun: 5, + jul: 6, + aug: 7, + sep: 8, + oct: 9, + nov: 10, + dec: 11 +}; + +const MAX_TIME = 2147483647000; // 31-bit max +const MIN_TIME = 0; // 31-bit min +const SAME_SITE_CONTEXT_VAL_ERR = + 'Invalid sameSiteContext option for getCookies(); expected one of "strict", "lax", or "none"'; - toString () { - return this.value +function checkSameSiteContext(value) { + const context = String(value).toLowerCase(); + if (context === "none" || context === "lax" || context === "strict") { + return context; + } else { + return null; } +} - test (version) { - debug('Comparator.test', version, this.options.loose) +const PrefixSecurityEnum = Object.freeze({ + SILENT: "silent", + STRICT: "strict", + DISABLED: "unsafe-disabled" +}); - if (this.semver === ANY || version === ANY) { - return true - } +// Dumped from ip-regex@4.0.0, with the following changes: +// * all capturing groups converted to non-capturing -- "(?:)" +// * support for IPv6 Scoped Literal ("%eth1") removed +// * lowercase hexadecimal only +var IP_REGEX_LOWERCASE =/(?:^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$)|(?:^(?:(?:[a-f\d]{1,4}:){7}(?:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,2}|:)|(?:[a-f\d]{1,4}:){4}(?:(?::[a-f\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,3}|:)|(?:[a-f\d]{1,4}:){3}(?:(?::[a-f\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,4}|:)|(?:[a-f\d]{1,4}:){2}(?:(?::[a-f\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,5}|:)|(?:[a-f\d]{1,4}:){1}(?:(?::[a-f\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,6}|:)|(?::(?:(?::[a-f\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,7}|:)))$)/; - if (typeof version === 'string') { - try { - version = new SemVer(version, this.options) - } catch (er) { - return false - } +/* + * Parses a Natural number (i.e., non-negative integer) with either the + * *DIGIT ( non-digit *OCTET ) + * or + * *DIGIT + * grammar (RFC6265 S5.1.1). + * + * The "trailingOK" boolean controls if the grammar accepts a + * "( non-digit *OCTET )" trailer. + */ +function parseDigits(token, minDigits, maxDigits, trailingOK) { + let count = 0; + while (count < token.length) { + const c = token.charCodeAt(count); + // "non-digit = %x00-2F / %x3A-FF" + if (c <= 0x2f || c >= 0x3a) { + break; } + count++; + } - return cmp(version, this.operator, this.semver, this.options) + // constrain to a minimum and maximum number of digits. + if (count < minDigits || count > maxDigits) { + return null; } - intersects (comp, options) { - if (!(comp instanceof Comparator)) { - throw new TypeError('a Comparator is required') - } + if (!trailingOK && count != token.length) { + return null; + } - if (!options || typeof options !== 'object') { - options = { - loose: !!options, - includePrerelease: false - } - } - - if (this.operator === '') { - if (this.value === '') { - return true - } - return new Range(comp.value, options).test(this.value) - } else if (comp.operator === '') { - if (comp.value === '') { - return true - } - return new Range(this.value, options).test(comp.semver) - } - - const sameDirectionIncreasing = - (this.operator === '>=' || this.operator === '>') && - (comp.operator === '>=' || comp.operator === '>') - const sameDirectionDecreasing = - (this.operator === '<=' || this.operator === '<') && - (comp.operator === '<=' || comp.operator === '<') - const sameSemVer = this.semver.version === comp.semver.version - const differentDirectionsInclusive = - (this.operator === '>=' || this.operator === '<=') && - (comp.operator === '>=' || comp.operator === '<=') - const oppositeDirectionsLessThan = - cmp(this.semver, '<', comp.semver, options) && - (this.operator === '>=' || this.operator === '>') && - (comp.operator === '<=' || comp.operator === '<') - const oppositeDirectionsGreaterThan = - cmp(this.semver, '>', comp.semver, options) && - (this.operator === '<=' || this.operator === '<') && - (comp.operator === '>=' || comp.operator === '>') - - return ( - sameDirectionIncreasing || - sameDirectionDecreasing || - (sameSemVer && differentDirectionsInclusive) || - oppositeDirectionsLessThan || - oppositeDirectionsGreaterThan - ) - } -} - -module.exports = Comparator - -const parseOptions = __nccwpck_require__(785) -const {re, t} = __nccwpck_require__(9523) -const cmp = __nccwpck_require__(5098) -const debug = __nccwpck_require__(427) -const SemVer = __nccwpck_require__(8088) -const Range = __nccwpck_require__(9828) - - -/***/ }), - -/***/ 9828: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -// hoisted class for cyclic dependency -class Range { - constructor (range, options) { - options = parseOptions(options) - - if (range instanceof Range) { - if ( - range.loose === !!options.loose && - range.includePrerelease === !!options.includePrerelease - ) { - return range - } else { - return new Range(range.raw, options) - } - } - - if (range instanceof Comparator) { - // just put it in the set and return - this.raw = range.value - this.set = [[range]] - this.format() - return this - } - - this.options = options - this.loose = !!options.loose - this.includePrerelease = !!options.includePrerelease - - // First, split based on boolean or || - this.raw = range - this.set = range - .split(/\s*\|\|\s*/) - // map the range to a 2d array of comparators - .map(range => this.parseRange(range.trim())) - // throw out any comparator lists that are empty - // this generally means that it was not a valid range, which is allowed - // in loose mode, but will still throw if the WHOLE range is invalid. - .filter(c => c.length) - - if (!this.set.length) { - throw new TypeError(`Invalid SemVer Range: ${range}`) - } - - // if we have any that are not the null set, throw out null sets. - if (this.set.length > 1) { - // keep the first one, in case they're all null sets - const first = this.set[0] - this.set = this.set.filter(c => !isNullSet(c[0])) - if (this.set.length === 0) - this.set = [first] - else if (this.set.length > 1) { - // if we have any that are *, then the range is just * - for (const c of this.set) { - if (c.length === 1 && isAny(c[0])) { - this.set = [c] - break - } - } - } - } - - this.format() - } - - format () { - this.range = this.set - .map((comps) => { - return comps.join(' ').trim() - }) - .join('||') - .trim() - return this.range - } - - toString () { - return this.range - } - - parseRange (range) { - range = range.trim() - - // memoize range parsing for performance. - // this is a very hot path, and fully deterministic. - const memoOpts = Object.keys(this.options).join(',') - const memoKey = `parseRange:${memoOpts}:${range}` - const cached = cache.get(memoKey) - if (cached) - return cached - - const loose = this.options.loose - // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` - const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE] - range = range.replace(hr, hyphenReplace(this.options.includePrerelease)) - debug('hyphen replace', range) - // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5` - range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace) - debug('comparator trim', range, re[t.COMPARATORTRIM]) - - // `~ 1.2.3` => `~1.2.3` - range = range.replace(re[t.TILDETRIM], tildeTrimReplace) - - // `^ 1.2.3` => `^1.2.3` - range = range.replace(re[t.CARETTRIM], caretTrimReplace) - - // normalize spaces - range = range.split(/\s+/).join(' ') - - // At this point, the range is completely trimmed and - // ready to be split into comparators. - - const compRe = loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR] - const rangeList = range - .split(' ') - .map(comp => parseComparator(comp, this.options)) - .join(' ') - .split(/\s+/) - // >=0.0.0 is equivalent to * - .map(comp => replaceGTE0(comp, this.options)) - // in loose mode, throw out any that are not valid comparators - .filter(this.options.loose ? comp => !!comp.match(compRe) : () => true) - .map(comp => new Comparator(comp, this.options)) - - // if any comparators are the null set, then replace with JUST null set - // if more than one comparator, remove any * comparators - // also, don't include the same comparator more than once - const l = rangeList.length - const rangeMap = new Map() - for (const comp of rangeList) { - if (isNullSet(comp)) - return [comp] - rangeMap.set(comp.value, comp) - } - if (rangeMap.size > 1 && rangeMap.has('')) - rangeMap.delete('') - - const result = [...rangeMap.values()] - cache.set(memoKey, result) - return result - } - - intersects (range, options) { - if (!(range instanceof Range)) { - throw new TypeError('a Range is required') - } - - return this.set.some((thisComparators) => { - return ( - isSatisfiable(thisComparators, options) && - range.set.some((rangeComparators) => { - return ( - isSatisfiable(rangeComparators, options) && - thisComparators.every((thisComparator) => { - return rangeComparators.every((rangeComparator) => { - return thisComparator.intersects(rangeComparator, options) - }) - }) - ) - }) - ) - }) - } - - // if ANY of the sets match ALL of its comparators, then pass - test (version) { - if (!version) { - return false - } - - if (typeof version === 'string') { - try { - version = new SemVer(version, this.options) - } catch (er) { - return false - } - } - - for (let i = 0; i < this.set.length; i++) { - if (testSet(this.set[i], version, this.options)) { - return true - } - } - return false - } -} -module.exports = Range - -const LRU = __nccwpck_require__(7129) -const cache = new LRU({ max: 1000 }) - -const parseOptions = __nccwpck_require__(785) -const Comparator = __nccwpck_require__(1532) -const debug = __nccwpck_require__(427) -const SemVer = __nccwpck_require__(8088) -const { - re, - t, - comparatorTrimReplace, - tildeTrimReplace, - caretTrimReplace -} = __nccwpck_require__(9523) - -const isNullSet = c => c.value === '<0.0.0-0' -const isAny = c => c.value === '' - -// take a set of comparators and determine whether there -// exists a version which can satisfy it -const isSatisfiable = (comparators, options) => { - let result = true - const remainingComparators = comparators.slice() - let testComparator = remainingComparators.pop() - - while (result && remainingComparators.length) { - result = remainingComparators.every((otherComparator) => { - return testComparator.intersects(otherComparator, options) - }) - - testComparator = remainingComparators.pop() - } - - return result -} - -// comprised of xranges, tildes, stars, and gtlt's at this point. -// already replaced the hyphen ranges -// turn into a set of JUST comparators. -const parseComparator = (comp, options) => { - debug('comp', comp, options) - comp = replaceCarets(comp, options) - debug('caret', comp) - comp = replaceTildes(comp, options) - debug('tildes', comp) - comp = replaceXRanges(comp, options) - debug('xrange', comp) - comp = replaceStars(comp, options) - debug('stars', comp) - return comp -} - -const isX = id => !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-0 -// ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0 -// ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0 -// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0 -// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0 -const replaceTildes = (comp, options) => - comp.trim().split(/\s+/).map((comp) => { - return replaceTilde(comp, options) - }).join(' ') - -const replaceTilde = (comp, options) => { - const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE] - return comp.replace(r, (_, M, m, p, pr) => { - debug('tilde', comp, _, M, m, p, pr) - let ret - - if (isX(M)) { - ret = '' - } else if (isX(m)) { - ret = `>=${M}.0.0 <${+M + 1}.0.0-0` - } else if (isX(p)) { - // ~1.2 == >=1.2.0 <1.3.0-0 - ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0` - } else if (pr) { - debug('replaceTilde pr', pr) - ret = `>=${M}.${m}.${p}-${pr - } <${M}.${+m + 1}.0-0` - } else { - // ~1.2.3 == >=1.2.3 <1.3.0-0 - ret = `>=${M}.${m}.${p - } <${M}.${+m + 1}.0-0` - } - - debug('tilde return', ret) - return ret - }) -} - -// ^ --> * (any, kinda silly) -// ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0 -// ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0 -// ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0 -// ^1.2.3 --> >=1.2.3 <2.0.0-0 -// ^1.2.0 --> >=1.2.0 <2.0.0-0 -const replaceCarets = (comp, options) => - comp.trim().split(/\s+/).map((comp) => { - return replaceCaret(comp, options) - }).join(' ') - -const replaceCaret = (comp, options) => { - debug('caret', comp, options) - const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET] - const z = options.includePrerelease ? '-0' : '' - return comp.replace(r, (_, M, m, p, pr) => { - debug('caret', comp, _, M, m, p, pr) - let ret - - if (isX(M)) { - ret = '' - } else if (isX(m)) { - ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0` - } else if (isX(p)) { - if (M === '0') { - ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0` - } else { - ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0` - } - } else if (pr) { - debug('replaceCaret pr', pr) - if (M === '0') { - if (m === '0') { - ret = `>=${M}.${m}.${p}-${pr - } <${M}.${m}.${+p + 1}-0` - } else { - ret = `>=${M}.${m}.${p}-${pr - } <${M}.${+m + 1}.0-0` - } - } else { - ret = `>=${M}.${m}.${p}-${pr - } <${+M + 1}.0.0-0` - } - } else { - debug('no pr') - if (M === '0') { - if (m === '0') { - ret = `>=${M}.${m}.${p - }${z} <${M}.${m}.${+p + 1}-0` - } else { - ret = `>=${M}.${m}.${p - }${z} <${M}.${+m + 1}.0-0` - } - } else { - ret = `>=${M}.${m}.${p - } <${+M + 1}.0.0-0` - } - } - - debug('caret return', ret) - return ret - }) -} - -const replaceXRanges = (comp, options) => { - debug('replaceXRanges', comp, options) - return comp.split(/\s+/).map((comp) => { - return replaceXRange(comp, options) - }).join(' ') -} - -const replaceXRange = (comp, options) => { - comp = comp.trim() - const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE] - return comp.replace(r, (ret, gtlt, M, m, p, pr) => { - debug('xRange', comp, ret, gtlt, M, m, p, pr) - const xM = isX(M) - const xm = xM || isX(m) - const xp = xm || isX(p) - const anyX = xp - - if (gtlt === '=' && anyX) { - gtlt = '' - } - - // if we're including prereleases in the match, then we need - // to fix this to -0, the lowest possible prerelease value - pr = options.includePrerelease ? '-0' : '' - - if (xM) { - if (gtlt === '>' || gtlt === '<') { - // nothing is allowed - ret = '<0.0.0-0' - } else { - // nothing is forbidden - ret = '*' - } - } else if (gtlt && anyX) { - // we know patch is an x, because we have any x at all. - // replace X with 0 - if (xm) { - m = 0 - } - p = 0 - - if (gtlt === '>') { - // >1 => >=2.0.0 - // >1.2 => >=1.3.0 - gtlt = '>=' - if (xm) { - M = +M + 1 - m = 0 - p = 0 - } else { - 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 - } - } - - if (gtlt === '<') - pr = '-0' - - ret = `${gtlt + M}.${m}.${p}${pr}` - } else if (xm) { - ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0` - } else if (xp) { - ret = `>=${M}.${m}.0${pr - } <${M}.${+m + 1}.0-0` - } - - debug('xRange return', ret) - - return ret - }) -} - -// Because * is AND-ed with everything else in the comparator, -// and '' means "any version", just remove the *s entirely. -const replaceStars = (comp, options) => { - debug('replaceStars', comp, options) - // Looseness is ignored here. star is always as loose as it gets! - return comp.trim().replace(re[t.STAR], '') -} - -const replaceGTE0 = (comp, options) => { - debug('replaceGTE0', comp, options) - return comp.trim() - .replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '') -} - -// This function is passed to string.replace(re[t.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-0 Any 3.4.x will do -// 1.2 - 3.4 => >=1.2.0 <3.5.0-0 -const hyphenReplace = incPr => ($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${incPr ? '-0' : ''}` - } else if (isX(fp)) { - from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}` - } else if (fpr) { - from = `>=${from}` - } else { - from = `>=${from}${incPr ? '-0' : ''}` - } - - if (isX(tM)) { - to = '' - } else if (isX(tm)) { - to = `<${+tM + 1}.0.0-0` - } else if (isX(tp)) { - to = `<${tM}.${+tm + 1}.0-0` - } else if (tpr) { - to = `<=${tM}.${tm}.${tp}-${tpr}` - } else if (incPr) { - to = `<${tM}.${tm}.${+tp + 1}-0` - } else { - to = `<=${to}` - } - - return (`${from} ${to}`).trim() -} - -const testSet = (set, version, options) => { - for (let i = 0; i < set.length; i++) { - if (!set[i].test(version)) { - return false - } - } - - if (version.prerelease.length && !options.includePrerelease) { - // 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 (let i = 0; i < set.length; i++) { - debug(set[i].semver) - if (set[i].semver === Comparator.ANY) { - continue - } - - if (set[i].semver.prerelease.length > 0) { - const 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 -} - - -/***/ }), - -/***/ 8088: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const debug = __nccwpck_require__(427) -const { MAX_LENGTH, MAX_SAFE_INTEGER } = __nccwpck_require__(2293) -const { re, t } = __nccwpck_require__(9523) - -const parseOptions = __nccwpck_require__(785) -const { compareIdentifiers } = __nccwpck_require__(2463) -class SemVer { - constructor (version, options) { - options = parseOptions(options) - - if (version instanceof SemVer) { - if (version.loose === !!options.loose && - version.includePrerelease === !!options.includePrerelease) { - 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` - ) - } - - debug('SemVer', version, options) - this.options = options - this.loose = !!options.loose - // this isn't actually relevant for versions, but keep it so that we - // don't run into trouble passing this.options around. - this.includePrerelease = !!options.includePrerelease - - const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.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((id) => { - if (/^[0-9]+$/.test(id)) { - const num = +id - if (num >= 0 && num < MAX_SAFE_INTEGER) { - return num - } - } - return id - }) - } - - this.build = m[5] ? m[5].split('.') : [] - this.format() - } - - format () { - this.version = `${this.major}.${this.minor}.${this.patch}` - if (this.prerelease.length) { - this.version += `-${this.prerelease.join('.')}` - } - return this.version - } - - toString () { - return this.version - } - - compare (other) { - debug('SemVer.compare', this.version, this.options, other) - if (!(other instanceof SemVer)) { - if (typeof other === 'string' && other === this.version) { - return 0 - } - other = new SemVer(other, this.options) - } - - if (other.version === this.version) { - return 0 - } - - return this.compareMain(other) || this.comparePre(other) - } - - compareMain (other) { - if (!(other instanceof SemVer)) { - other = new SemVer(other, this.options) - } - - return ( - compareIdentifiers(this.major, other.major) || - compareIdentifiers(this.minor, other.minor) || - compareIdentifiers(this.patch, other.patch) - ) - } - - comparePre (other) { - if (!(other instanceof SemVer)) { - other = new SemVer(other, this.options) - } - - // 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 - } - - let i = 0 - do { - const a = this.prerelease[i] - const 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) - } - - compareBuild (other) { - if (!(other instanceof SemVer)) { - other = new SemVer(other, this.options) - } - - let i = 0 - do { - const a = this.build[i] - const b = other.build[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. - inc (release, identifier) { - 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 { - let i = this.prerelease.length - while (--i >= 0) { - if (typeof this.prerelease[i] === 'number') { - this.prerelease[i]++ - i = -2 - } - } - if (i === -1) { - // didn't increment anything - this.prerelease.push(0) - } - } - 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 - } -} - -module.exports = SemVer - - -/***/ }), - -/***/ 8848: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const parse = __nccwpck_require__(5925) -const clean = (version, options) => { - const s = parse(version.trim().replace(/^[=v]+/, ''), options) - return s ? s.version : null -} -module.exports = clean - - -/***/ }), - -/***/ 5098: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const eq = __nccwpck_require__(1898) -const neq = __nccwpck_require__(6017) -const gt = __nccwpck_require__(4123) -const gte = __nccwpck_require__(5522) -const lt = __nccwpck_require__(194) -const lte = __nccwpck_require__(7520) - -const cmp = (a, op, b, loose) => { - switch (op) { - case '===': - if (typeof a === 'object') - a = a.version - if (typeof b === 'object') - b = b.version - return a === b - - case '!==': - if (typeof a === 'object') - a = a.version - if (typeof b === 'object') - b = b.version - return a !== b - - case '': - case '=': - case '==': - return eq(a, b, loose) - - case '!=': - return neq(a, b, loose) - - case '>': - return gt(a, b, loose) - - case '>=': - return gte(a, b, loose) - - case '<': - return lt(a, b, loose) - - case '<=': - return lte(a, b, loose) - - default: - throw new TypeError(`Invalid operator: ${op}`) - } -} -module.exports = cmp - - -/***/ }), - -/***/ 3466: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const parse = __nccwpck_require__(5925) -const {re, t} = __nccwpck_require__(9523) - -const coerce = (version, options) => { - if (version instanceof SemVer) { - return version - } - - if (typeof version === 'number') { - version = String(version) - } - - if (typeof version !== 'string') { - return null - } - - options = options || {} - - let match = null - if (!options.rtl) { - match = version.match(re[t.COERCE]) - } else { - // Find the right-most coercible string that does not share - // a terminus with a more left-ward coercible string. - // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4' - // - // Walk through the string checking with a /g regexp - // Manually set the index so as to pick up overlapping matches. - // Stop when we get a match that ends at the string end, since no - // coercible string can be more right-ward without the same terminus. - let next - while ((next = re[t.COERCERTL].exec(version)) && - (!match || match.index + match[0].length !== version.length) - ) { - if (!match || - next.index + next[0].length !== match.index + match[0].length) { - match = next - } - re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length - } - // leave it in a clean state - re[t.COERCERTL].lastIndex = -1 - } - - if (match === null) - return null - - return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options) -} -module.exports = coerce - - -/***/ }), - -/***/ 2156: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const compareBuild = (a, b, loose) => { - const versionA = new SemVer(a, loose) - const versionB = new SemVer(b, loose) - return versionA.compare(versionB) || versionA.compareBuild(versionB) -} -module.exports = compareBuild - - -/***/ }), - -/***/ 2804: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const compareLoose = (a, b) => compare(a, b, true) -module.exports = compareLoose - - -/***/ }), - -/***/ 4309: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const compare = (a, b, loose) => - new SemVer(a, loose).compare(new SemVer(b, loose)) - -module.exports = compare - - -/***/ }), - -/***/ 4297: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const parse = __nccwpck_require__(5925) -const eq = __nccwpck_require__(1898) - -const diff = (version1, version2) => { - if (eq(version1, version2)) { - return null - } else { - const v1 = parse(version1) - const v2 = parse(version2) - const hasPre = v1.prerelease.length || v2.prerelease.length - const prefix = hasPre ? 'pre' : '' - const defaultResult = hasPre ? 'prerelease' : '' - for (const key in v1) { - if (key === 'major' || key === 'minor' || key === 'patch') { - if (v1[key] !== v2[key]) { - return prefix + key - } - } - } - return defaultResult // may be undefined - } -} -module.exports = diff - - -/***/ }), - -/***/ 1898: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const eq = (a, b, loose) => compare(a, b, loose) === 0 -module.exports = eq - - -/***/ }), - -/***/ 4123: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const gt = (a, b, loose) => compare(a, b, loose) > 0 -module.exports = gt - - -/***/ }), - -/***/ 5522: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const gte = (a, b, loose) => compare(a, b, loose) >= 0 -module.exports = gte - - -/***/ }), - -/***/ 900: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) - -const inc = (version, release, options, identifier) => { - if (typeof (options) === 'string') { - identifier = options - options = undefined - } - - try { - return new SemVer(version, options).inc(release, identifier).version - } catch (er) { - return null - } -} -module.exports = inc - - -/***/ }), - -/***/ 194: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const lt = (a, b, loose) => compare(a, b, loose) < 0 -module.exports = lt - - -/***/ }), - -/***/ 7520: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const lte = (a, b, loose) => compare(a, b, loose) <= 0 -module.exports = lte - - -/***/ }), - -/***/ 6688: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const major = (a, loose) => new SemVer(a, loose).major -module.exports = major - - -/***/ }), - -/***/ 8447: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const minor = (a, loose) => new SemVer(a, loose).minor -module.exports = minor - - -/***/ }), - -/***/ 6017: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const neq = (a, b, loose) => compare(a, b, loose) !== 0 -module.exports = neq - - -/***/ }), - -/***/ 5925: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const {MAX_LENGTH} = __nccwpck_require__(2293) -const { re, t } = __nccwpck_require__(9523) -const SemVer = __nccwpck_require__(8088) - -const parseOptions = __nccwpck_require__(785) -const parse = (version, options) => { - options = parseOptions(options) - - if (version instanceof SemVer) { - return version - } - - if (typeof version !== 'string') { - return null - } - - if (version.length > MAX_LENGTH) { - return null - } - - const r = options.loose ? re[t.LOOSE] : re[t.FULL] - if (!r.test(version)) { - return null - } - - try { - return new SemVer(version, options) - } catch (er) { - return null - } -} - -module.exports = parse - - -/***/ }), - -/***/ 2866: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const patch = (a, loose) => new SemVer(a, loose).patch -module.exports = patch - - -/***/ }), - -/***/ 4016: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const parse = __nccwpck_require__(5925) -const prerelease = (version, options) => { - const parsed = parse(version, options) - return (parsed && parsed.prerelease.length) ? parsed.prerelease : null -} -module.exports = prerelease - - -/***/ }), - -/***/ 6417: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compare = __nccwpck_require__(4309) -const rcompare = (a, b, loose) => compare(b, a, loose) -module.exports = rcompare - - -/***/ }), - -/***/ 8701: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compareBuild = __nccwpck_require__(2156) -const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose)) -module.exports = rsort - - -/***/ }), - -/***/ 6055: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const Range = __nccwpck_require__(9828) -const satisfies = (version, range, options) => { - try { - range = new Range(range, options) - } catch (er) { - return false - } - return range.test(version) -} -module.exports = satisfies - - -/***/ }), - -/***/ 1426: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const compareBuild = __nccwpck_require__(2156) -const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose)) -module.exports = sort - - -/***/ }), - -/***/ 9601: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const parse = __nccwpck_require__(5925) -const valid = (version, options) => { - const v = parse(version, options) - return v ? v.version : null -} -module.exports = valid - - -/***/ }), - -/***/ 1383: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -// just pre-load all the stuff that index.js lazily exports -const internalRe = __nccwpck_require__(9523) -module.exports = { - re: internalRe.re, - src: internalRe.src, - tokens: internalRe.t, - SEMVER_SPEC_VERSION: (__nccwpck_require__(2293).SEMVER_SPEC_VERSION), - SemVer: __nccwpck_require__(8088), - compareIdentifiers: (__nccwpck_require__(2463).compareIdentifiers), - rcompareIdentifiers: (__nccwpck_require__(2463).rcompareIdentifiers), - parse: __nccwpck_require__(5925), - valid: __nccwpck_require__(9601), - clean: __nccwpck_require__(8848), - inc: __nccwpck_require__(900), - diff: __nccwpck_require__(4297), - major: __nccwpck_require__(6688), - minor: __nccwpck_require__(8447), - patch: __nccwpck_require__(2866), - prerelease: __nccwpck_require__(4016), - compare: __nccwpck_require__(4309), - rcompare: __nccwpck_require__(6417), - compareLoose: __nccwpck_require__(2804), - compareBuild: __nccwpck_require__(2156), - sort: __nccwpck_require__(1426), - rsort: __nccwpck_require__(8701), - gt: __nccwpck_require__(4123), - lt: __nccwpck_require__(194), - eq: __nccwpck_require__(1898), - neq: __nccwpck_require__(6017), - gte: __nccwpck_require__(5522), - lte: __nccwpck_require__(7520), - cmp: __nccwpck_require__(5098), - coerce: __nccwpck_require__(3466), - Comparator: __nccwpck_require__(1532), - Range: __nccwpck_require__(9828), - satisfies: __nccwpck_require__(6055), - toComparators: __nccwpck_require__(2706), - maxSatisfying: __nccwpck_require__(579), - minSatisfying: __nccwpck_require__(832), - minVersion: __nccwpck_require__(4179), - validRange: __nccwpck_require__(2098), - outside: __nccwpck_require__(420), - gtr: __nccwpck_require__(9380), - ltr: __nccwpck_require__(3323), - intersects: __nccwpck_require__(7008), - simplifyRange: __nccwpck_require__(5297), - subset: __nccwpck_require__(7863), -} - - -/***/ }), - -/***/ 2293: -/***/ ((module) => { - -// Note: this is the semver.org version of the spec that it implements -// Not necessarily the package version of this code. -const SEMVER_SPEC_VERSION = '2.0.0' - -const MAX_LENGTH = 256 -const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || - /* istanbul ignore next */ 9007199254740991 - -// Max safe segment length for coercion. -const MAX_SAFE_COMPONENT_LENGTH = 16 - -module.exports = { - SEMVER_SPEC_VERSION, - MAX_LENGTH, - MAX_SAFE_INTEGER, - MAX_SAFE_COMPONENT_LENGTH -} - - -/***/ }), - -/***/ 427: -/***/ ((module) => { - -const debug = ( - typeof process === 'object' && - process.env && - process.env.NODE_DEBUG && - /\bsemver\b/i.test(process.env.NODE_DEBUG) -) ? (...args) => console.error('SEMVER', ...args) - : () => {} - -module.exports = debug - - -/***/ }), - -/***/ 2463: -/***/ ((module) => { - -const numeric = /^[0-9]+$/ -const compareIdentifiers = (a, b) => { - const anum = numeric.test(a) - const bnum = numeric.test(b) - - if (anum && bnum) { - a = +a - b = +b - } - - return a === b ? 0 - : (anum && !bnum) ? -1 - : (bnum && !anum) ? 1 - : a < b ? -1 - : 1 -} - -const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a) - -module.exports = { - compareIdentifiers, - rcompareIdentifiers -} - - -/***/ }), - -/***/ 785: -/***/ ((module) => { - -// parse out just the options we care about so we always get a consistent -// obj with keys in a consistent order. -const opts = ['includePrerelease', 'loose', 'rtl'] -const parseOptions = options => - !options ? {} - : typeof options !== 'object' ? { loose: true } - : opts.filter(k => options[k]).reduce((options, k) => { - options[k] = true - return options - }, {}) -module.exports = parseOptions - - -/***/ }), - -/***/ 9523: -/***/ ((module, exports, __nccwpck_require__) => { - -const { MAX_SAFE_COMPONENT_LENGTH } = __nccwpck_require__(2293) -const debug = __nccwpck_require__(427) -exports = module.exports = {} - -// The actual regexps go on exports.re -const re = exports.re = [] -const src = exports.src = [] -const t = exports.t = {} -let R = 0 - -const createToken = (name, value, isGlobal) => { - const index = R++ - debug(index, value) - t[name] = index - src[index] = value - re[index] = new RegExp(value, isGlobal ? 'g' : undefined) -} - -// 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. - -createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*') -createToken('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. - -createToken('NONNUMERICIDENTIFIER', '\\d*[a-zA-Z-][a-zA-Z0-9-]*') - -// ## Main Version -// Three dot-separated numeric identifiers. - -createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` + - `(${src[t.NUMERICIDENTIFIER]})\\.` + - `(${src[t.NUMERICIDENTIFIER]})`) - -createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + - `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` + - `(${src[t.NUMERICIDENTIFIERLOOSE]})`) - -// ## Pre-release Version Identifier -// A numeric identifier, or a non-numeric identifier. - -createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NUMERICIDENTIFIER] -}|${src[t.NONNUMERICIDENTIFIER]})`) - -createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NUMERICIDENTIFIERLOOSE] -}|${src[t.NONNUMERICIDENTIFIER]})`) - -// ## Pre-release Version -// Hyphen, followed by one or more dot-separated pre-release version -// identifiers. - -createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER] -}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`) - -createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE] -}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`) - -// ## Build Metadata Identifier -// Any combination of digits, letters, or hyphens. - -createToken('BUILDIDENTIFIER', '[0-9A-Za-z-]+') - -// ## Build Metadata -// Plus sign, followed by one or more period-separated build metadata -// identifiers. - -createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER] -}(?:\\.${src[t.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. - -createToken('FULLPLAIN', `v?${src[t.MAINVERSION] -}${src[t.PRERELEASE]}?${ - src[t.BUILD]}?`) - -createToken('FULL', `^${src[t.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. -createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE] -}${src[t.PRERELEASELOOSE]}?${ - src[t.BUILD]}?`) - -createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`) - -createToken('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. -createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`) -createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`) - -createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` + - `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + - `(?:\\.(${src[t.XRANGEIDENTIFIER]})` + - `(?:${src[t.PRERELEASE]})?${ - src[t.BUILD]}?` + - `)?)?`) - -createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` + - `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + - `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` + - `(?:${src[t.PRERELEASELOOSE]})?${ - src[t.BUILD]}?` + - `)?)?`) - -createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`) -createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`) - -// Coercion. -// Extract anything that could conceivably be a part of a valid semver -createToken('COERCE', `${'(^|[^\\d])' + - '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` + - `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + - `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + - `(?:$|[^\\d])`) -createToken('COERCERTL', src[t.COERCE], true) - -// Tilde ranges. -// Meaning is "reasonably at or greater than" -createToken('LONETILDE', '(?:~>?)') - -createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true) -exports.tildeTrimReplace = '$1~' - -createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`) -createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`) - -// Caret ranges. -// Meaning is "at least and backwards compatible with" -createToken('LONECARET', '(?:\\^)') - -createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true) -exports.caretTrimReplace = '$1^' - -createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`) -createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`) - -// A simple gt/lt/eq thing, or just "" to indicate "any version" -createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`) -createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`) - -// An expression to strip any whitespace between the gtlt and the thing -// it modifies, so that `> 1.2.3` ==> `>1.2.3` -createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT] -}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true) -exports.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. -createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` + - `\\s+-\\s+` + - `(${src[t.XRANGEPLAIN]})` + - `\\s*$`) - -createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` + - `\\s+-\\s+` + - `(${src[t.XRANGEPLAINLOOSE]})` + - `\\s*$`) - -// Star ranges basically just allow anything at all. -createToken('STAR', '(<|>)?=?\\s*\\*') -// >=0.0.0 is like a star -createToken('GTE0', '^\\s*>=\\s*0\.0\.0\\s*$') -createToken('GTE0PRE', '^\\s*>=\\s*0\.0\.0-0\\s*$') - - -/***/ }), - -/***/ 9380: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -// Determine if version is greater than all the versions possible in the range. -const outside = __nccwpck_require__(420) -const gtr = (version, range, options) => outside(version, range, '>', options) -module.exports = gtr - - -/***/ }), - -/***/ 7008: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const Range = __nccwpck_require__(9828) -const intersects = (r1, r2, options) => { - r1 = new Range(r1, options) - r2 = new Range(r2, options) - return r1.intersects(r2) -} -module.exports = intersects - - -/***/ }), - -/***/ 3323: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const outside = __nccwpck_require__(420) -// Determine if version is less than all the versions possible in the range -const ltr = (version, range, options) => outside(version, range, '<', options) -module.exports = ltr - - -/***/ }), - -/***/ 579: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const Range = __nccwpck_require__(9828) - -const maxSatisfying = (versions, range, options) => { - let max = null - let maxSV = null - let rangeObj = null - try { - rangeObj = new Range(range, options) - } catch (er) { - return null - } - versions.forEach((v) => { - if (rangeObj.test(v)) { - // satisfies(v, range, options) - if (!max || maxSV.compare(v) === -1) { - // compare(max, v, true) - max = v - maxSV = new SemVer(max, options) - } - } - }) - return max -} -module.exports = maxSatisfying - - -/***/ }), - -/***/ 832: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const Range = __nccwpck_require__(9828) -const minSatisfying = (versions, range, options) => { - let min = null - let minSV = null - let rangeObj = null - try { - rangeObj = new Range(range, options) - } catch (er) { - return null - } - versions.forEach((v) => { - if (rangeObj.test(v)) { - // satisfies(v, range, options) - if (!min || minSV.compare(v) === 1) { - // compare(min, v, true) - min = v - minSV = new SemVer(min, options) - } - } - }) - return min -} -module.exports = minSatisfying - - -/***/ }), - -/***/ 4179: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const Range = __nccwpck_require__(9828) -const gt = __nccwpck_require__(4123) - -const minVersion = (range, loose) => { - range = new Range(range, loose) - - let minver = new SemVer('0.0.0') - if (range.test(minver)) { - return minver - } - - minver = new SemVer('0.0.0-0') - if (range.test(minver)) { - return minver - } - - minver = null - for (let i = 0; i < range.set.length; ++i) { - const comparators = range.set[i] - - let setMin = null - comparators.forEach((comparator) => { - // Clone to avoid manipulating the comparator's semver object. - const compver = new SemVer(comparator.semver.version) - switch (comparator.operator) { - case '>': - if (compver.prerelease.length === 0) { - compver.patch++ - } else { - compver.prerelease.push(0) - } - compver.raw = compver.format() - /* fallthrough */ - case '': - case '>=': - if (!setMin || gt(compver, setMin)) { - setMin = compver - } - break - case '<': - case '<=': - /* Ignore maximum versions */ - break - /* istanbul ignore next */ - default: - throw new Error(`Unexpected operation: ${comparator.operator}`) - } - }) - if (setMin && (!minver || gt(minver, setMin))) - minver = setMin - } - - if (minver && range.test(minver)) { - return minver - } - - return null -} -module.exports = minVersion - - -/***/ }), - -/***/ 420: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const SemVer = __nccwpck_require__(8088) -const Comparator = __nccwpck_require__(1532) -const {ANY} = Comparator -const Range = __nccwpck_require__(9828) -const satisfies = __nccwpck_require__(6055) -const gt = __nccwpck_require__(4123) -const lt = __nccwpck_require__(194) -const lte = __nccwpck_require__(7520) -const gte = __nccwpck_require__(5522) - -const outside = (version, range, hilo, options) => { - version = new SemVer(version, options) - range = new Range(range, options) - - let 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 satisfies the range it is not outside - if (satisfies(version, range, options)) { - 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 (let i = 0; i < range.set.length; ++i) { - const comparators = range.set[i] - - let high = null - let low = null - - comparators.forEach((comparator) => { - if (comparator.semver === ANY) { - comparator = new Comparator('>=0.0.0') - } - high = high || comparator - low = low || comparator - if (gtfn(comparator.semver, high.semver, options)) { - high = comparator - } else if (ltfn(comparator.semver, low.semver, options)) { - 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 -} - -module.exports = outside - - -/***/ }), - -/***/ 5297: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -// given a set of versions and a range, create a "simplified" range -// that includes the same versions that the original range does -// If the original range is shorter than the simplified one, return that. -const satisfies = __nccwpck_require__(6055) -const compare = __nccwpck_require__(4309) -module.exports = (versions, range, options) => { - const set = [] - let min = null - let prev = null - const v = versions.sort((a, b) => compare(a, b, options)) - for (const version of v) { - const included = satisfies(version, range, options) - if (included) { - prev = version - if (!min) - min = version - } else { - if (prev) { - set.push([min, prev]) - } - prev = null - min = null - } - } - if (min) - set.push([min, null]) - - const ranges = [] - for (const [min, max] of set) { - if (min === max) - ranges.push(min) - else if (!max && min === v[0]) - ranges.push('*') - else if (!max) - ranges.push(`>=${min}`) - else if (min === v[0]) - ranges.push(`<=${max}`) - else - ranges.push(`${min} - ${max}`) - } - const simplified = ranges.join(' || ') - const original = typeof range.raw === 'string' ? range.raw : String(range) - return simplified.length < original.length ? simplified : range -} - - -/***/ }), - -/***/ 7863: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const Range = __nccwpck_require__(9828) -const Comparator = __nccwpck_require__(1532) -const { ANY } = Comparator -const satisfies = __nccwpck_require__(6055) -const compare = __nccwpck_require__(4309) - -// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff: -// - Every simple range `r1, r2, ...` is a null set, OR -// - Every simple range `r1, r2, ...` which is not a null set is a subset of -// some `R1, R2, ...` -// -// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff: -// - If c is only the ANY comparator -// - If C is only the ANY comparator, return true -// - Else if in prerelease mode, return false -// - else replace c with `[>=0.0.0]` -// - If C is only the ANY comparator -// - if in prerelease mode, return true -// - else replace C with `[>=0.0.0]` -// - Let EQ be the set of = comparators in c -// - If EQ is more than one, return true (null set) -// - Let GT be the highest > or >= comparator in c -// - Let LT be the lowest < or <= comparator in c -// - If GT and LT, and GT.semver > LT.semver, return true (null set) -// - If any C is a = range, and GT or LT are set, return false -// - If EQ -// - If GT, and EQ does not satisfy GT, return true (null set) -// - If LT, and EQ does not satisfy LT, return true (null set) -// - If EQ satisfies every C, return true -// - Else return false -// - If GT -// - If GT.semver is lower than any > or >= comp in C, return false -// - If GT is >=, and GT.semver does not satisfy every C, return false -// - If GT.semver has a prerelease, and not in prerelease mode -// - If no C has a prerelease and the GT.semver tuple, return false -// - If LT -// - If LT.semver is greater than any < or <= comp in C, return false -// - If LT is <=, and LT.semver does not satisfy every C, return false -// - If GT.semver has a prerelease, and not in prerelease mode -// - If no C has a prerelease and the LT.semver tuple, return false -// - Else return true - -const subset = (sub, dom, options = {}) => { - if (sub === dom) - return true - - sub = new Range(sub, options) - dom = new Range(dom, options) - let sawNonNull = false - - OUTER: for (const simpleSub of sub.set) { - for (const simpleDom of dom.set) { - const isSub = simpleSubset(simpleSub, simpleDom, options) - sawNonNull = sawNonNull || isSub !== null - if (isSub) - continue OUTER - } - // the null set is a subset of everything, but null simple ranges in - // a complex range should be ignored. so if we saw a non-null range, - // then we know this isn't a subset, but if EVERY simple range was null, - // then it is a subset. - if (sawNonNull) - return false - } - return true -} - -const simpleSubset = (sub, dom, options) => { - if (sub === dom) - return true - - if (sub.length === 1 && sub[0].semver === ANY) { - if (dom.length === 1 && dom[0].semver === ANY) - return true - else if (options.includePrerelease) - sub = [ new Comparator('>=0.0.0-0') ] - else - sub = [ new Comparator('>=0.0.0') ] - } - - if (dom.length === 1 && dom[0].semver === ANY) { - if (options.includePrerelease) - return true - else - dom = [ new Comparator('>=0.0.0') ] - } - - const eqSet = new Set() - let gt, lt - for (const c of sub) { - if (c.operator === '>' || c.operator === '>=') - gt = higherGT(gt, c, options) - else if (c.operator === '<' || c.operator === '<=') - lt = lowerLT(lt, c, options) - else - eqSet.add(c.semver) - } - - if (eqSet.size > 1) - return null - - let gtltComp - if (gt && lt) { - gtltComp = compare(gt.semver, lt.semver, options) - if (gtltComp > 0) - return null - else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) - return null - } - - // will iterate one or zero times - for (const eq of eqSet) { - if (gt && !satisfies(eq, String(gt), options)) - return null - - if (lt && !satisfies(eq, String(lt), options)) - return null - - for (const c of dom) { - if (!satisfies(eq, String(c), options)) - return false - } - - return true - } - - let higher, lower - let hasDomLT, hasDomGT - // if the subset has a prerelease, we need a comparator in the superset - // with the same tuple and a prerelease, or it's not a subset - let needDomLTPre = lt && - !options.includePrerelease && - lt.semver.prerelease.length ? lt.semver : false - let needDomGTPre = gt && - !options.includePrerelease && - gt.semver.prerelease.length ? gt.semver : false - // exception: <1.2.3-0 is the same as <1.2.3 - if (needDomLTPre && needDomLTPre.prerelease.length === 1 && - lt.operator === '<' && needDomLTPre.prerelease[0] === 0) { - needDomLTPre = false - } - - for (const c of dom) { - hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=' - hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=' - if (gt) { - if (needDomGTPre) { - if (c.semver.prerelease && c.semver.prerelease.length && - c.semver.major === needDomGTPre.major && - c.semver.minor === needDomGTPre.minor && - c.semver.patch === needDomGTPre.patch) { - needDomGTPre = false - } - } - if (c.operator === '>' || c.operator === '>=') { - higher = higherGT(gt, c, options) - if (higher === c && higher !== gt) - return false - } else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) - return false - } - if (lt) { - if (needDomLTPre) { - if (c.semver.prerelease && c.semver.prerelease.length && - c.semver.major === needDomLTPre.major && - c.semver.minor === needDomLTPre.minor && - c.semver.patch === needDomLTPre.patch) { - needDomLTPre = false - } - } - if (c.operator === '<' || c.operator === '<=') { - lower = lowerLT(lt, c, options) - if (lower === c && lower !== lt) - return false - } else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) - return false - } - if (!c.operator && (lt || gt) && gtltComp !== 0) - return false - } - - // if there was a < or >, and nothing in the dom, then must be false - // UNLESS it was limited by another range in the other direction. - // Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0 - if (gt && hasDomLT && !lt && gtltComp !== 0) - return false - - if (lt && hasDomGT && !gt && gtltComp !== 0) - return false - - // we needed a prerelease range in a specific tuple, but didn't get one - // then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0, - // because it includes prereleases in the 1.2.3 tuple - if (needDomGTPre || needDomLTPre) - return false - - return true -} - -// >=1.2.3 is lower than >1.2.3 -const higherGT = (a, b, options) => { - if (!a) - return b - const comp = compare(a.semver, b.semver, options) - return comp > 0 ? a - : comp < 0 ? b - : b.operator === '>' && a.operator === '>=' ? b - : a -} - -// <=1.2.3 is higher than <1.2.3 -const lowerLT = (a, b, options) => { - if (!a) - return b - const comp = compare(a.semver, b.semver, options) - return comp < 0 ? a - : comp > 0 ? b - : b.operator === '<' && a.operator === '<=' ? b - : a -} - -module.exports = subset - - -/***/ }), - -/***/ 2706: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const Range = __nccwpck_require__(9828) - -// Mostly just for testing and legacy API reasons -const toComparators = (range, options) => - new Range(range, options).set - .map(comp => comp.map(c => c.value).join(' ').trim().split(' ')) - -module.exports = toComparators - - -/***/ }), - -/***/ 2098: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const Range = __nccwpck_require__(9828) -const validRange = (range, options) => { - try { - // Return '*' instead of '' so that truthiness works. - // This will throw if it's invalid anyway - return new Range(range, options).range || '*' - } catch (er) { - return null - } -} -module.exports = validRange - - -/***/ }), - -/***/ 7372: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { - -"use strict"; -/*! - * Copyright (c) 2015, Salesforce.com, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * 3. Neither the name of Salesforce.com nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -const punycode = __nccwpck_require__(5477); -const urlParse = (__nccwpck_require__(7310).parse); -const util = __nccwpck_require__(3837); -const pubsuffix = __nccwpck_require__(4401); -const Store = (__nccwpck_require__(460)/* .Store */ .y); -const MemoryCookieStore = (__nccwpck_require__(2640)/* .MemoryCookieStore */ .m); -const pathMatch = (__nccwpck_require__(4336)/* .pathMatch */ .U); -const VERSION = __nccwpck_require__(3199); -const { fromCallback } = __nccwpck_require__(260); - -// From RFC6265 S4.1.1 -// note that it excludes \x3B ";" -const COOKIE_OCTETS = /^[\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]+$/; - -const CONTROL_CHARS = /[\x00-\x1F]/; - -// From Chromium // '\r', '\n' and '\0' should be treated as a terminator in -// the "relaxed" mode, see: -// https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60 -const TERMINATORS = ["\n", "\r", "\0"]; - -// RFC6265 S4.1.1 defines path value as 'any CHAR except CTLs or ";"' -// Note ';' is \x3B -const PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/; - -// date-time parsing constants (RFC6265 S5.1.1) - -const DATE_DELIM = /[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]/; - -const MONTH_TO_NUM = { - jan: 0, - feb: 1, - mar: 2, - apr: 3, - may: 4, - jun: 5, - jul: 6, - aug: 7, - sep: 8, - oct: 9, - nov: 10, - dec: 11 -}; - -const MAX_TIME = 2147483647000; // 31-bit max -const MIN_TIME = 0; // 31-bit min -const SAME_SITE_CONTEXT_VAL_ERR = - 'Invalid sameSiteContext option for getCookies(); expected one of "strict", "lax", or "none"'; - -function checkSameSiteContext(value) { - const context = String(value).toLowerCase(); - if (context === "none" || context === "lax" || context === "strict") { - return context; - } else { - return null; - } -} - -const PrefixSecurityEnum = Object.freeze({ - SILENT: "silent", - STRICT: "strict", - DISABLED: "unsafe-disabled" -}); - -// Dumped from ip-regex@4.0.0, with the following changes: -// * all capturing groups converted to non-capturing -- "(?:)" -// * support for IPv6 Scoped Literal ("%eth1") removed -// * lowercase hexadecimal only -var IP_REGEX_LOWERCASE =/(?:^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$)|(?:^(?:(?:[a-f\d]{1,4}:){7}(?:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,2}|:)|(?:[a-f\d]{1,4}:){4}(?:(?::[a-f\d]{1,4}){0,1}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,3}|:)|(?:[a-f\d]{1,4}:){3}(?:(?::[a-f\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,4}|:)|(?:[a-f\d]{1,4}:){2}(?:(?::[a-f\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,5}|:)|(?:[a-f\d]{1,4}:){1}(?:(?::[a-f\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,6}|:)|(?::(?:(?::[a-f\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,7}|:)))$)/; - -/* - * Parses a Natural number (i.e., non-negative integer) with either the - * *DIGIT ( non-digit *OCTET ) - * or - * *DIGIT - * grammar (RFC6265 S5.1.1). - * - * The "trailingOK" boolean controls if the grammar accepts a - * "( non-digit *OCTET )" trailer. - */ -function parseDigits(token, minDigits, maxDigits, trailingOK) { - let count = 0; - while (count < token.length) { - const c = token.charCodeAt(count); - // "non-digit = %x00-2F / %x3A-FF" - if (c <= 0x2f || c >= 0x3a) { - break; - } - count++; - } - - // constrain to a minimum and maximum number of digits. - if (count < minDigits || count > maxDigits) { - return null; - } - - if (!trailingOK && count != token.length) { - return null; - } - - return parseInt(token.substr(0, count), 10); -} + return parseInt(token.substr(0, count), 10); +} function parseTime(token) { const parts = token.split(":"); @@ -67146,794 +64536,155 @@ module.exports = v4; })(); -}).call(this); - - -/***/ }), - -/***/ 2958: -/***/ (function(module, __unused_webpack_exports, __nccwpck_require__) { - -// Generated by CoffeeScript 1.12.7 -(function() { - var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref; - - ref = __nccwpck_require__(8229), assign = ref.assign, isFunction = ref.isFunction; - - XMLDOMImplementation = __nccwpck_require__(8310); - - XMLDocument = __nccwpck_require__(3730); - - XMLDocumentCB = __nccwpck_require__(7356); - - XMLStringWriter = __nccwpck_require__(5913); - - XMLStreamWriter = __nccwpck_require__(8601); - - NodeType = __nccwpck_require__(9267); - - WriterState = __nccwpck_require__(9766); - - module.exports.create = function(name, xmldec, doctype, options) { - var doc, root; - if (name == null) { - throw new Error("Root element needs a name."); - } - options = assign({}, xmldec, doctype, options); - doc = new XMLDocument(options); - root = doc.element(name); - if (!options.headless) { - doc.declaration(options); - if ((options.pubID != null) || (options.sysID != null)) { - doc.dtd(options); - } - } - return root; - }; - - module.exports.begin = function(options, onData, onEnd) { - var ref1; - if (isFunction(options)) { - ref1 = [options, onData], onData = ref1[0], onEnd = ref1[1]; - options = {}; - } - if (onData) { - return new XMLDocumentCB(options, onData, onEnd); - } else { - return new XMLDocument(options); - } - }; - - module.exports.stringWriter = function(options) { - return new XMLStringWriter(options); - }; - - module.exports.streamWriter = function(stream, options) { - return new XMLStreamWriter(stream, options); - }; - - module.exports.implementation = new XMLDOMImplementation(); - - module.exports.nodeType = NodeType; - - module.exports.writerState = WriterState; - -}).call(this); - - -/***/ }), - -/***/ 4091: -/***/ ((module) => { - -"use strict"; - -module.exports = function (Yallist) { - Yallist.prototype[Symbol.iterator] = function* () { - for (let walker = this.head; walker; walker = walker.next) { - yield walker.value - } - } -} - - -/***/ }), - -/***/ 665: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -"use strict"; - -module.exports = Yallist - -Yallist.Node = Node -Yallist.create = Yallist - -function Yallist (list) { - var self = this - if (!(self instanceof Yallist)) { - self = new Yallist() - } - - self.tail = null - self.head = null - self.length = 0 - - if (list && typeof list.forEach === 'function') { - list.forEach(function (item) { - self.push(item) - }) - } else if (arguments.length > 0) { - for (var i = 0, l = arguments.length; i < l; i++) { - self.push(arguments[i]) - } - } - - return self -} - -Yallist.prototype.removeNode = function (node) { - if (node.list !== this) { - throw new Error('removing node which does not belong to this list') - } - - var next = node.next - var prev = node.prev - - if (next) { - next.prev = prev - } - - if (prev) { - prev.next = next - } - - if (node === this.head) { - this.head = next - } - if (node === this.tail) { - this.tail = prev - } - - node.list.length-- - node.next = null - node.prev = null - node.list = null - - return next -} - -Yallist.prototype.unshiftNode = function (node) { - if (node === this.head) { - return - } - - if (node.list) { - node.list.removeNode(node) - } - - var head = this.head - node.list = this - node.next = head - if (head) { - head.prev = node - } - - this.head = node - if (!this.tail) { - this.tail = node - } - this.length++ -} - -Yallist.prototype.pushNode = function (node) { - if (node === this.tail) { - return - } - - if (node.list) { - node.list.removeNode(node) - } - - var tail = this.tail - node.list = this - node.prev = tail - if (tail) { - tail.next = node - } - - this.tail = node - if (!this.head) { - this.head = node - } - this.length++ -} - -Yallist.prototype.push = function () { - for (var i = 0, l = arguments.length; i < l; i++) { - push(this, arguments[i]) - } - return this.length -} - -Yallist.prototype.unshift = function () { - for (var i = 0, l = arguments.length; i < l; i++) { - unshift(this, arguments[i]) - } - return this.length -} - -Yallist.prototype.pop = function () { - if (!this.tail) { - return undefined - } - - var res = this.tail.value - this.tail = this.tail.prev - if (this.tail) { - this.tail.next = null - } else { - this.head = null - } - this.length-- - return res -} - -Yallist.prototype.shift = function () { - if (!this.head) { - return undefined - } - - var res = this.head.value - this.head = this.head.next - if (this.head) { - this.head.prev = null - } else { - this.tail = null - } - this.length-- - return res -} - -Yallist.prototype.forEach = function (fn, thisp) { - thisp = thisp || this - for (var walker = this.head, i = 0; walker !== null; i++) { - fn.call(thisp, walker.value, i, this) - walker = walker.next - } -} - -Yallist.prototype.forEachReverse = function (fn, thisp) { - thisp = thisp || this - for (var walker = this.tail, i = this.length - 1; walker !== null; i--) { - fn.call(thisp, walker.value, i, this) - walker = walker.prev - } -} - -Yallist.prototype.get = function (n) { - for (var i = 0, walker = this.head; walker !== null && i < n; i++) { - // abort out of the list early if we hit a cycle - walker = walker.next - } - if (i === n && walker !== null) { - return walker.value - } -} - -Yallist.prototype.getReverse = function (n) { - for (var i = 0, walker = this.tail; walker !== null && i < n; i++) { - // abort out of the list early if we hit a cycle - walker = walker.prev - } - if (i === n && walker !== null) { - return walker.value - } -} - -Yallist.prototype.map = function (fn, thisp) { - thisp = thisp || this - var res = new Yallist() - for (var walker = this.head; walker !== null;) { - res.push(fn.call(thisp, walker.value, this)) - walker = walker.next - } - return res -} - -Yallist.prototype.mapReverse = function (fn, thisp) { - thisp = thisp || this - var res = new Yallist() - for (var walker = this.tail; walker !== null;) { - res.push(fn.call(thisp, walker.value, this)) - walker = walker.prev - } - return res -} - -Yallist.prototype.reduce = function (fn, initial) { - var acc - var walker = this.head - if (arguments.length > 1) { - acc = initial - } else if (this.head) { - walker = this.head.next - acc = this.head.value - } else { - throw new TypeError('Reduce of empty list with no initial value') - } - - for (var i = 0; walker !== null; i++) { - acc = fn(acc, walker.value, i) - walker = walker.next - } - - return acc -} - -Yallist.prototype.reduceReverse = function (fn, initial) { - var acc - var walker = this.tail - if (arguments.length > 1) { - acc = initial - } else if (this.tail) { - walker = this.tail.prev - acc = this.tail.value - } else { - throw new TypeError('Reduce of empty list with no initial value') - } - - for (var i = this.length - 1; walker !== null; i--) { - acc = fn(acc, walker.value, i) - walker = walker.prev - } - - return acc -} - -Yallist.prototype.toArray = function () { - var arr = new Array(this.length) - for (var i = 0, walker = this.head; walker !== null; i++) { - arr[i] = walker.value - walker = walker.next - } - return arr -} - -Yallist.prototype.toArrayReverse = function () { - var arr = new Array(this.length) - for (var i = 0, walker = this.tail; walker !== null; i++) { - arr[i] = walker.value - walker = walker.prev - } - return arr -} - -Yallist.prototype.slice = function (from, to) { - to = to || this.length - if (to < 0) { - to += this.length - } - from = from || 0 - if (from < 0) { - from += this.length - } - var ret = new Yallist() - if (to < from || to < 0) { - return ret - } - if (from < 0) { - from = 0 - } - if (to > this.length) { - to = this.length - } - for (var i = 0, walker = this.head; walker !== null && i < from; i++) { - walker = walker.next - } - for (; walker !== null && i < to; i++, walker = walker.next) { - ret.push(walker.value) - } - return ret -} - -Yallist.prototype.sliceReverse = function (from, to) { - to = to || this.length - if (to < 0) { - to += this.length - } - from = from || 0 - if (from < 0) { - from += this.length - } - var ret = new Yallist() - if (to < from || to < 0) { - return ret - } - if (from < 0) { - from = 0 - } - if (to > this.length) { - to = this.length - } - for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) { - walker = walker.prev - } - for (; walker !== null && i > from; i--, walker = walker.prev) { - ret.push(walker.value) - } - return ret -} - -Yallist.prototype.splice = function (start, deleteCount, ...nodes) { - if (start > this.length) { - start = this.length - 1 - } - if (start < 0) { - start = this.length + start; - } - - for (var i = 0, walker = this.head; walker !== null && i < start; i++) { - walker = walker.next - } - - var ret = [] - for (var i = 0; walker && i < deleteCount; i++) { - ret.push(walker.value) - walker = this.removeNode(walker) - } - if (walker === null) { - walker = this.tail - } - - if (walker !== this.head && walker !== this.tail) { - walker = walker.prev - } - - for (var i = 0; i < nodes.length; i++) { - walker = insert(this, walker, nodes[i]) - } - return ret; -} - -Yallist.prototype.reverse = function () { - var head = this.head - var tail = this.tail - for (var walker = head; walker !== null; walker = walker.prev) { - var p = walker.prev - walker.prev = walker.next - walker.next = p - } - this.head = tail - this.tail = head - return this -} - -function insert (self, node, value) { - var inserted = node === self.head ? - new Node(value, null, node, self) : - new Node(value, node, node.next, self) - - if (inserted.next === null) { - self.tail = inserted - } - if (inserted.prev === null) { - self.head = inserted - } - - self.length++ +}).call(this); - return inserted -} -function push (self, item) { - self.tail = new Node(item, self.tail, null, self) - if (!self.head) { - self.head = self.tail - } - self.length++ -} +/***/ }), -function unshift (self, item) { - self.head = new Node(item, null, self.head, self) - if (!self.tail) { - self.tail = self.head - } - self.length++ -} +/***/ 2958: +/***/ (function(module, __unused_webpack_exports, __nccwpck_require__) { -function Node (value, prev, next, list) { - if (!(this instanceof Node)) { - return new Node(value, prev, next, list) - } +// Generated by CoffeeScript 1.12.7 +(function() { + var NodeType, WriterState, XMLDOMImplementation, XMLDocument, XMLDocumentCB, XMLStreamWriter, XMLStringWriter, assign, isFunction, ref; - this.list = list - this.value = value + ref = __nccwpck_require__(8229), assign = ref.assign, isFunction = ref.isFunction; - if (prev) { - prev.next = this - this.prev = prev - } else { - this.prev = null - } + XMLDOMImplementation = __nccwpck_require__(8310); - if (next) { - next.prev = this - this.next = next - } else { - this.next = null - } -} + XMLDocument = __nccwpck_require__(3730); -try { - // add if support for Symbol.iterator is present - __nccwpck_require__(4091)(Yallist) -} catch (er) {} + XMLDocumentCB = __nccwpck_require__(7356); + XMLStringWriter = __nccwpck_require__(5913); -/***/ }), + XMLStreamWriter = __nccwpck_require__(8601); -/***/ 4190: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + NodeType = __nccwpck_require__(9267); -"use strict"; + WriterState = __nccwpck_require__(9766); -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.setupAction = void 0; -const core_1 = __nccwpck_require__(2186); -const install_1 = __nccwpck_require__(1649); -const packager_1 = __nccwpck_require__(6466); -const tools = __importStar(__nccwpck_require__(5905)); -// Auto-execute in GitHub actions -tools.performAction(setupAction); -async function setupAction() { - const expoVersion = await installCli('expo-cli'); - const easVersion = await installCli('eas-cli'); - await (0, core_1.group)('Checking current authenticated account', () => tools.maybeAuthenticate({ - cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined, - token: (0, core_1.getInput)('token') || undefined, - username: (0, core_1.getInput)('username') || undefined, - password: (0, core_1.getInput)('password') || undefined, - })); - if (!(0, core_1.getInput)('patch-watchers') || (0, core_1.getBooleanInput)('patch-watchers') !== false) { - await (0, core_1.group)('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers()); + module.exports.create = function(name, xmldec, doctype, options) { + var doc, root; + if (name == null) { + throw new Error("Root element needs a name."); } -} -exports.setupAction = setupAction; -async function installCli(name) { - const shortName = tools.getBinaryName(name); - const inputVersion = (0, core_1.getInput)(`${shortName}-version`); - const packager = (0, core_1.getInput)('packager') || 'yarn'; - if (!inputVersion) { - return (0, core_1.info)(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`); - } - const version = await (0, packager_1.resolveVersion)(name, inputVersion); - const cache = (0, core_1.getBooleanInput)(`${shortName}-cache`); - try { - const path = await (0, core_1.group)(cache - ? `Installing ${name} (${version}) from cache or with ${packager}` - : `Installing ${name} (${version}) with ${packager}`, () => (0, install_1.install)({ - packager, - version, - cache, - package: name, - cacheKey: (0, core_1.getInput)(`${shortName}-cache-key`) || undefined, - })); - (0, core_1.addPath)(path); + options = assign({}, xmldec, doctype, options); + doc = new XMLDocument(options); + root = doc.element(name); + if (!options.headless) { + doc.declaration(options); + if ((options.pubID != null) || (options.sysID != null)) { + doc.dtd(options); + } } - catch (error) { - tools.handleError(name, error); + return root; + }; + + module.exports.begin = function(options, onData, onEnd) { + var ref1; + if (isFunction(options)) { + ref1 = [options, onData], onData = ref1[0], onEnd = ref1[1]; + options = {}; } - return version; -} + if (onData) { + return new XMLDocumentCB(options, onData, onEnd); + } else { + return new XMLDocument(options); + } + }; + + module.exports.stringWriter = function(options) { + return new XMLStringWriter(options); + }; + + module.exports.streamWriter = function(stream, options) { + return new XMLStreamWriter(stream, options); + }; + + module.exports.implementation = new XMLDOMImplementation(); + + module.exports.nodeType = NodeType; + + module.exports.writerState = WriterState; + +}).call(this); /***/ }), -/***/ 4810: +/***/ 331: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.toRemoteCache = exports.fromRemoteCache = exports.toLocalCache = exports.fromLocalCache = void 0; +exports.handleCacheError = exports.saveToCache = exports.restoreFromCache = exports.cacheKey = void 0; const cache_1 = __nccwpck_require__(7799); -const core = __importStar(__nccwpck_require__(2186)); -const toolCache = __importStar(__nccwpck_require__(7784)); +const core_1 = __nccwpck_require__(2186); const os_1 = __importDefault(__nccwpck_require__(2037)); -const path_1 = __importDefault(__nccwpck_require__(1017)); -/** - * Get the path to the `expo-cli` from cache, if any. - * Note, this cache is **NOT** shared between jobs. - * - * @see https://github.com/actions/toolkit/issues/47 - */ -async function fromLocalCache(config) { - return toolCache.find(config.package, config.version); -} -exports.fromLocalCache = fromLocalCache; +const worker_1 = __nccwpck_require__(8912); /** - * Store the root of `expo-cli` in the cache, for future reuse. - * Note, this cache is **NOT** shared between jobs. - * - * @see https://github.com/actions/toolkit/issues/47 + * Get the exact cache key for the package. + * We can prefix this when there are breaking changes in this action. */ -async function toLocalCache(root, config) { - return toolCache.cacheDir(root, config.package, config.version); +function cacheKey(name, version, manager) { + return `${name}-${process.platform}-${os_1.default.arch()}-${manager}-${version}`; } -exports.toLocalCache = toLocalCache; +exports.cacheKey = cacheKey; /** - * Download the remotely stored `expo-cli` from cache, if any. - * Note, this cache is shared between jobs. + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. */ -async function fromRemoteCache(config) { - // see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401 - const target = path_1.default.join(process.env['RUNNER_TOOL_CACHE'] || '', config.package, config.version, os_1.default.arch()); - const cacheKey = config.cacheKey || getRemoteKey(config); +async function restoreFromCache(name, version, manager) { + const dir = (0, worker_1.toolPath)(name, version); try { - // When running with nektos/act, or other custom environments, the cache might not be set up. - const hit = await (0, cache_1.restoreCache)([target], cacheKey); - if (hit) { - return target; + if (await (0, cache_1.restoreCache)([dir], cacheKey(name, version, manager))) { + return dir; } } catch (error) { - if (!handleRemoteCacheError(error)) { - throw error; - } + handleCacheError(error); } } -exports.fromRemoteCache = fromRemoteCache; +exports.restoreFromCache = restoreFromCache; /** - * Store the root of `expo-cli` in the remote cache, for future reuse. - * Note, this cache is shared between jobs. + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. */ -async function toRemoteCache(source, config) { - const cacheKey = config.cacheKey || getRemoteKey(config); +async function saveToCache(name, version, manager) { try { - await (0, cache_1.saveCache)([source], cacheKey); + await (0, cache_1.saveCache)([(0, worker_1.toolPath)(name, version)], cacheKey(name, version, manager)); } catch (error) { - if (!handleRemoteCacheError(error)) { - throw error; - } + handleCacheError(error); } } -exports.toRemoteCache = toRemoteCache; -/** - * Get the cache key to use when (re)storing the Expo CLI from remote cache. - */ -function getRemoteKey(config) { - return `${config.package}-${process.platform}-${os_1.default.arch()}-${config.packager}-${config.version}`; -} +exports.saveToCache = saveToCache; /** - * Handle any incoming errors from cache methods. - * This can include actual errors like `ReserveCacheErrors` or unavailability errors. - * When the error is handled, it MUST provide feedback for the developer. + * Try to handle incoming cache errors. + * Because workers can operate in environments without cache configured, + * we need to make sure to only skip the cache instead of fail. * - * @returns If the error was handled properly. + * Currently we handle these types of errors: + * - ReserveCacheError + * - "cache service url not found" */ -function handleRemoteCacheError(error) { +function handleCacheError(error) { const isReserveCacheError = error instanceof cache_1.ReserveCacheError; const isCacheUnavailable = error.message.toLowerCase().includes('cache service url not found'); if (isReserveCacheError || isCacheUnavailable) { - core.warning('Skipping remote cache storage, encountered error:'); - core.warning(error.message); - return true; - } - return false; -} - - -/***/ }), - -/***/ 1649: -/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { - -"use strict"; - -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.fromPackager = exports.install = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const cli = __importStar(__nccwpck_require__(1514)); -const io = __importStar(__nccwpck_require__(7436)); -const path = __importStar(__nccwpck_require__(1017)); -const cache_1 = __nccwpck_require__(4810); -/** - * Install `expo-cli`, by version, using the packager. - * Here you can provide any semver range or dist tag used in the registry. - * It returns the path where Expo is installed. - */ -async function install(config) { - let root = await (0, cache_1.fromLocalCache)(config); - if (!root && config.cache) { - root = await (0, cache_1.fromRemoteCache)(config); + (0, core_1.warning)('Skipped remote cache, encountered error:'); + (0, core_1.warning)(error.message); } else { - core.info('Skipping remote cache, not enabled...'); - } - if (!root) { - root = await fromPackager(config); - root = await (0, cache_1.toLocalCache)(root, config); - if (config.cache) { - await (0, cache_1.toRemoteCache)(root, config); - } + throw error; } - return path.join(root, 'node_modules', '.bin'); -} -exports.install = install; -/** - * Install `expo-cli`, by version, using npm or yarn. - * It creates a temporary directory to store all required files. - */ -async function fromPackager(config) { - const root = process.env['RUNNER_TEMP'] || ''; - const tool = await io.which(config.packager); - await io.mkdirP(root); - await cli.exec(tool, ['add', `${config.package}@${config.version}`], { cwd: root }); - return root; } -exports.fromPackager = fromPackager; +exports.handleCacheError = handleCacheError; /***/ }), @@ -67944,14 +64695,16 @@ exports.fromPackager = fromPackager; "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.resolveVersion = void 0; +exports.installPackage = exports.resolvePackage = void 0; const exec_1 = __nccwpck_require__(1514); +const io_1 = __nccwpck_require__(7436); +const worker_1 = __nccwpck_require__(8912); /** * Resolve a package with version range to an exact version. * This is useful to invalidate the cache _and_ using dist-tags or version ranges. * It executes `npm info` and parses the latest manifest. */ -async function resolveVersion(name, range) { +async function resolvePackage(name, range) { let stdout = ''; try { await (0, exec_1.exec)('npm', ['info', `${name}@${range}`, 'version', '--json'], { @@ -67964,7 +64717,7 @@ async function resolveVersion(name, range) { }); } catch (error) { - throw new Error(`Could not resolve version "${range}" of "${name}", reason:\n${error.message || error}`); + throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`); } // thanks npm, for returning a "x.x.x" json value... if (stdout.startsWith('"')) { @@ -67972,151 +64725,124 @@ async function resolveVersion(name, range) { } return JSON.parse(stdout).at(-1); } -exports.resolveVersion = resolveVersion; +exports.resolvePackage = resolvePackage; +/** + * Install a module using a node package manager. + * The installation is executed in a temporary folder. + * After this is complete, it's "installed" into the worker's tool cache. + */ +async function installPackage(name, version, manager) { + const temp = (0, worker_1.tempPath)(name, version); + const tool = await (0, io_1.which)(manager); + await (0, io_1.mkdirP)(temp); + await (0, exec_1.exec)(tool, ['add', `${name}@${version}`], { cwd: temp }); + return (0, worker_1.cacheTool)(temp, name, version); +} +exports.installPackage = installPackage; /***/ }), -/***/ 5905: +/***/ 8912: /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.performAction = exports.handleError = exports.maybeWarnForUpdate = exports.maybePatchWatchers = exports.maybeAuthenticate = exports.getBinaryName = void 0; -const core = __importStar(__nccwpck_require__(2186)); -const cli = __importStar(__nccwpck_require__(1514)); -const semver_1 = __importDefault(__nccwpck_require__(1383)); -const packager_1 = __nccwpck_require__(6466); -/** - * Convert `expo-cli` or `eas-cli` to just their binary name. - * For windows we have to use `.cmd`, toolkit will handle the Windows binary with that. - */ -function getBinaryName(name, forWindows = false) { - const bin = name.toLowerCase().replace('-cli', ''); - return forWindows ? `${bin}.cmd` : bin; +exports.executeAction = exports.expoAuthenticate = exports.patchWatchers = exports.installToolFromPackage = exports.toolPath = exports.tempPath = exports.cacheTool = exports.findTool = void 0; +const core_1 = __nccwpck_require__(2186); +const exec_1 = __nccwpck_require__(1514); +const os_1 = __importDefault(__nccwpck_require__(2037)); +const path_1 = __importDefault(__nccwpck_require__(1017)); +var tool_cache_1 = __nccwpck_require__(7784); +Object.defineProperty(exports, "findTool", ({ enumerable: true, get: function () { return tool_cache_1.find; } })); +Object.defineProperty(exports, "cacheTool", ({ enumerable: true, get: function () { return tool_cache_1.cacheDir; } })); +function tempPath(name, version) { + const temp = process.env['RUNNER_TEMP'] || ''; + if (!temp) { + throw new Error(`Could not resolve temporary path, 'RUNNER_TEMP' not defined.`); + } + return path_1.default.join(temp, name, version, os_1.default.arch()); +} +exports.tempPath = tempPath; +function toolPath(name, version) { + const toolCache = process.env['RUNNER_TOOL_CACHE'] || ''; + if (!toolCache) { + throw new Error(`Could not resolve the local tool cache, 'RUNNER_TOOL_CACHE' not defined.`); + } + // https://github.com/actions/toolkit/blob/daf8bb00606d37ee2431d9b1596b88513dcf9c59/packages/tool-cache/src/tool-cache.ts#L747-L749 + return path_1.default.join(toolCache, name, version, os_1.default.arch()); } -exports.getBinaryName = getBinaryName; +exports.toolPath = toolPath; /** - * Authenticate with Expo using either the token or username/password method. - * If both of them are set, token has priority. + * Install a "tool" from a node package. + * This will add the folder, containing the `node_modules`, to the global path. */ -async function maybeAuthenticate(options = {}) { - if (options.token) { - if (options.cli) { - const bin = getBinaryName(options.cli, process.platform === 'win32'); - await cli.exec(bin, ['whoami'], { - env: { ...process.env, EXPO_TOKEN: options.token }, - }); - } - else { - core.info("Skipping token validation: no CLI installed, can't run `whoami`."); - } - return core.exportVariable('EXPO_TOKEN', options.token); - } - if (options.username || options.password) { - if (options.cli !== 'expo-cli') { - return core.warning('Skipping authentication: only Expo CLI supports programmatic credentials, use `token` instead.'); - } - if (!options.username || !options.password) { - return core.info('Skipping authentication: `username` and/or `password` not set...'); - } - const bin = getBinaryName(options.cli, process.platform === 'win32'); - await cli.exec(bin, ['login', `--username=${options.username}`], { - env: { ...process.env, EXPO_CLI_PASSWORD: options.password }, - }); - } - core.info('Skipping authentication: `token`, `username`, and/or `password` not set...'); +function installToolFromPackage(dir) { + return (0, core_1.addPath)(path_1.default.join(dir, 'node_modules', '.bin')); } -exports.maybeAuthenticate = maybeAuthenticate; +exports.installToolFromPackage = installToolFromPackage; /** - * Try to patch the default watcher/inotify limit. - * This is a limitation from GitHub Actions and might be an issue in some Expo projects. - * It sets the system's `fs.inotify` limits to a more sensible setting. + * Try to patch Linux's inotify limits to a more sensible setting on Linux. + * This limitation could cause `ENOSPC` errors when bundling Expo or React Native projects. + * + * It will try to change these `fs.inotify.` limits: + * - .max_user_instances = 524288 + * - .max_user_watches = 524288 + * - .max_queued_events = 524288 * * @see https://github.com/expo/expo-github-action/issues/20 */ -async function maybePatchWatchers() { +async function patchWatchers() { if (process.platform !== 'linux') { - return core.info('Skipping patch for watchers, not running on Linux...'); + return (0, core_1.info)('Skipped patching watchers: not running on Linux.'); } - core.info('Patching system watchers for the `ENOSPC` error...'); try { // see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177 - await cli.exec('sudo sysctl fs.inotify.max_user_instances=524288'); - await cli.exec('sudo sysctl fs.inotify.max_user_watches=524288'); - await cli.exec('sudo sysctl fs.inotify.max_queued_events=524288'); - await cli.exec('sudo sysctl -p'); - } - catch { - core.warning("Looks like we can't patch watchers/inotify limits, you might encouter the `ENOSPC` error."); - core.warning('For more info, https://github.com/expo/expo-github-action/issues/20'); + await (0, exec_1.exec)('sudo sysctl fs.inotify.max_user_instances=524288'); + await (0, exec_1.exec)('sudo sysctl fs.inotify.max_user_watches=524288'); + await (0, exec_1.exec)('sudo sysctl fs.inotify.max_queued_events=524288'); + await (0, exec_1.exec)('sudo sysctl -p'); + (0, core_1.info)('Patched system watchers for the `ENOSPC` error.'); } -} -exports.maybePatchWatchers = maybePatchWatchers; -/** - * Check if there is a new major version available. - * If there is, create a warning for people to upgrade their workflow. - * Because this introduces additional requests, it should only be executed when necessary. - */ -async function maybeWarnForUpdate(name) { - const binaryName = getBinaryName(name); - const latest = await (0, packager_1.resolveVersion)(name, 'latest'); - const current = await (0, packager_1.resolveVersion)(name, core.getInput(`${getBinaryName(name)}-version`) || 'latest'); - if (semver_1.default.diff(latest, current) === 'major') { - core.warning(`There is a new major version available of the Expo CLI (${latest})`); - core.warning(`If you run into issues, try upgrading your workflow to "${binaryName}-version: ${semver_1.default.major(latest)}.x"`); + catch (error) { + (0, core_1.warning)(`Looks like we can't patch watchers/inotify limits, you might encouter the 'ENOSPC' error.`); + (0, core_1.warning)('For more info: https://github.com/expo/expo-github-action/issues/20, encountered error:'); + (0, core_1.warning)(error.message); } } -exports.maybeWarnForUpdate = maybeWarnForUpdate; +exports.patchWatchers = patchWatchers; /** - * Handle errors when this action fails, providing useful next-steps for developers. - * This mostly checks if the installed version is the latest version. + * Try to authenticate the user using either Expo or EAS CLI. + * This method tries to invoke 'whoami' to validate if the token is valid. + * If that passes, the token is exported as EXPO_TOKEN for all steps within the job. */ -async function handleError(name, error) { - try { - await maybeWarnForUpdate(name); +async function expoAuthenticate(token, cli) { + if (!cli) { + (0, core_1.info)(`Skipped token validation: no CLI installed, can't run 'whoami'.`); } - catch { - // If this fails, ignore it + else { + await (0, exec_1.exec)('npx --no-install', [cli, 'whoami'], { + env: { ...process.env, EXPO_TOKEN: token }, + }); } - core.setFailed(error); + (0, core_1.exportVariable)('EXPO_TOKEN', token); } -exports.handleError = handleError; +exports.expoAuthenticate = expoAuthenticate; /** * Auto-execute the action if it's not running in a test environment. - * This is useful to test the action, without running it in tests. - * The method can also be mocked. + * This also propagate possible errors to GitHub actions, with setFailed. */ -function performAction(action) { +async function executeAction(action) { if (process.env.JEST_WORKER_ID) { return Promise.resolve(null); } - return action(); + return action().catch(core_1.setFailed); } -exports.performAction = performAction; +exports.executeAction = executeAction; /***/ }), @@ -68391,12 +65117,84 @@ module.exports = JSON.parse('["ac","com.ac","edu.ac","gov.ac","net.ac","mil.ac", /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ -/******/ -/******/ // startup -/******/ // Load entry module and return exports -/******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __nccwpck_require__(4190); -/******/ module.exports = __webpack_exports__; -/******/ +var __webpack_exports__ = {}; +// This entry need to be wrapped in an IIFE because it need to be in strict mode. +(() => { +"use strict"; +var exports = __webpack_exports__; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.setupAction = exports.setupInput = void 0; +const core_1 = __nccwpck_require__(2186); +const cacher_1 = __nccwpck_require__(331); +const packager_1 = __nccwpck_require__(6466); +const worker_1 = __nccwpck_require__(8912); +// Auto-execute in GitHub actions +(0, worker_1.executeAction)(setupAction); +function setupInput() { + return { + easCache: (0, core_1.getBooleanInput)('eas-cache'), + easVersion: (0, core_1.getInput)('eas-version'), + expoCache: (0, core_1.getBooleanInput)('expo-cache'), + expoVersion: (0, core_1.getInput)('expo-version'), + packager: (0, core_1.getInput)('packager') || 'yarn', + patchWatchers: !(0, core_1.getInput)('patch-watchers') || (0, core_1.getBooleanInput)('patch-watchers'), + token: (0, core_1.getInput)('token'), + }; +} +exports.setupInput = setupInput; +async function setupAction(input = setupInput()) { + if (!input.expoVersion) { + (0, core_1.info)(`Skipped installing expo-cli: 'expo-version' not provided.`); + } + else { + const version = await (0, packager_1.resolvePackage)('expo-cli', input.expoVersion); + const message = input.expoCache + ? `Installing expo-cli (${version}) from cache or with ${input.packager}` + : `Installing expo-cli (${version}) with ${input.packager}`; + await (0, core_1.group)(message, () => installCli('expo-cli', version, input.packager, input.expoCache)); + } + if (!input.easVersion) { + (0, core_1.info)(`Skipped installing eas-cli: 'eas-version' not provided.`); + } + else { + const version = await (0, packager_1.resolvePackage)('eas-cli', input.easVersion); + const message = input.easCache + ? `Installing eas-cli (${version}) from cache or with ${input.packager}` + : `Installing eas-cli (${version}) with ${input.packager}`; + await (0, core_1.group)(message, () => installCli('eas-cli', input.easVersion, input.packager, input.easCache)); + } + if (!input.token) { + (0, core_1.info)(`Skipped authentication: 'token' not provided.`); + } + else { + await (0, core_1.group)('Validating authenticated account', () => (0, worker_1.expoAuthenticate)(input.token, input.easVersion ? 'eas' : input.expoVersion ? 'expo' : undefined)); + } + if (!input.patchWatchers) { + (0, core_1.info)(`Skipped patching watchers: 'patch-watchers' disabled.`); + } + else { + await (0, core_1.group)(`Patching system watchers for the 'ENOSPC' error`, worker_1.patchWatchers); + } +} +exports.setupAction = setupAction; +async function installCli(name, version, packager, cache = true) { + const cliVersion = await (0, packager_1.resolvePackage)(name, version); + let cliPath = (0, worker_1.findTool)(name, cliVersion) || undefined; + if (!cliPath && cache) { + cliPath = await (0, cacher_1.restoreFromCache)(name, cliVersion, packager); + } + if (!cliPath) { + cliPath = await (0, packager_1.installPackage)(name, cliVersion, packager); + if (cache) { + await (0, cacher_1.saveToCache)(name, cliVersion, packager); + } + } + (0, worker_1.installToolFromPackage)(cliPath); +} + +})(); + +module.exports = __webpack_exports__; /******/ })() ; \ No newline at end of file diff --git a/build/setup/license.txt b/build/setup/license.txt index a68248d0..bd8ae2a4 100644 --- a/build/setup/license.txt +++ b/build/setup/license.txt @@ -736,25 +736,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -lru-cache -ISC -The ISC License - -Copyright (c) Isaac Z. Schlueter and Contributors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - - mime-db MIT @@ -1106,22 +1087,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -yallist -ISC -The ISC License - -Copyright (c) Isaac Z. Schlueter and Contributors - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/package.json b/package.json index 67c8646a..6f594e84 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "@actions/core": "^1.6.0", "@actions/exec": "^1.1.0", "@actions/io": "^1.1.1", - "@actions/tool-cache": "^1.7.1", - "semver": "^7.3.5" + "@actions/tool-cache": "^1.7.1" }, "devDependencies": { "@semantic-release/changelog": "^6.0.1", @@ -34,7 +33,6 @@ "@tsconfig/node16": "^1.0.2", "@types/jest": "^27.4.0", "@types/node": "^16.11.19", - "@types/semver": "^7.3.9", "@typescript-eslint/eslint-plugin": "^5.9.1", "@typescript-eslint/parser": "^5.9.1", "@vercel/ncc": "^0.33.1", diff --git a/src/actions/setup.ts b/src/actions/setup.ts index 2c66f816..dd00c54d 100644 --- a/src/actions/setup.ts +++ b/src/actions/setup.ts @@ -1,61 +1,79 @@ -import { addPath, getBooleanInput, getInput, group, info } from '@actions/core'; +import { getBooleanInput, getInput, group, info } from '@actions/core'; -import { install } from '../install'; -import { resolveVersion } from '../packager'; -import * as tools from '../tools'; +import { restoreFromCache, saveToCache } from '../cacher'; +import { installPackage, resolvePackage } from '../packager'; +import { executeAction, expoAuthenticate, findTool, installToolFromPackage, patchWatchers } from '../worker'; // Auto-execute in GitHub actions -tools.performAction(setupAction); - -export async function setupAction(): Promise { - const expoVersion = await installCli('expo-cli'); - const easVersion = await installCli('eas-cli'); - - await group('Checking current authenticated account', () => - tools.maybeAuthenticate({ - cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined, - token: getInput('token') || undefined, - username: getInput('username') || undefined, - password: getInput('password') || undefined, - }) - ); - - if (!getInput('patch-watchers') || getBooleanInput('patch-watchers') !== false) { - await group('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers()); - } +executeAction(setupAction); + +export type SetupInput = ReturnType; + +export function setupInput() { + return { + easCache: getBooleanInput('eas-cache'), + easVersion: getInput('eas-version'), + expoCache: getBooleanInput('expo-cache'), + expoVersion: getInput('expo-version'), + packager: getInput('packager') || 'yarn', + patchWatchers: !getInput('patch-watchers') || getBooleanInput('patch-watchers'), + token: getInput('token'), + }; } -async function installCli(name: tools.PackageName): Promise { - const shortName = tools.getBinaryName(name); - const inputVersion = getInput(`${shortName}-version`); - const packager = getInput('packager') || 'yarn'; +export async function setupAction(input: SetupInput = setupInput()): Promise { + if (!input.expoVersion) { + info(`Skipped installing expo-cli: 'expo-version' not provided.`); + } else { + const version = await resolvePackage('expo-cli', input.expoVersion); + const message = input.expoCache + ? `Installing expo-cli (${version}) from cache or with ${input.packager}` + : `Installing expo-cli (${version}) with ${input.packager}`; - if (!inputVersion) { - return info(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`); + await group(message, () => installCli('expo-cli', version, input.packager, input.expoCache)); } - const version = await resolveVersion(name, inputVersion); - const cache = getBooleanInput(`${shortName}-cache`); - - try { - const path = await group( - cache - ? `Installing ${name} (${version}) from cache or with ${packager}` - : `Installing ${name} (${version}) with ${packager}`, - () => - install({ - packager, - version, - cache, - package: name, - cacheKey: getInput(`${shortName}-cache-key`) || undefined, - }) + if (!input.easVersion) { + info(`Skipped installing eas-cli: 'eas-version' not provided.`); + } else { + const version = await resolvePackage('eas-cli', input.easVersion); + const message = input.easCache + ? `Installing eas-cli (${version}) from cache or with ${input.packager}` + : `Installing eas-cli (${version}) with ${input.packager}`; + + await group(message, () => installCli('eas-cli', input.easVersion, input.packager, input.easCache)); + } + + if (!input.token) { + info(`Skipped authentication: 'token' not provided.`); + } else { + await group('Validating authenticated account', () => + expoAuthenticate(input.token, input.easVersion ? 'eas' : input.expoVersion ? 'expo' : undefined) ); + } + + if (!input.patchWatchers) { + info(`Skipped patching watchers: 'patch-watchers' disabled.`); + } else { + await group(`Patching system watchers for the 'ENOSPC' error`, patchWatchers); + } +} + +async function installCli(name: string, version: string, packager: string, cache: boolean = true) { + const cliVersion = await resolvePackage(name, version); + let cliPath = findTool(name, cliVersion) || undefined; + + if (!cliPath && cache) { + cliPath = await restoreFromCache(name, cliVersion, packager); + } + + if (!cliPath) { + cliPath = await installPackage(name, cliVersion, packager); - addPath(path); - } catch (error) { - tools.handleError(name, error); + if (cache) { + await saveToCache(name, cliVersion, packager); + } } - return version; + installToolFromPackage(cliPath); } diff --git a/src/cache.ts b/src/cache.ts deleted file mode 100644 index c0a32b98..00000000 --- a/src/cache.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { ReserveCacheError, restoreCache, saveCache } from '@actions/cache'; -import * as core from '@actions/core'; -import * as toolCache from '@actions/tool-cache'; -import os from 'os'; -import path from 'path'; - -import type { InstallConfig } from './install'; - -export type CacheConfig = Omit; - -/** - * Get the path to the `expo-cli` from cache, if any. - * Note, this cache is **NOT** shared between jobs. - * - * @see https://github.com/actions/toolkit/issues/47 - */ -export async function fromLocalCache(config: CacheConfig): Promise { - return toolCache.find(config.package, config.version); -} - -/** - * Store the root of `expo-cli` in the cache, for future reuse. - * Note, this cache is **NOT** shared between jobs. - * - * @see https://github.com/actions/toolkit/issues/47 - */ -export async function toLocalCache(root: string, config: CacheConfig): Promise { - return toolCache.cacheDir(root, config.package, config.version); -} - -/** - * Download the remotely stored `expo-cli` from cache, if any. - * Note, this cache is shared between jobs. - */ -export async function fromRemoteCache(config: CacheConfig): Promise { - // see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401 - const target = path.join(process.env['RUNNER_TOOL_CACHE'] || '', config.package, config.version, os.arch()); - const cacheKey = config.cacheKey || getRemoteKey(config); - - try { - // When running with nektos/act, or other custom environments, the cache might not be set up. - const hit = await restoreCache([target], cacheKey); - if (hit) { - return target; - } - } catch (error) { - if (!handleRemoteCacheError(error)) { - throw error; - } - } -} - -/** - * Store the root of `expo-cli` in the remote cache, for future reuse. - * Note, this cache is shared between jobs. - */ -export async function toRemoteCache(source: string, config: CacheConfig): Promise { - const cacheKey = config.cacheKey || getRemoteKey(config); - - try { - await saveCache([source], cacheKey); - } catch (error) { - if (!handleRemoteCacheError(error)) { - throw error; - } - } -} - -/** - * Get the cache key to use when (re)storing the Expo CLI from remote cache. - */ -function getRemoteKey(config: Omit): string { - return `${config.package}-${process.platform}-${os.arch()}-${config.packager}-${config.version}`; -} - -/** - * Handle any incoming errors from cache methods. - * This can include actual errors like `ReserveCacheErrors` or unavailability errors. - * When the error is handled, it MUST provide feedback for the developer. - * - * @returns If the error was handled properly. - */ -function handleRemoteCacheError(error: Error): boolean { - const isReserveCacheError = error instanceof ReserveCacheError; - const isCacheUnavailable = error.message.toLowerCase().includes('cache service url not found'); - - if (isReserveCacheError || isCacheUnavailable) { - core.warning('Skipping remote cache storage, encountered error:'); - core.warning(error.message); - return true; - } - - return false; -} diff --git a/src/cacher.ts b/src/cacher.ts new file mode 100644 index 00000000..4bb44377 --- /dev/null +++ b/src/cacher.ts @@ -0,0 +1,61 @@ +import { saveCache, restoreCache, ReserveCacheError } from '@actions/cache'; +import { warning } from '@actions/core'; +import os from 'os'; + +import { toolPath } from './worker'; + +/** + * Get the exact cache key for the package. + * We can prefix this when there are breaking changes in this action. + */ +export function cacheKey(name: string, version: string, manager: string): string { + return `${name}-${process.platform}-${os.arch()}-${manager}-${version}`; +} + +/** + * Restore a tool from the remote cache. + * This will install the tool back into the local tool cache. + */ +export async function restoreFromCache(name: string, version: string, manager: string) { + const dir = toolPath(name, version)!; + try { + if (await restoreCache([dir], cacheKey(name, version, manager))) { + return dir; + } + } catch (error) { + handleCacheError(error); + } +} + +/** + * Save a tool to the remote cache. + * This will fetch the tool from the local tool cache. + */ +export async function saveToCache(name: string, version: string, manager: string) { + try { + await saveCache([toolPath(name, version)], cacheKey(name, version, manager)); + } catch (error) { + handleCacheError(error); + } +} + +/** + * Try to handle incoming cache errors. + * Because workers can operate in environments without cache configured, + * we need to make sure to only skip the cache instead of fail. + * + * Currently we handle these types of errors: + * - ReserveCacheError + * - "cache service url not found" + */ +export function handleCacheError(error: Error): void { + const isReserveCacheError = error instanceof ReserveCacheError; + const isCacheUnavailable = error.message.toLowerCase().includes('cache service url not found'); + + if (isReserveCacheError || isCacheUnavailable) { + warning('Skipped remote cache, encountered error:'); + warning(error.message); + } else { + throw error; + } +} diff --git a/src/install.ts b/src/install.ts deleted file mode 100644 index 8d9a93e1..00000000 --- a/src/install.ts +++ /dev/null @@ -1,60 +0,0 @@ -import * as core from '@actions/core'; -import * as cli from '@actions/exec'; -import * as io from '@actions/io'; -import * as path from 'path'; - -import { fromLocalCache, fromRemoteCache, toLocalCache, toRemoteCache } from './cache'; -import { PackageName } from './tools'; - -export type InstallConfig = { - /** The exact version to install */ - version: string; - /** The name of the package to install */ - package: PackageName; - /** The packager to install with, likely to be `yarn` or `npm` */ - packager: string; - /** If remote caching is enabled or not */ - cache?: boolean; - /** The custom remote cache key */ - cacheKey?: string; -}; - -/** - * Install `expo-cli`, by version, using the packager. - * Here you can provide any semver range or dist tag used in the registry. - * It returns the path where Expo is installed. - */ -export async function install(config: InstallConfig): Promise { - let root: string | undefined = await fromLocalCache(config); - - if (!root && config.cache) { - root = await fromRemoteCache(config); - } else { - core.info('Skipping remote cache, not enabled...'); - } - - if (!root) { - root = await fromPackager(config); - root = await toLocalCache(root, config); - - if (config.cache) { - await toRemoteCache(root, config); - } - } - - return path.join(root, 'node_modules', '.bin'); -} - -/** - * Install `expo-cli`, by version, using npm or yarn. - * It creates a temporary directory to store all required files. - */ -export async function fromPackager(config: InstallConfig): Promise { - const root = process.env['RUNNER_TEMP'] || ''; - const tool = await io.which(config.packager); - - await io.mkdirP(root); - await cli.exec(tool, ['add', `${config.package}@${config.version}`], { cwd: root }); - - return root; -} diff --git a/src/packager.ts b/src/packager.ts index 951512a2..7c265ffa 100644 --- a/src/packager.ts +++ b/src/packager.ts @@ -1,11 +1,14 @@ import { exec } from '@actions/exec'; +import { which, mkdirP } from '@actions/io'; + +import { cacheTool, tempPath } from './worker'; /** * Resolve a package with version range to an exact version. * This is useful to invalidate the cache _and_ using dist-tags or version ranges. * It executes `npm info` and parses the latest manifest. */ -export async function resolveVersion(name: string, range: string): Promise { +export async function resolvePackage(name: string, range: string): Promise { let stdout = ''; try { @@ -18,7 +21,7 @@ export async function resolveVersion(name: string, range: string): Promise.cmd`, toolkit will handle the Windows binary with that. - */ -export function getBinaryName(name: PackageName, forWindows = false): string { - const bin = name.toLowerCase().replace('-cli', ''); - return forWindows ? `${bin}.cmd` : bin; -} - -/** - * Authenticate with Expo using either the token or username/password method. - * If both of them are set, token has priority. - */ -export async function maybeAuthenticate(options: AuthenticateOptions = {}): Promise { - if (options.token) { - if (options.cli) { - const bin = getBinaryName(options.cli, process.platform === 'win32'); - await cli.exec(bin, ['whoami'], { - env: { ...process.env, EXPO_TOKEN: options.token }, - }); - } else { - core.info("Skipping token validation: no CLI installed, can't run `whoami`."); - } - - return core.exportVariable('EXPO_TOKEN', options.token); - } - - if (options.username || options.password) { - if (options.cli !== 'expo-cli') { - return core.warning( - 'Skipping authentication: only Expo CLI supports programmatic credentials, use `token` instead.' - ); - } - - if (!options.username || !options.password) { - return core.info('Skipping authentication: `username` and/or `password` not set...'); - } - - const bin = getBinaryName(options.cli, process.platform === 'win32'); - await cli.exec(bin, ['login', `--username=${options.username}`], { - env: { ...process.env, EXPO_CLI_PASSWORD: options.password }, - }); - } - - core.info('Skipping authentication: `token`, `username`, and/or `password` not set...'); -} - -/** - * Try to patch the default watcher/inotify limit. - * This is a limitation from GitHub Actions and might be an issue in some Expo projects. - * It sets the system's `fs.inotify` limits to a more sensible setting. - * - * @see https://github.com/expo/expo-github-action/issues/20 - */ -export async function maybePatchWatchers(): Promise { - if (process.platform !== 'linux') { - return core.info('Skipping patch for watchers, not running on Linux...'); - } - - core.info('Patching system watchers for the `ENOSPC` error...'); - - try { - // see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177 - await cli.exec('sudo sysctl fs.inotify.max_user_instances=524288'); - await cli.exec('sudo sysctl fs.inotify.max_user_watches=524288'); - await cli.exec('sudo sysctl fs.inotify.max_queued_events=524288'); - await cli.exec('sudo sysctl -p'); - } catch { - core.warning("Looks like we can't patch watchers/inotify limits, you might encouter the `ENOSPC` error."); - core.warning('For more info, https://github.com/expo/expo-github-action/issues/20'); - } -} - -/** - * Check if there is a new major version available. - * If there is, create a warning for people to upgrade their workflow. - * Because this introduces additional requests, it should only be executed when necessary. - */ -export async function maybeWarnForUpdate(name: PackageName): Promise { - const binaryName = getBinaryName(name); - const latest = await resolveVersion(name, 'latest'); - const current = await resolveVersion(name, core.getInput(`${getBinaryName(name)}-version`) || 'latest'); - - if (semver.diff(latest, current) === 'major') { - core.warning(`There is a new major version available of the Expo CLI (${latest})`); - core.warning( - `If you run into issues, try upgrading your workflow to "${binaryName}-version: ${semver.major(latest)}.x"` - ); - } -} - -/** - * Handle errors when this action fails, providing useful next-steps for developers. - * This mostly checks if the installed version is the latest version. - */ -export async function handleError(name: PackageName, error: Error) { - try { - await maybeWarnForUpdate(name); - } catch { - // If this fails, ignore it - } - - core.setFailed(error); -} - -/** - * Auto-execute the action if it's not running in a test environment. - * This is useful to test the action, without running it in tests. - * The method can also be mocked. - */ -export function performAction(action: () => Promise) { - if (process.env.JEST_WORKER_ID) { - return Promise.resolve(null); - } - - return action(); -} diff --git a/src/worker.ts b/src/worker.ts new file mode 100644 index 00000000..23a22bc4 --- /dev/null +++ b/src/worker.ts @@ -0,0 +1,92 @@ +import { addPath, exportVariable, info, setFailed, warning } from '@actions/core'; +import { exec } from '@actions/exec'; +import os from 'os'; +import path from 'path'; + +export { find as findTool, cacheDir as cacheTool } from '@actions/tool-cache'; + +export function tempPath(name: string, version: string): string { + const temp = process.env['RUNNER_TEMP'] || ''; + if (!temp) { + throw new Error(`Could not resolve temporary path, 'RUNNER_TEMP' not defined.`); + } + + return path.join(temp, name, version, os.arch()); +} + +export function toolPath(name: string, version: string): string { + const toolCache = process.env['RUNNER_TOOL_CACHE'] || ''; + if (!toolCache) { + throw new Error(`Could not resolve the local tool cache, 'RUNNER_TOOL_CACHE' not defined.`); + } + + // https://github.com/actions/toolkit/blob/daf8bb00606d37ee2431d9b1596b88513dcf9c59/packages/tool-cache/src/tool-cache.ts#L747-L749 + return path.join(toolCache, name, version, os.arch()); +} + +/** + * Install a "tool" from a node package. + * This will add the folder, containing the `node_modules`, to the global path. + */ +export function installToolFromPackage(dir: string) { + return addPath(path.join(dir, 'node_modules', '.bin')); +} + +/** + * Try to patch Linux's inotify limits to a more sensible setting on Linux. + * This limitation could cause `ENOSPC` errors when bundling Expo or React Native projects. + * + * It will try to change these `fs.inotify.` limits: + * - .max_user_instances = 524288 + * - .max_user_watches = 524288 + * - .max_queued_events = 524288 + * + * @see https://github.com/expo/expo-github-action/issues/20 + */ +export async function patchWatchers(): Promise { + if (process.platform !== 'linux') { + return info('Skipped patching watchers: not running on Linux.'); + } + + try { + // see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177 + await exec('sudo sysctl fs.inotify.max_user_instances=524288'); + await exec('sudo sysctl fs.inotify.max_user_watches=524288'); + await exec('sudo sysctl fs.inotify.max_queued_events=524288'); + await exec('sudo sysctl -p'); + info('Patched system watchers for the `ENOSPC` error.'); + } catch (error) { + warning(`Looks like we can't patch watchers/inotify limits, you might encouter the 'ENOSPC' error.`); + warning('For more info: https://github.com/expo/expo-github-action/issues/20, encountered error:'); + warning(error.message); + } +} + +/** + * Try to authenticate the user using either Expo or EAS CLI. + * This method tries to invoke 'whoami' to validate if the token is valid. + * If that passes, the token is exported as EXPO_TOKEN for all steps within the job. + */ +export async function expoAuthenticate(token: string, cli?: 'expo' | 'eas'): Promise { + if (!cli) { + info(`Skipped token validation: no CLI installed, can't run 'whoami'.`); + } else { + await exec('npx --no-install', [cli, 'whoami'], { + env: { ...process.env, EXPO_TOKEN: token }, + }); + } + + exportVariable('EXPO_TOKEN', token); +} + +/** + * Auto-execute the action if it's not running in a test environment. + * This also propagate possible errors to GitHub actions, with setFailed. + */ +export async function executeAction(action: () => Promise) { + if (process.env.JEST_WORKER_ID) { + return Promise.resolve(null); + } + + return action().catch(setFailed); +} diff --git a/tests/actions/setup.test.ts b/tests/actions/setup.test.ts index bca912f9..329bbccd 100644 --- a/tests/actions/setup.test.ts +++ b/tests/actions/setup.test.ts @@ -1,133 +1,108 @@ -/* eslint-disable import/order,import/first */ -import { getToolsMock, mockInput } from '../utils'; +import * as core from '@actions/core'; -jest.mock('../../src/tools', () => getToolsMock()); -jest.mock('../../src/packager', () => ({ - async resolveVersion(_: string, version: string) { - return version; - }, -})); +import { SetupInput, setupInput, setupAction } from '../../src/actions/setup'; +import * as cacher from '../../src/cacher'; +import * as packager from '../../src/packager'; +import * as worker from '../../src/worker'; +import { mockInput } from '../utils'; + +jest.mock('@actions/core'); +jest.mock('../../src/cacher'); +jest.mock('../../src/packager'); +jest.mock('../../src/worker'); + +describe(setupInput, () => { + it('returns object with correct defaults', () => { + expect(setupInput()).toMatchObject({ + easCache: undefined, + easVersion: undefined, + expoCache: undefined, + expoVersion: undefined, + packager: 'yarn', + patchWatchers: true, + token: undefined, + }); + }); -import * as core from '@actions/core'; + it('returns expo version and cache', () => { + mockInput({ 'expo-version': '5.x', 'expo-cache': 'true' }); + expect(setupInput()).toMatchObject({ expoVersion: '5.x', expoCache: true }); + }); -import * as install from '../../src/install'; -import * as tools from '../../src/tools'; -import { setupAction } from '../../src/actions/setup'; + it('returns eas version and cache', () => { + mockInput({ 'eas-version': 'latest', 'eas-cache': 'true' }); + expect(setupInput()).toMatchObject({ easVersion: 'latest', easCache: true }); + }); -describe(setupAction, () => { - describe('patch watchers', () => { - it('patches the system when set to true', async () => { - mockInput({ 'patch-watchers': 'true' }); - await setupAction(); - expect(tools.maybePatchWatchers).toHaveBeenCalled(); - }); + it('returns different packager', () => { + mockInput({ packager: 'npm' }); + expect(setupInput()).toMatchObject({ packager: 'npm' }); + }); - it('patches the system when not set', async () => { - mockInput({ 'patch-watchers': '' }); - await setupAction(); - expect(tools.maybePatchWatchers).toHaveBeenCalled(); - }); + it('returns disabled patch watchers', () => { + mockInput({ 'patch-watchers': 'false' }); + expect(setupInput()).toMatchObject({ patchWatchers: false }); + }); - it('skips the system patch when set to false', async () => { - mockInput({ 'patch-watchers': 'false' }); - await setupAction(); - expect(tools.maybePatchWatchers).not.toHaveBeenCalled(); - }); + it('returns token', () => { + mockInput({ token: 'faketoken' }); + expect(setupInput()).toMatchObject({ token: 'faketoken' }); }); +}); + +describe(setupAction, () => { + const input: SetupInput = { + easCache: false, + easVersion: '', + expoCache: false, + expoVersion: '', + packager: 'yarn', + patchWatchers: true, + token: '', + }; + + beforeAll(() => { + jest.mocked(core.group).mockImplementation((_, action) => action()); + }); + + ['expo', 'eas'].forEach(cli => { + const cliName = `${cli}-cli`; + const cliVersion = `${cli}Version`; + const cliCache = `${cli}Cache`; - describe('authentication', () => { - it('authenticates with provided credentials', async () => { - mockInput({ username: 'bycedric', password: 'mypassword' }); - await setupAction(); - expect(tools.maybeAuthenticate).toBeCalledWith({ username: 'bycedric', password: 'mypassword' }); + it(`installs ${cliName} using npm`, async () => { + jest.mocked(packager.resolvePackage).mockResolvedValue('5.0.3'); + await setupAction({ ...input, [cliVersion]: '5.x', packager: 'npm' }); + expect(packager.installPackage).toBeCalledWith(cliName, '5.0.3', 'npm'); + expect(worker.installToolFromPackage).toBeCalled(); }); - it('authenticates with provided token', async () => { - mockInput({ token: 'ABC123' }); - await setupAction(); - expect(tools.maybeAuthenticate).toBeCalledWith({ token: 'ABC123' }); + it(`installs ${cliName} from cache`, async () => { + jest.mocked(packager.resolvePackage).mockResolvedValue('5.0.3'); + jest.mocked(cacher.restoreFromCache).mockResolvedValue('fake/path'); + await setupAction({ ...input, [cliVersion]: 'latest', [cliCache]: true }); + expect(packager.installPackage).not.toBeCalled(); + expect(worker.installToolFromPackage).toBeCalledWith('fake/path'); }); }); - ['expo', 'eas'].forEach(cliName => { - const packageName = `${cliName}-cli`; - let installMock: jest.SpyInstance; + it('authenticates token with eas-cli by default', async () => { + await setupAction({ ...input, expoVersion: 'latest', easVersion: 'latest', token: 'faketoken' }); + expect(worker.expoAuthenticate).toBeCalledWith('faketoken', 'eas'); + }); - beforeEach(() => { - installMock = jest.spyOn(install, 'install').mockImplementation(); - }); + it('authenticates token with expo-cli without eas-cli', async () => { + await setupAction({ ...input, expoVersion: 'latest', token: 'faketoken' }); + expect(worker.expoAuthenticate).toBeCalledWith('faketoken', 'expo'); + }); - afterEach(() => { - installMock.mockRestore(); - }); + it('authenticates token without any cli', async () => { + await setupAction({ ...input, token: 'faketoken' }); + expect(worker.expoAuthenticate).toBeCalledWith('faketoken', undefined); + }); - describe(packageName, () => { - it(`skips installation without \`${cliName}-version\``, async () => { - mockInput(); - await setupAction(); - expect(installMock).not.toBeCalledWith({ package: packageName }); - }); - - it('installs with yarn by default', async () => { - mockInput({ [`${cliName}-version`]: 'latest' }); - await setupAction(); - expect(installMock).toBeCalledWith({ - package: packageName, - version: 'latest', - packager: 'yarn', - cache: false, - }); - }); - - it('installs provided version with npm', async () => { - mockInput({ [`${cliName}-version`]: '3.0.10', packager: 'npm' }); - await setupAction(); - expect(installMock).toBeCalledWith({ - package: packageName, - version: '3.0.10', - packager: 'npm', - cache: false, - }); - }); - - it('installs with yarn and cache enabled', async () => { - mockInput({ - packager: 'yarn', - [`${cliName}-version`]: '4.2.0', - [`${cliName}-cache`]: 'true', - }); - await setupAction(); - expect(installMock).toBeCalledWith({ - package: packageName, - version: '4.2.0', - packager: 'yarn', - cache: true, - }); - }); - - it('installs with yarn and custom cache key', async () => { - mockInput({ - packager: 'yarn', - [`${cliName}-version`]: '4.2.0', - [`${cliName}-cache`]: 'true', - [`${cliName}-cache-key`]: 'custom-key', - }); - await setupAction(); - expect(installMock).toBeCalledWith({ - package: packageName, - version: '4.2.0', - packager: 'yarn', - cache: true, - cacheKey: 'custom-key', - }); - }); - - it('installs path to global path', async () => { - installMock.mockResolvedValue(`/${cliName}/install/path`); - const addPathSpy = jest.spyOn(core, 'addPath').mockImplementation(); - await setupAction(); - expect(addPathSpy).toBeCalledWith(`/${cliName}/install/path`); - }); - }); + it('patches watchers', async () => { + await setupAction({ ...input, patchWatchers: true }); + expect(worker.patchWatchers).toBeCalled(); }); }); diff --git a/tests/cache.test.ts b/tests/cache.test.ts deleted file mode 100644 index cd8ecd88..00000000 --- a/tests/cache.test.ts +++ /dev/null @@ -1,153 +0,0 @@ -import * as remoteCache from '@actions/cache'; -import * as core from '@actions/core'; -import * as toolCache from '@actions/tool-cache'; -import os from 'os'; -import { join } from 'path'; - -import * as cache from '../src/cache'; -import * as utils from './utils'; - -describe(cache.fromLocalCache, () => { - it('fetches the version specific cache', async () => { - const path = join('path', 'to', 'local', 'cache'); - // todo: check why jest wants `never` instead of `string` - const find = jest.spyOn(toolCache, 'find').mockResolvedValue(path as never); - const result = await cache.fromLocalCache({ package: 'eas-cli', version: '4.2.0', packager: 'npm' }); - expect(result).toBe(path); - expect(find).toBeCalledWith('eas-cli', '4.2.0'); - }); -}); - -describe(cache.toLocalCache, () => { - it('stores the version specific cache', async () => { - const path = join('path', 'to', 'local', 'cache'); - const root = join('path', 'from', 'source'); - const cacheDir = jest.spyOn(toolCache, 'cacheDir').mockResolvedValue(path); - const result = await cache.toLocalCache(root, { package: 'expo-cli', version: '4.2.0', packager: 'yarn' }); - expect(result).toBe(path); - expect(cacheDir).toBeCalledWith(root, 'expo-cli', '4.2.0'); - }); -}); - -describe(cache.fromRemoteCache, () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(), - warning: jest.spyOn(core, 'warning').mockImplementation(), - }; - }); - - beforeAll(() => { - utils.setEnv('RUNNER_TOOL_CACHE', join('cache', 'path')); - }); - - afterAll(() => { - utils.restoreEnv(); - spy.restore.mockRestore(); - spy.warning.mockRestore(); - }); - - it('restores remote cache with default key', async () => { - expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: 'yarn' })).toBeUndefined(); - expect(remoteCache.restoreCache).toBeCalledWith( - [join('cache', 'path', 'expo-cli', '3.20.1', os.arch())], - `expo-cli-${process.platform}-${os.arch()}-yarn-3.20.1` - ); - }); - - it('restores remote cache with custom key', async () => { - expect( - await cache.fromRemoteCache({ - package: 'eas-cli', - version: '4.2.0', - packager: 'yarn', - cacheKey: 'custom-cache-key', - }) - ).toBeUndefined(); - expect(remoteCache.restoreCache).toBeCalledWith( - [join('cache', 'path', 'eas-cli', '4.2.0', os.arch())], - 'custom-cache-key' - ); - }); - - it('returns path when remote cache exists', async () => { - spy.restore.mockResolvedValueOnce(true); - expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: 'npm' })).toBe( - join('cache', 'path', 'expo-cli', '3.20.1', os.arch()) - ); - }); - - it('fails when remote cache throws', async () => { - const error = new Error('Remote cache restore failed'); - spy.restore.mockRejectedValueOnce(error); - await expect(cache.fromRemoteCache({ package: 'eas-cli', version: '3.20.1', packager: 'yarn' })).rejects.toBe( - error - ); - }); - - it('skips remote cache when unavailable', async () => { - // see: https://github.com/actions/toolkit/blob/9167ce1f3a32ad495fc1dbcb574c03c0e013ae53/packages/cache/src/internal/cacheHttpClient.ts#L41 - const error = new Error('Cache Service Url not found, unable to restore cache.'); - spy.restore.mockRejectedValueOnce(error); - expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: 'yarn' })).toBeUndefined(); - expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache')); - }); -}); - -describe(cache.toRemoteCache, () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(), - warning: jest.spyOn(core, 'warning').mockImplementation(), - }; - }); - - afterAll(() => { - spy.save.mockRestore(); - spy.warning.mockRestore(); - }); - - it('saves remote cache with default key', async () => { - expect( - await cache.toRemoteCache(join('local', 'path'), { package: 'eas-cli', version: '3.20.1', packager: 'npm' }) - ).toBeUndefined(); - expect(remoteCache.saveCache).toBeCalledWith( - [join('local', 'path')], - `eas-cli-${process.platform}-${os.arch()}-npm-3.20.1` - ); - }); - - it('saves remote cache with custom key', async () => { - expect( - await cache.toRemoteCache(join('local', 'path'), { - package: 'eas-cli', - version: '3.20.1', - packager: 'yarn', - cacheKey: 'custom-cache-key', - }) - ).toBeUndefined(); - expect(remoteCache.saveCache).toBeCalledWith([join('local', 'path')], 'custom-cache-key'); - }); - - it('fails when remote cache throws', async () => { - const error = new Error('Remote cache save failed'); - spy.save.mockRejectedValueOnce(error); - await expect( - cache.toRemoteCache(join('local', 'path'), { package: 'expo-cli', version: '3.20.1', packager: 'yarn' }) - ).rejects.toBe(error); - }); - - it('skips remote cache when unavailable', async () => { - // see: https://github.com/actions/toolkit/blob/9167ce1f3a32ad495fc1dbcb574c03c0e013ae53/packages/cache/src/internal/cacheHttpClient.ts#L41 - const error = new Error('Cache Service Url not found, unable to restore cache.'); - spy.save.mockRejectedValueOnce(error); - await expect( - cache.toRemoteCache(join('local', 'path'), { package: 'expo-cli', version: '3.20.1', packager: 'yarn' }) - ).resolves.toBeUndefined(); - expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache')); - }); -}); diff --git a/tests/cacher.test.ts b/tests/cacher.test.ts new file mode 100644 index 00000000..025c3fce --- /dev/null +++ b/tests/cacher.test.ts @@ -0,0 +1,70 @@ +import * as cache from '@actions/cache'; +import os from 'os'; + +import { cacheKey, restoreFromCache, saveToCache } from '../src/cacher'; +import { toolPath } from '../src/worker'; +import { resetEnv, setEnv } from './utils'; + +jest.mock('@actions/cache'); +jest.mock('@actions/core'); + +beforeAll(() => { + setEnv('RUNNER_TOOL_CACHE', os.tmpdir()); +}); + +afterAll(resetEnv); + +describe(cacheKey, () => { + it('returns contains package name, version, and manager', () => { + expect(cacheKey('expo-cli', '5.0.3', 'yarn')).toMatch('expo-cli'); + expect(cacheKey('expo-cli', '5.0.3', 'yarn')).toMatch('5.0.3'); + expect(cacheKey('eas-cli', '5.0.3', 'npm')).toMatch('npm'); + }); + + it('contains the os arch type', () => { + expect(cacheKey('eas-cli', '5.0.3', 'yarn')).toMatch(os.arch()); + }); + + it('contains the platform type', () => { + expect(cacheKey('eas-cli', '5.0.3', 'yarn')).toMatch(process.platform); + }); +}); + +describe(restoreFromCache, () => { + it('skips when cache is unavailable', async () => { + jest.mocked(cache.restoreCache).mockRejectedValue(new Error('Cache service url not found')); + await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined(); + }); + + it('throws when cache has unexpected error', async () => { + jest.mocked(cache.restoreCache).mockRejectedValue(new Error('Node registry is down')); + await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).rejects.toThrow('Node registry is down'); + }); + + it('returns expo-cli path from cache when available', async () => { + jest.mocked(cache.restoreCache).mockResolvedValue('fake/path'); + await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).resolves.toBe(toolPath('expo-cli', '5.0.3')); + }); + + it('returns nothing when cache is empty', async () => { + jest.mocked(cache.restoreCache).mockResolvedValue(undefined); + await expect(restoreFromCache('eas-cli', '0.46.2', 'npm')).resolves.toBeUndefined(); + }); +}); + +describe(saveToCache, () => { + it('skips when cache is unavailable', async () => { + jest.mocked(cache.saveCache).mockRejectedValue(new Error('Cache service url not found')); + await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined(); + }); + + it('throws when cache has unexpected error', async () => { + jest.mocked(cache.saveCache).mockRejectedValue(new Error('Node registry is down')); + await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).rejects.toThrow('Node registry is down'); + }); + + it('saves expo-cli to cache when available', async () => { + jest.mocked(cache.saveCache).mockResolvedValue(1337); + await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined(); + }); +}); diff --git a/tests/install.test.ts b/tests/install.test.ts deleted file mode 100644 index 51f75b4b..00000000 --- a/tests/install.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* eslint-disable import/order,import/first */ -const cli = { exec: jest.fn() }; -const io = { mkdirP: jest.fn(), which: jest.fn() }; -const cache = { - fromLocalCache: jest.fn(), - fromRemoteCache: jest.fn(), - toLocalCache: jest.fn(), - toRemoteCache: jest.fn(), -}; - -jest.mock('@actions/exec', () => cli); -jest.mock('@actions/io', () => io); -jest.mock('../src/cache', () => cache); - -import { join } from 'path'; - -import * as install from '../src/install'; -import * as utils from './utils'; - -describe('install', () => { - it('installs path from local cache', async () => { - cache.fromLocalCache.mockResolvedValue(join('cache', 'path')); - const expoPath = await install.install({ package: 'expo-cli', version: '3.0.10', packager: 'npm' }); - expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin')); - }); - - it('installs path from packager and cache it locally', async () => { - utils.setEnv('RUNNER_TEMP', join('temp', 'path')); - cache.fromLocalCache.mockResolvedValue(undefined); - cache.toLocalCache.mockResolvedValue(join('cache', 'path')); - const expoPath = await install.install({ package: 'expo-cli', version: '3.0.10', packager: 'npm' }); - expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin')); - expect(cache.toLocalCache).toBeCalledWith(join('temp', 'path'), { - package: 'expo-cli', - version: '3.0.10', - packager: 'npm', - }); - utils.restoreEnv(); - }); - - it('installs path from remote cache', async () => { - cache.fromLocalCache.mockResolvedValue(undefined); - cache.fromRemoteCache.mockResolvedValue(join('cache', 'path')); - const expoPath = await install.install({ package: 'eas-cli', version: '4.2.0', packager: 'yarn', cache: true }); - expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin')); - expect(cache.fromRemoteCache).toBeCalledWith({ - package: 'eas-cli', - version: '4.2.0', - packager: 'yarn', - cache: true, - }); - }); - - it('installs path from packager and cache it remotely', async () => { - utils.setEnv('RUNNER_TEMP', join('temp', 'path')); - cache.fromLocalCache.mockResolvedValue(undefined); - cache.fromRemoteCache.mockResolvedValue(undefined); - cache.toLocalCache.mockResolvedValue(join('cache', 'path')); - const expoPath = await install.install({ package: 'expo-cli', version: '3.20.1', packager: 'npm', cache: true }); - expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin')); - expect(cache.toRemoteCache).toBeCalledWith(join('cache', 'path'), { - package: 'expo-cli', - version: '3.20.1', - packager: 'npm', - cache: true, - }); - utils.restoreEnv(); - }); -}); - -describe('fromPackager', () => { - it('resolves tool path', async () => { - await install.fromPackager({ package: 'expo-cli', version: '3.0.10', packager: 'npm' }); - expect(io.which).toBeCalledWith('npm'); - }); - - it('creates temporary folder', async () => { - utils.setEnv('RUNNER_TEMP', join('temp', 'path')); - await install.fromPackager({ package: 'eas-cli', version: 'latest', packager: 'yarn' }); - expect(io.mkdirP).toBeCalledWith(join('temp', 'path')); - utils.restoreEnv(); - }); - - it('installs expo with tool', async () => { - utils.setEnv('RUNNER_TEMP', join('temp', 'path')); - io.which.mockResolvedValue('npm'); - const expoPath = await install.fromPackager({ package: 'eas-cli', version: 'beta', packager: 'npm' }); - expect(expoPath).toBe(join('temp', 'path')); - expect(cli.exec).toBeCalled(); - expect(cli.exec.mock.calls[0][0]).toBe('npm'); - expect(cli.exec.mock.calls[0][1]).toStrictEqual(['add', 'eas-cli@beta']); - expect(cli.exec.mock.calls[0][2]).toMatchObject({ cwd: join('temp', 'path') }); - utils.restoreEnv(); - }); -}); diff --git a/tests/packager.test.ts b/tests/packager.test.ts index 29e52d11..d390353a 100644 --- a/tests/packager.test.ts +++ b/tests/packager.test.ts @@ -1,28 +1,25 @@ -import { valid as validVersion } from 'semver'; +import { resolvePackage } from '../src/packager'; -import { resolveVersion } from '../src/packager'; - -describe(resolveVersion, () => { +describe(resolvePackage, () => { it('resolves expo-cli@^2.0.0 to 2.21.2', async () => { - await expect(resolveVersion('expo-cli', '^2.0.0')).resolves.toBe('2.21.2'); + await expect(resolvePackage('expo-cli', '^2.0.0')).resolves.toBe('2.21.2'); }); it('resolves expo-cli@~3.15.0 to 3.15.5', async () => { - await expect(resolveVersion('expo-cli', '~3.15.0')).resolves.toBe('3.15.5'); + await expect(resolvePackage('expo-cli', '~3.15.0')).resolves.toBe('3.15.5'); }); it('resolves eas-cli@~0.33.0 to 0.33.1', async () => { - await expect(resolveVersion('eas-cli', '~0.33.0')).resolves.toBe('0.33.1'); + await expect(resolvePackage('eas-cli', '~0.33.0')).resolves.toBe('0.33.1'); }); - it('resolves expo-cli@latest to a valid version', async () => { - const version = await resolveVersion('expo-cli', 'latest'); - expect(validVersion(version)).not.toBeNull(); + it('resolves expo-cli@latest to a version', async () => { + await expect(resolvePackage('expo-cli', 'latest')).resolves.not.toMatch('latest'); }); it('rejects donotpublishthispackageoryouwillbefired with proper error', async () => { - await expect(resolveVersion('donotpublishthispackageoryouwillbefired', 'latest')).rejects.toThrow( - 'Could not resolve version "latest" of "donotpublishthispackageoryouwillbefired"' + await expect(resolvePackage('donotpublishthispackageoryouwillbefired', 'latest')).rejects.toThrow( + 'Could not resolve' ); }); }); diff --git a/tests/tools.test.ts b/tests/tools.test.ts deleted file mode 100644 index e0f589cf..00000000 --- a/tests/tools.test.ts +++ /dev/null @@ -1,328 +0,0 @@ -import * as core from '@actions/core'; -import * as cli from '@actions/exec'; - -import * as packager from '../src/packager'; -import * as tools from '../src/tools'; -import * as utils from './utils'; - -describe(tools.getBinaryName, () => { - it('returns expo for `expo-cli`', () => { - expect(tools.getBinaryName('expo-cli')).toBe('expo'); - }); - - it('returns eas for `eas-cli`', () => { - expect(tools.getBinaryName('eas-cli')).toBe('eas'); - }); - - it('returns eas.cmd for `eas-cli` for windows', () => { - expect(tools.getBinaryName('eas-cli', true)).toBe('eas.cmd'); - }); -}); - -describe(tools.maybeAuthenticate, () => { - const token = 'ABC123'; - const username = 'bycedric'; - const password = 'mypassword'; - - describe('with token', () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - exportVariable: jest.spyOn(core, 'exportVariable').mockImplementation(), - exec: jest.spyOn(cli, 'exec').mockImplementation(), - info: jest.spyOn(core, 'info').mockImplementation(), - }; - }); - - afterAll(() => { - spy.exportVariable.mockRestore(); - spy.exec.mockRestore(); - spy.info.mockRestore(); - }); - - it('skips authentication without token', async () => { - await tools.maybeAuthenticate(); - expect(spy.exec).not.toBeCalled(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication')); - }); - - it('executes whoami command with token through environment', async () => { - utils.setEnv('TEST_INCLUDED', 'hellyeah'); - await tools.maybeAuthenticate({ token, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][1]).toStrictEqual(['whoami']); - expect(spy.exec.mock.calls[0][2]).toMatchObject({ - env: { - TEST_INCLUDED: 'hellyeah', - EXPO_TOKEN: token, - }, - }); - utils.restoreEnv(); - }); - - it('fails when token is incorrect', async () => { - const error = new Error('Not logged in'); - spy.exec.mockRejectedValue(error); - await expect(tools.maybeAuthenticate({ token, cli: 'expo-cli' })).rejects.toBe(error); - }); - - it('skips validation without cli', async () => { - await tools.maybeAuthenticate({ token }); - expect(spy.exec).not.toBeCalled(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping token validation')); - }); - - it('executes whoami command with `expo` on macos', async () => { - utils.setPlatform('darwin'); - await tools.maybeAuthenticate({ token, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('expo'); - utils.restorePlatform(); - }); - - it('executes whoami command with `eas` on ubuntu', async () => { - utils.setPlatform('linux'); - await tools.maybeAuthenticate({ token, cli: 'eas-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('eas'); - utils.restorePlatform(); - }); - - it('executes whoami command with `expo.cmd` on windows', async () => { - utils.setPlatform('win32'); - await tools.maybeAuthenticate({ token, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd'); - utils.restorePlatform(); - }); - }); - - describe('credentials', () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - exec: jest.spyOn(cli, 'exec').mockImplementation(), - info: jest.spyOn(core, 'info').mockImplementation(), - warning: jest.spyOn(core, 'warning').mockImplementation(), - }; - }); - - afterAll(() => { - spy.exec.mockRestore(); - spy.info.mockRestore(); - spy.warning.mockRestore(); - }); - - it('skips authentication without cli', async () => { - await tools.maybeAuthenticate({}); - expect(spy.exec).not.toBeCalled(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication')); - }); - - it('skips authentication without credentials', async () => { - await tools.maybeAuthenticate({ cli: 'expo-cli' }); - expect(spy.exec).not.toBeCalled(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication')); - }); - - it('skips authentication without password', async () => { - await tools.maybeAuthenticate({ username, cli: 'expo-cli' }); - expect(spy.exec).not.toBeCalled(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication')); - }); - - it('skips authentication with credentials for eas-cli', async () => { - await tools.maybeAuthenticate({ username, password, cli: 'eas-cli' }); - expect(spy.exec).not.toBeCalled(); - expect(spy.warning).toBeCalledWith(expect.stringContaining('Skipping authentication')); - }); - - it('executes login command with password through environment', async () => { - utils.setEnv('TEST_INCLUDED', 'hellyeah'); - await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][1]).toStrictEqual(['login', `--username=${username}`]); - expect(spy.exec.mock.calls[0][2]).toMatchObject({ - env: { - TEST_INCLUDED: 'hellyeah', - EXPO_CLI_PASSWORD: password, - }, - }); - utils.restoreEnv(); - }); - - it('fails when credentials are incorrect', async () => { - const error = new Error('Invalid username/password. Please try again.'); - spy.exec.mockRejectedValue(error); - await expect(tools.maybeAuthenticate({ username, password, cli: 'expo-cli' })).rejects.toBe(error); - }); - - it('executes login command with `expo` on macos', async () => { - utils.setPlatform('darwin'); - await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('expo'); - utils.restorePlatform(); - }); - - it('executes login command with `expo` on ubuntu', async () => { - utils.setPlatform('linux'); - await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('expo'); - utils.restorePlatform(); - }); - - it('executes login command with `expo.cmd` on windows', async () => { - utils.setPlatform('win32'); - await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' }); - expect(spy.exec).toBeCalled(); - expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd'); - utils.restorePlatform(); - }); - }); -}); - -describe(tools.maybePatchWatchers, () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - info: jest.spyOn(core, 'info').mockImplementation(), - warning: jest.spyOn(core, 'warning').mockImplementation(), - exec: jest.spyOn(cli, 'exec').mockImplementation(), - }; - }); - - afterEach(() => { - utils.restorePlatform(); - }); - - afterAll(() => { - spy.info.mockRestore(); - spy.warning.mockRestore(); - spy.exec.mockRestore(); - }); - - it('increses fs inotify settings with sysctl', async () => { - utils.setPlatform('linux'); - await tools.maybePatchWatchers(); - expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_instances=524288'); - expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_watches=524288'); - expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_queued_events=524288'); - expect(spy.exec).toBeCalledWith('sudo sysctl -p'); - }); - - it('warns for unsuccessful patches', async () => { - const error = new Error('Something went wrong'); - spy.exec.mockRejectedValueOnce(error); - utils.setPlatform('linux'); - await tools.maybePatchWatchers(); - expect(core.warning).toBeCalledWith(expect.stringContaining("can't patch watchers")); - expect(core.warning).toBeCalledWith( - expect.stringContaining('https://github.com/expo/expo-github-action/issues/20') - ); - }); - - it('skips on windows platform', async () => { - utils.setPlatform('win32'); - await tools.maybePatchWatchers(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping')); - expect(spy.exec).not.toHaveBeenCalled(); - }); - - it('skips on macos platform', async () => { - utils.setPlatform('darwin'); - await tools.maybePatchWatchers(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping')); - expect(spy.exec).not.toHaveBeenCalled(); - }); - - it('runs on linux platform', async () => { - utils.setPlatform('linux'); - await tools.maybePatchWatchers(); - expect(spy.info).toBeCalledWith(expect.stringContaining('Patching')); - expect(spy.exec).toHaveBeenCalled(); - }); -}); - -describe(tools.maybeWarnForUpdate, () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - warning: jest.spyOn(core, 'warning').mockImplementation(), - resolveVersion: jest.spyOn(packager, 'resolveVersion').mockImplementation(), - }; - }); - - afterAll(() => { - spy.warning.mockRestore(); - spy.resolveVersion.mockRestore(); - }); - - it('is silent when major version is up to date', async () => { - spy.resolveVersion.mockResolvedValueOnce('4.1.0').mockResolvedValueOnce('4.0.1'); - await tools.maybeWarnForUpdate('eas-cli'); - expect(spy.warning).not.toBeCalled(); - }); - - it('warns when major version is outdated', async () => { - spy.resolveVersion.mockResolvedValueOnce('4.1.0').mockResolvedValueOnce('3.0.1'); - await tools.maybeWarnForUpdate('expo-cli'); - expect(spy.warning).toBeCalledWith('There is a new major version available of the Expo CLI (4.1.0)'); - expect(spy.warning).toBeCalledWith('If you run into issues, try upgrading your workflow to "expo-version: 4.x"'); - }); -}); - -describe(tools.handleError, () => { - let spy: { [key: string]: jest.SpyInstance } = {}; - - beforeEach(() => { - spy = { - setFailed: jest.spyOn(core, 'setFailed').mockImplementation(), - resolveVersion: jest.spyOn(packager, 'resolveVersion').mockImplementation(), - }; - }); - - afterAll(() => { - spy.setFailed.mockRestore(); - spy.resolveVersion.mockRestore(); - }); - - it('marks the job as failed with expo-cli', async () => { - const error = new Error('test'); - spy.resolveVersion.mockResolvedValue('4.0.0'); - await tools.handleError('expo-cli', error); - expect(core.setFailed).toBeCalledWith(error); - }); - - it('fails with original error when update warning failed', async () => { - const error = new Error('test'); - spy.resolveVersion.mockRejectedValue(new Error('npm issue')); - await tools.handleError('eas-cli', error); - expect(core.setFailed).toBeCalledWith(error); - }); -}); - -describe(tools.performAction, () => { - it('skips the test in a jest environment', async () => { - utils.setEnv('JEST_WORKER_ID', '69'); - const action = jest.fn(); - const result = await tools.performAction(action); - expect(result).toBeNull(); - expect(action).not.toBeCalled(); - utils.restoreEnv(); - }); - - it('runs the test outside a jest environment', async () => { - utils.setEnv('JEST_WORKER_ID', ''); - const action = jest.fn(); - const result = await tools.performAction(action); - expect(result).toBeUndefined(); - expect(action).toBeCalled(); - utils.restoreEnv(); - }); -}); diff --git a/tests/utils.ts b/tests/utils.ts index 48b4b770..ce0b2b07 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -14,7 +14,7 @@ export function setPlatform(platform: NodeJS.Platform): void { /** * Revert the platform to the original one. */ -export function restorePlatform(): void { +export function resetPlatform(): void { setPlatform(originalPlatform); } @@ -31,28 +31,14 @@ export function setEnv(name: string, value: string): void { /** * Revert the environment variable changes. */ -export function restoreEnv(): void { +export function resetEnv(): void { process.env = originalEnv; } -/** - * Get a mocked version of the tools. - */ -export function getToolsMock() { - return { - getBinaryName: jest.fn(v => v.replace('-cli', '')), - maybeAuthenticate: jest.fn(), - maybePatchWatchers: jest.fn(), - maybeWarnForUpdate: jest.fn(), - handleError: jest.fn(), - performAction: jest.fn(), - }; -} - /** * Mock both the input and boolean input methods from `@actions/core`. */ export function mockInput(inputs: Record = {}) { - jest.spyOn(core, 'getInput').mockImplementation(name => inputs[name]); - jest.spyOn(core, 'getBooleanInput').mockImplementation(name => inputs[name] === 'true'); + jest.mocked(core.getInput).mockImplementation(name => inputs[name]); + jest.mocked(core.getBooleanInput).mockImplementation(name => inputs[name] === 'true'); } diff --git a/tests/worker.test.ts b/tests/worker.test.ts new file mode 100644 index 00000000..7a885e0f --- /dev/null +++ b/tests/worker.test.ts @@ -0,0 +1,133 @@ +import * as core from '@actions/core'; +import * as exec from '@actions/exec'; +import os from 'os'; +import path from 'path'; + +import { + tempPath, + toolPath, + installToolFromPackage, + patchWatchers, + expoAuthenticate, + executeAction, +} from '../src/worker'; +import { resetEnv, setEnv, setPlatform, resetPlatform } from './utils'; + +jest.mock('@actions/core'); +jest.mock('@actions/exec'); + +describe(tempPath, () => { + afterEach(resetEnv); + + it('throws when RUNNER_TEMP is undefined', () => { + setEnv('RUNNER_TEMP', ''); + expect(tempPath).toThrow(`'RUNNER_TEMP' not defined`); + }); + + it('returns path with name, version, and arch type', () => { + setEnv('RUNNER_TEMP', 'fake/temp'); + expect(tempPath('expo-cli', '5.0.3')).toBe(path.join('fake', 'temp', 'expo-cli', '5.0.3', os.arch())); + }); +}); + +describe(toolPath, () => { + afterEach(resetEnv); + + it('throws when RUNNER_TOOL_CACHE is undefined', () => { + setEnv('RUNNER_TOOL_CACHE', ''); + expect(toolPath).toThrow(`'RUNNER_TOOL_CACHE' not defined`); + }); + + it('returns path with name, version, and arch type', () => { + setEnv('RUNNER_TOOL_CACHE', 'fake/tool'); + expect(toolPath('eas-cli', '0.34.3')).toBe(path.join('fake', 'tool', 'eas-cli', '0.34.3', os.arch())); + }); +}); + +describe(installToolFromPackage, () => { + it('registers path to /node_modules/.bin', () => { + installToolFromPackage('fake/install'); + expect(core.addPath).toBeCalledWith(path.join('fake', 'install', 'node_modules', '.bin')); + }); +}); + +describe(patchWatchers, () => { + afterEach(resetPlatform); + + it('skips patches on windows', async () => { + setPlatform('win32'); + await patchWatchers(); + expect(exec.exec).not.toBeCalled(); + }); + + it('skips patches on macos', async () => { + setPlatform('darwin'); + await patchWatchers(); + expect(exec.exec).not.toBeCalled(); + }); + + it('patches on ubuntu', async () => { + setPlatform('linux'); + await patchWatchers(); + expect(exec.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_instances=524288'); + expect(exec.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_watches=524288'); + expect(exec.exec).toBeCalledWith('sudo sysctl fs.inotify.max_queued_events=524288'); + expect(exec.exec).toBeCalledWith('sudo sysctl -p'); + }); + + it('handles exception from commands', async () => { + setPlatform('linux'); + jest + .mocked(exec.exec) + .mockResolvedValueOnce(0) + .mockResolvedValueOnce(0) + .mockRejectedValueOnce(new Error('fake error')); + await expect(patchWatchers()).resolves.not.toThrow(); + }); +}); + +describe(expoAuthenticate, () => { + it('exports EXPO_TOKEN variable', async () => { + await expoAuthenticate('faketoken', undefined); + expect(core.exportVariable).toBeCalledWith('EXPO_TOKEN', 'faketoken'); + }); + + it('validates EXPO_TOKEN with expo-cli', async () => { + await expoAuthenticate('faketoken', 'expo'); + expect(exec.exec).toBeCalledWith('npx --no-install', ['expo', 'whoami'], { + env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }), + }); + }); + + it('validates EXPO_TOKEN with eas-cli', async () => { + await expoAuthenticate('faketoken', 'eas'); + expect(exec.exec).toBeCalledWith('npx --no-install', ['eas', 'whoami'], { + env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }), + }); + }); +}); + +describe(executeAction, () => { + afterEach(resetEnv); + + it('skips executing action in jest', async () => { + const action = jest.fn(() => Promise.resolve()); + await executeAction(action); + expect(action).not.toBeCalled(); + }); + + it('executes action outside jest', async () => { + setEnv('JEST_WORKER_ID', ''); + const action = jest.fn(() => Promise.resolve()); + await executeAction(action); + expect(action).toBeCalled(); + }); + + it('handles action errors', async () => { + setEnv('JEST_WORKER_ID', ''); + const error = new Error('fake error'); + const action = jest.fn(() => Promise.reject(error)); + await expect(executeAction(action)).resolves.not.toThrow(); + expect(core.setFailed).toBeCalledWith(error); + }); +}); diff --git a/yarn.lock b/yarn.lock index 10ef97b8..a71aaa8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1426,11 +1426,6 @@ resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d" integrity sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA== -"@types/semver@^7.3.9": - version "7.3.9" - resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.9.tgz#152c6c20a7688c30b967ec1841d31ace569863fc" - integrity sha512-L/TMpyURfBkf+o/526Zb6kd/tchUP3iBDEPjqjb+U2MAJhVRxxrmr2fwpe08E7QsV7YLcpq0tUaQ9O9x97ZIxQ== - "@types/stack-utils@^2.0.0": version "2.0.0" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff"