mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
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:
@@ -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)),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user