diff --git a/src/cli/outdated_command.zig b/src/cli/outdated_command.zig index cda60a3f82..83963b1f48 100644 --- a/src/cli/outdated_command.zig +++ b/src/cli/outdated_command.zig @@ -21,6 +21,17 @@ const WorkspaceFilter = PackageManager.WorkspaceFilter; const OOM = bun.OOM; pub const OutdatedCommand = struct { + fn resolveCatalogDependency(manager: *PackageManager, dep: Install.Dependency) ?Install.Dependency.Version { + return if (dep.version.tag == .catalog) blk: { + const catalog_dep = manager.lockfile.catalogs.get( + manager.lockfile, + dep.version.value.catalog, + dep.name, + ) orelse return null; + break :blk catalog_dep.version; + } else dep.version; + } + pub fn exec(ctx: Command.Context) !void { Output.prettyln("bun outdated v" ++ Global.package_json_version_with_sha ++ "", .{}); Output.flush(); @@ -281,7 +292,8 @@ pub const OutdatedCommand = struct { const package_id = lockfile.buffers.resolutions.items[dep_id]; if (package_id == invalid_package_id) continue; const dep = lockfile.buffers.dependencies.items[dep_id]; - if (dep.version.tag != .npm and dep.version.tag != .dist_tag) continue; + const resolved_version = resolveCatalogDependency(manager, dep) orelse continue; + if (resolved_version.tag != .npm and resolved_version.tag != .dist_tag) continue; const resolution = pkg_resolutions[package_id]; if (resolution.tag != .npm) continue; @@ -320,10 +332,10 @@ pub const OutdatedCommand = struct { const latest = manifest.findByDistTag("latest") orelse continue; - const update_version = if (dep.version.tag == .npm) - manifest.findBestVersion(dep.version.value.npm.version, string_buf) orelse continue + const update_version = if (resolved_version.tag == .npm) + manifest.findBestVersion(resolved_version.value.npm.version, string_buf) orelse continue else - manifest.findByDistTag(dep.version.value.dist_tag.tag.slice(string_buf)) orelse continue; + manifest.findByDistTag(resolved_version.value.dist_tag.tag.slice(string_buf)) orelse continue; if (resolution.value.npm.version.order(latest.version, string_buf, manifest.string_buf) != .lt) continue; @@ -440,10 +452,11 @@ pub const OutdatedCommand = struct { ) orelse continue; const latest = manifest.findByDistTag("latest") orelse continue; - const update = if (dep.version.tag == .npm) - manifest.findBestVersion(dep.version.value.npm.version, string_buf) orelse continue + const resolved_version = resolveCatalogDependency(manager, dep) orelse continue; + const update = if (resolved_version.tag == .npm) + manifest.findBestVersion(resolved_version.value.npm.version, string_buf) orelse continue else - manifest.findByDistTag(dep.version.value.dist_tag.tag.slice(string_buf)) orelse continue; + manifest.findByDistTag(resolved_version.value.dist_tag.tag.slice(string_buf)) orelse continue; table.printLineSeparator(); @@ -537,7 +550,8 @@ pub const OutdatedCommand = struct { const package_id = resolutions[dep_id]; if (package_id == invalid_package_id) continue; const dep = dependencies[dep_id]; - if (dep.version.tag != .npm and dep.version.tag != .dist_tag) continue; + const resolved_version = resolveCatalogDependency(manager, dep) orelse continue; + if (resolved_version.tag != .npm and resolved_version.tag != .dist_tag) continue; const resolution: Install.Resolution = pkg_resolutions[package_id]; if (resolution.tag != .npm) continue; diff --git a/test/cli/install/bun-install-registry.test.ts b/test/cli/install/bun-install-registry.test.ts index b207f597fb..fb4cd5b189 100644 --- a/test/cli/install/bun-install-registry.test.ts +++ b/test/cli/install/bun-install-registry.test.ts @@ -8444,6 +8444,46 @@ describe("outdated", () => { expect(out).not.toContain("@foo/bar"); expect(out).toContain("@scope/pkg1"); }); + + test("catalog dependencies", async () => { + await Promise.all([ + write( + packageJson, + JSON.stringify({ + name: "catalog-outdated-test", + workspaces: { + packages: ["packages/*"], + catalog: { + "no-deps": "1.0.0", + }, + catalogs: { + dev: { + "a-dep": "1.0.1", + }, + }, + }, + }), + ), + write( + join(packageDir, "packages", "pkg1", "package.json"), + JSON.stringify({ + name: "pkg1", + dependencies: { + "no-deps": "catalog:", + }, + devDependencies: { + "a-dep": "catalog:dev", + }, + }), + ), + ]); + + await runBunInstall(env, packageDir); + + const out = await runBunOutdated(env, packageDir, "--filter", "*"); + expect(out).toContain("no-deps"); + expect(out).toContain("a-dep"); + }); }); // TODO: setup registry to run across multiple test files, then move this and a few other describe