semver 6.0.0 → 6.1.0

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 +5 -2
  2. package/package.json +3 -3
  3. package/semver.js +41 -8
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.
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
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,7 +805,7 @@ 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
 
@@ -800,9 +831,15 @@ Comparator.prototype.intersects = function (comp, options) {
800
831
  var rangeTmp
801
832
 
802
833
  if (this.operator === '') {
834
+ if (this.value === '') {
835
+ return true
836
+ }
803
837
  rangeTmp = new Range(comp.value, options)
804
838
  return satisfies(this.value, rangeTmp, options)
805
839
  } else if (comp.operator === '') {
840
+ if (comp.value === '') {
841
+ return true
842
+ }
806
843
  rangeTmp = new Range(this.value, options)
807
844
  return satisfies(comp.semver, rangeTmp, options)
808
845
  }
@@ -1219,10 +1256,6 @@ function hyphenReplace ($0,
1219
1256
 
1220
1257
  // if ANY of the sets match ALL of its comparators, then pass
1221
1258
  Range.prototype.test = function (version) {
1222
- if (!version) {
1223
- return false
1224
- }
1225
-
1226
1259
  if (typeof version === 'string') {
1227
1260
  version = new SemVer(version, this.options)
1228
1261
  }