aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/bun-types/bun.d.ts6
-rw-r--r--src/bun.js/bindings/generated_classes.zig4
-rw-r--r--src/bun.js/bindings/header-gen.zig8
-rw-r--r--src/bun.js/child_process.exports.js20
-rw-r--r--test/bun.js/spawn.test.ts7
5 files changed, 23 insertions, 22 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts
index c9ea2fb66..ea72c2a85 100644
--- a/packages/bun-types/bun.d.ts
+++ b/packages/bun-types/bun.d.ts
@@ -2612,7 +2612,11 @@ declare module "bun" {
/**
* Callback that runs when the {@link Subprocess} exits
*
- * You can also do `await subprocess.exited` to wait for the process to exit.
+ * This is called even if the process exits with a non-zero exit code.
+ *
+ * Warning: this may run before the `Bun.spawn` function returns.
+ *
+ * A simple alternative is `await subprocess.exited`.
*
* @example
*
diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig
index 7689dc4bb..0099d2c9f 100644
--- a/src/bun.js/bindings/generated_classes.zig
+++ b/src/bun.js/bindings/generated_classes.zig
@@ -570,6 +570,9 @@ pub const JSSubprocess = struct {
if (@TypeOf(Subprocess.doRef) != CallbackType)
@compileLog("Expected Subprocess.doRef to be a callback");
+ if (@TypeOf(Subprocess.getSignalCode) != GetterType)
+ @compileLog("Expected Subprocess.getSignalCode to be a getter");
+
if (@TypeOf(Subprocess.getStderr) != GetterType)
@compileLog("Expected Subprocess.getStderr to be a getter");
@@ -592,6 +595,7 @@ pub const JSSubprocess = struct {
@export(Subprocess.getExited, .{ .name = "SubprocessPrototype__getExited" });
@export(Subprocess.getKilled, .{ .name = "SubprocessPrototype__getKilled" });
@export(Subprocess.getPid, .{ .name = "SubprocessPrototype__getPid" });
+ @export(Subprocess.getSignalCode, .{ .name = "SubprocessPrototype__getSignalCode" });
@export(Subprocess.getStderr, .{ .name = "SubprocessPrototype__getStderr" });
@export(Subprocess.getStdin, .{ .name = "SubprocessPrototype__getStdin" });
@export(Subprocess.getStdout, .{ .name = "SubprocessPrototype__getStdout" });
diff --git a/src/bun.js/bindings/header-gen.zig b/src/bun.js/bindings/header-gen.zig
index 6fb426a27..5281aa0f0 100644
--- a/src/bun.js/bindings/header-gen.zig
+++ b/src/bun.js/bindings/header-gen.zig
@@ -9,7 +9,7 @@ const warn = std.debug.warn;
const StaticExport = @import("./static_export.zig");
const typeBaseName = @import("../../meta.zig").typeBaseName;
-const TypeNameMap = std.StringHashMap([]const u8);
+const TypeNameMap = bun.StringHashMap([]const u8);
fn isCppObject(comptime Type: type) bool {
return switch (@typeInfo(Type)) {
@@ -76,8 +76,8 @@ var impl_writer = impl_buffer.writer();
var bufset = std.BufSet.init(std.heap.c_allocator);
var type_names = TypeNameMap.init(std.heap.c_allocator);
var opaque_types = std.BufSet.init(std.heap.c_allocator);
-var size_map = std.StringHashMap(u32).init(std.heap.c_allocator);
-var align_map = std.StringHashMap(u29).init(std.heap.c_allocator);
+var size_map = bun.StringHashMap(u32).init(std.heap.c_allocator);
+var align_map = bun.StringHashMap(u29).init(std.heap.c_allocator);
pub const C_Generator = struct {
filebase: []const u8,
@@ -934,7 +934,7 @@ pub fn HeaderGen(comptime first_import: type, comptime second_import: type, comp
dom_buffer.items,
}) catch unreachable;
- const NamespaceMap = std.StringArrayHashMap(std.BufMap);
+ const NamespaceMap = bun.StringArrayHashMap(std.BufMap);
var namespaces = NamespaceMap.init(std.heap.c_allocator);
var size_iter = size_map.iterator();
diff --git a/src/bun.js/child_process.exports.js b/src/bun.js/child_process.exports.js
index a727522c8..fdeec31f8 100644
--- a/src/bun.js/child_process.exports.js
+++ b/src/bun.js/child_process.exports.js
@@ -889,13 +889,10 @@ export class ChildProcess extends EventEmitter {
// this.#handle[owner_symbol] = this;
// }
- async #handleOnExit(exitCode, signalCode) {
+ #handleOnExit(exitCode, signalCode, err) {
if (this.#exited) return;
- if (signalCode) {
- this.signalCode = signalCode;
- } else {
- this.exitCode = this.#handle.exitCode;
- }
+ this.exitCode = this.#handle.exitCode;
+ this.signalCode = exitCode > 0 ? signalCode : null;
if (this.#stdin) {
this.#stdin.destroy();
@@ -919,12 +916,6 @@ export class ChildProcess extends EventEmitter {
err.spawnargs = ArrayPrototypeSlice.call(this.spawnargs, 1);
this.emit("error", err);
} else {
- const maybeExited = Bun.peek(this.#handleExited);
- if (maybeExited === this.#handleExited) {
- this.exitCode = await this.#handleExited;
- } else {
- this.exitCode = maybeExited;
- }
this.emit("exit", this.exitCode, this.signalCode);
}
@@ -1079,7 +1070,10 @@ export class ChildProcess extends EventEmitter {
stderr: bunStdio[2],
cwd: options.cwd || undefined,
env,
- onExit: this.#handleOnExit.bind(this),
+ onExit: (handle, exitCode, signalCode, err) => {
+ this.#handle = handle;
+ this.#handleOnExit(exitCode, signalCode, err);
+ },
lazy: true,
});
diff --git a/test/bun.js/spawn.test.ts b/test/bun.js/spawn.test.ts
index fafabcd7b..d34a217a8 100644
--- a/test/bun.js/spawn.test.ts
+++ b/test/bun.js/spawn.test.ts
@@ -140,8 +140,7 @@ for (let [gcTick, label] of [
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
- onExit(code) {
- console.log("first");
+ onExit(subprocess, code) {
exitCode1 = code;
counter++;
if (counter === 2) {
@@ -155,10 +154,10 @@ for (let [gcTick, label] of [
stdin: "ignore",
stdout: "ignore",
stderr: "ignore",
- onExit(code) {
- console.log("second");
+ onExit(subprocess, code) {
exitCode2 = code;
counter++;
+
if (counter === 2) {
resolve();
}