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

@@ -7,6 +7,8 @@ pub const String = extern struct {
/// 3. If the final bit is not set, then it's a string that is stored in an external buffer.
bytes: [max_inline_len]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
pub const empty: String = .{};
/// Create an inline string
pub fn from(comptime inlinable_buffer: []const u8) String {
comptime {
@@ -212,33 +214,47 @@ pub const String = extern struct {
}
pub const HashContext = struct {
a_buf: []const u8,
b_buf: []const u8,
arg_buf: []const u8,
existing_buf: []const u8,
pub fn eql(ctx: HashContext, a: String, b: String) bool {
return a.eql(b, ctx.a_buf, ctx.b_buf);
pub fn eql(ctx: HashContext, arg: String, existing: String) bool {
return arg.eql(existing, ctx.arg_buf, ctx.existing_buf);
}
pub fn hash(ctx: HashContext, a: String) u64 {
const str = a.slice(ctx.a_buf);
pub fn hash(ctx: HashContext, arg: String) u64 {
const str = arg.slice(ctx.arg_buf);
return bun.hash(str);
}
};
pub const ArrayHashContext = struct {
a_buf: []const u8,
b_buf: []const u8,
pub fn hashContext(l_lockfile: *Lockfile, r_lockfile: ?*Lockfile) HashContext {
return .{
.arg_buf = l_lockfile.buffers.string_bytes.items,
.existing_buf = if (r_lockfile) |r| r.buffers.string_bytes.items else l_lockfile.buffers.string_bytes.items,
};
}
pub fn eql(ctx: ArrayHashContext, a: String, b: String, _: usize) bool {
return a.eql(b, ctx.a_buf, ctx.b_buf);
pub const ArrayHashContext = struct {
arg_buf: []const u8,
existing_buf: []const u8,
pub fn eql(ctx: ArrayHashContext, arg: String, existing: String, _: usize) bool {
return arg.eql(existing, ctx.arg_buf, ctx.existing_buf);
}
pub fn hash(ctx: ArrayHashContext, a: String) u32 {
const str = a.slice(ctx.a_buf);
pub fn hash(ctx: ArrayHashContext, arg: String) u32 {
const str = arg.slice(ctx.arg_buf);
return @as(u32, @truncate(bun.hash(str)));
}
};
pub fn arrayHashContext(l_lockfile: *const Lockfile, r_lockfile: ?*const Lockfile) ArrayHashContext {
return .{
.arg_buf = l_lockfile.buffers.string_bytes.items,
.existing_buf = if (r_lockfile) |r| r.buffers.string_bytes.items else l_lockfile.buffers.string_bytes.items,
};
}
pub fn init(
buf: string,
in: string,