Skip to content

Commit e349857

Browse files
andypostclaude
andcommitted
fix: correct plugin subpath handling in module replacement logic
- Fix plugin download logic to properly distinguish between exact matches and subpaths - Add two-phase approach: skip subpaths, handle exact matches as replaced modules - Ensure replaced modules (both core and plugins) are required in go.mod with placeholder versions The key fix changes the condition from `strings.HasPrefix(p.Path, repl)` to `p.Path \!= repl && strings.HasPrefix(p.Path, repl)` to avoid incorrectly skipping plugins that exactly match replaced module paths. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent bff01b3 commit e349857

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

plugins/builder/environment.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,52 @@ 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.
125133
nextPlugin:
126134
for _, p := range opts.Plugins {
127135
// Do not get plugins of module subpath.
128136
for repl := range opts.ModReplace {
129-
if strings.HasPrefix(p.Path, repl) {
137+
if p.Path != repl && strings.HasPrefix(p.Path, repl) {
130138
continue nextPlugin
131139
}
132140
}
133-
err = env.execGoGet(ctx, p.String())
134-
if err != nil {
135-
return err
141+
142+
// Check if this plugin is replaced.
143+
var pluginReplaced bool
144+
for repl := range opts.ModReplace {
145+
if p.Path == repl {
146+
pluginReplaced = true
147+
break
148+
}
149+
}
150+
151+
if !pluginReplaced {
152+
err = env.execGoGet(ctx, p.String())
153+
if err != nil {
154+
return err
155+
}
156+
} else {
157+
// If plugin is replaced, we still need to require it.
158+
// We use go mod edit -require to add the requirement without downloading.
159+
// Since the module is replaced, we use a placeholder version if none specified.
160+
pkgStr := p.String()
161+
if !strings.Contains(pkgStr, "@") {
162+
pkgStr += "@v0.0.0"
163+
}
164+
err = env.execGoMod(ctx, "edit", "-require", pkgStr)
165+
if err != nil {
166+
return err
167+
}
136168
}
137169
}
138170
// @todo update all but with fixed versions if requested

0 commit comments

Comments
 (0)