Skip to content

Commit 68734ec

Browse files
committed
adds semver module resolution
1 parent a32698b commit 68734ec

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

build/build.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"path"
1111
"path/filepath"
1212
"strings"
13+
14+
"github.com/Masterminds/semver"
15+
"github.com/barelyhuman/goblin/resolver"
1316
)
1417

1518
type Binary struct {
@@ -147,6 +150,15 @@ func (bin *Binary) addAsDep(dir string) error {
147150
func normalizeModuleDep(bin *Binary) string {
148151
mod := bin.Module
149152
version := bin.Version
153+
154+
if resolver.IsSemver(version) {
155+
parsedVersion := semver.MustParse(version)
156+
if semver.MustParse(version).GreaterThan(semver.MustParse("v2")) {
157+
mod += "/v" + fmt.Sprint(parsedVersion.Major())
158+
}
159+
version = "v" + parsedVersion.String()
160+
}
161+
150162
dep := fmt.Sprintf("%s@%s", mod, version)
151163
return dep
152164
}

resolver/resolver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (v *Resolver) ResolveVersion() (string, error) {
102102
// In case the value from the fallback (github's tag version )
103103
// is greater than the version from proxy (proxy.golang) then
104104
// pick the version from the fallback
105-
if isSemver(fallbackVersion.Version.String()) && isSemver(proxyVersion.Version) &&
105+
if IsSemver(fallbackVersion.Version.String()) && IsSemver(proxyVersion.Version) &&
106106
semver.MustParse(fallbackVersion.Version.String()).GreaterThan(semver.MustParse(proxyVersion.Version)) {
107107
return fallbackVersion.Hash, nil
108108
}
@@ -182,7 +182,7 @@ func (v *Resolver) ParseVersion(version string) error {
182182
}
183183

184184
// return the string back if it's a valid hash string
185-
if !isSemver(version) && !isValidSemverConstraint(version) {
185+
if !IsSemver(version) && !isValidSemverConstraint(version) {
186186
matched, err := regexp.MatchString(hashRegex, version)
187187
if matched {
188188
v.Hash = true
@@ -194,7 +194,7 @@ func (v *Resolver) ParseVersion(version string) error {
194194
}
195195
}
196196

197-
if isSemver(version) {
197+
if IsSemver(version) {
198198
check, err := semver.NewConstraint("= " + version)
199199
if err != nil {
200200
return err
@@ -267,7 +267,7 @@ func (v *Resolver) ResolveClosestVersion() (string, error) {
267267

268268
// check if the given string is valid semver string and if yest
269269
// create a constraint checker out of it
270-
func isSemver(version string) bool {
270+
func IsSemver(version string) bool {
271271
_, err := semver.NewVersion(version)
272272
return err == nil
273273
}

0 commit comments

Comments
 (0)