mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 04:18:58 +00:00
[bun install] Fix case when lockfile exists
This commit is contained in:
@@ -222,6 +222,7 @@ pub fn main() anyerror!void {
|
||||
};
|
||||
ctx.http.callback = HTTP.HTTPChannelContext.callback;
|
||||
ctx.http.schedule(default_allocator, &batch);
|
||||
|
||||
}
|
||||
NetworkThread.global.pool.schedule(batch);
|
||||
|
||||
|
||||
@@ -499,9 +499,13 @@ pub const FileSystem = struct {
|
||||
};
|
||||
|
||||
pub var tmpdir_path: []const u8 = undefined;
|
||||
pub var tmpdir_path_set = false;
|
||||
pub fn openTmpDir(fs: *const RealFS) !std.fs.Dir {
|
||||
var tmpdir_base = std.os.getenv("TMPDIR") orelse PLATFORM_TMP_DIR;
|
||||
tmpdir_path = try std.fs.realpath(tmpdir_base, &tmpdir_buf);
|
||||
if (!tmpdir_path_set) {
|
||||
tmpdir_path = std.os.getenv("TMPDIR") orelse PLATFORM_TMP_DIR;
|
||||
tmpdir_path_set = true;
|
||||
}
|
||||
|
||||
return try std.fs.openDirAbsolute(tmpdir_path, .{ .access_sub_paths = true, .iterate = true });
|
||||
}
|
||||
|
||||
|
||||
@@ -204,9 +204,10 @@ pub const HTTPChannelContext = struct {
|
||||
http: AsyncHTTP = undefined,
|
||||
channel: *HTTPChannel,
|
||||
|
||||
pub fn callback(http: *AsyncHTTP) void {
|
||||
pub fn callback(http: *AsyncHTTP, sender: *AsyncHTTP.HTTPSender) void {
|
||||
var this: *HTTPChannelContext = @fieldParentPtr(HTTPChannelContext, "http", http);
|
||||
this.channel.writeItem(http) catch unreachable;
|
||||
sender.onFinish();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -242,7 +243,7 @@ pub const AsyncHTTP = struct {
|
||||
/// Executes on the network thread
|
||||
callback: ?CompletionCallback = null,
|
||||
|
||||
pub const CompletionCallback = fn (this: *AsyncHTTP) void;
|
||||
pub const CompletionCallback = fn (this: *AsyncHTTP, sender: *HTTPSender) void;
|
||||
pub var active_requests_count = std.atomic.Atomic(u32).init(0);
|
||||
|
||||
pub const State = enum(u32) {
|
||||
@@ -286,38 +287,54 @@ pub const AsyncHTTP = struct {
|
||||
batch.push(ThreadPool.Batch.from(&sender.task));
|
||||
}
|
||||
|
||||
const HTTPSender = struct {
|
||||
var http_sender_head: std.atomic.Atomic(?*HTTPSender) = std.atomic.Atomic(?*HTTPSender).init(null);
|
||||
|
||||
pub const HTTPSender = struct {
|
||||
task: ThreadPool.Task = .{ .callback = callback },
|
||||
frame: @Frame(AsyncHTTP.do) = undefined,
|
||||
http: *AsyncHTTP = undefined,
|
||||
|
||||
next: ?*HTTPSender = null,
|
||||
|
||||
var head: ?*HTTPSender = null;
|
||||
|
||||
pub fn get(http: *AsyncHTTP, allocator: *std.mem.Allocator) *HTTPSender {
|
||||
if (head == null) {
|
||||
head = allocator.create(HTTPSender) catch unreachable;
|
||||
head.?.* = HTTPSender{};
|
||||
@fence(.Acquire);
|
||||
|
||||
var head_ = http_sender_head.load(.Monotonic);
|
||||
|
||||
if (head_ == null) {
|
||||
var new_head = allocator.create(HTTPSender) catch unreachable;
|
||||
new_head.* = HTTPSender{};
|
||||
new_head.next = null;
|
||||
new_head.task = .{ .callback = callback };
|
||||
new_head.http = http;
|
||||
return new_head;
|
||||
}
|
||||
|
||||
var head_ = head.?;
|
||||
head = head.?.next;
|
||||
head_.next = null;
|
||||
head_.task = .{ .callback = callback };
|
||||
head_.http = http;
|
||||
http_sender_head.store(head_.?.next, .Monotonic);
|
||||
|
||||
return head_;
|
||||
head_.?.* = HTTPSender{};
|
||||
head_.?.next = null;
|
||||
head_.?.task = .{ .callback = callback };
|
||||
head_.?.http = http;
|
||||
|
||||
return head_.?;
|
||||
}
|
||||
|
||||
pub fn release(this: *HTTPSender) void {}
|
||||
pub fn release(this: *HTTPSender) void {
|
||||
@fence(.Acquire);
|
||||
this.task = .{ .callback = callback };
|
||||
this.http = undefined;
|
||||
this.next = http_sender_head.swap(this, .Monotonic);
|
||||
}
|
||||
|
||||
pub fn callback(task: *ThreadPool.Task) void {
|
||||
var this = @fieldParentPtr(HTTPSender, "task", task);
|
||||
this.frame = async AsyncHTTP.do(this);
|
||||
}
|
||||
|
||||
pub fn onFinish(this: *HTTPSender) void {}
|
||||
pub fn onFinish(this: *HTTPSender) void {
|
||||
this.release();
|
||||
}
|
||||
};
|
||||
|
||||
pub fn do(sender: *HTTPSender) void {
|
||||
@@ -348,10 +365,8 @@ pub const AsyncHTTP = struct {
|
||||
}
|
||||
|
||||
if (sender.http.callback) |callback| {
|
||||
callback(sender.http);
|
||||
callback(sender.http, sender);
|
||||
}
|
||||
|
||||
sender.release();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2020,7 +2020,7 @@ pub const Expr = struct {
|
||||
pub fn isEmpty(expr: *Expr) bool {
|
||||
return std.meta.activeTag(expr.data) == .e_missing;
|
||||
}
|
||||
pub const Query = struct { expr: Expr, loc: logger.Loc };
|
||||
pub const Query = struct { expr: Expr, loc: logger.Loc, i: u32 = 0 };
|
||||
|
||||
pub fn getArray(exp: *const Expr) *E.Array {
|
||||
return exp.data.e_array;
|
||||
@@ -2145,13 +2145,17 @@ pub const Expr = struct {
|
||||
const obj = expr.data.e_object;
|
||||
if (@ptrToInt(obj.properties.ptr) == 0) return null;
|
||||
|
||||
for (obj.properties) |prop| {
|
||||
for (obj.properties) |prop, i| {
|
||||
const value = prop.value orelse continue;
|
||||
const key = prop.key orelse continue;
|
||||
if (std.meta.activeTag(key.data) != .e_string) continue;
|
||||
const key_str = key.data.e_string;
|
||||
if (key_str.eql(string, name)) {
|
||||
return Query{ .expr = value, .loc = key.loc };
|
||||
return Query{
|
||||
.expr = value,
|
||||
.loc = key.loc,
|
||||
.i = @truncate(u32, i),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user