mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Add support for catalogs in bun outdated (#20090)
Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -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("<r><b>bun outdated <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
|
||||
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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user