diff --git a/dist/index.js b/dist/index.js index fac717173..7e2f93f63 100644 --- a/dist/index.js +++ b/dist/index.js @@ -128840,6 +128840,7 @@ class Comparator { static get ANY () { return ANY } + constructor (comp, options) { options = parseOptions(options) @@ -128916,7 +128917,7 @@ class Comparator { if (!options || typeof options !== 'object') { options = { loose: !!options, - includePrerelease: false + includePrerelease: false, } } @@ -128964,7 +128965,7 @@ class Comparator { module.exports = Comparator const parseOptions = __nccwpck_require__(40785) -const {re, t} = __nccwpck_require__(92566) +const { re, t } = __nccwpck_require__(92566) const cmp = __nccwpck_require__(75098) const debug = __nccwpck_require__(50427) const SemVer = __nccwpck_require__(48088) @@ -129007,9 +129008,9 @@ class Range { // First, split based on boolean or || this.raw = range this.set = range - .split(/\s*\|\|\s*/) + .split('||') // map the range to a 2d array of comparators - .map(range => this.parseRange(range.trim())) + .map(r => this.parseRange(r.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. @@ -129024,9 +129025,9 @@ class Range { // 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) + if (this.set.length === 0) { this.set = [first] - else if (this.set.length > 1) { + } 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])) { @@ -129062,8 +129063,9 @@ class Range { const memoOpts = Object.keys(this.options).join(',') const memoKey = `parseRange:${memoOpts}:${range}` const cached = cache.get(memoKey) - if (cached) + if (cached) { return cached + } const loose = this.options.loose // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4` @@ -129072,7 +129074,7 @@ class Range { 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]) + debug('comparator trim', range) // `~ 1.2.3` => `~1.2.3` range = range.replace(re[t.TILDETRIM], tildeTrimReplace) @@ -129086,30 +129088,37 @@ class Range { // 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 + let rangeList = range .split(' ') .map(comp => parseComparator(comp, this.options)) .join(' ') .split(/\s+/) // >=0.0.0 is equivalent to * .map(comp => replaceGTE0(comp, this.options)) + + if (loose) { // 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)) + rangeList = rangeList.filter(comp => { + debug('loose invalid filter', comp, this.options) + return !!comp.match(re[t.COMPARATORLOOSE]) + }) + } + debug('range list', rangeList) // 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)) + const comparators = rangeList.map(comp => new Comparator(comp, this.options)) + for (const comp of comparators) { + if (isNullSet(comp)) { return [comp] + } rangeMap.set(comp.value, comp) } - if (rangeMap.size > 1 && rangeMap.has('')) + if (rangeMap.size > 1 && rangeMap.has('')) { rangeMap.delete('') + } const result = [...rangeMap.values()] cache.set(memoKey, result) @@ -129162,7 +129171,7 @@ class Range { } module.exports = Range -const LRU = __nccwpck_require__(7129) +const LRU = __nccwpck_require__(81196) const cache = new LRU({ max: 1000 }) const parseOptions = __nccwpck_require__(40785) @@ -129174,7 +129183,7 @@ const { t, comparatorTrimReplace, tildeTrimReplace, - caretTrimReplace + caretTrimReplace, } = __nccwpck_require__(92566) const isNullSet = c => c.value === '<0.0.0-0' @@ -129223,8 +129232,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*' // ~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) + comp.trim().split(/\s+/).map((c) => { + return replaceTilde(c, options) }).join(' ') const replaceTilde = (comp, options) => { @@ -129262,8 +129271,8 @@ const replaceTilde = (comp, options) => { // ^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) + comp.trim().split(/\s+/).map((c) => { + return replaceCaret(c, options) }).join(' ') const replaceCaret = (comp, options) => { @@ -129321,8 +129330,8 @@ const replaceCaret = (comp, options) => { const replaceXRanges = (comp, options) => { debug('replaceXRanges', comp, options) - return comp.split(/\s+/).map((comp) => { - return replaceXRange(comp, options) + return comp.split(/\s+/).map((c) => { + return replaceXRange(c, options) }).join(' ') } @@ -129383,8 +129392,9 @@ const replaceXRange = (comp, options) => { } } - if (gtlt === '<') + if (gtlt === '<') { pr = '-0' + } ret = `${gtlt + M}.${m}.${p}${pr}` } else if (xm) { @@ -129810,17 +129820,21 @@ const lte = __nccwpck_require__(77520) const cmp = (a, op, b, loose) => { switch (op) { case '===': - if (typeof a === 'object') + if (typeof a === 'object') { a = a.version - if (typeof b === 'object') + } + if (typeof b === 'object') { b = b.version + } return a === b case '!==': - if (typeof a === 'object') + if (typeof a === 'object') { a = a.version - if (typeof b === 'object') + } + if (typeof b === 'object') { b = b.version + } return a !== b case '': @@ -129857,7 +129871,7 @@ module.exports = cmp const SemVer = __nccwpck_require__(48088) const parse = __nccwpck_require__(75925) -const {re, t} = __nccwpck_require__(92566) +const { re, t } = __nccwpck_require__(92566) const coerce = (version, options) => { if (version instanceof SemVer) { @@ -129900,8 +129914,9 @@ const coerce = (version, options) => { re[t.COERCERTL].lastIndex = -1 } - if (match === null) + if (match === null) { return null + } return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options) } @@ -130081,7 +130096,7 @@ module.exports = neq /***/ 75925: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { -const {MAX_LENGTH} = __nccwpck_require__(42293) +const { MAX_LENGTH } = __nccwpck_require__(42293) const { re, t } = __nccwpck_require__(92566) const SemVer = __nccwpck_require__(48088) @@ -130265,7 +130280,7 @@ const SEMVER_SPEC_VERSION = '2.0.0' const MAX_LENGTH = 256 const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || - /* istanbul ignore next */ 9007199254740991 +/* istanbul ignore next */ 9007199254740991 // Max safe segment length for coercion. const MAX_SAFE_COMPONENT_LENGTH = 16 @@ -130274,7 +130289,7 @@ module.exports = { SEMVER_SPEC_VERSION, MAX_LENGTH, MAX_SAFE_INTEGER, - MAX_SAFE_COMPONENT_LENGTH + MAX_SAFE_COMPONENT_LENGTH, } @@ -130320,7 +130335,7 @@ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a) module.exports = { compareIdentifiers, - rcompareIdentifiers + rcompareIdentifiers, } @@ -130335,9 +130350,9 @@ 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 + : opts.filter(k => options[k]).reduce((o, k) => { + o[k] = true + return o }, {}) module.exports = parseOptions @@ -130359,7 +130374,7 @@ let R = 0 const createToken = (name, value, isGlobal) => { const index = R++ - debug(index, value) + debug(name, index, value) t[name] = index src[index] = value re[index] = new RegExp(value, isGlobal ? 'g' : undefined) @@ -130527,8 +130542,813 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` + // 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*$') +createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$') +createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$') + + +/***/ }), + +/***/ 81196: +/***/ ((module) => { + +const perf = typeof performance === 'object' && performance && + typeof performance.now === 'function' ? performance : Date + +const hasAbortController = typeof AbortController !== 'undefined' + +/* istanbul ignore next - minimal backwards compatibility polyfill */ +const AC = hasAbortController ? AbortController : Object.assign( + class AbortController { + constructor () { this.signal = new AC.AbortSignal } + abort () { this.signal.aborted = true } + }, + { AbortSignal: class AbortSignal { constructor () { this.aborted = false }}} +) + +const warned = new Set() +const deprecatedOption = (opt, instead) => { + const code = `LRU_CACHE_OPTION_${opt}` + if (shouldWarn(code)) { + warn(code, `${opt} option`, `options.${instead}`, LRUCache) + } +} +const deprecatedMethod = (method, instead) => { + const code = `LRU_CACHE_METHOD_${method}` + if (shouldWarn(code)) { + const { prototype } = LRUCache + const { get } = Object.getOwnPropertyDescriptor(prototype, method) + warn(code, `${method} method`, `cache.${instead}()`, get) + } +} +const deprecatedProperty = (field, instead) => { + const code = `LRU_CACHE_PROPERTY_${field}` + if (shouldWarn(code)) { + const { prototype } = LRUCache + const { get } = Object.getOwnPropertyDescriptor(prototype, field) + warn(code, `${field} property`, `cache.${instead}`, get) + } +} + +const shouldWarn = code => typeof process === 'object' && + process && + !warned.has(code) + +const warn = (code, what, instead, fn) => { + warned.add(code) + const msg = `The ${what} is deprecated. Please use ${instead} instead.` + process.emitWarning(msg, 'DeprecationWarning', code, fn) +} + +const isPosInt = n => n && n === Math.floor(n) && n > 0 && isFinite(n) + +/* istanbul ignore next - This is a little bit ridiculous, tbh. + * The maximum array length is 2^32-1 or thereabouts on most JS impls. + * And well before that point, you're caching the entire world, I mean, + * that's ~32GB of just integers for the next/prev links, plus whatever + * else to hold that many keys and values. Just filling the memory with + * zeroes at init time is brutal when you get that big. + * But why not be complete? + * Maybe in the future, these limits will have expanded. */ +const getUintArray = max => !isPosInt(max) ? null +: max <= Math.pow(2, 8) ? Uint8Array +: max <= Math.pow(2, 16) ? Uint16Array +: max <= Math.pow(2, 32) ? Uint32Array +: max <= Number.MAX_SAFE_INTEGER ? ZeroArray +: null + +class ZeroArray extends Array { + constructor (size) { + super(size) + this.fill(0) + } +} + +class Stack { + constructor (max) { + const UintArray = max ? getUintArray(max) : Array + this.heap = new UintArray(max) + this.length = 0 + } + push (n) { + this.heap[this.length++] = n + } + pop () { + return this.heap[--this.length] + } +} + +class LRUCache { + constructor (options = {}) { + const { + max = 0, + ttl, + ttlResolution = 1, + ttlAutopurge, + updateAgeOnGet, + allowStale, + dispose, + disposeAfter, + noDisposeOnSet, + noUpdateTTL, + maxSize = 0, + sizeCalculation, + fetchMethod, + } = options + + // deprecated options, don't trigger a warning for getting them if + // the thing being passed in is another LRUCache we're copying. + const { + length, + maxAge, + stale, + } = options instanceof LRUCache ? {} : options + + if (max !== 0 && !isPosInt(max)) { + throw new TypeError('max option must be a nonnegative integer') + } + + const UintArray = max ? getUintArray(max) : Array + if (!UintArray) { + throw new Error('invalid max value: ' + max) + } + + this.max = max + this.maxSize = maxSize + this.sizeCalculation = sizeCalculation || length + if (this.sizeCalculation) { + if (!this.maxSize) { + throw new TypeError('cannot set sizeCalculation without setting maxSize') + } + if (typeof this.sizeCalculation !== 'function') { + throw new TypeError('sizeCalculation set to non-function') + } + } + + this.fetchMethod = fetchMethod || null + if (this.fetchMethod && typeof this.fetchMethod !== 'function') { + throw new TypeError('fetchMethod must be a function if specified') + } + + + this.keyMap = new Map() + this.keyList = new Array(max).fill(null) + this.valList = new Array(max).fill(null) + this.next = new UintArray(max) + this.prev = new UintArray(max) + this.head = 0 + this.tail = 0 + this.free = new Stack(max) + this.initialFill = 1 + this.size = 0 + + if (typeof dispose === 'function') { + this.dispose = dispose + } + if (typeof disposeAfter === 'function') { + this.disposeAfter = disposeAfter + this.disposed = [] + } else { + this.disposeAfter = null + this.disposed = null + } + this.noDisposeOnSet = !!noDisposeOnSet + this.noUpdateTTL = !!noUpdateTTL + + if (this.maxSize !== 0) { + if (!isPosInt(this.maxSize)) { + throw new TypeError('maxSize must be a positive integer if specified') + } + this.initializeSizeTracking() + } + + this.allowStale = !!allowStale || !!stale + this.updateAgeOnGet = !!updateAgeOnGet + this.ttlResolution = isPosInt(ttlResolution) || ttlResolution === 0 + ? ttlResolution : 1 + this.ttlAutopurge = !!ttlAutopurge + this.ttl = ttl || maxAge || 0 + if (this.ttl) { + if (!isPosInt(this.ttl)) { + throw new TypeError('ttl must be a positive integer if specified') + } + this.initializeTTLTracking() + } + + // do not allow completely unbounded caches + if (this.max === 0 && this.ttl === 0 && this.maxSize === 0) { + throw new TypeError('At least one of max, maxSize, or ttl is required') + } + if (!this.ttlAutopurge && !this.max && !this.maxSize) { + const code = 'LRU_CACHE_UNBOUNDED' + if (shouldWarn(code)) { + warned.add(code) + const msg = 'TTL caching without ttlAutopurge, max, or maxSize can ' + + 'result in unbounded memory consumption.' + process.emitWarning(msg, 'UnboundedCacheWarning', code, LRUCache) + } + } + + if (stale) { + deprecatedOption('stale', 'allowStale') + } + if (maxAge) { + deprecatedOption('maxAge', 'ttl') + } + if (length) { + deprecatedOption('length', 'sizeCalculation') + } + } + + getRemainingTTL (key) { + return this.has(key) ? Infinity : 0 + } + + initializeTTLTracking () { + this.ttls = new ZeroArray(this.max) + this.starts = new ZeroArray(this.max) + + this.setItemTTL = (index, ttl) => { + this.starts[index] = ttl !== 0 ? perf.now() : 0 + this.ttls[index] = ttl + if (ttl !== 0 && this.ttlAutopurge) { + const t = setTimeout(() => { + if (this.isStale(index)) { + this.delete(this.keyList[index]) + } + }, ttl + 1) + /* istanbul ignore else - unref() not supported on all platforms */ + if (t.unref) { + t.unref() + } + } + } + + this.updateItemAge = (index) => { + this.starts[index] = this.ttls[index] !== 0 ? perf.now() : 0 + } + + // debounce calls to perf.now() to 1s so we're not hitting + // that costly call repeatedly. + let cachedNow = 0 + const getNow = () => { + const n = perf.now() + if (this.ttlResolution > 0) { + cachedNow = n + const t = setTimeout(() => cachedNow = 0, this.ttlResolution) + /* istanbul ignore else - not available on all platforms */ + if (t.unref) { + t.unref() + } + } + return n + } + + this.getRemainingTTL = (key) => { + const index = this.keyMap.get(key) + if (index === undefined) { + return 0 + } + return this.ttls[index] === 0 || this.starts[index] === 0 ? Infinity + : ((this.starts[index] + this.ttls[index]) - (cachedNow || getNow())) + } + + this.isStale = (index) => { + return this.ttls[index] !== 0 && this.starts[index] !== 0 && + ((cachedNow || getNow()) - this.starts[index] > this.ttls[index]) + } + } + updateItemAge (index) {} + setItemTTL (index, ttl) {} + isStale (index) { return false } + + initializeSizeTracking () { + this.calculatedSize = 0 + this.sizes = new ZeroArray(this.max) + this.removeItemSize = index => this.calculatedSize -= this.sizes[index] + this.requireSize = (k, v, size, sizeCalculation) => { + if (!isPosInt(size)) { + if (sizeCalculation) { + if (typeof sizeCalculation !== 'function') { + throw new TypeError('sizeCalculation must be a function') + } + size = sizeCalculation(v, k) + if (!isPosInt(size)) { + throw new TypeError('sizeCalculation return invalid (expect positive integer)') + } + } else { + throw new TypeError('invalid size value (must be positive integer)') + } + } + return size + } + this.addItemSize = (index, v, k, size) => { + this.sizes[index] = size + const maxSize = this.maxSize - this.sizes[index] + while (this.calculatedSize > maxSize) { + this.evict() + } + this.calculatedSize += this.sizes[index] + } + this.delete = k => { + if (this.size !== 0) { + const index = this.keyMap.get(k) + if (index !== undefined) { + this.calculatedSize -= this.sizes[index] + } + } + return LRUCache.prototype.delete.call(this, k) + } + } + removeItemSize (index) {} + addItemSize (index, v, k, size) {} + requireSize (k, v, size, sizeCalculation) { + if (size || sizeCalculation) { + throw new TypeError('cannot set size without setting maxSize on cache') + } + } + + *indexes ({ allowStale = this.allowStale } = {}) { + if (this.size) { + for (let i = this.tail; true; ) { + if (!this.isValidIndex(i)) { + break + } + if (allowStale || !this.isStale(i)) { + yield i + } + if (i === this.head) { + break + } else { + i = this.prev[i] + } + } + } + } + + *rindexes ({ allowStale = this.allowStale } = {}) { + if (this.size) { + for (let i = this.head; true; ) { + if (!this.isValidIndex(i)) { + break + } + if (allowStale || !this.isStale(i)) { + yield i + } + if (i === this.tail) { + break + } else { + i = this.next[i] + } + } + } + } + + isValidIndex (index) { + return this.keyMap.get(this.keyList[index]) === index + } + + *entries () { + for (const i of this.indexes()) { + yield [this.keyList[i], this.valList[i]] + } + } + *rentries () { + for (const i of this.rindexes()) { + yield [this.keyList[i], this.valList[i]] + } + } + + *keys () { + for (const i of this.indexes()) { + yield this.keyList[i] + } + } + *rkeys () { + for (const i of this.rindexes()) { + yield this.keyList[i] + } + } + + *values () { + for (const i of this.indexes()) { + yield this.valList[i] + } + } + *rvalues () { + for (const i of this.rindexes()) { + yield this.valList[i] + } + } + + [Symbol.iterator] () { + return this.entries() + } + + find (fn, getOptions = {}) { + for (const i of this.indexes()) { + if (fn(this.valList[i], this.keyList[i], this)) { + return this.get(this.keyList[i], getOptions) + } + } + } + + forEach (fn, thisp = this) { + for (const i of this.indexes()) { + fn.call(thisp, this.valList[i], this.keyList[i], this) + } + } + + rforEach (fn, thisp = this) { + for (const i of this.rindexes()) { + fn.call(thisp, this.valList[i], this.keyList[i], this) + } + } + + get prune () { + deprecatedMethod('prune', 'purgeStale') + return this.purgeStale + } + + purgeStale () { + let deleted = false + for (const i of this.rindexes({ allowStale: true })) { + if (this.isStale(i)) { + this.delete(this.keyList[i]) + deleted = true + } + } + return deleted + } + + dump () { + const arr = [] + for (const i of this.indexes()) { + const key = this.keyList[i] + const value = this.valList[i] + const entry = { value } + if (this.ttls) { + entry.ttl = this.ttls[i] + } + if (this.sizes) { + entry.size = this.sizes[i] + } + arr.unshift([key, entry]) + } + return arr + } + + load (arr) { + this.clear() + for (const [key, entry] of arr) { + this.set(key, entry.value, entry) + } + } + + dispose (v, k, reason) {} + + set (k, v, { + ttl = this.ttl, + noDisposeOnSet = this.noDisposeOnSet, + size = 0, + sizeCalculation = this.sizeCalculation, + noUpdateTTL = this.noUpdateTTL, + } = {}) { + size = this.requireSize(k, v, size, sizeCalculation) + let index = this.size === 0 ? undefined : this.keyMap.get(k) + if (index === undefined) { + // addition + index = this.newIndex() + this.keyList[index] = k + this.valList[index] = v + this.keyMap.set(k, index) + this.next[this.tail] = index + this.prev[index] = this.tail + this.tail = index + this.size ++ + this.addItemSize(index, v, k, size) + noUpdateTTL = false + } else { + // update + const oldVal = this.valList[index] + if (v !== oldVal) { + if (this.isBackgroundFetch(oldVal)) { + oldVal.__abortController.abort() + } else { + if (!noDisposeOnSet) { + this.dispose(oldVal, k, 'set') + if (this.disposeAfter) { + this.disposed.push([oldVal, k, 'set']) + } + } + } + this.removeItemSize(index) + this.valList[index] = v + this.addItemSize(index, v, k, size) + } + this.moveToTail(index) + } + if (ttl !== 0 && this.ttl === 0 && !this.ttls) { + this.initializeTTLTracking() + } + if (!noUpdateTTL) { + this.setItemTTL(index, ttl) + } + if (this.disposeAfter) { + while (this.disposed.length) { + this.disposeAfter(...this.disposed.shift()) + } + } + return this + } + + newIndex () { + if (this.size === 0) { + return this.tail + } + if (this.size === this.max) { + return this.evict() + } + if (this.free.length !== 0) { + return this.free.pop() + } + // initial fill, just keep writing down the list + return this.initialFill++ + } + + pop () { + if (this.size) { + const val = this.valList[this.head] + this.evict() + return val + } + } + + evict () { + const head = this.head + const k = this.keyList[head] + const v = this.valList[head] + if (this.isBackgroundFetch(v)) { + v.__abortController.abort() + } else { + this.dispose(v, k, 'evict') + if (this.disposeAfter) { + this.disposed.push([v, k, 'evict']) + } + } + this.removeItemSize(head) + this.head = this.next[head] + this.keyMap.delete(k) + this.size -- + return head + } + + has (k) { + return this.keyMap.has(k) && !this.isStale(this.keyMap.get(k)) + } + + // like get(), but without any LRU updating or TTL expiration + peek (k, { allowStale = this.allowStale } = {}) { + const index = this.keyMap.get(k) + if (index !== undefined && (allowStale || !this.isStale(index))) { + return this.valList[index] + } + } + + backgroundFetch (k, index, options) { + const v = index === undefined ? undefined : this.valList[index] + if (this.isBackgroundFetch(v)) { + return v + } + const ac = new AC() + const fetchOpts = { + signal: ac.signal, + options, + } + const p = Promise.resolve(this.fetchMethod(k, v, fetchOpts)).then(v => { + if (!ac.signal.aborted) { + this.set(k, v, fetchOpts.options) + } + return v + }) + p.__abortController = ac + p.__staleWhileFetching = v + if (index === undefined) { + this.set(k, p, fetchOpts.options) + index = this.keyMap.get(k) + } else { + this.valList[index] = p + } + return p + } + + isBackgroundFetch (p) { + return p && typeof p === 'object' && typeof p.then === 'function' && + Object.prototype.hasOwnProperty.call(p, '__staleWhileFetching') + } + + // this takes the union of get() and set() opts, because it does both + async fetch (k, { + allowStale = this.allowStale, + updateAgeOnGet = this.updateAgeOnGet, + ttl = this.ttl, + noDisposeOnSet = this.noDisposeOnSet, + size = 0, + sizeCalculation = this.sizeCalculation, + noUpdateTTL = this.noUpdateTTL, + } = {}) { + if (!this.fetchMethod) { + return this.get(k, {allowStale, updateAgeOnGet}) + } + + const options = { + allowStale, + updateAgeOnGet, + ttl, + noDisposeOnSet, + size, + sizeCalculation, + noUpdateTTL, + } + + let index = this.keyMap.get(k) + if (index === undefined) { + return this.backgroundFetch(k, index, options) + } else { + // in cache, maybe already fetching + const v = this.valList[index] + if (this.isBackgroundFetch(v)) { + return allowStale && v.__staleWhileFetching !== undefined + ? v.__staleWhileFetching : v + } + + if (!this.isStale(index)) { + this.moveToTail(index) + if (updateAgeOnGet) { + this.updateItemAge(index) + } + return v + } + + // ok, it is stale, and not already fetching + // refresh the cache. + const p = this.backgroundFetch(k, index, options) + return allowStale && p.__staleWhileFetching !== undefined + ? p.__staleWhileFetching : p + } + } + + get (k, { + allowStale = this.allowStale, + updateAgeOnGet = this.updateAgeOnGet, + } = {}) { + const index = this.keyMap.get(k) + if (index !== undefined) { + const value = this.valList[index] + const fetching = this.isBackgroundFetch(value) + if (this.isStale(index)) { + // delete only if not an in-flight background fetch + if (!fetching) { + this.delete(k) + return allowStale ? value : undefined + } else { + return allowStale ? value.__staleWhileFetching : undefined + } + } else { + // if we're currently fetching it, we don't actually have it yet + // it's not stale, which means this isn't a staleWhileRefetching, + // so we just return undefined + if (fetching) { + return undefined + } + this.moveToTail(index) + if (updateAgeOnGet) { + this.updateItemAge(index) + } + return value + } + } + } + + connect (p, n) { + this.prev[n] = p + this.next[p] = n + } + + moveToTail (index) { + // if tail already, nothing to do + // if head, move head to next[index] + // else + // move next[prev[index]] to next[index] (head has no prev) + // move prev[next[index]] to prev[index] + // prev[index] = tail + // next[tail] = index + // tail = index + if (index !== this.tail) { + if (index === this.head) { + this.head = this.next[index] + } else { + this.connect(this.prev[index], this.next[index]) + } + this.connect(this.tail, index) + this.tail = index + } + } + + get del () { + deprecatedMethod('del', 'delete') + return this.delete + } + delete (k) { + let deleted = false + if (this.size !== 0) { + const index = this.keyMap.get(k) + if (index !== undefined) { + deleted = true + if (this.size === 1) { + this.clear() + } else { + this.removeItemSize(index) + const v = this.valList[index] + if (this.isBackgroundFetch(v)) { + v.__abortController.abort() + } else { + this.dispose(v, k, 'delete') + if (this.disposeAfter) { + this.disposed.push([v, k, 'delete']) + } + } + this.keyMap.delete(k) + this.keyList[index] = null + this.valList[index] = null + if (index === this.tail) { + this.tail = this.prev[index] + } else if (index === this.head) { + this.head = this.next[index] + } else { + this.next[this.prev[index]] = this.next[index] + this.prev[this.next[index]] = this.prev[index] + } + this.size -- + this.free.push(index) + } + } + } + if (this.disposed) { + while (this.disposed.length) { + this.disposeAfter(...this.disposed.shift()) + } + } + return deleted + } + + clear () { + for (const index of this.rindexes({ allowStale: true })) { + const v = this.valList[index] + if (this.isBackgroundFetch(v)) { + v.__abortController.abort() + } else { + const k = this.keyList[index] + this.dispose(v, k, 'delete') + if (this.disposeAfter) { + this.disposed.push([v, k, 'delete']) + } + } + } + + this.keyMap.clear() + this.valList.fill(null) + this.keyList.fill(null) + if (this.ttls) { + this.ttls.fill(0) + this.starts.fill(0) + } + if (this.sizes) { + this.sizes.fill(0) + } + this.head = 0 + this.tail = 0 + this.initialFill = 1 + this.free.length = 0 + this.calculatedSize = 0 + this.size = 0 + if (this.disposed) { + while (this.disposed.length) { + this.disposeAfter(...this.disposed.shift()) + } + } + } + get reset () { + deprecatedMethod('reset', 'clear') + return this.clear + } + + get length () { + deprecatedProperty('length', 'size') + return this.size + } +} + +module.exports = LRUCache /***/ }), @@ -130684,8 +131504,9 @@ const minVersion = (range, loose) => { throw new Error(`Unexpected operation: ${comparator.operator}`) } }) - if (setMin && (!minver || gt(minver, setMin))) + if (setMin && (!minver || gt(minver, setMin))) { minver = setMin + } } if (minver && range.test(minver)) { @@ -130704,7 +131525,7 @@ module.exports = minVersion const SemVer = __nccwpck_require__(48088) const Comparator = __nccwpck_require__(91532) -const {ANY} = Comparator +const { ANY } = Comparator const Range = __nccwpck_require__(9828) const satisfies = __nccwpck_require__(6055) const gt = __nccwpck_require__(84123) @@ -130796,38 +131617,41 @@ const satisfies = __nccwpck_require__(6055) const compare = __nccwpck_require__(44309) module.exports = (versions, range, options) => { const set = [] - let min = null + let first = 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 + if (!first) { + first = version + } } else { if (prev) { - set.push([min, prev]) + set.push([first, prev]) } prev = null - min = null + first = null } } - if (min) - set.push([min, null]) + if (first) { + set.push([first, null]) + } const ranges = [] for (const [min, max] of set) { - if (min === max) + if (min === max) { ranges.push(min) - else if (!max && min === v[0]) + } else if (!max && min === v[0]) { ranges.push('*') - else if (!max) + } else if (!max) { ranges.push(`>=${min}`) - else if (min === v[0]) + } else if (min === v[0]) { ranges.push(`<=${max}`) - else + } else { ranges.push(`${min} - ${max}`) + } } const simplified = ranges.join(' || ') const original = typeof range.raw === 'string' ? range.raw : String(range) @@ -130883,8 +131707,9 @@ const compare = __nccwpck_require__(44309) // - Else return true const subset = (sub, dom, options = {}) => { - if (sub === dom) + if (sub === dom) { return true + } sub = new Range(sub, options) dom = new Range(dom, options) @@ -130894,73 +131719,84 @@ const subset = (sub, dom, options = {}) => { for (const simpleDom of dom.set) { const isSub = simpleSubset(simpleSub, simpleDom, options) sawNonNull = sawNonNull || isSub !== null - if (isSub) + 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) + if (sawNonNull) { return false + } } return true } const simpleSubset = (sub, dom, options) => { - if (sub === dom) + if (sub === dom) { return true + } if (sub.length === 1 && sub[0].semver === ANY) { - if (dom.length === 1 && dom[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') ] + } 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) + if (options.includePrerelease) { return true - else - dom = [ new Comparator('>=0.0.0') ] + } else { + dom = [new Comparator('>=0.0.0')] + } } const eqSet = new Set() let gt, lt for (const c of sub) { - if (c.operator === '>' || c.operator === '>=') + if (c.operator === '>' || c.operator === '>=') { gt = higherGT(gt, c, options) - else if (c.operator === '<' || c.operator === '<=') + } else if (c.operator === '<' || c.operator === '<=') { lt = lowerLT(lt, c, options) - else + } else { eqSet.add(c.semver) + } } - if (eqSet.size > 1) + if (eqSet.size > 1) { return null + } let gtltComp if (gt && lt) { gtltComp = compare(gt.semver, lt.semver, options) - if (gtltComp > 0) + if (gtltComp > 0) { return null - else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) + } 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)) + if (gt && !satisfies(eq, String(gt), options)) { return null + } - if (lt && !satisfies(eq, String(lt), options)) + if (lt && !satisfies(eq, String(lt), options)) { return null + } for (const c of dom) { - if (!satisfies(eq, String(c), options)) + if (!satisfies(eq, String(c), options)) { return false + } } return true @@ -130996,10 +131832,12 @@ const simpleSubset = (sub, dom, options) => { } if (c.operator === '>' || c.operator === '>=') { higher = higherGT(gt, c, options) - if (higher === c && higher !== gt) + if (higher === c && higher !== gt) { return false - } else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) + } + } else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) { return false + } } if (lt) { if (needDomLTPre) { @@ -131012,37 +131850,44 @@ const simpleSubset = (sub, dom, options) => { } if (c.operator === '<' || c.operator === '<=') { lower = lowerLT(lt, c, options) - if (lower === c && lower !== lt) + if (lower === c && lower !== lt) { return false - } else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) + } + } else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) { return false + } } - if (!c.operator && (lt || gt) && gtltComp !== 0) + 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) + if (gt && hasDomLT && !lt && gtltComp !== 0) { return false + } - if (lt && hasDomGT && !gt && gtltComp !== 0) + 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) + if (needDomGTPre || needDomLTPre) { return false + } return true } // >=1.2.3 is lower than >1.2.3 const higherGT = (a, b, options) => { - if (!a) + if (!a) { return b + } const comp = compare(a.semver, b.semver, options) return comp > 0 ? a : comp < 0 ? b @@ -131052,8 +131897,9 @@ const higherGT = (a, b, options) => { // <=1.2.3 is higher than <1.2.3 const lowerLT = (a, b, options) => { - if (!a) + if (!a) { return b + } const comp = compare(a.semver, b.semver, options) return comp < 0 ? a : comp > 0 ? b diff --git a/package.json b/package.json index cc9afdd5b..bc9b272d3 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "lodash": "4.17.21", "probot": "12.2.2", "regex-parser": "2.2.11", - "semver": "7.3.5" + "semver": "7.3.6" }, "devDependencies": { "@koa-lite/joi-schema": "0.0.1", diff --git a/yarn.lock b/yarn.lock index aed804e20..10ac2f6fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3583,6 +3583,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lru-cache@^7.4.0: + version "7.7.3" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-7.7.3.tgz#98cd19eef89ce6a4a3c4502c17c833888677c252" + integrity sha512-WY9wjJNQt9+PZilnLbuFKM+SwDull9+6IAguOrarOMoOHTcJ9GnXSO11+Gw6c7xtDkBkthR57OZMtZKYr+1CEw== + lru_map@^0.3.3: version "0.3.3" resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd" @@ -4431,12 +4436,12 @@ semver-diff@^3.1.1: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@7.3.5, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5: - version "7.3.5" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.5.tgz#0b621c879348d8998e4b0e4be94b3f12e6018ef7" - integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== +semver@7.3.6, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5: + version "7.3.6" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.6.tgz#5d73886fb9c0c6602e79440b97165c29581cbb2b" + integrity sha512-HZWqcgwLsjaX1HBD31msI/rXktuIhS+lWvdE4kN9z+8IVT4Itc7vqU2WvYsyD6/sjYCt4dEKH/m1M3dwI9CC5w== dependencies: - lru-cache "^6.0.0" + lru-cache "^7.4.0" semver@^6.0.0, semver@^6.2.0, semver@^6.3.0: version "6.3.0"