Skip to content

Commit e087caa

Browse files
committed
fix: dedup should not remove ruby
1 parent e6fc80b commit e087caa

File tree

3 files changed

+12
-20
lines changed

3 files changed

+12
-20
lines changed

lockfile/normalize.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,16 @@ import (
77
"strings"
88
)
99

10-
var (
11-
darwinPlatformVersionRegex = regexp.MustCompile(`^(.*-darwin)(\d+)$`)
12-
)
10+
var darwinPlatformVersionRegex = regexp.MustCompile(`^(.*-darwin)(\d+)$`)
1311

1412
func normalizePlatformForLockfileOutput(platform string) string {
1513
normalized := strings.ToLower(strings.TrimSpace(platform))
1614
if normalized == "" {
1715
return ""
1816
}
19-
2017
if matches := darwinPlatformVersionRegex.FindStringSubmatch(normalized); matches != nil {
2118
normalized = matches[1] + "-" + matches[2]
2219
}
23-
2420
return normalized
2521
}
2622

lockfile/writer.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,22 @@ func (w *LockfileWriter) writePlatformsSection(lf *Lockfile, buf *bufio.Writer)
417417
return nil
418418
}
419419

420-
if _, err := buf.WriteString("\nPLATFORMS\n"); err != nil {
421-
return err
422-
}
423-
424-
// Deduplicate and sort platforms
420+
// Deduplicate and sort platforms (excluding ruby, which Bundler omits).
425421
platformSet := make(map[string]bool)
426422
for _, p := range lf.Platforms {
427423
normalized := normalizePlatformForLockfileOutput(p)
428-
if normalized == "" {
424+
if normalized == "" || normalized == "ruby" {
429425
continue
430426
}
431427
platformSet[normalized] = true
432428
}
429+
if len(platformSet) == 0 {
430+
return nil
431+
}
432+
433+
if _, err := buf.WriteString("\nPLATFORMS\n"); err != nil {
434+
return err
435+
}
433436

434437
platforms := make([]string, 0, len(platformSet))
435438
for p := range platformSet {

lockfile/writer_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,6 @@ func TestIndentationAndFormatting(t *testing.T) {
531531
t.Errorf("Line %d: gem dependency should have 6-space indent: %q", i+1, line)
532532
}
533533

534-
// Platform entries should have 2-space indent
535-
if strings.TrimSpace(line) == "ruby" && strings.HasPrefix(buf.String()[strings.Index(buf.String(), line)-20:], "PLATFORMS") {
536-
if !strings.HasPrefix(line, " ruby") {
537-
t.Errorf("Line %d: platform should have 2-space indent: %q", i+1, line)
538-
}
539-
}
540-
541534
// Top-level dependencies should have 2-space indent
542535
if strings.Contains(line, "rails (~> 8.1.0.rc1)") && !strings.HasPrefix(line, " rails") {
543536
t.Errorf("Line %d: dependency should have 2-space indent: %q", i+1, line)
@@ -572,8 +565,8 @@ func TestPlatformDeduplication(t *testing.T) {
572565
rubyCount := strings.Count(output, " ruby\n")
573566
linuxCount := strings.Count(output, " x86_64-linux\n")
574567

575-
if rubyCount != 1 {
576-
t.Errorf("Expected 'ruby' platform to appear once, found %d times", rubyCount)
568+
if rubyCount != 0 {
569+
t.Errorf("Expected 'ruby' platform to be omitted, found %d times", rubyCount)
577570
}
578571
if linuxCount != 1 {
579572
t.Errorf("Expected 'x86_64-linux' platform to appear once, found %d times", linuxCount)

0 commit comments

Comments
 (0)