@@ -13,29 +13,31 @@ import (
1313 "path/filepath"
1414 "runtime/trace"
1515 "slices"
16+ "strconv"
1617 "strings"
1718 "time"
1819
1920 "github.com/pkg/errors"
2021 "github.com/samber/lo"
22+
23+ "go.jetify.com/devbox/internal/boxcli/usererr"
24+ "go.jetify.com/devbox/internal/debug"
2125 "go.jetify.com/devbox/internal/devbox/devopt"
2226 "go.jetify.com/devbox/internal/devbox/providers/nixcache"
2327 "go.jetify.com/devbox/internal/devconfig"
2428 "go.jetify.com/devbox/internal/devconfig/configfile"
2529 "go.jetify.com/devbox/internal/devpkg"
2630 "go.jetify.com/devbox/internal/devpkg/pkgtype"
2731 "go.jetify.com/devbox/internal/lock"
32+ "go.jetify.com/devbox/internal/nix"
33+ "go.jetify.com/devbox/internal/plugin"
34+ "go.jetify.com/devbox/internal/searcher"
2835 "go.jetify.com/devbox/internal/setup"
2936 "go.jetify.com/devbox/internal/shellgen"
3037 "go.jetify.com/devbox/internal/telemetry"
38+ "go.jetify.com/devbox/internal/ux"
3139 "go.jetify.com/devbox/nix/flake"
3240 "go.jetify.com/pkg/auth"
33-
34- "go.jetify.com/devbox/internal/boxcli/usererr"
35- "go.jetify.com/devbox/internal/debug"
36- "go.jetify.com/devbox/internal/nix"
37- "go.jetify.com/devbox/internal/plugin"
38- "go.jetify.com/devbox/internal/ux"
3941)
4042
4143const StateOutOfDateMessage = "Your devbox environment may be out of date. Run %s to update it.\n "
@@ -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