semver 7.8.3 → 7.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/classes/range.js +15 -2
  2. package/package.json +1 -1
package/classes/range.js CHANGED
@@ -277,6 +277,11 @@ const parseComparator = (comp, options) => {
277
277
 
278
278
  const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
279
279
 
280
+ const invalidXRangeOrder = (M, m, p) => (
281
+ (isX(M) && !isX(m)) ||
282
+ (isX(m) && p && !isX(p))
283
+ )
284
+
280
285
  // ~, ~> --> * (any, kinda silly)
281
286
  // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
282
287
  // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
@@ -294,6 +299,10 @@ const replaceTildes = (comp, options) => {
294
299
 
295
300
  const replaceTilde = (comp, options) => {
296
301
  const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE]
302
+ // if we're including prereleases in the match, then the lower bound is
303
+ // -0, the lowest possible prerelease value, just like x-ranges and carets.
304
+ // this keeps `~1.2` equivalent to the `1.2.x` x-range it's documented as.
305
+ const z = options.includePrerelease ? '-0' : ''
297
306
  return comp.replace(r, (_, M, m, p, pr) => {
298
307
  debug('tilde', comp, _, M, m, p, pr)
299
308
  let ret
@@ -301,10 +310,10 @@ const replaceTilde = (comp, options) => {
301
310
  if (isX(M)) {
302
311
  ret = ''
303
312
  } else if (isX(m)) {
304
- ret = `>=${M}.0.0 <${+M + 1}.0.0-0`
313
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`
305
314
  } else if (isX(p)) {
306
315
  // ~1.2 == >=1.2.0 <1.3.0-0
307
- ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`
316
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`
308
317
  } else if (pr) {
309
318
  debug('replaceTilde pr', pr)
310
319
  ret = `>=${M}.${m}.${p}-${pr
@@ -402,6 +411,10 @@ const replaceXRange = (comp, options) => {
402
411
  const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE]
403
412
  return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
404
413
  debug('xRange', comp, ret, gtlt, M, m, p, pr)
414
+ if (invalidXRangeOrder(M, m, p)) {
415
+ return comp
416
+ }
417
+
405
418
  const xM = isX(M)
406
419
  const xm = xM || isX(m)
407
420
  const xp = xm || isX(p)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "7.8.3",
3
+ "version": "7.8.5",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "index.js",
6
6
  "scripts": {