@@ -13,6 +13,7 @@ import (
13
13
"path/filepath"
14
14
"runtime/trace"
15
15
"slices"
16
+ "strconv"
16
17
"strings"
17
18
"time"
18
19
@@ -25,6 +26,7 @@ import (
25
26
"go.jetpack.io/devbox/internal/devpkg"
26
27
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
27
28
"go.jetpack.io/devbox/internal/lock"
29
+ "go.jetpack.io/devbox/internal/searcher"
28
30
"go.jetpack.io/devbox/internal/setup"
29
31
"go.jetpack.io/devbox/internal/shellgen"
30
32
"go.jetpack.io/devbox/internal/telemetry"
@@ -60,17 +62,25 @@ func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error)
60
62
continue
61
63
}
62
64
63
- lockPackage , err := lockfile . FetchResolvedPackage ( pkg .Versioned ())
65
+ result , err := searcher . Client (). Search ( ctx , pkg .CanonicalName ())
64
66
if err != nil {
65
67
warnings = append (warnings , fmt .Sprintf ("Note: unable to check updates for %s" , pkg .CanonicalName ()))
66
68
continue
67
69
}
68
- existingLockPackage := lockfile .Packages [pkg .Raw ]
69
- if lockPackage .Version == existingLockPackage .Version {
70
- continue
71
- }
72
70
73
- outdatedPackages [pkg .Versioned ()] = UpdateVersion {Current : existingLockPackage .Version , Latest : lockPackage .Version }
71
+ for _ , p := range result .Packages {
72
+ if p .Name != pkg .CanonicalName () {
73
+ continue
74
+ }
75
+
76
+ for _ , v := range p .Versions {
77
+ existingLockPackage := lockfile .Packages [pkg .Raw ]
78
+ if isGreater (v .Version , existingLockPackage .Version ) {
79
+ outdatedPackages [pkg .Versioned ()] = UpdateVersion {Current : existingLockPackage .Version , Latest : v .Version }
80
+ break
81
+ }
82
+ }
83
+ }
74
84
}
75
85
76
86
for _ , warning := range warnings {
@@ -80,6 +90,32 @@ func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error)
80
90
return outdatedPackages , nil
81
91
}
82
92
93
+ // isGreater returns true if v1 is greater than v2
94
+ func isGreater (v1 , v2 string ) bool {
95
+ parts1 := strings .Split (v1 , "." )
96
+ parts2 := strings .Split (v2 , "." )
97
+
98
+ maxLen := max (len (parts2 ), len (parts1 ))
99
+
100
+ for i := range maxLen {
101
+ var num1 , num2 int
102
+ if i < len (parts1 ) {
103
+ num1 , _ = strconv .Atoi (parts1 [i ])
104
+ }
105
+ if i < len (parts2 ) {
106
+ num2 , _ = strconv .Atoi (parts2 [i ])
107
+ }
108
+
109
+ if num1 > num2 {
110
+ return true
111
+ } else if num1 < num2 {
112
+ return false
113
+ }
114
+ }
115
+
116
+ return false
117
+ }
118
+
83
119
// Add adds the `pkgs` to the config (i.e. devbox.json) and nix profile for this
84
120
// devbox project
85
121
func (d * Devbox ) Add (ctx context.Context , pkgsNames []string , opts devopt.AddOpts ) error {
0 commit comments