Skip to content

Commit 49689c3

Browse files
generate dist
1 parent ca58102 commit 49689c3

File tree

1 file changed

+87
-52
lines changed

1 file changed

+87
-52
lines changed

dist/index.js

Lines changed: 87 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8601,6 +8601,7 @@ class Comparator {
86018601
}
86028602
}
86038603

8604+
comp = comp.trim().split(/\s+/).join(' ')
86048605
debug('comparator', comp, options)
86058606
this.options = options
86068607
this.loose = !!options.loose
@@ -8718,7 +8719,7 @@ class Comparator {
87188719
module.exports = Comparator
87198720

87208721
const parseOptions = __nccwpck_require__(785)
8721-
const { re, t } = __nccwpck_require__(9523)
8722+
const { safeRe: re, t } = __nccwpck_require__(9523)
87228723
const cmp = __nccwpck_require__(5098)
87238724
const debug = __nccwpck_require__(427)
87248725
const SemVer = __nccwpck_require__(8088)
@@ -8758,19 +8759,26 @@ class Range {
87588759
this.loose = !!options.loose
87598760
this.includePrerelease = !!options.includePrerelease
87608761

8761-
// First, split based on boolean or ||
8762+
// First reduce all whitespace as much as possible so we do not have to rely
8763+
// on potentially slow regexes like \s*. This is then stored and used for
8764+
// future error messages as well.
87628765
this.raw = range
8763-
this.set = range
8766+
.trim()
8767+
.split(/\s+/)
8768+
.join(' ')
8769+
8770+
// First, split on ||
8771+
this.set = this.raw
87648772
.split('||')
87658773
// map the range to a 2d array of comparators
8766-
.map(r => this.parseRange(r.trim()))
8774+
.map(r => this.parseRange(r))
87678775
// throw out any comparator lists that are empty
87688776
// this generally means that it was not a valid range, which is allowed
87698777
// in loose mode, but will still throw if the WHOLE range is invalid.
87708778
.filter(c => c.length)
87718779

87728780
if (!this.set.length) {
8773-
throw new TypeError(`Invalid SemVer Range: ${range}`)
8781+
throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
87748782
}
87758783

87768784
// if we have any that are not the null set, throw out null sets.
@@ -8796,9 +8804,7 @@ class Range {
87968804

87978805
format () {
87988806
this.range = this.set
8799-
.map((comps) => {
8800-
return comps.join(' ').trim()
8801-
})
8807+
.map((comps) => comps.join(' ').trim())
88028808
.join('||')
88038809
.trim()
88048810
return this.range
@@ -8809,8 +8815,6 @@ class Range {
88098815
}
88108816

88118817
parseRange (range) {
8812-
range = range.trim()
8813-
88148818
// memoize range parsing for performance.
88158819
// this is a very hot path, and fully deterministic.
88168820
const memoOpts =
@@ -8837,9 +8841,6 @@ class Range {
88378841
// `^ 1.2.3` => `^1.2.3`
88388842
range = range.replace(re[t.CARETTRIM], caretTrimReplace)
88398843

8840-
// normalize spaces
8841-
range = range.split(/\s+/).join(' ')
8842-
88438844
// At this point, the range is completely trimmed and
88448845
// ready to be split into comparators.
88458846

@@ -8935,7 +8936,7 @@ const Comparator = __nccwpck_require__(1532)
89358936
const debug = __nccwpck_require__(427)
89368937
const SemVer = __nccwpck_require__(8088)
89378938
const {
8938-
re,
8939+
safeRe: re,
89398940
t,
89408941
comparatorTrimReplace,
89418942
tildeTrimReplace,
@@ -8989,10 +8990,13 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
89898990
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
89908991
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
89918992
// ~0.0.1 --> >=0.0.1 <0.1.0-0
8992-
const replaceTildes = (comp, options) =>
8993-
comp.trim().split(/\s+/).map((c) => {
8994-
return replaceTilde(c, options)
8995-
}).join(' ')
8993+
const replaceTildes = (comp, options) => {
8994+
return comp
8995+
.trim()
8996+
.split(/\s+/)
8997+
.map((c) => replaceTilde(c, options))
8998+
.join(' ')
8999+
}
89969000

89979001
const replaceTilde = (comp, options) => {
89989002
const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
@@ -9030,10 +9034,13 @@ const replaceTilde = (comp, options) => {
90309034
// ^1.2.0 --> >=1.2.0 <2.0.0-0
90319035
// ^0.0.1 --> >=0.0.1 <0.0.2-0
90329036
// ^0.1.0 --> >=0.1.0 <0.2.0-0
9033-
const replaceCarets = (comp, options) =>
9034-
comp.trim().split(/\s+/).map((c) => {
9035-
return replaceCaret(c, options)
9036-
}).join(' ')
9037+
const replaceCarets = (comp, options) => {
9038+
return comp
9039+
.trim()
9040+
.split(/\s+/)
9041+
.map((c) => replaceCaret(c, options))
9042+
.join(' ')
9043+
}
90379044

90389045
const replaceCaret = (comp, options) => {
90399046
debug('caret', comp, options)
@@ -9090,9 +9097,10 @@ const replaceCaret = (comp, options) => {
90909097

90919098
const replaceXRanges = (comp, options) => {
90929099
debug('replaceXRanges', comp, options)
9093-
return comp.split(/\s+/).map((c) => {
9094-
return replaceXRange(c, options)
9095-
}).join(' ')
9100+
return comp
9101+
.split(/\s+/)
9102+
.map((c) => replaceXRange(c, options))
9103+
.join(' ')
90969104
}
90979105

90989106
const replaceXRange = (comp, options) => {
@@ -9175,12 +9183,15 @@ const replaceXRange = (comp, options) => {
91759183
const replaceStars = (comp, options) => {
91769184
debug('replaceStars', comp, options)
91779185
// Looseness is ignored here. star is always as loose as it gets!
9178-
return comp.trim().replace(re[t.STAR], '')
9186+
return comp
9187+
.trim()
9188+
.replace(re[t.STAR], '')
91799189
}
91809190

91819191
const replaceGTE0 = (comp, options) => {
91829192
debug('replaceGTE0', comp, options)
9183-
return comp.trim()
9193+
return comp
9194+
.trim()
91849195
.replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
91859196
}
91869197

@@ -9218,7 +9229,7 @@ const hyphenReplace = incPr => ($0,
92189229
to = `<=${to}`
92199230
}
92209231

9221-
return (`${from} ${to}`).trim()
9232+
return `${from} ${to}`.trim()
92229233
}
92239234

92249235
const testSet = (set, version, options) => {
@@ -9265,7 +9276,7 @@ const testSet = (set, version, options) => {
92659276

92669277
const debug = __nccwpck_require__(427)
92679278
const { MAX_LENGTH, MAX_SAFE_INTEGER } = __nccwpck_require__(2293)
9268-
const { re, t } = __nccwpck_require__(9523)
9279+
const { safeRe: re, t } = __nccwpck_require__(9523)
92699280

92709281
const parseOptions = __nccwpck_require__(785)
92719282
const { compareIdentifiers } = __nccwpck_require__(2463)
@@ -9556,8 +9567,10 @@ class SemVer {
95569567
default:
95579568
throw new Error(`invalid increment argument: ${release}`)
95589569
}
9559-
this.format()
9560-
this.raw = this.version
9570+
this.raw = this.format()
9571+
if (this.build.length) {
9572+
this.raw += `+${this.build.join('.')}`
9573+
}
95619574
return this
95629575
}
95639576
}
@@ -9644,7 +9657,7 @@ module.exports = cmp
96449657

96459658
const SemVer = __nccwpck_require__(8088)
96469659
const parse = __nccwpck_require__(5925)
9647-
const { re, t } = __nccwpck_require__(9523)
9660+
const { safeRe: re, t } = __nccwpck_require__(9523)
96489661

96499662
const coerce = (version, options) => {
96509663
if (version instanceof SemVer) {
@@ -9752,6 +9765,35 @@ const diff = (version1, version2) => {
97529765
const highVersion = v1Higher ? v1 : v2
97539766
const lowVersion = v1Higher ? v2 : v1
97549767
const highHasPre = !!highVersion.prerelease.length
9768+
const lowHasPre = !!lowVersion.prerelease.length
9769+
9770+
if (lowHasPre && !highHasPre) {
9771+
// Going from prerelease -> no prerelease requires some special casing
9772+
9773+
// If the low version has only a major, then it will always be a major
9774+
// Some examples:
9775+
// 1.0.0-1 -> 1.0.0
9776+
// 1.0.0-1 -> 1.1.1
9777+
// 1.0.0-1 -> 2.0.0
9778+
if (!lowVersion.patch && !lowVersion.minor) {
9779+
return 'major'
9780+
}
9781+
9782+
// Otherwise it can be determined by checking the high version
9783+
9784+
if (highVersion.patch) {
9785+
// anything higher than a patch bump would result in the wrong version
9786+
return 'patch'
9787+
}
9788+
9789+
if (highVersion.minor) {
9790+
// anything higher than a minor bump would result in the wrong version
9791+
return 'minor'
9792+
}
9793+
9794+
// bumping major/minor/patch all have same result
9795+
return 'major'
9796+
}
97559797

97569798
// add the `pre` prefix if we are going to a prerelease version
97579799
const prefix = highHasPre ? 'pre' : ''
@@ -9768,26 +9810,8 @@ const diff = (version1, version2) => {
97689810
return prefix + 'patch'
97699811
}
97709812

9771-
// at this point we know stable versions match but overall versions are not equal,
9772-
// so either they are both prereleases, or the lower version is a prerelease
9773-
9774-
if (highHasPre) {
9775-
// high and low are preleases
9776-
return 'prerelease'
9777-
}
9778-
9779-
if (lowVersion.patch) {
9780-
// anything higher than a patch bump would result in the wrong version
9781-
return 'patch'
9782-
}
9783-
9784-
if (lowVersion.minor) {
9785-
// anything higher than a minor bump would result in the wrong version
9786-
return 'minor'
9787-
}
9788-
9789-
// bumping major/minor/patch all have same result
9790-
return 'major'
9813+
// high and low are preleases
9814+
return 'prerelease'
97919815
}
97929816

97939817
module.exports = diff
@@ -10217,16 +10241,27 @@ exports = module.exports = {}
1021710241

1021810242
// The actual regexps go on exports.re
1021910243
const re = exports.re = []
10244+
const safeRe = exports.safeRe = []
1022010245
const src = exports.src = []
1022110246
const t = exports.t = {}
1022210247
let R = 0
1022310248

1022410249
const createToken = (name, value, isGlobal) => {
10250+
// Replace all greedy whitespace to prevent regex dos issues. These regex are
10251+
// used internally via the safeRe object since all inputs in this library get
10252+
// normalized first to trim and collapse all extra whitespace. The original
10253+
// regexes are exported for userland consumption and lower level usage. A
10254+
// future breaking change could export the safer regex only with a note that
10255+
// all input should have extra whitespace removed.
10256+
const safe = value
10257+
.split('\\s*').join('\\s{0,1}')
10258+
.split('\\s+').join('\\s')
1022510259
const index = R++
1022610260
debug(name, index, value)
1022710261
t[name] = index
1022810262
src[index] = value
1022910263
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
10264+
safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined)
1023010265
}
1023110266

1023210267
// The following Regular Expressions can be used for tokenizing,

0 commit comments

Comments
 (0)