| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Handles version numbers, following the [Semantic Versioning][semver] spec. | 5 /// Handles version numbers, following the [Semantic Versioning][semver] spec. |
| 6 /// | 6 /// |
| 7 /// [semver]: http://semver.org/ | 7 /// [semver]: http://semver.org/ |
| 8 library pub.version; | 8 library pub.version; |
| 9 | 9 |
| 10 import 'dart:math'; | 10 import 'dart:math'; |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 includeMin == other.includeMin && | 467 includeMin == other.includeMin && |
| 468 includeMax == other.includeMax; | 468 includeMax == other.includeMax; |
| 469 } | 469 } |
| 470 | 470 |
| 471 bool get isEmpty => false; | 471 bool get isEmpty => false; |
| 472 | 472 |
| 473 bool get isAny => min == null && max == null; | 473 bool get isAny => min == null && max == null; |
| 474 | 474 |
| 475 /// Tests if [other] matches falls within this version range. | 475 /// Tests if [other] matches falls within this version range. |
| 476 bool allows(Version other) { | 476 bool allows(Version other) { |
| 477 if (min != null && other < min) return false; | 477 if (min != null) { |
| 478 if (min != null && !includeMin && other == min) return false; | 478 if (other < min) return false; |
| 479 if (max != null && other > max) return false; | 479 if (!includeMin && other == min) return false; |
| 480 if (max != null && !includeMax && other == max) return false; | 480 } |
| 481 |
| 482 if (max != null) { |
| 483 if (other > max) return false; |
| 484 if (!includeMax && other == max) return false; |
| 485 |
| 486 // If the max isn't itself a pre-release, don't allow any pre-release |
| 487 // versions of the max. |
| 488 // |
| 489 // See: https://www.npmjs.org/doc/misc/semver.html |
| 490 if (!includeMax && |
| 491 !max.isPreRelease && other.isPreRelease && |
| 492 other.major == max.major && other.minor == max.minor && |
| 493 other.patch == max.patch) { |
| 494 return false; |
| 495 } |
| 496 } |
| 497 |
| 481 return true; | 498 return true; |
| 482 } | 499 } |
| 483 | 500 |
| 484 VersionConstraint intersect(VersionConstraint other) { | 501 VersionConstraint intersect(VersionConstraint other) { |
| 485 if (other.isEmpty) return other; | 502 if (other.isEmpty) return other; |
| 486 | 503 |
| 487 // A range and a Version just yields the version if it's in the range. | 504 // A range and a Version just yields the version if it's in the range. |
| 488 if (other is Version) { | 505 if (other is Version) { |
| 489 return allows(other) ? other : VersionConstraint.empty; | 506 return allows(other) ? other : VersionConstraint.empty; |
| 490 } | 507 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 583 |
| 567 class _EmptyVersion implements VersionConstraint { | 584 class _EmptyVersion implements VersionConstraint { |
| 568 const _EmptyVersion(); | 585 const _EmptyVersion(); |
| 569 | 586 |
| 570 bool get isEmpty => true; | 587 bool get isEmpty => true; |
| 571 bool get isAny => false; | 588 bool get isAny => false; |
| 572 bool allows(Version other) => false; | 589 bool allows(Version other) => false; |
| 573 VersionConstraint intersect(VersionConstraint other) => this; | 590 VersionConstraint intersect(VersionConstraint other) => this; |
| 574 String toString() => '<empty>'; | 591 String toString() => '<empty>'; |
| 575 } | 592 } |
| OLD | NEW |