@@ -13,6 +13,7 @@ import (
1313 "path/filepath"
1414 "runtime/trace"
1515 "slices"
16+ "strconv"
1617 "strings"
1718 "time"
1819
@@ -25,6 +26,7 @@ import (
2526 "go.jetpack.io/devbox/internal/devpkg"
2627 "go.jetpack.io/devbox/internal/devpkg/pkgtype"
2728 "go.jetpack.io/devbox/internal/lock"
29+ "go.jetpack.io/devbox/internal/searcher"
2830 "go.jetpack.io/devbox/internal/setup"
2931 "go.jetpack.io/devbox/internal/shellgen"
3032 "go.jetpack.io/devbox/internal/telemetry"
@@ -60,17 +62,25 @@ func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error)
6062 continue
6163 }
6264
63- lockPackage , err := lockfile . FetchResolvedPackage ( pkg .Versioned ())
65+ result , err := searcher . Client (). Search ( ctx , pkg .CanonicalName ())
6466 if err != nil {
6567 warnings = append (warnings , fmt .Sprintf ("Note: unable to check updates for %s" , pkg .CanonicalName ()))
6668 continue
6769 }
68- existingLockPackage := lockfile .Packages [pkg .Raw ]
69- if lockPackage .Version == existingLockPackage .Version {
70- continue
71- }
7270
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+ }
7484 }
7585
7686 for _ , warning := range warnings {
@@ -80,6 +90,32 @@ func (d *Devbox) Outdated(ctx context.Context) (map[string]UpdateVersion, error)
8090 return outdatedPackages , nil
8191}
8292
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+
83119// Add adds the `pkgs` to the config (i.e. devbox.json) and nix profile for this
84120// devbox project
85121func (d * Devbox ) Add (ctx context.Context , pkgsNames []string , opts devopt.AddOpts ) error {
0 commit comments