Skip to content

Commit 5fec71b

Browse files
Co-authored-by: Jarred Sumner <[email protected]>
1 parent 3d8c10c commit 5fec71b

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-3
lines changed

src/bun.js/api/bun/process.zig

+22
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,28 @@ pub const Status = union(enum) {
543543
else => null,
544544
};
545545
}
546+
547+
pub fn format(self: @This(), comptime _: []const u8, _: anytype, writer: anytype) !void {
548+
if (self.signalCode()) |signal_code| {
549+
if (signal_code.toExitCode()) |code| {
550+
try writer.print("code: {d}", .{code});
551+
return;
552+
}
553+
}
554+
555+
switch (self) {
556+
.exited => |exit| {
557+
try writer.print("code: {d}", .{exit.code});
558+
},
559+
.signaled => |signal| {
560+
try writer.print("signal: {d}", .{@intFromEnum(signal)});
561+
},
562+
.err => |err| {
563+
try writer.print("{}", .{err});
564+
},
565+
else => {},
566+
}
567+
}
546568
};
547569

548570
pub const PollerPosix = union(enum) {

src/install/install.zig

+9-1
Original file line numberDiff line numberDiff line change
@@ -8482,6 +8482,7 @@ pub const PackageManager = struct {
84828482
.package_version = resolution_label,
84838483
// .install_order = this.tree_iterator.order,
84848484
};
8485+
debug("Installing {s}@{s}", .{ name, resolution_label });
84858486

84868487
switch (resolution.tag) {
84878488
.npm => {
@@ -8742,7 +8743,14 @@ pub const PackageManager = struct {
87428743
);
87438744
},
87448745
.npm => {
8745-
if (comptime Environment.allow_assert) std.debug.assert(!resolution.value.npm.url.isEmpty());
8746+
if (comptime Environment.isDebug) {
8747+
// Very old versions of Bun didn't store the tarball url when it didn't seem necessary
8748+
// This caused bugs. We can't assert on it because they could come from old lockfiles
8749+
if (resolution.value.npm.url.isEmpty()) {
8750+
Output.debugWarn("package {s}@{} missing tarball_url", .{ name, resolution.fmt(buf) });
8751+
}
8752+
}
8753+
87468754
this.manager.enqueuePackageForDownload(
87478755
name,
87488756
dependency_id,

src/install/lifecycle_script_runner.zig

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const WaiterThread = bun.spawn.WaiterThread;
1212
const Timer = std.time.Timer;
1313

1414
const Process = bun.spawn.Process;
15+
const log = Output.scoped(.Script, false);
1516
pub const LifecycleScriptSubprocess = struct {
1617
package_name: []const u8,
1718

@@ -28,6 +29,8 @@ pub const LifecycleScriptSubprocess = struct {
2829

2930
timer: ?Timer = null,
3031

32+
has_incremented_alive_count: bool = false,
33+
3134
pub usingnamespace bun.New(@This());
3235

3336
pub const min_milliseconds_to_log = 500;
@@ -84,8 +87,17 @@ pub const LifecycleScriptSubprocess = struct {
8487
var cwd_z_buf: bun.PathBuffer = undefined;
8588

8689
pub fn spawnNextScript(this: *LifecycleScriptSubprocess, next_script_index: u8) !void {
87-
_ = alive_count.fetchAdd(1, .Monotonic);
88-
errdefer _ = alive_count.fetchSub(1, .Monotonic);
90+
if (!this.has_incremented_alive_count) {
91+
this.has_incremented_alive_count = true;
92+
_ = alive_count.fetchAdd(1, .Monotonic);
93+
}
94+
95+
errdefer {
96+
if (this.has_incremented_alive_count) {
97+
this.has_incremented_alive_count = false;
98+
_ = alive_count.fetchSub(1, .Monotonic);
99+
}
100+
}
89101

90102
const manager = this.manager;
91103
const original_script = this.scripts.items[next_script_index].?;
@@ -119,6 +131,8 @@ pub const LifecycleScriptSubprocess = struct {
119131

120132
const combined_script: [:0]u8 = copy_script.items[0 .. copy_script.items.len - 1 :0];
121133

134+
log("{s} - {s} $ {s}", .{ this.package_name, this.scriptName(), combined_script });
135+
122136
var argv = [_]?[*:0]const u8{
123137
shell_bin,
124138
if (Environment.isWindows) "/c" else "-c",
@@ -225,6 +239,13 @@ pub const LifecycleScriptSubprocess = struct {
225239
}
226240

227241
fn handleExit(this: *LifecycleScriptSubprocess, status: bun.spawn.Status) void {
242+
log("{s} - {s} finished {}", .{ this.package_name, this.scriptName(), status });
243+
244+
if (this.has_incremented_alive_count) {
245+
this.has_incremented_alive_count = false;
246+
_ = alive_count.fetchSub(1, .Monotonic);
247+
}
248+
228249
switch (status) {
229250
.exited => |exit| {
230251
const maybe_duration = if (this.timer) |*t| t.read() else null;

src/install/lockfile.zig

+6
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,12 @@ pub const Package = extern struct {
31533153
dependencies_list.items = dependencies_list.items.ptr[0..new_length];
31543154
resolutions_list.items = resolutions_list.items.ptr[0..new_length];
31553155

3156+
if (comptime Environment.isDebug) {
3157+
if (package.resolution.value.npm.url.isEmpty()) {
3158+
Output.panic("tarball_url is empty for package {s}@{}", .{ manifest.name(), version });
3159+
}
3160+
}
3161+
31563162
return package;
31573163
}
31583164
}

0 commit comments

Comments
 (0)