@@ -13,6 +13,12 @@ import (
13
13
type Constraints struct {
14
14
constraints [][]* constraint
15
15
containsPre []bool
16
+
17
+ // IncludePrerelease specifies if pre-releases should be included in
18
+ // the results. Note, if a constraint range has a prerelease than
19
+ // prereleases will be included for that AND group even if this is
20
+ // set to false.
21
+ IncludePrerelease bool
16
22
}
17
23
18
24
// NewConstraint returns a Constraints instance that a Version instance can
@@ -70,7 +76,7 @@ func (cs Constraints) Check(v *Version) bool {
70
76
for i , o := range cs .constraints {
71
77
joy := true
72
78
for _ , c := range o {
73
- if check , _ := c .check (v , cs .containsPre [i ]); ! check {
79
+ if check , _ := c .check (v , ( cs .IncludePrerelease || cs . containsPre [i ]) ); ! check {
74
80
joy = false
75
81
break
76
82
}
@@ -98,7 +104,7 @@ func (cs Constraints) Validate(v *Version) (bool, []error) {
98
104
for _ , c := range o {
99
105
// Before running the check handle the case there the version is
100
106
// a prerelease and the check is not searching for prereleases.
101
- if ! cs .containsPre [i ] && v .pre != "" {
107
+ if ! ( cs .IncludePrerelease || cs . containsPre [i ]) && v .pre != "" {
102
108
if ! prerelesase {
103
109
em := fmt .Errorf ("%s is a prerelease version and the constraint is only looking for release versions" , v )
104
110
e = append (e , em )
@@ -108,7 +114,7 @@ func (cs Constraints) Validate(v *Version) (bool, []error) {
108
114
109
115
} else {
110
116
111
- if _ , err := c .check (v , cs .containsPre [i ]); err != nil {
117
+ if _ , err := c .check (v , ( cs .IncludePrerelease || cs . containsPre [i ]) ); err != nil {
112
118
e = append (e , err )
113
119
joy = false
114
120
}
0 commit comments