semver 5.7.1 → 6.1.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # changes log
2
2
 
3
+ ## 6.0
4
+
5
+ * Fix `intersects` logic.
6
+
7
+ This is technically a bug fix, but since it is also a change to behavior
8
+ that may require users updating their code, it is marked as a major
9
+ version increment.
10
+
3
11
  ## 5.7
4
12
 
5
13
  * Add `minVersion` method
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.
@@ -398,15 +401,30 @@ range, use the `satisfies(version, range)` function.
398
401
 
399
402
  * `coerce(version)`: Coerces a string to semver if possible
400
403
 
401
- This aims to provide a very forgiving translation of a non-semver string to
402
- semver. It looks for the first digit in a string, and consumes all
403
- remaining characters which satisfy at least a partial semver (e.g., `1`,
404
- `1.2`, `1.2.3`) up to the max permitted length (256 characters). Longer
405
- versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`). All
406
- surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes
407
- `3.4.0`). Only text which lacks digits will fail coercion (`version one`
408
- is not valid). The maximum length for any semver component considered for
409
- coercion is 16 characters; longer components will be ignored
410
- (`10000000000000000.4.7.4` becomes `4.7.4`). The maximum value for any
411
- semver component is `Number.MAX_SAFE_INTEGER || (2**53 - 1)`; higher value
412
- components are invalid (`9999999999999999.4.7.4` is likely invalid).
404
+ This aims to provide a very forgiving translation of a non-semver
405
+ string to semver. It looks for the first digit in a string, and
406
+ consumes all remaining characters which satisfy at least a partial semver
407
+ (e.g., `1`, `1.2`, `1.2.3`) up to the max permitted length (256 characters).
408
+ Longer versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`).
409
+ All surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes `3.4.0`).
410
+ Only text which lacks digits will fail coercion (`version one` is not valid).
411
+ The maximum length for any semver component considered for coercion is 16 characters;
412
+ longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
413
+ The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
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": "5.7.1",
3
+ "version": "6.1.2",
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
  }
@@ -934,16 +975,40 @@ Range.prototype.intersects = function (range, options) {
934
975
  }
935
976
 
936
977
  return this.set.some(function (thisComparators) {
937
- return thisComparators.every(function (thisComparator) {
938
- return range.set.some(function (rangeComparators) {
939
- return rangeComparators.every(function (rangeComparator) {
940
- return thisComparator.intersects(rangeComparator, options)
941
- })
978
+ return (
979
+ isSatisfiable(thisComparators, options) &&
980
+ range.set.some(function (rangeComparators) {
981
+ return (
982
+ isSatisfiable(rangeComparators, options) &&
983
+ thisComparators.every(function (thisComparator) {
984
+ return rangeComparators.every(function (rangeComparator) {
985
+ return thisComparator.intersects(rangeComparator, options)
986
+ })
987
+ })
988
+ )
942
989
  })
943
- })
990
+ )
944
991
  })
945
992
  }
946
993
 
994
+ // take a set of comparators and determine whether there
995
+ // exists a version which can satisfy it
996
+ function isSatisfiable (comparators, options) {
997
+ var result = true
998
+ var remainingComparators = comparators.slice()
999
+ var testComparator = remainingComparators.pop()
1000
+
1001
+ while (result && remainingComparators.length) {
1002
+ result = remainingComparators.every(function (otherComparator) {
1003
+ return testComparator.intersects(otherComparator, options)
1004
+ })
1005
+
1006
+ testComparator = remainingComparators.pop()
1007
+ }
1008
+
1009
+ return result
1010
+ }
1011
+
947
1012
  // Mostly just for testing and legacy API reasons
948
1013
  exports.toComparators = toComparators
949
1014
  function toComparators (range, options) {
@@ -1200,7 +1265,11 @@ Range.prototype.test = function (version) {
1200
1265
  }
1201
1266
 
1202
1267
  if (typeof version === 'string') {
1203
- version = new SemVer(version, this.options)
1268
+ try {
1269
+ version = new SemVer(version, this.options)
1270
+ } catch (er) {
1271
+ return false
1272
+ }
1204
1273
  }
1205
1274
 
1206
1275
  for (var i = 0; i < this.set.length; i++) {
@@ -1462,7 +1531,7 @@ function intersects (r1, r2, options) {
1462
1531
  }
1463
1532
 
1464
1533
  exports.coerce = coerce
1465
- function coerce (version) {
1534
+ function coerce (version, options) {
1466
1535
  if (version instanceof SemVer) {
1467
1536
  return version
1468
1537
  }
@@ -1479,5 +1548,5 @@ function coerce (version) {
1479
1548
 
1480
1549
  return parse(match[1] +
1481
1550
  '.' + (match[2] || '0') +
1482
- '.' + (match[3] || '0'))
1551
+ '.' + (match[3] || '0'), options)
1483
1552
  }