Skip to content

Commit b8fa602

Browse files
committed
fix: respect configured Gemfile sources in resolver
Use first rubygems source from Gemfile as default instead of hardcoding https://rubygems.org. Maintains fallback to rubygems.org if no sources are configured. Fixes issue where custom gem sources (mirrors, private registries) were ignored during dependency resolution.
1 parent b4658f3 commit b8fa602

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

internal/resolver/lock_generator.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,22 @@ func GenerateLockfileWithPlatforms(gemfilePath string, versionPins map[string]st
5252
}
5353
}
5454

55+
// Determine default source URL from Gemfile sources
56+
// Respects configured sources, fallback to rubygems.org
57+
defaultSourceURL := "https://rubygems.org"
58+
for _, src := range parsed.Sources {
59+
if src.Type == "rubygems" && src.URL != "" {
60+
defaultSourceURL = src.URL
61+
break // Use first rubygems source as default
62+
}
63+
}
64+
5565
// Create RubyGems sources for different gem servers
5666
// This is like Bundler's source management (rubygems.org, custom mirrors, etc.)
5767
sources := make(map[string]*RubyGemsSource)
5868
getSource := func(url string) *RubyGemsSource {
5969
if url == "" {
60-
url = "https://rubygems.org"
70+
url = defaultSourceURL
6171
}
6272
if src, ok := sources[url]; ok {
6373
return src
@@ -68,7 +78,7 @@ func GenerateLockfileWithPlatforms(gemfilePath string, versionPins map[string]st
6878
}
6979

7080
// Default source for gems without explicit source
71-
defaultSource := getSource("https://rubygems.org")
81+
defaultSource := getSource(defaultSourceURL)
7282

7383
// Apply version pins to all sources for selective updates
7484
if versionPins != nil {
@@ -191,7 +201,8 @@ func GenerateLockfileWithPlatforms(gemfilePath string, versionPins map[string]st
191201
}
192202

193203
// Determine which source URL to record for this gem
194-
gemSourceURL := "https://rubygems.org/"
204+
// Respect configured source, fallback to default
205+
gemSourceURL := defaultSourceURL + "/"
195206
if dep.Source != nil && dep.Source.Type == "rubygems" {
196207
gemSourceURL = dep.Source.URL
197208
if gemSourceURL != "" {
@@ -269,9 +280,9 @@ func GenerateLockfileWithPlatforms(gemfilePath string, versionPins map[string]st
269280
seenPackages[pkgName] = pkg.Version
270281
allSolutions = append(allSolutions, pkg)
271282

272-
// Inherit source from dependencies
283+
// Inherit source from dependencies (use default if not set)
273284
if gemSources[pkgName] == "" {
274-
gemSources[pkgName] = "https://rubygems.org/"
285+
gemSources[pkgName] = defaultSourceURL + "/"
275286
}
276287
}
277288

0 commit comments

Comments
 (0)