semver 5.7.1 → 6.0.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.
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
@@ -398,15 +398,14 @@ range, use the `satisfies(version, range)` function.
398
398
 
399
399
  * `coerce(version)`: Coerces a string to semver if possible
400
400
 
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).
401
+ This aims to provide a very forgiving translation of a non-semver
402
+ string to semver. It looks for the first digit in a string, and
403
+ consumes all remaining characters which satisfy at least a partial semver
404
+ (e.g., `1`, `1.2`, `1.2.3`) up to the max permitted length (256 characters).
405
+ Longer versions are simply truncated (`4.6.3.9.2-alpha2` becomes `4.6.3`).
406
+ All surrounding text is simply ignored (`v3.4 replaces v3.3.1` becomes `3.4.0`).
407
+ Only text which lacks digits will fail coercion (`version one` is not valid).
408
+ The maximum length for any semver component considered for coercion is 16 characters;
409
+ longer components will be ignored (`10000000000000000.4.7.4` becomes `4.7.4`).
410
+ The maximum value for any semver component is `Integer.MAX_SAFE_INTEGER || (2**53 - 1)`;
411
+ higher value components are invalid (`9999999999999999.4.7.4` is likely invalid).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semver",
3
- "version": "5.7.1",
3
+ "version": "6.0.0",
4
4
  "description": "The semantic version parser used by npm.",
5
5
  "main": "semver.js",
6
6
  "scripts": {
package/semver.js CHANGED
@@ -934,16 +934,40 @@ Range.prototype.intersects = function (range, options) {
934
934
  }
935
935
 
936
936
  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
- })
937
+ return (
938
+ isSatisfiable(thisComparators, options) &&
939
+ range.set.some(function (rangeComparators) {
940
+ return (
941
+ isSatisfiable(rangeComparators, options) &&
942
+ thisComparators.every(function (thisComparator) {
943
+ return rangeComparators.every(function (rangeComparator) {
944
+ return thisComparator.intersects(rangeComparator, options)
945
+ })
946
+ })
947
+ )
942
948
  })
943
- })
949
+ )
944
950
  })
945
951
  }
946
952
 
953
+ // take a set of comparators and determine whether there
954
+ // exists a version which can satisfy it
955
+ function isSatisfiable (comparators, options) {
956
+ var result = true
957
+ var remainingComparators = comparators.slice()
958
+ var testComparator = remainingComparators.pop()
959
+
960
+ while (result && remainingComparators.length) {
961
+ result = remainingComparators.every(function (otherComparator) {
962
+ return testComparator.intersects(otherComparator, options)
963
+ })
964
+
965
+ testComparator = remainingComparators.pop()
966
+ }
967
+
968
+ return result
969
+ }
970
+
947
971
  // Mostly just for testing and legacy API reasons
948
972
  exports.toComparators = toComparators
949
973
  function toComparators (range, options) {