Implement catalogs in bun install (#19809)

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
Dylan Conway
2025-05-20 23:03:21 -07:00
committed by GitHub
parent 562a65037d
commit 98ee30eccf
16 changed files with 1606 additions and 106 deletions

View File

@@ -2035,7 +2035,7 @@ pub const PackCommand = struct {
return entry.clear();
}
/// Strip workspace protocols from dependency versions then
/// Strips workspace and catalog protocols from dependency versions then
/// returns the printed json
fn editRootPackageJSON(
allocator: std.mem.Allocator,
@@ -2126,6 +2126,48 @@ pub const PackCommand = struct {
},
.{},
);
} else if (strings.withoutPrefixIfPossibleComptime(package_spec, "catalog:")) |catalog_name_str| {
const dep_name_str = dependency.key.?.asString(allocator).?;
const lockfile = maybe_lockfile orelse {
Output.errGeneric("Failed to resolve catalog version for \"{s}\" in `{s}` (catalogs require a lockfile).", .{
dep_name_str,
dependency_group,
});
Global.crash();
};
const catalog_name = Semver.String.init(catalog_name_str, catalog_name_str);
const catalog = lockfile.catalogs.getGroup(lockfile.buffers.string_bytes.items, catalog_name, catalog_name_str) orelse {
Output.errGeneric("Failed to resolve catalog version for \"{s}\" in `{s}` (no matching catalog).", .{
dep_name_str,
dependency_group,
});
Global.crash();
};
const dep_name = Semver.String.init(dep_name_str, dep_name_str);
const dep = catalog.getContext(dep_name, Semver.String.ArrayHashContext{
.arg_buf = dep_name_str,
.existing_buf = lockfile.buffers.string_bytes.items,
}) orelse {
Output.errGeneric("Failed to resolve catalog version for \"{s}\" in `{s}` (no matching catalog dependency).", .{
dep_name_str,
dependency_group,
});
Global.crash();
};
dependency.value = Expr.allocate(
allocator,
E.String,
.{
.data = try allocator.dupe(u8, dep.version.literal.slice(lockfile.buffers.string_bytes.items)),
},
.{},
);
}
}
},