OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub_semver.src.version_range; | 5 library pub_semver.src.version_range; |
6 | 6 |
7 import 'version.dart'; | 7 import 'version.dart'; |
8 import 'version_constraint.dart'; | 8 import 'version_constraint.dart'; |
9 import 'version_union.dart'; | 9 import 'version_union.dart'; |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 bool allows(Version other) { | 78 bool allows(Version other) { |
79 if (min != null) { | 79 if (min != null) { |
80 if (other < min) return false; | 80 if (other < min) return false; |
81 if (!includeMin && other == min) return false; | 81 if (!includeMin && other == min) return false; |
82 } | 82 } |
83 | 83 |
84 if (max != null) { | 84 if (max != null) { |
85 if (other > max) return false; | 85 if (other > max) return false; |
86 if (!includeMax && other == max) return false; | 86 if (!includeMax && other == max) return false; |
87 | 87 |
88 // If the max isn't itself a pre-release, don't allow any pre-release | 88 |
89 // versions of the max. | 89 // Disallow pre-release versions that have the same major, minor, and |
90 // patch version as the max, but only if neither the max nor the min is a | |
91 // pre-release of that version. This ensures that "^1.2.3" doesn't include | |
92 // "2.0.0-pre", while also allowing both ">=2.0.0-pre.2 <2.0.0" and | |
93 // ">=1.2.3 <2.0.0-pre.7" to match "2.0.0-pre.5". | |
90 // | 94 // |
91 // See: https://www.npmjs.org/doc/misc/semver.html | 95 // It's worth noting that this is different than [NPM's semantics][]. NPM |
92 if (!includeMax && | 96 // disallows **all** pre-release versions unless their major, minor, and |
97 // patch numbers match those of a prerelease min or max. This ensures that | |
98 // no prerelease versions will ever be selected if the user doesn't | |
99 // explicitly allow them. | |
100 // | |
101 // [NPM's semantics]: https://www.npmjs.org/doc/misc/semver.html#prereleas e-tags | |
102 // | |
103 // Instead, we ensure that release versions will always be preferred to | |
Bob Nystrom
2015/05/20 21:48:45
"to" -> "over"
nweiz
2015/05/20 23:46:55
Done.
| |
104 // prerelease versions by ordering the release versions first in | |
105 // [Version.prioritize]. This means that constraints like "any" or | |
106 // ">1.2.3" can still match prerelease versions if they're the only things | |
107 // available. | |
108 var maxIsReleaseOfOther = !includeMax && | |
93 !max.isPreRelease && other.isPreRelease && | 109 !max.isPreRelease && other.isPreRelease && |
94 other.major == max.major && other.minor == max.minor && | 110 _equalsWithoutPreRelease(other, max); |
95 other.patch == max.patch) { | 111 var minIsPreReleaseOfOther = min != null && min.isPreRelease && |
96 return false; | 112 _equalsWithoutPreRelease(other, min); |
97 } | 113 if (maxIsReleaseOfOther && !minIsPreReleaseOfOther) return false; |
98 } | 114 } |
99 | 115 |
100 return true; | 116 return true; |
101 } | 117 } |
102 | 118 |
119 bool _equalsWithoutPreRelease(Version version1, Version version2) => | |
120 version1.major == version2.major && | |
121 version1.minor == version2.minor && | |
122 version1.patch == version2.patch; | |
123 | |
103 bool allowsAll(VersionConstraint other) { | 124 bool allowsAll(VersionConstraint other) { |
104 if (other.isEmpty) return true; | 125 if (other.isEmpty) return true; |
105 if (other is Version) return allows(other); | 126 if (other is Version) return allows(other); |
106 | 127 |
107 if (other is VersionUnion) { | 128 if (other is VersionUnion) { |
108 return other.constraints.every((constraint) => allowsAll(constraint)); | 129 return other.constraints.every((constraint) => allowsAll(constraint)); |
109 } | 130 } |
110 | 131 |
111 if (other is VersionRange) { | 132 if (other is VersionRange) { |
112 if (min != null) { | 133 if (min != null) { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 if (max != null) { | 328 if (max != null) { |
308 if (min != null) buffer.write(' '); | 329 if (min != null) buffer.write(' '); |
309 buffer.write(includeMax ? '<=' : '<'); | 330 buffer.write(includeMax ? '<=' : '<'); |
310 buffer.write(max); | 331 buffer.write(max); |
311 } | 332 } |
312 | 333 |
313 if (min == null && max == null) buffer.write('any'); | 334 if (min == null && max == null) buffer.write('any'); |
314 return buffer.toString(); | 335 return buffer.toString(); |
315 } | 336 } |
316 } | 337 } |
OLD | NEW |