bun-types 1.2.6-canary.20250314T140704 → 1.2.6-canary.20250315T140627

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bun.d.ts CHANGED
@@ -7010,7 +7010,8 @@ declare module "bun" {
7010
7010
  * This is useful for aborting a subprocess when some other part of the
7011
7011
  * program is aborted, such as a `fetch` response.
7012
7012
  *
7013
- * Internally, this works by calling `subprocess.kill(1)`.
7013
+ * If the signal is aborted, the process will be killed with the signal
7014
+ * specified by `killSignal` (defaults to SIGTERM).
7014
7015
  *
7015
7016
  * @example
7016
7017
  * ```ts
@@ -7029,6 +7030,41 @@ declare module "bun" {
7029
7030
  * ```
7030
7031
  */
7031
7032
  signal?: AbortSignal;
7033
+
7034
+ /**
7035
+ * The maximum amount of time the process is allowed to run in milliseconds.
7036
+ *
7037
+ * If the timeout is reached, the process will be killed with the signal
7038
+ * specified by `killSignal` (defaults to SIGTERM).
7039
+ *
7040
+ * @example
7041
+ * ```ts
7042
+ * // Kill the process after 5 seconds
7043
+ * const subprocess = Bun.spawn({
7044
+ * cmd: ["sleep", "10"],
7045
+ * timeout: 5000,
7046
+ * });
7047
+ * await subprocess.exited; // Will resolve after 5 seconds
7048
+ * ```
7049
+ */
7050
+ timeout?: number;
7051
+
7052
+ /**
7053
+ * The signal to use when killing the process after a timeout or when the AbortSignal is aborted.
7054
+ *
7055
+ * @default "SIGTERM" (signal 15)
7056
+ *
7057
+ * @example
7058
+ * ```ts
7059
+ * // Kill the process with SIGKILL after 5 seconds
7060
+ * const subprocess = Bun.spawn({
7061
+ * cmd: ["sleep", "10"],
7062
+ * timeout: 5000,
7063
+ * killSignal: "SIGKILL",
7064
+ * });
7065
+ * ```
7066
+ */
7067
+ killSignal?: string | number;
7032
7068
  }
7033
7069
 
7034
7070
  type OptionsToSubprocess<Opts extends OptionsObject> =
package/devserver.d.ts CHANGED
@@ -3,6 +3,7 @@ export {};
3
3
  declare global {
4
4
  namespace Bun {
5
5
  type HMREventNames =
6
+ | "bun:ready"
6
7
  | "bun:beforeUpdate"
7
8
  | "bun:afterUpdate"
8
9
  | "bun:beforeFullReload"
@@ -49,8 +50,6 @@ declare global {
49
50
  *
50
51
  * In production, `data` is inlined to be `{}`. This is handy because Bun
51
52
  * knows it can minify `{}.prop ??= value` into `value` in production.
52
- *
53
- *
54
53
  */
55
54
  data: any;
56
55
 
package/docs/api/fetch.md CHANGED
@@ -337,7 +337,7 @@ This will print the request and response headers to your terminal:
337
337
  ```sh
338
338
  [fetch] > HTTP/1.1 GET http://example.com/
339
339
  [fetch] > Connection: keep-alive
340
- [fetch] > User-Agent: Bun/1.2.6-canary.20250314T140704
340
+ [fetch] > User-Agent: Bun/1.2.6-canary.20250315T140627
341
341
  [fetch] > Accept: */*
342
342
  [fetch] > Host: example.com
343
343
  [fetch] > Accept-Encoding: gzip, deflate, br
package/docs/api/spawn.md CHANGED
@@ -77,6 +77,16 @@ console.log(text); // "const input = "hello world".repeat(400); ..."
77
77
 
78
78
  ---
79
79
 
80
+ - `ReadableStream`
81
+ - Use a readable stream as input.
82
+
83
+ ---
84
+
85
+ - `Blob`
86
+ - Use a blob as input.
87
+
88
+ ---
89
+
80
90
  - `number`
81
91
  - Read from the file with a given file descriptor.
82
92
 
@@ -110,7 +120,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
110
120
  ```ts
111
121
  const proc = Bun.spawn(["bun", "--version"]);
112
122
  const text = await new Response(proc.stdout).text();
113
- console.log(text); // => "1.2.6-canary.20250314T140704"
123
+ console.log(text); // => "1.2.6-canary.20250315T140627"
114
124
  ```
115
125
 
116
126
  Configure the output stream by passing one of the following values to `stdout/stderr`:
@@ -129,13 +139,13 @@ Configure the output stream by passing one of the following values to `stdout/st
129
139
 
130
140
  ---
131
141
 
132
- - `Bun.file()`
133
- - Write to the specified file.
142
+ - `"ignore"`
143
+ - Discard the output.
134
144
 
135
145
  ---
136
146
 
137
- - `null`
138
- - Write to `/dev/null`.
147
+ - `Bun.file()`
148
+ - Write to the specified file.
139
149
 
140
150
  ---
141
151
 
@@ -174,7 +184,8 @@ const proc = Bun.spawn(["bun", "--version"]);
174
184
  proc.kill();
175
185
  proc.killed; // true
176
186
 
177
- proc.kill(); // specify an exit code
187
+ proc.kill(15); // specify a signal code
188
+ proc.kill("SIGTERM"); // specify a signal name
178
189
  ```
179
190
 
180
191
  The parent `bun` process will not terminate until all child processes have exited. Use `proc.unref()` to detach the child process from the parent.
@@ -184,6 +195,64 @@ const proc = Bun.spawn(["bun", "--version"]);
184
195
  proc.unref();
185
196
  ```
186
197
 
198
+ ## Resource usage
199
+
200
+ You can get information about the process's resource usage after it has exited:
201
+
202
+ ```ts
203
+ const proc = Bun.spawn(["bun", "--version"]);
204
+ await proc.exited;
205
+
206
+ const usage = proc.resourceUsage();
207
+ console.log(`Max memory used: ${usage.maxRSS} bytes`);
208
+ console.log(`CPU time (user): ${usage.cpuTime.user} µs`);
209
+ console.log(`CPU time (system): ${usage.cpuTime.system} µs`);
210
+ ```
211
+
212
+ ## Using AbortSignal
213
+
214
+ You can abort a subprocess using an `AbortSignal`:
215
+
216
+ ```ts
217
+ const controller = new AbortController();
218
+ const { signal } = controller;
219
+
220
+ const proc = Bun.spawn({
221
+ cmd: ["sleep", "100"],
222
+ signal,
223
+ });
224
+
225
+ // Later, to abort the process:
226
+ controller.abort();
227
+ ```
228
+
229
+ ## Using timeout and killSignal
230
+
231
+ You can set a timeout for a subprocess to automatically terminate after a specific duration:
232
+
233
+ ```ts
234
+ // Kill the process after 5 seconds
235
+ const proc = Bun.spawn({
236
+ cmd: ["sleep", "10"],
237
+ timeout: 5000, // 5 seconds in milliseconds
238
+ });
239
+
240
+ await proc.exited; // Will resolve after 5 seconds
241
+ ```
242
+
243
+ By default, timed-out processes are killed with the `SIGTERM` signal. You can specify a different signal with the `killSignal` option:
244
+
245
+ ```ts
246
+ // Kill the process with SIGKILL after 5 seconds
247
+ const proc = Bun.spawn({
248
+ cmd: ["sleep", "10"],
249
+ timeout: 5000,
250
+ killSignal: "SIGKILL", // Can be string name or signal number
251
+ });
252
+ ```
253
+
254
+ The `killSignal` option also controls which signal is sent when an AbortSignal is aborted.
255
+
187
256
  ## Inter-process communication (IPC)
188
257
 
189
258
  Bun supports direct inter-process communication channel between two `bun` processes. To receive messages from a spawned Bun subprocess, specify an `ipc` handler.
@@ -233,11 +302,17 @@ process.send("Hello from child as string");
233
302
  process.send({ message: "Hello from child as object" });
234
303
  ```
235
304
 
236
- The `ipcMode` option controls the underlying communication format between the two processes:
305
+ The `serialization` option controls the underlying communication format between the two processes:
237
306
 
238
307
  - `advanced`: (default) Messages are serialized using the JSC `serialize` API, which supports cloning [everything `structuredClone` supports](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). This does not support transferring ownership of objects.
239
308
  - `json`: Messages are serialized using `JSON.stringify` and `JSON.parse`, which does not support as many object types as `advanced` does.
240
309
 
310
+ To disconnect the IPC channel from the parent process, call:
311
+
312
+ ```ts
313
+ childProc.disconnect();
314
+ ```
315
+
241
316
  ### IPC between Bun & Node.js
242
317
 
243
318
  To use IPC between a `bun` process and a Node.js process, set `serialization: "json"` in `Bun.spawn`. This is because Node.js and Bun use different JavaScript engines with different object serialization formats.
@@ -310,7 +385,7 @@ spawnSync echo hi 1.47 ms/iter (1.14 ms … 2.64 ms) 1.57 ms 2.37 ms
310
385
 
311
386
  ## Reference
312
387
 
313
- A simple reference of the Spawn API and types are shown below. The real types have complex generics to strongly type the `Subprocess` streams with the options passed to `Bun.spawn` and `Bun.spawnSync`. For full details, find these types as defined [bun.d.ts](https://github.com/oven-sh/bun/blob/main/packages/bun-types/bun.d.ts).
388
+ A reference of the Spawn API and types are shown below. The real types have complex generics to strongly type the `Subprocess` streams with the options passed to `Bun.spawn` and `Bun.spawnSync`. For full details, find these types as defined [bun.d.ts](https://github.com/oven-sh/bun/blob/main/packages/bun-types/bun.d.ts).
314
389
 
315
390
  ```ts
316
391
  interface Bun {
@@ -329,16 +404,25 @@ interface Bun {
329
404
  namespace SpawnOptions {
330
405
  interface OptionsObject {
331
406
  cwd?: string;
332
- env?: Record<string, string>;
333
- stdin?: SpawnOptions.Readable;
334
- stdout?: SpawnOptions.Writable;
335
- stderr?: SpawnOptions.Writable;
336
- onExit?: (
337
- proc: Subprocess,
407
+ env?: Record<string, string | undefined>;
408
+ stdio?: [Writable, Readable, Readable];
409
+ stdin?: Writable;
410
+ stdout?: Readable;
411
+ stderr?: Readable;
412
+ onExit?(
413
+ subprocess: Subprocess,
338
414
  exitCode: number | null,
339
- signalCode: string | null,
340
- error: Error | null,
341
- ) => void;
415
+ signalCode: number | null,
416
+ error?: ErrorLike,
417
+ ): void | Promise<void>;
418
+ ipc?(message: any, subprocess: Subprocess): void;
419
+ serialization?: "json" | "advanced";
420
+ windowsHide?: boolean;
421
+ windowsVerbatimArguments?: boolean;
422
+ argv0?: string;
423
+ signal?: AbortSignal;
424
+ timeout?: number;
425
+ killSignal?: string | number;
342
426
  }
343
427
 
344
428
  type Readable =
@@ -366,39 +450,62 @@ namespace SpawnOptions {
366
450
  | Request;
367
451
  }
368
452
 
369
- interface Subprocess<Stdin, Stdout, Stderr> {
453
+ interface Subprocess extends AsyncDisposable {
454
+ readonly stdin: FileSink | number | undefined;
455
+ readonly stdout: ReadableStream<Uint8Array> | number | undefined;
456
+ readonly stderr: ReadableStream<Uint8Array> | number | undefined;
457
+ readonly readable: ReadableStream<Uint8Array> | number | undefined;
370
458
  readonly pid: number;
371
- // the exact stream types here are derived from the generic parameters
372
- readonly stdin: number | ReadableStream | FileSink | undefined;
373
- readonly stdout: number | ReadableStream | undefined;
374
- readonly stderr: number | ReadableStream | undefined;
375
-
376
459
  readonly exited: Promise<number>;
377
-
378
- readonly exitCode: number | undefined;
379
- readonly signalCode: Signal | null;
460
+ readonly exitCode: number | null;
461
+ readonly signalCode: NodeJS.Signals | null;
380
462
  readonly killed: boolean;
381
463
 
464
+ kill(exitCode?: number | NodeJS.Signals): void;
382
465
  ref(): void;
383
466
  unref(): void;
384
- kill(code?: number): void;
385
- }
386
467
 
387
- interface SyncSubprocess<Stdout, Stderr> {
388
- readonly pid: number;
389
- readonly success: boolean;
390
- // the exact buffer types here are derived from the generic parameters
391
- readonly stdout: Buffer | undefined;
392
- readonly stderr: Buffer | undefined;
468
+ send(message: any): void;
469
+ disconnect(): void;
470
+ resourceUsage(): ResourceUsage | undefined;
393
471
  }
394
472
 
395
- type ReadableSubprocess = Subprocess<any, "pipe", "pipe">;
396
- type WritableSubprocess = Subprocess<"pipe", any, any>;
397
- type PipedSubprocess = Subprocess<"pipe", "pipe", "pipe">;
398
- type NullSubprocess = Subprocess<null, null, null>;
473
+ interface SyncSubprocess {
474
+ stdout: Buffer | undefined;
475
+ stderr: Buffer | undefined;
476
+ exitCode: number;
477
+ success: boolean;
478
+ resourceUsage: ResourceUsage;
479
+ signalCode?: string;
480
+ exitedDueToTimeout?: true;
481
+ pid: number;
482
+ }
399
483
 
400
- type ReadableSyncSubprocess = SyncSubprocess<"pipe", "pipe">;
401
- type NullSyncSubprocess = SyncSubprocess<null, null>;
484
+ interface ResourceUsage {
485
+ contextSwitches: {
486
+ voluntary: number;
487
+ involuntary: number;
488
+ };
489
+
490
+ cpuTime: {
491
+ user: number;
492
+ system: number;
493
+ total: number;
494
+ };
495
+ maxRSS: number;
496
+
497
+ messages: {
498
+ sent: number;
499
+ received: number;
500
+ };
501
+ ops: {
502
+ in: number;
503
+ out: number;
504
+ };
505
+ shmSize: number;
506
+ signalCount: number;
507
+ swapCount: number;
508
+ }
402
509
 
403
510
  type Signal =
404
511
  | "SIGABRT"
@@ -7,7 +7,7 @@ Use `bun publish` to publish a package to the npm registry.
7
7
  $ bun publish
8
8
 
9
9
  ## Output
10
- bun publish v1.2.6-canary.20250314T140704 (ca7428e9)
10
+ bun publish v1.2.6-canary.20250315T140627 (ca7428e9)
11
11
 
12
12
  packed 203B package.json
13
13
  packed 224B README.md
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
9
9
  ✔ Which package manager would you like to use?
10
10
  bun
11
11
  ◐ Installing dependencies...
12
- bun install v1.2.6-canary.20250314T140704 (16b4bf34)
12
+ bun install v1.2.6-canary.20250315T140627 (16b4bf34)
13
13
  + @nuxt/devtools@0.8.2
14
14
  + nuxt@3.7.0
15
15
  785 packages installed [2.67s]
@@ -16,7 +16,7 @@ This will add the package to `peerDependencies` in `package.json`.
16
16
  ```json-diff
17
17
  {
18
18
  "peerDependencies": {
19
- + "@types/bun": "^1.2.6-canary.20250314T140704"
19
+ + "@types/bun": "^1.2.6-canary.20250315T140627"
20
20
  }
21
21
  }
22
22
  ```
@@ -28,7 +28,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
28
28
  ```json-diff
29
29
  {
30
30
  "peerDependencies": {
31
- "@types/bun": "^1.2.6-canary.20250314T140704"
31
+ "@types/bun": "^1.2.6-canary.20250315T140627"
32
32
  },
33
33
  "peerDependenciesMeta": {
34
34
  + "@types/bun": {
@@ -97,7 +97,7 @@ $ bun update
97
97
  $ bun update @types/bun --latest
98
98
 
99
99
  # Update a dependency to a specific version
100
- $ bun update @types/bun@1.2.6-canary.20250314T140704
100
+ $ bun update @types/bun@1.2.6-canary.20250315T140627
101
101
 
102
102
  # Update all dependencies to the latest versions
103
103
  $ bun update --latest
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
21
21
 
22
22
  ```sh
23
23
  $ bun test
24
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
24
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
25
25
 
26
26
  test.test.js:
27
27
  ✓ add [0.87ms]
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
47
47
 
48
48
  ```sh
49
49
  $ bun test test3
50
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
50
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
51
51
 
52
52
  test3.test.js:
53
53
  ✓ add [1.40ms]
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
85
85
 
86
86
  ```sh
87
87
  $ bun test -t add
88
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
88
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
89
89
 
90
90
  test.test.js:
91
91
  ✓ add [1.79ms]
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
18
18
 
19
19
  ```sh
20
20
  $ bun test test/snap
21
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
21
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
22
22
 
23
23
  test/snap.test.ts:
24
24
  ✓ snapshot [1.48ms]
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
61
61
 
62
62
  ```sh
63
63
  $ bun test
64
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
64
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
65
65
 
66
66
  test/snap.test.ts:
67
67
  ✓ snapshot [1.05ms]
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
78
78
 
79
79
  ```sh
80
80
  $ bun test --update-snapshots
81
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
81
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
82
82
 
83
83
  test/snap.test.ts:
84
84
  ✓ snapshot [0.86ms]
@@ -29,7 +29,7 @@ To regenerate snapshots, use the `--update-snapshots` flag.
29
29
 
30
30
  ```sh
31
31
  $ bun test --update-snapshots
32
- bun test v1.2.6-canary.20250314T140704 (9c68abdb)
32
+ bun test v1.2.6-canary.20250315T140627 (9c68abdb)
33
33
 
34
34
  test/snap.test.ts:
35
35
  ✓ snapshot [0.86ms]
@@ -5,7 +5,7 @@ name: Get the current Bun version
5
5
  Get the current version of Bun in a semver format.
6
6
 
7
7
  ```ts#index.ts
8
- Bun.version; // => "1.2.6-canary.20250314T140704"
8
+ Bun.version; // => "1.2.6-canary.20250315T140627"
9
9
  ```
10
10
 
11
11
  ---
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
14
14
  ```bash#macOS/Linux_(curl)
15
15
  $ curl -fsSL https://bun.sh/install | bash # for macOS, Linux, and WSL
16
16
  # to install a specific version
17
- $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.6-canary.20250314T140704"
17
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.6-canary.20250315T140627"
18
18
  ```
19
19
 
20
20
  ```bash#npm
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
189
189
 
190
190
  ### Installing a specific version of Bun on Linux/Mac
191
191
 
192
- To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.6-canary.20250314T140704`.
192
+ To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.6-canary.20250315T140627`.
193
193
 
194
194
  ```sh
195
- $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.6-canary.20250314T140704"
195
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.6-canary.20250315T140627"
196
196
  ```
197
197
 
198
198
  ### Installing a specific version of Bun on Windows
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
201
201
 
202
202
  ```sh
203
203
  # PowerShell:
204
- $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.6-canary.20250314T140704"
204
+ $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.6-canary.20250315T140627"
205
205
  ```
206
206
 
207
207
  ## Downloading Bun binaries directly
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
124
124
  This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
125
125
 
126
126
  ```sh
127
- [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.6-canary.20250314T140704" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
127
+ [fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.6-canary.20250315T140627" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
128
128
  [fetch] > HTTP/1.1 POST https://example.com/
129
129
  [fetch] > content-type: application/json
130
130
  [fetch] > Connection: keep-alive
131
- [fetch] > User-Agent: Bun/1.2.6-canary.20250314T140704
131
+ [fetch] > User-Agent: Bun/1.2.6-canary.20250315T140627
132
132
  [fetch] > Accept: */*
133
133
  [fetch] > Host: example.com
134
134
  [fetch] > Accept-Encoding: gzip, deflate, br
@@ -170,7 +170,7 @@ This prints the following to the console:
170
170
  [fetch] > HTTP/1.1 POST https://example.com/
171
171
  [fetch] > content-type: application/json
172
172
  [fetch] > Connection: keep-alive
173
- [fetch] > User-Agent: Bun/1.2.6-canary.20250314T140704
173
+ [fetch] > User-Agent: Bun/1.2.6-canary.20250315T140627
174
174
  [fetch] > Accept: */*
175
175
  [fetch] > Host: example.com
176
176
  [fetch] > Accept-Encoding: gzip, deflate, br
package/docs/test/dom.md CHANGED
@@ -55,7 +55,7 @@ Let's run this test with `bun test`:
55
55
 
56
56
  ```bash
57
57
  $ bun test
58
- bun test v1.2.6-canary.20250314T140704
58
+ bun test v1.2.6-canary.20250315T140627
59
59
 
60
60
  dom.test.ts:
61
61
  ✓ dom test [0.82ms]
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.6-canary.20250314T140704",
2
+ "version": "1.2.6-canary.20250315T140627",
3
3
  "name": "bun-types",
4
4
  "license": "MIT",
5
5
  "types": "./index.d.ts",