From e4c5f53dd279c54d8ea42e25c6fd01aea226c971 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 28 Sep 2022 10:25:38 -0600 Subject: [PATCH] Don't include version in replacement source Follow-up to #69 I had a situation where caddy/v2 v2.4.6 was in my go.mod and a replace on it to use local caddy repo. When I ran `xcaddy run` to test a caddy module, it failed to run because the replace included the version v2.4.6, even though somehow the buildenv go.mod had v2.6.1 (the latest), and the replace directive specified @v2.4.6 only, so the replacement didn't happen. I don't think versions in the replacement source/origin are really that useful for xcaddy. If experience proves this wrong, we can figure out a better solution. --- cmd/main.go | 4 +--- cmd/main_unix_test.go | 10 +++++----- cmd/main_windows_test.go | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 0a3b2f4..c9bc76e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -292,8 +292,6 @@ func parseGoListJson(out []byte) (currentModule, moduleDir string, replacements continue } - src := mod.Path + "@" + mod.Version - // 1. Target is module, version is required in this case // 2A. Target is absolute path // 2B. Target is relative path, proper handling is required in this case @@ -315,7 +313,7 @@ func parseGoListJson(out []byte) (currentModule, moduleDir string, replacements } } - replacements = append(replacements, xcaddy.NewReplace(src, dst)) + replacements = append(replacements, xcaddy.NewReplace(mod.Path, dst)) } for _, idx := range unjoinedReplaces { unresolved := string(replacements[idx].New) diff --git a/cmd/main_unix_test.go b/cmd/main_unix_test.go index e226425..a340623 100644 --- a/cmd/main_unix_test.go +++ b/cmd/main_unix_test.go @@ -95,12 +95,12 @@ func TestParseGoListJson(t *testing.T) { t.Errorf("Unexpected module path") } expected := []xcaddy.Replace{ - xcaddy.NewReplace("replacetest1@v1.2.3", "golang.org/x/example@v0.0.0-20210811190340-787a929d5a0d"), - xcaddy.NewReplace("replacetest2@v0.0.1", "golang.org/x/example@v0.0.0-20210407023211-09c3a5e06b5d"), - xcaddy.NewReplace("replacetest3@v1.2.3", "/home/work/module/fork1"), + xcaddy.NewReplace("replacetest1", "golang.org/x/example@v0.0.0-20210811190340-787a929d5a0d"), + xcaddy.NewReplace("replacetest2", "golang.org/x/example@v0.0.0-20210407023211-09c3a5e06b5d"), + xcaddy.NewReplace("replacetest3", "/home/work/module/fork1"), xcaddy.NewReplace("github.com/simnalamburt/module", "/home/work/module"), - xcaddy.NewReplace("replacetest4@v0.0.1", "/srv/fork2"), - xcaddy.NewReplace("replacetest5@v1.2.3", "/home/work/module/fork3"), + xcaddy.NewReplace("replacetest4", "/srv/fork2"), + xcaddy.NewReplace("replacetest5", "/home/work/module/fork3"), } if !reflect.DeepEqual(replacements, expected) { t.Errorf("Expected replacements '%v' but got '%v'", expected, replacements) diff --git a/cmd/main_windows_test.go b/cmd/main_windows_test.go index 3d65e58..173ff84 100644 --- a/cmd/main_windows_test.go +++ b/cmd/main_windows_test.go @@ -99,12 +99,12 @@ func TestParseGoListJson(t *testing.T) { t.Errorf("Unexpected module path") } expected := []xcaddy.Replace{ - xcaddy.NewReplace("replacetest1@v1.2.3", "golang.org/x/example@v0.0.0-20210811190340-787a929d5a0d"), - xcaddy.NewReplace("replacetest2@v0.0.1", "golang.org/x/example@v0.0.0-20210407023211-09c3a5e06b5d"), - xcaddy.NewReplace("replacetest3@v1.2.3", "C:\\Users\\work\\module\\fork1"), + xcaddy.NewReplace("replacetest1", "golang.org/x/example@v0.0.0-20210811190340-787a929d5a0d"), + xcaddy.NewReplace("replacetest2", "golang.org/x/example@v0.0.0-20210407023211-09c3a5e06b5d"), + xcaddy.NewReplace("replacetest3", "C:\\Users\\work\\module\\fork1"), xcaddy.NewReplace("github.com/simnalamburt/module", "C:\\Users\\work\\module"), - xcaddy.NewReplace("replacetest4@v0.0.1", "C:\\go\\fork2"), - xcaddy.NewReplace("replacetest5@v1.2.3", "C:\\Users\\work\\module\\fork3"), + xcaddy.NewReplace("replacetest4", "C:\\go\\fork2"), + xcaddy.NewReplace("replacetest5", "C:\\Users\\work\\module\\fork3"), } if !reflect.DeepEqual(replacements, expected) { t.Errorf("Expected replacements '%v' but got '%v'", expected, replacements)