semver 6.0.0 → 6.1.3

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 (3) hide show
  1. package/README.md +21 -2
  2. package/package.json +3 -3
  3. package/semver.js +62 -12
package/README.md CHANGED
@@ -4,7 +4,7 @@ semver(1) -- The semantic versioner for npm
4
4
  ## Install
5
5
 
6
6
  ```bash
7
- npm install --save semver
7
+ npm install semver
8
8
  ````
9
9
 
10
10
  ## Usage
@@ -231,7 +231,7 @@ comparator. Allows minor-level changes if not.
231
231
 
232
232
  #### Caret Ranges `^1.2.3` `^0.2.5` `^0.0.4`
233
233
 
234
- Allows changes that do not modify the left-most non-zero digit in the
234
+ Allows changes that do not modify the left-most non-zero element in the
235
235
  `[major, minor, patch]` tuple. In other words, this allows patch and
236
236
  minor updates for versions `1.0.0` and above, patch updates for
237
237
  versions `0.X >=0.1.0`, and *no* updates for versions `0.0.X`.
@@ -354,6 +354,9 @@ strings that they parse.
354
354
  `v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
355
355
  * `rcompare(v1, v2)`: The reverse of compare. Sorts an array of versions
356
356
  in descending order when passed to `Array.sort()`.
357
+ * `compareBuild(v1, v2)`: The same as `compare` but considers `build` when two versions
358
+ are equal. Sorts in ascending order if passed to `Array.sort()`.
359
+ `v2` is greater. Sorts in ascending order if passed to `Array.sort()`.
357
360
  * `diff(v1, v2)`: Returns difference between two versions by the release type
358
361
  (`major`, `premajor`, `minor`, `preminor`, `patch`, `prepatch`, or `prerelease`),
359
362
  or null if the versions are the same.
@@ -409,3 +412,19 @@ The maximum length for any semver component considered for coercion is 16 chara
409
412
  longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
410
413
  The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
411
414
  higher value components are invalid (`9999999999999999.4.7.4` is likely invalid).
415
+
416
+ ### Clean
417
+
418
+ * `clean(version)`: Clean a string to be a valid semver if possible
419
+
420
+ This will return a cleaned and trimmed semver version. If the provided version is not valid a null will be returned. This does not work for ranges.
421
+
422
+ ex.
423
+ * `s.clean(' = v 2.1.5foo')`: `null`
424
+ * `s.clean(' = v 2.1.5foo', { loose: true })`: `'2.1.5-foo'`
425
+ * `s.clean(' = v 2.1.5-foo')`: `null`
426
+ * `s.clean(' = v 2.1.5-foo', { loose: true })`: `'2.1.5-foo'`
427
+ * `s.clean('=v2.1.5')`: `'2.1.5'`
428
+ * `s.clean(' =v2.1.5')`: `2.1.5`
429
+ * `s.clean(' 2.1.5 ')`: `'2.1.5'`
430
+ * `s.clean('~1.0.0')`: `null`
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "6.0.0",
3
+ "version": "6.1.3",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "semver.js",
6
6
  "scripts": {
7
7
  "test": "tap",
8
8
  "preversion": "npm test",
9
9
  "postversion": "npm publish",
10
- "postpublish": "git push origin --all; git push origin --tags"
10
+ "postpublish": "git push origin --follow-tags"
11
11
  },
12
12
  "devDependencies": {
13
- "tap": "^13.0.0-rc.18"
13
+ "tap": "^14.1.6"
14
14
  },
15
15
  "license": "ISC",
16
16
  "repository": "https://github.com/npm/node-semver",
package/semver.js CHANGED
@@ -425,6 +425,30 @@ SemVer.prototype.comparePre = function (other) {
425
425
  } while (++i)
426
426
  }
427
427
 
428
+ SemVer.prototype.compareBuild = function (other) {
429
+ if (!(other instanceof SemVer)) {
430
+ other = new SemVer(other, this.options)
431
+ }
432
+
433
+ var i = 0
434
+ do {
435
+ var a = this.build[i]
436
+ var b = other.build[i]
437
+ debug('prerelease compare', i, a, b)
438
+ if (a === undefined && b === undefined) {
439
+ return 0
440
+ } else if (b === undefined) {
441
+ return 1
442
+ } else if (a === undefined) {
443
+ return -1
444
+ } else if (a === b) {
445
+ continue
446
+ } else {
447
+ return compareIdentifiers(a, b)
448
+ }
449
+ } while (++i)
450
+ }
451
+
428
452
  // preminor will bump the version up to the next minor release, and immediately
429
453
  // down to pre-release. premajor and prepatch work the same way.
430
454
  SemVer.prototype.inc = function (release, identifier) {
@@ -619,6 +643,13 @@ function compareLoose (a, b) {
619
643
  return compare(a, b, true)
620
644
  }
621
645
 
646
+ exports.compareBuild = compareBuild
647
+ function compareBuild (a, b, loose) {
648
+ var versionA = new SemVer(a, loose)
649
+ var versionB = new SemVer(b, loose)
650
+ return versionA.compare(versionB) || versionA.compareBuild(versionB)
651
+ }
652
+
622
653
  exports.rcompare = rcompare
623
654
  function rcompare (a, b, loose) {
624
655
  return compare(b, a, loose)
@@ -627,14 +658,14 @@ function rcompare (a, b, loose) {
627
658
  exports.sort = sort
628
659
  function sort (list, loose) {
629
660
  return list.sort(function (a, b) {
630
- return exports.compare(a, b, loose)
661
+ return exports.compareBuild(a, b, loose)
631
662
  })
632
663
  }
633
664
 
634
665
  exports.rsort = rsort
635
666
  function rsort (list, loose) {
636
667
  return list.sort(function (a, b) {
637
- return exports.rcompare(a, b, loose)
668
+ return exports.compareBuild(b, a, loose)
638
669
  })
639
670
  }
640
671
 
@@ -754,7 +785,7 @@ Comparator.prototype.parse = function (comp) {
754
785
  throw new TypeError('Invalid comparator: ' + comp)
755
786
  }
756
787
 
757
- this.operator = m[1]
788
+ this.operator = m[1] !== undefined ? m[1] : ''
758
789
  if (this.operator === '=') {
759
790
  this.operator = ''
760
791
  }
@@ -774,12 +805,16 @@ Comparator.prototype.toString = function () {
774
805
  Comparator.prototype.test = function (version) {
775
806
  debug('Comparator.test', version, this.options.loose)
776
807
 
777
- if (this.semver === ANY) {
808
+ if (this.semver === ANY || version === ANY) {
778
809
  return true
779
810
  }
780
811
 
781
812
  if (typeof version === 'string') {
782
- version = new SemVer(version, this.options)
813
+ try {
814
+ version = new SemVer(version, this.options)
815
+ } catch (er) {
816
+ return false
817
+ }
783
818
  }
784
819
 
785
820
  return cmp(version, this.operator, this.semver, this.options)
@@ -800,9 +835,15 @@ Comparator.prototype.intersects = function (comp, options) {
800
835
  var rangeTmp
801
836
 
802
837
  if (this.operator === '') {
838
+ if (this.value === '') {
839
+ return true
840
+ }
803
841
  rangeTmp = new Range(comp.value, options)
804
842
  return satisfies(this.value, rangeTmp, options)
805
843
  } else if (comp.operator === '') {
844
+ if (comp.value === '') {
845
+ return true
846
+ }
806
847
  rangeTmp = new Range(this.value, options)
807
848
  return satisfies(comp.semver, rangeTmp, options)
808
849
  }
@@ -1123,10 +1164,14 @@ function replaceXRange (comp, options) {
1123
1164
  gtlt = ''
1124
1165
  }
1125
1166
 
1167
+ // if we're including prereleases in the match, then we need
1168
+ // to fix this to -0, the lowest possible prerelease value
1169
+ pr = options.includePrerelease ? '-0' : ''
1170
+
1126
1171
  if (xM) {
1127
1172
  if (gtlt === '>' || gtlt === '<') {
1128
1173
  // nothing is allowed
1129
- ret = '<0.0.0'
1174
+ ret = '<0.0.0-0'
1130
1175
  } else {
1131
1176
  // nothing is forbidden
1132
1177
  ret = '*'
@@ -1163,11 +1208,12 @@ function replaceXRange (comp, options) {
1163
1208
  }
1164
1209
  }
1165
1210
 
1166
- ret = gtlt + M + '.' + m + '.' + p
1211
+ ret = gtlt + M + '.' + m + '.' + p + pr
1167
1212
  } else if (xm) {
1168
- ret = '>=' + M + '.0.0 <' + (+M + 1) + '.0.0'
1213
+ ret = '>=' + M + '.0.0' + pr + ' <' + (+M + 1) + '.0.0' + pr
1169
1214
  } else if (xp) {
1170
- ret = '>=' + M + '.' + m + '.0 <' + M + '.' + (+m + 1) + '.0'
1215
+ ret = '>=' + M + '.' + m + '.0' + pr +
1216
+ ' <' + M + '.' + (+m + 1) + '.0' + pr
1171
1217
  }
1172
1218
 
1173
1219
  debug('xRange return', ret)
@@ -1224,7 +1270,11 @@ Range.prototype.test = function (version) {
1224
1270
  }
1225
1271
 
1226
1272
  if (typeof version === 'string') {
1227
- version = new SemVer(version, this.options)
1273
+ try {
1274
+ version = new SemVer(version, this.options)
1275
+ } catch (er) {
1276
+ return false
1277
+ }
1228
1278
  }
1229
1279
 
1230
1280
  for (var i = 0; i < this.set.length; i++) {
@@ -1486,7 +1536,7 @@ function intersects (r1, r2, options) {
1486
1536
  }
1487
1537
 
1488
1538
  exports.coerce = coerce
1489
- function coerce (version) {
1539
+ function coerce (version, options) {
1490
1540
  if (version instanceof SemVer) {
1491
1541
  return version
1492
1542
  }
@@ -1503,5 +1553,5 @@ function coerce (version) {
1503
1553
 
1504
1554
  return parse(match[1] +
1505
1555
  '.' + (match[2] || '0') +
1506
- '.' + (match[3] || '0'))
1556
+ '.' + (match[3] || '0'), options)
1507
1557
  }