@@ -13,6 +13,12 @@ import (
1313type Constraints struct {
1414constraints [][]* constraint
1515containsPre []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 {
7076for i , o := range cs .constraints {
7177joy := true
7278for _ , 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 {
7480joy = false
7581break
7682}
@@ -98,7 +104,7 @@ func (cs Constraints) Validate(v *Version) (bool, []error) {
98104for _ , 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 != "" {
102108if ! prerelesase {
103109em := fmt .Errorf ("%s is a prerelease version and the constraint is only looking for release versions" , v )
104110e = 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 {
112118e = append (e , err )
113119joy = false
114120}
0 commit comments