mirror of
https://github.com/oven-sh/bun
synced 2026-02-15 13:22:07 +00:00
[bun install] Generate a lockfile
This commit is contained in:
@@ -247,6 +247,10 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
|
||||
// only need the mutex on append
|
||||
var mutex: Mutex = undefined;
|
||||
|
||||
const EmptyType = struct {
|
||||
len: usize = 0,
|
||||
};
|
||||
|
||||
pub fn init(allocator: *std.mem.Allocator) *Self {
|
||||
if (!loaded) {
|
||||
instance = Self{
|
||||
@@ -277,6 +281,16 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
|
||||
return constStrToU8(appended);
|
||||
}
|
||||
|
||||
pub fn getMutable(self: *Self, len: usize) ![]u8 {
|
||||
return try self.appendMutable(EmptyType, EmptyType{ .len = len });
|
||||
}
|
||||
|
||||
pub fn print(self: *Self, comptime fmt: []const u8, args: anytype) ![]const u8 {
|
||||
var buf = try self.appendMutable(EmptyType, EmptyType{ .len = std.fmt.count(fmt, args) + 1 });
|
||||
buf[buf.len - 1] = 0;
|
||||
return std.fmt.bufPrint(buf.ptr[0 .. buf.len - 1], fmt, args) catch unreachable;
|
||||
}
|
||||
|
||||
pub fn append(self: *Self, comptime AppendType: type, _value: AppendType) ![]const u8 {
|
||||
mutex.lock();
|
||||
defer mutex.unlock();
|
||||
@@ -307,7 +321,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
|
||||
) ![]const u8 {
|
||||
const value_len: usize = brk: {
|
||||
switch (comptime AppendType) {
|
||||
[]const u8, []u8, [:0]const u8, [:0]u8 => {
|
||||
EmptyType, []const u8, []u8, [:0]const u8, [:0]u8 => {
|
||||
break :brk _value.len;
|
||||
},
|
||||
else => {
|
||||
@@ -327,6 +341,9 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
|
||||
backing_buf_used += value_len;
|
||||
|
||||
switch (AppendType) {
|
||||
EmptyType => {
|
||||
backing_buf[backing_buf_used - 1] = 0;
|
||||
},
|
||||
[]const u8, []u8, [:0]const u8, [:0]u8 => {
|
||||
std.mem.copy(u8, backing_buf[start .. backing_buf_used - 1], _value);
|
||||
backing_buf[backing_buf_used - 1] = 0;
|
||||
@@ -346,6 +363,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
|
||||
var value_buf = try self.allocator.alloc(u8, value_len);
|
||||
|
||||
switch (comptime AppendType) {
|
||||
EmptyType => {},
|
||||
[]const u8, []u8, [:0]const u8, [:0]u8 => {
|
||||
std.mem.copy(u8, value_buf, _value);
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -128,6 +128,19 @@ pub const Version = extern struct {
|
||||
tag: Tag = Tag{},
|
||||
// raw: RawType = RawType{},
|
||||
|
||||
pub fn cloneInto(this: Version, slice: []const u8, buf: []u8) Version {
|
||||
return Version{
|
||||
.major = this.major,
|
||||
.minor = this.minor,
|
||||
.patch = this.patch,
|
||||
.tag = this.tag.cloneInto(slice, buf),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn len(this: *const Version) u32 {
|
||||
return this.tag.build.len + this.tag.pre.len;
|
||||
}
|
||||
|
||||
pub fn fmt(this: Version, input: string) Formatter {
|
||||
return Formatter{ .version = this, .input = input };
|
||||
}
|
||||
@@ -137,7 +150,7 @@ pub const Version = extern struct {
|
||||
if (this.tag.hasBuild()) builder.count(this.tag.build.slice(buf));
|
||||
}
|
||||
|
||||
pub fn clone(this: Version, comptime StringBuilder: type, builder: StringBuilder) Version {
|
||||
pub fn clone(this: Version, buf: []const u8, comptime StringBuilder: type, builder: StringBuilder) Version {
|
||||
var that = this;
|
||||
|
||||
if (this.tag.hasPre()) that.tag.pre = builder.append(ExternalString, this.tag.pre.slice(buf));
|
||||
@@ -214,6 +227,25 @@ pub const Version = extern struct {
|
||||
pre: ExternalString = ExternalString{},
|
||||
build: ExternalString = ExternalString{},
|
||||
|
||||
pub fn cloneInto(this: Tag, slice: []const u8, buf: []u8) Tag {
|
||||
const pre_slice = this.pre.slice(slice);
|
||||
const build_slice = this.build.slice(slice);
|
||||
std.mem.copy(u8, buf, pre_slice);
|
||||
std.mem.copy(u8, buf[pre_slice.len..], build_slice);
|
||||
return Tag{
|
||||
.pre = .{
|
||||
.off = 0,
|
||||
.len = this.pre.len,
|
||||
.hash = this.pre.hash,
|
||||
},
|
||||
.build = .{
|
||||
.off = this.pre.len,
|
||||
.len = this.build.len,
|
||||
.hash = this.build.hash,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn hasPre(this: Tag) bool {
|
||||
return this.pre.len > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user