Skip to content

Commit acc6fbf

Browse files
andypostclaude
andcommitted
fix: ensure replaced modules are required in go.mod during build
When using the --replace flag, the build process was skipping go get for replaced modules but not adding them as requirements, causing Go compilation errors. This fix ensures replaced modules are properly required using go mod edit -require with placeholder versions. Fixes #87 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 221e137 commit acc6fbf

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

plugins/builder/environment.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,44 @@ func (env *buildEnvironment) CreateModFile(ctx context.Context, opts *BuildOptio
119119
if err != nil {
120120
return err
121121
}
122+
} else {
123+
// If core package is replaced, we still need to require it.
124+
// We use go mod edit -require to add the requirement without downloading.
125+
// Since the module is replaced, we use a placeholder version.
126+
err = env.execGoMod(ctx, "edit", "-require", opts.CorePkg.String()+"@v0.0.0")
127+
if err != nil {
128+
return err
129+
}
122130
}
123131

124132
// Download plugins.
125-
nextPlugin:
126133
for _, p := range opts.Plugins {
127-
// Do not get plugins of module subpath.
134+
// Check if this plugin is replaced.
135+
var pluginReplaced bool
128136
for repl := range opts.ModReplace {
129137
if strings.HasPrefix(p.Path, repl) {
130-
continue nextPlugin
138+
pluginReplaced = true
139+
break
131140
}
132141
}
133-
err = env.execGoGet(ctx, p.String())
134-
if err != nil {
135-
return err
142+
143+
if !pluginReplaced {
144+
err = env.execGoGet(ctx, p.String())
145+
if err != nil {
146+
return err
147+
}
148+
} else {
149+
// If plugin is replaced, we still need to require it.
150+
// We use go mod edit -require to add the requirement without downloading.
151+
// Since the module is replaced, we use a placeholder version if none specified.
152+
pkgStr := p.String()
153+
if !strings.Contains(pkgStr, "@") {
154+
pkgStr += "@v0.0.0"
155+
}
156+
err = env.execGoMod(ctx, "edit", "-require", pkgStr)
157+
if err != nil {
158+
return err
159+
}
136160
}
137161
}
138162
// @todo update all but with fixed versions if requested

0 commit comments

Comments
 (0)