@@ -13,6 +13,12 @@ import (
1313type Constraints struct {
1414 constraints [][]* constraint
1515 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
1622}
1723
1824// NewConstraint returns a Constraints instance that a Version instance can
@@ -70,7 +76,7 @@ func (cs Constraints) Check(v *Version) bool {
7076 for i , o := range cs .constraints {
7177 joy := true
7278 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 {
7480 joy = false
7581 break
7682 }
@@ -98,7 +104,7 @@ func (cs Constraints) Validate(v *Version) (bool, []error) {
98104 for _ , c := range o {
99105 // Before running the check handle the case there the version is
100106 // 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 != "" {
102108 if ! prerelesase {
103109 em := fmt .Errorf ("%s is a prerelease version and the constraint is only looking for release versions" , v )
104110 e = append (e , em )
@@ -108,7 +114,7 @@ func (cs Constraints) Validate(v *Version) (bool, []error) {
108114
109115 } else {
110116
111- if _ , err := c .check (v , cs .containsPre [i ]); err != nil {
117+ if _ , err := c .check (v , ( cs .IncludePrerelease || cs . containsPre [i ]) ); err != nil {
112118 e = append (e , err )
113119 joy = false
114120 }
0 commit comments