diff --git a/completions/bun.bash b/completions/bun.bash index b62d8ef2475e95..ccabb1d73b61c5 100644 --- a/completions/bun.bash +++ b/completions/bun.bash @@ -82,7 +82,7 @@ _bun_completions() { declare -A PACKAGE_OPTIONS; declare -A PM_OPTIONS; - local SUBCOMMANDS="dev bun create run install add remove upgrade completions discord help init pm x test repl update link unlink build"; + local SUBCOMMANDS="dev bun create run install add remove upgrade completions discord help init pm x test repl update outdated link unlink build"; GLOBAL_OPTIONS[LONG_OPTIONS]="--use --cwd --bunfile --server-bunfile --config --disable-react-fast-refresh --disable-hmr --env-file --extension-order --jsx-factory --jsx-fragment --extension-order --jsx-factory --jsx-fragment --jsx-import-source --jsx-production --jsx-runtime --main-fields --no-summary --version --platform --public-dir --tsconfig-override --define --external --help --inject --loader --origin --port --dump-environment-variables --dump-limits --disable-bun-js"; GLOBAL_OPTIONS[SHORT_OPTIONS]="-c -v -d -e -h -i -l -u -p"; diff --git a/completions/bun.fish b/completions/bun.fish index 3cb9366b7d91a5..a5c51aef0587cb 100644 --- a/completions/bun.fish +++ b/completions/bun.fish @@ -179,6 +179,7 @@ complete -c bun -n "__fish_use_subcommand" -a "remove" -d "Remove a dependency f complete -c bun -n "__fish_use_subcommand" -a "add" -d "Add a dependency to package.json" -f complete -c bun -n "__fish_use_subcommand" -a "init" -d "Initialize a Bun project in this directory" -f complete -c bun -n "__fish_use_subcommand" -a "link" -d "Register or link a local npm package" -f -complete -c bun -n "__fish_use_subcommand" -a "link" -d "Unregister a local npm package" -f +complete -c bun -n "__fish_use_subcommand" -a "unlink" -d "Unregister a local npm package" -f complete -c bun -n "__fish_use_subcommand" -a "pm" -d "Additional package management utilities" -f complete -c bun -n "__fish_use_subcommand" -a "x" -d "Execute a package binary, installing if needed" -f +complete -c bun -n "__fish_use_subcommand" -a "outdated" -d "Display the latest versions of outdated dependencies" -f diff --git a/completions/bun.zsh b/completions/bun.zsh index a19a44bec8f81d..d75f2aa2f06685 100644 --- a/completions/bun.zsh +++ b/completions/bun.zsh @@ -563,6 +563,22 @@ _bun_update_completion() { esac } +_bun_outdated_completion() { + _arguments -s -C \ + '--cwd[Set a specific cwd]:cwd' \ + '--verbose[Excessively verbose logging]' \ + '--no-progress[Disable the progress bar]' \ + '--help[Print this help menu]' && + ret=0 + + case $state in + config) + _bun_list_bunfig_toml + + ;; + esac +} + _bun_test_completion() { _arguments -s -C \ '1: :->cmd1' \ @@ -669,6 +685,7 @@ _bun() { 'add\:"Add a dependency to package.json (bun a)" ' 'remove\:"Remove a dependency from package.json (bun rm)" ' 'update\:"Update outdated dependencies & save to package.json" ' + 'outdated\:"Display the latest versions of outdated dependencies" ' 'link\:"Link an npm package globally" ' 'unlink\:"Globally unlink an npm package" ' 'pm\:"More commands for managing packages" ' @@ -740,6 +757,10 @@ _bun() { update) _bun_update_completion + ;; + outdated) + _bun_outdated_completion + ;; 'test') _bun_test_completion @@ -819,6 +840,10 @@ _bun() { update) _bun_update_completion + ;; + outdated) + _bun_outdated_completion + ;; 'test') _bun_test_completion diff --git a/docs/cli/outdated.md b/docs/cli/outdated.md new file mode 100644 index 00000000000000..75d38e9c903c9b --- /dev/null +++ b/docs/cli/outdated.md @@ -0,0 +1,27 @@ +Use `bun outdated` to display a table of outdated dependencies with their latest versions: + +```sh +$ bun outdated + +|--------------------------------------------------------------------| +| Packages | Current | Update | Latest | +|----------------------------------------|---------|--------|--------| +| @types/bun (dev) | 1.1.6 | 1.1.7 | 1.1.7 | +|----------------------------------------|---------|--------|--------| +| @types/react (dev) | 18.3.3 | 18.3.4 | 18.3.4 | +|----------------------------------------|---------|--------|--------| +| @typescript-eslint/eslint-plugin (dev) | 7.16.1 | 7.18.0 | 8.2.0 | +|----------------------------------------|---------|--------|--------| +| @typescript-eslint/parser (dev) | 7.16.1 | 7.18.0 | 8.2.0 | +|----------------------------------------|---------|--------|--------| +| esbuild (dev) | 0.21.5 | 0.21.5 | 0.23.1 | +|----------------------------------------|---------|--------|--------| +| eslint (dev) | 9.7.0 | 9.9.1 | 9.9.1 | +|----------------------------------------|---------|--------|--------| +| typescript (dev) | 5.5.3 | 5.5.4 | 5.5.4 | +|--------------------------------------------------------------------| +``` + +The `Update` column shows the version that would be installed if you ran `bun update [package]`. This version is the latest version that satisfies the version range specified in your `package.json`. + +The `Latest` column shows the latest version available from the registry. `bun update --latest [package]` will update to this version. diff --git a/src/cli.zig b/src/cli.zig index 943afb2bf16e79..c85bfb3ea325aa 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -1083,6 +1083,7 @@ pub const HelpCommand = struct { \\ add {s:<16} Add a dependency to package.json (bun a) \\ remove {s:<16} Remove a dependency from package.json (bun rm) \\ update {s:<16} Update outdated dependencies + \\ outdated Display latest versions of outdated dependencies \\ link [\] Register or link a local npm package \\ unlink Unregister a local npm package \\ patch \ Prepare a package for patching diff --git a/src/cli/outdated_command.zig b/src/cli/outdated_command.zig index ea92b5f23784ab..2cbd5f9643add9 100644 --- a/src/cli/outdated_command.zig +++ b/src/cli/outdated_command.zig @@ -111,6 +111,9 @@ fn Table( pub const OutdatedCommand = struct { pub fn exec(ctx: Command.Context) !void { + Output.prettyErrorln("bun outdated v" ++ Global.package_json_version_with_sha ++ "", .{}); + Output.flush(); + const cli = try PackageManager.CommandLineArguments.parse(ctx.allocator, .outdated); const manager = PackageManager.init(ctx, cli, .outdated) catch |err| { @@ -183,9 +186,6 @@ pub const OutdatedCommand = struct { if (root_pkg_id == invalid_package_id) return; const root_pkg_deps = lockfile.packages.items(.dependencies)[root_pkg_id]; - Output.prettyErrorln("bun outdated v" ++ Global.package_json_version_with_sha ++ "", .{}); - Output.flush(); - try updateManifestsIfNecessary(manager, log_level, root_pkg_deps); try switch (Output.enable_ansi_colors) { diff --git a/src/install/semver.zig b/src/install/semver.zig index 7cf78042805344..cbd76749945f51 100644 --- a/src/install/semver.zig +++ b/src/install/semver.zig @@ -668,7 +668,7 @@ pub const Version = extern struct { const diff = this.version.whichVersionIsDifferent(this.other, this.buf, this.other_buf) orelse .none; switch (diff) { - .major => try writer.print(Output.prettyFmt("{d}.{d}.{d}", true), .{ + .major => try writer.print(Output.prettyFmt("{d}.{d}.{d}", true), .{ this.version.major, this.version.minor, this.version.patch, }), .minor => { @@ -677,7 +677,7 @@ pub const Version = extern struct { this.version.major, this.version.minor, this.version.patch, }); } else { - try writer.print(Output.prettyFmt("{d}.{d}.{d}", true), .{ + try writer.print(Output.prettyFmt("{d}.{d}.{d}", true), .{ this.version.major, this.version.minor, this.version.patch, }); } diff --git a/test/cli/install/registry/__snapshots__/bun-install-registry.test.ts.snap b/test/cli/install/registry/__snapshots__/bun-install-registry.test.ts.snap index a505c6d547aabc..c20750bd03f01d 100644 --- a/test/cli/install/registry/__snapshots__/bun-install-registry.test.ts.snap +++ b/test/cli/install/registry/__snapshots__/bun-install-registry.test.ts.snap @@ -46,20 +46,11 @@ what-bin@1.0.0: " `; -exports[`outdated NO_COLOR works 1`] = ` -"|--------------------------------------| -| Packages | Current | Update | Latest | -|----------|---------|--------|--------| -| a-dep | 1.0.1 | 1.0.1 | 1.0.10 | -|--------------------------------------| -" -`; - exports[`outdated normal dep, smaller than column title 1`] = ` "┌──────────┬─────────┬────────┬────────┐ │ Packages │ Current │ Update │ Latest │ ├──────────┼─────────┼────────┼────────┤ -│ no-deps │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +│ no-deps │ 1.0.0 │ 1.0.0 │ 2.0.0 │ └──────────┴─────────┴────────┴────────┘ " `; @@ -77,7 +68,7 @@ exports[`outdated dev dep, smaller than column title 1`] = ` "┌───────────────┬─────────┬────────┬────────┐ │ Packages │ Current │ Update │ Latest │ ├───────────────┼─────────┼────────┼────────┤ -│ no-deps (dev) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +│ no-deps (dev) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ └───────────────┴─────────┴────────┴────────┘ " `; @@ -95,7 +86,7 @@ exports[`outdated peer dep, smaller than column title 1`] = ` "┌────────────────┬─────────┬────────┬────────┐ │ Packages │ Current │ Update │ Latest │ ├────────────────┼─────────┼────────┼────────┤ -│ no-deps (peer) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +│ no-deps (peer) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ └────────────────┴─────────┴────────┴────────┘ " `; @@ -113,7 +104,7 @@ exports[`outdated optional dep, smaller than column title 1`] = ` "┌────────────────────┬─────────┬────────┬────────┐ │ Packages │ Current │ Update │ Latest │ ├────────────────────┼─────────┼────────┼────────┤ -│ no-deps (optional) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +│ no-deps (optional) │ 1.0.0 │ 1.0.0 │ 2.0.0 │ └────────────────────┴─────────┴────────┴────────┘ " `; @@ -126,3 +117,12 @@ exports[`outdated optional dep, larger than column title 1`] = ` └──────────────────────────┴────────────────┴────────────────┴────────────────┘ " `; + +exports[`outdated NO_COLOR works 1`] = ` +"|--------------------------------------| +| Packages | Current | Update | Latest | +|----------|---------|--------|--------| +| a-dep | 1.0.1 | 1.0.1 | 1.0.10 | +|--------------------------------------| +" +`;