bun-types 1.2.11-canary.20250418T140557 → 1.2.11-canary.20250420T140512
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 +348 -289
- package/docs/api/fetch.md +1 -1
- package/docs/api/spawn.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/install/add-peer.md +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/debugger.md +3 -3
- package/docs/runtime/nodejs-apis.md +1 -2
- package/docs/test/dom.md +1 -1
- package/fetch.d.ts +1 -1
- package/globals.d.ts +1 -3
- package/package.json +1 -1
- package/redis.d.ts +0 -6
- package/s3.d.ts +0 -1
- package/shell.d.ts +46 -22
- package/test.d.ts +403 -402
package/bun.d.ts
CHANGED
|
@@ -46,9 +46,6 @@ declare module "bun" {
|
|
|
46
46
|
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
47
47
|
type BlobOrStringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike | Blob;
|
|
48
48
|
|
|
49
|
-
/**
|
|
50
|
-
* @private
|
|
51
|
-
*/
|
|
52
49
|
namespace __internal {
|
|
53
50
|
type LibDomIsLoaded = typeof globalThis extends { onabort: any } ? true : false;
|
|
54
51
|
|
|
@@ -62,8 +59,6 @@ declare module "bun" {
|
|
|
62
59
|
* Unfortunately some symbols cannot be defined when both Bun types and lib.dom.d.ts types are loaded,
|
|
63
60
|
* and since we can't redeclare the symbol in a way that satisfies both, we need to fallback
|
|
64
61
|
* to the type that lib.dom.d.ts provides.
|
|
65
|
-
*
|
|
66
|
-
* @internal
|
|
67
62
|
*/
|
|
68
63
|
type UseLibDomIfAvailable<GlobalThisKeyName extends PropertyKey, Otherwise> =
|
|
69
64
|
// `onabort` is defined in lib.dom.d.ts, so we can check to see if lib dom is loaded by checking if `onabort` is defined
|
|
@@ -74,6 +69,7 @@ declare module "bun" {
|
|
|
74
69
|
: Otherwise; // Lib dom not loaded anyway, so no conflict. We can safely use our own definition
|
|
75
70
|
}
|
|
76
71
|
|
|
72
|
+
/** @deprecated This type is unused in Bun's types and might be removed in the near future */
|
|
77
73
|
type Platform =
|
|
78
74
|
| "aix"
|
|
79
75
|
| "android"
|
|
@@ -87,16 +83,21 @@ declare module "bun" {
|
|
|
87
83
|
| "cygwin"
|
|
88
84
|
| "netbsd";
|
|
89
85
|
|
|
86
|
+
/** @deprecated This type is unused in Bun's types and might be removed in the near future */
|
|
90
87
|
type Architecture = "arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x64";
|
|
91
88
|
|
|
89
|
+
/** @deprecated This type is unused in Bun's types and might be removed in the near future */
|
|
92
90
|
type UncaughtExceptionListener = (error: Error, origin: UncaughtExceptionOrigin) => void;
|
|
93
91
|
|
|
94
92
|
/**
|
|
95
93
|
* Most of the time the unhandledRejection will be an Error, but this should not be relied upon
|
|
96
94
|
* as *anything* can be thrown/rejected, it is therefore unsafe to assume that the value is an Error.
|
|
95
|
+
*
|
|
96
|
+
* @deprecated This type is unused in Bun's types and might be removed in the near future
|
|
97
97
|
*/
|
|
98
98
|
type UnhandledRejectionListener = (reason: unknown, promise: Promise<unknown>) => void;
|
|
99
99
|
|
|
100
|
+
/** @deprecated This type is unused in Bun's types and might be removed in the near future */
|
|
100
101
|
type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<unknown>, value: unknown) => void;
|
|
101
102
|
|
|
102
103
|
interface ErrorEventInit extends EventInit {
|
|
@@ -522,18 +523,44 @@ declare module "bun" {
|
|
|
522
523
|
* The raw arguments passed to the process, including flags passed to Bun. If you want to easily read flags passed to your script, consider using `process.argv` instead.
|
|
523
524
|
*/
|
|
524
525
|
const argv: string[];
|
|
525
|
-
|
|
526
|
+
|
|
527
|
+
interface WhichOptions {
|
|
528
|
+
/**
|
|
529
|
+
* Overrides the PATH environment variable
|
|
530
|
+
*/
|
|
531
|
+
PATH?: string;
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* When given a relative path, use this path to join it.
|
|
535
|
+
*/
|
|
536
|
+
cwd?: string;
|
|
537
|
+
}
|
|
526
538
|
|
|
527
539
|
/**
|
|
528
540
|
* Find the path to an executable, similar to typing which in your terminal. Reads the `PATH` environment variable unless overridden with `options.PATH`.
|
|
529
541
|
*
|
|
530
542
|
* @category Utilities
|
|
531
543
|
*
|
|
532
|
-
* @param command The name of the executable or script
|
|
533
|
-
* @param options
|
|
534
|
-
* @param options.cwd When given a relative path, use this path to join it.
|
|
544
|
+
* @param command The name of the executable or script to find
|
|
545
|
+
* @param options Options for the search
|
|
535
546
|
*/
|
|
536
|
-
function which(command: string, options?:
|
|
547
|
+
function which(command: string, options?: WhichOptions): string | null;
|
|
548
|
+
|
|
549
|
+
interface StringWidthOptions {
|
|
550
|
+
/**
|
|
551
|
+
* If `true`, count ANSI escape codes as part of the string width. If `false`, ANSI escape codes are ignored when calculating the string width.
|
|
552
|
+
*
|
|
553
|
+
* @default false
|
|
554
|
+
*/
|
|
555
|
+
countAnsiEscapeCodes?: boolean;
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* When it's ambiugous and `true`, count emoji as 1 characters wide. If `false`, emoji are counted as 2 character wide.
|
|
559
|
+
*
|
|
560
|
+
* @default true
|
|
561
|
+
*/
|
|
562
|
+
ambiguousIsNarrow?: boolean;
|
|
563
|
+
}
|
|
537
564
|
|
|
538
565
|
/**
|
|
539
566
|
* Get the column count of a string as it would be displayed in a terminal.
|
|
@@ -565,20 +592,7 @@ declare module "bun" {
|
|
|
565
592
|
* The string to measure
|
|
566
593
|
*/
|
|
567
594
|
input: string,
|
|
568
|
-
options?:
|
|
569
|
-
/**
|
|
570
|
-
* If `true`, count ANSI escape codes as part of the string width. If `false`, ANSI escape codes are ignored when calculating the string width.
|
|
571
|
-
*
|
|
572
|
-
* @default false
|
|
573
|
-
*/
|
|
574
|
-
countAnsiEscapeCodes?: boolean;
|
|
575
|
-
/**
|
|
576
|
-
* When it's ambiugous and `true`, count emoji as 1 characters wide. If `false`, emoji are counted as 2 character wide.
|
|
577
|
-
*
|
|
578
|
-
* @default true
|
|
579
|
-
*/
|
|
580
|
-
ambiguousIsNarrow?: boolean;
|
|
581
|
-
},
|
|
595
|
+
options?: StringWidthOptions,
|
|
582
596
|
): number;
|
|
583
597
|
|
|
584
598
|
/**
|
|
@@ -621,13 +635,17 @@ declare module "bun" {
|
|
|
621
635
|
*
|
|
622
636
|
* @param destination The file or file path to write to
|
|
623
637
|
* @param input The data to copy into `destination`.
|
|
638
|
+
* @param options Options for the write
|
|
639
|
+
*
|
|
624
640
|
* @returns A promise that resolves with the number of bytes written.
|
|
625
641
|
*/
|
|
626
642
|
function write(
|
|
627
643
|
destination: BunFile | S3File | PathLike,
|
|
628
644
|
input: Blob | NodeJS.TypedArray | ArrayBufferLike | string | BlobPart[],
|
|
629
645
|
options?: {
|
|
630
|
-
/**
|
|
646
|
+
/**
|
|
647
|
+
* If writing to a PathLike, set the permissions of the file.
|
|
648
|
+
*/
|
|
631
649
|
mode?: number;
|
|
632
650
|
/**
|
|
633
651
|
* If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
|
|
@@ -648,6 +666,8 @@ declare module "bun" {
|
|
|
648
666
|
* overwritten. If `input`'s size is less than `destination`'s size,
|
|
649
667
|
* `destination` will be truncated.
|
|
650
668
|
* @param input - `Response` object
|
|
669
|
+
* @param options Options for the write
|
|
670
|
+
*
|
|
651
671
|
* @returns A promise that resolves with the number of bytes written.
|
|
652
672
|
*/
|
|
653
673
|
function write(
|
|
@@ -856,7 +876,8 @@ declare module "bun" {
|
|
|
856
876
|
* @param multipartBoundaryExcludingDashes Optional boundary to use for multipart form data. If none is provided, assumes it is a URLEncoded form.
|
|
857
877
|
* @returns A promise that resolves with the data encoded into a {@link FormData} object.
|
|
858
878
|
*
|
|
859
|
-
* @example
|
|
879
|
+
* @example
|
|
880
|
+
* **Multipart form data example**
|
|
860
881
|
* ```ts
|
|
861
882
|
* // without dashes
|
|
862
883
|
* const boundary = "WebKitFormBoundary" + Math.random().toString(16).slice(2);
|
|
@@ -866,7 +887,7 @@ declare module "bun" {
|
|
|
866
887
|
* formData.get("foo"); // "bar"
|
|
867
888
|
* ```
|
|
868
889
|
*
|
|
869
|
-
*
|
|
890
|
+
* **URL-encoded form data example**
|
|
870
891
|
* ```ts
|
|
871
892
|
* const stream = new Response("hello=123").body;
|
|
872
893
|
* const formData = await Bun.readableStreamToFormData(stream);
|
|
@@ -944,14 +965,13 @@ declare module "bun" {
|
|
|
944
965
|
*/
|
|
945
966
|
function pathToFileURL(path: string): URL;
|
|
946
967
|
|
|
947
|
-
interface Peek {
|
|
948
|
-
<T = undefined>(promise: T | Promise<T>): Promise<T> | T;
|
|
949
|
-
status<T = undefined>(promise: T | Promise<T>): "pending" | "fulfilled" | "rejected";
|
|
950
|
-
}
|
|
951
968
|
/**
|
|
952
969
|
* Extract the value from the Promise in the same tick of the event loop
|
|
953
970
|
*/
|
|
954
|
-
|
|
971
|
+
function peek<T = undefined>(promise: T | Promise<T>): Promise<T> | T;
|
|
972
|
+
namespace peek {
|
|
973
|
+
function status<T = undefined>(promise: T | Promise<T>): "pending" | "fulfilled" | "rejected";
|
|
974
|
+
}
|
|
955
975
|
|
|
956
976
|
/**
|
|
957
977
|
* Convert a {@link URL} to a filesystem path.
|
|
@@ -1014,29 +1034,27 @@ declare module "bun" {
|
|
|
1014
1034
|
* @param hostname The hostname to lookup
|
|
1015
1035
|
* @param options Options for the lookup
|
|
1016
1036
|
*
|
|
1017
|
-
*
|
|
1018
|
-
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ## Basic usage
|
|
1019
1039
|
* ```js
|
|
1020
1040
|
* const [{ address }] = await Bun.dns.lookup('example.com');
|
|
1021
1041
|
* ```
|
|
1022
1042
|
*
|
|
1023
|
-
*
|
|
1024
|
-
*
|
|
1043
|
+
* ## Filter results to IPv4
|
|
1025
1044
|
* ```js
|
|
1026
1045
|
* import { dns } from 'bun';
|
|
1027
1046
|
* const [{ address }] = await dns.lookup('example.com', {family: 4});
|
|
1028
1047
|
* console.log(address); // "123.122.22.126"
|
|
1029
1048
|
* ```
|
|
1030
1049
|
*
|
|
1031
|
-
*
|
|
1032
|
-
*
|
|
1050
|
+
* ## Filter results to IPv6
|
|
1033
1051
|
* ```js
|
|
1034
1052
|
* import { dns } from 'bun';
|
|
1035
1053
|
* const [{ address }] = await dns.lookup('example.com', {family: 6});
|
|
1036
1054
|
* console.log(address); // "2001:db8::1"
|
|
1037
1055
|
* ```
|
|
1038
1056
|
*
|
|
1039
|
-
*
|
|
1057
|
+
* ## DNS resolver client
|
|
1040
1058
|
*
|
|
1041
1059
|
* Bun supports three DNS resolvers:
|
|
1042
1060
|
* - `c-ares` - Uses the c-ares library to perform DNS resolution. This is the default on Linux.
|
|
@@ -1700,14 +1718,14 @@ declare module "bun" {
|
|
|
1700
1718
|
*
|
|
1701
1719
|
* @category Security
|
|
1702
1720
|
*/
|
|
1703
|
-
|
|
1721
|
+
namespace CSRF {
|
|
1704
1722
|
/**
|
|
1705
1723
|
* Generate a CSRF token.
|
|
1706
1724
|
* @param secret The secret to use for the token. If not provided, a random default secret will be generated in memory and used.
|
|
1707
1725
|
* @param options The options for the token.
|
|
1708
1726
|
* @returns The generated token.
|
|
1709
1727
|
*/
|
|
1710
|
-
generate(secret?: string, options?: CSRFGenerateOptions): string;
|
|
1728
|
+
function generate(secret?: string, options?: CSRFGenerateOptions): string;
|
|
1711
1729
|
|
|
1712
1730
|
/**
|
|
1713
1731
|
* Verify a CSRF token.
|
|
@@ -1715,8 +1733,8 @@ declare module "bun" {
|
|
|
1715
1733
|
* @param options The options for the token.
|
|
1716
1734
|
* @returns True if the token is valid, false otherwise.
|
|
1717
1735
|
*/
|
|
1718
|
-
verify(token: string, options?: CSRFVerifyOptions): boolean;
|
|
1719
|
-
}
|
|
1736
|
+
function verify(token: string, options?: CSRFVerifyOptions): boolean;
|
|
1737
|
+
}
|
|
1720
1738
|
|
|
1721
1739
|
/**
|
|
1722
1740
|
* This lets you use macros as regular imports
|
|
@@ -2236,8 +2254,8 @@ declare module "bun" {
|
|
|
2236
2254
|
* Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
|
|
2237
2255
|
* work on this.
|
|
2238
2256
|
*
|
|
2239
|
-
*
|
|
2240
|
-
*
|
|
2257
|
+
* @example
|
|
2258
|
+
* **Example with argon2**
|
|
2241
2259
|
* ```ts
|
|
2242
2260
|
* import {password} from "bun";
|
|
2243
2261
|
*
|
|
@@ -2246,7 +2264,7 @@ declare module "bun" {
|
|
|
2246
2264
|
* console.log(verify); // true
|
|
2247
2265
|
* ```
|
|
2248
2266
|
*
|
|
2249
|
-
*
|
|
2267
|
+
* **Example with bcrypt**
|
|
2250
2268
|
* ```ts
|
|
2251
2269
|
* import {password} from "bun";
|
|
2252
2270
|
*
|
|
@@ -2301,14 +2319,16 @@ declare module "bun" {
|
|
|
2301
2319
|
*
|
|
2302
2320
|
* @returns A promise that resolves to the hashed password
|
|
2303
2321
|
*
|
|
2304
|
-
*
|
|
2322
|
+
* @example
|
|
2323
|
+
* **Example with argon2**
|
|
2305
2324
|
* ```ts
|
|
2306
2325
|
* import {password} from "bun";
|
|
2307
2326
|
* const hash = await password.hash("hello world");
|
|
2308
2327
|
* console.log(hash); // $argon2id$v=1...
|
|
2309
2328
|
* const verify = await password.verify("hello world", hash);
|
|
2310
2329
|
* ```
|
|
2311
|
-
*
|
|
2330
|
+
*
|
|
2331
|
+
* **Example with bcrypt**
|
|
2312
2332
|
* ```ts
|
|
2313
2333
|
* import {password} from "bun";
|
|
2314
2334
|
* const hash = await password.hash("hello world", "bcrypt");
|
|
@@ -2341,8 +2361,8 @@ declare module "bun" {
|
|
|
2341
2361
|
* Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
|
|
2342
2362
|
* work on this.
|
|
2343
2363
|
*
|
|
2344
|
-
*
|
|
2345
|
-
*
|
|
2364
|
+
* @example
|
|
2365
|
+
* **Example with argon2**
|
|
2346
2366
|
* ```ts
|
|
2347
2367
|
* import {password} from "bun";
|
|
2348
2368
|
*
|
|
@@ -2351,7 +2371,7 @@ declare module "bun" {
|
|
|
2351
2371
|
* console.log(verify); // true
|
|
2352
2372
|
* ```
|
|
2353
2373
|
*
|
|
2354
|
-
*
|
|
2374
|
+
* **Example with bcrypt**
|
|
2355
2375
|
* ```ts
|
|
2356
2376
|
* import {password} from "bun";
|
|
2357
2377
|
*
|
|
@@ -2386,8 +2406,8 @@ declare module "bun" {
|
|
|
2386
2406
|
* Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
|
|
2387
2407
|
* work on this.
|
|
2388
2408
|
*
|
|
2389
|
-
*
|
|
2390
|
-
*
|
|
2409
|
+
* @example
|
|
2410
|
+
* **Example with argon2**
|
|
2391
2411
|
* ```ts
|
|
2392
2412
|
* import {password} from "bun";
|
|
2393
2413
|
*
|
|
@@ -2396,7 +2416,7 @@ declare module "bun" {
|
|
|
2396
2416
|
* console.log(verify); // true
|
|
2397
2417
|
* ```
|
|
2398
2418
|
*
|
|
2399
|
-
*
|
|
2419
|
+
* **Example with bcrypt**
|
|
2400
2420
|
* ```ts
|
|
2401
2421
|
* import {password} from "bun";
|
|
2402
2422
|
*
|
|
@@ -2452,227 +2472,251 @@ declare module "bun" {
|
|
|
2452
2472
|
/**
|
|
2453
2473
|
* Bundles JavaScript, TypeScript, CSS, HTML and other supported files into optimized outputs.
|
|
2454
2474
|
*
|
|
2455
|
-
* @param
|
|
2456
|
-
* @returns
|
|
2475
|
+
* @param config - Build configuration options
|
|
2476
|
+
* @returns Promise that resolves to build output containing generated artifacts and build status
|
|
2457
2477
|
* @throws {AggregateError} When build fails and config.throw is true (default in Bun 1.2+)
|
|
2458
2478
|
*
|
|
2459
2479
|
* @category Bundler
|
|
2460
2480
|
*
|
|
2461
|
-
* @example
|
|
2462
|
-
*
|
|
2481
|
+
* @example
|
|
2482
|
+
* Basic usage - Bundle a single entrypoint and check results
|
|
2483
|
+
*```ts
|
|
2463
2484
|
* const result = await Bun.build({
|
|
2464
2485
|
* entrypoints: ['./src/index.tsx'],
|
|
2465
2486
|
* outdir: './dist'
|
|
2466
2487
|
* });
|
|
2467
2488
|
*
|
|
2468
|
-
*
|
|
2469
|
-
*
|
|
2470
|
-
*
|
|
2471
|
-
*
|
|
2472
|
-
|
|
2473
|
-
*
|
|
2474
|
-
*
|
|
2475
|
-
*
|
|
2476
|
-
|
|
2477
|
-
*
|
|
2478
|
-
*
|
|
2479
|
-
*
|
|
2480
|
-
*
|
|
2481
|
-
*
|
|
2482
|
-
*
|
|
2483
|
-
|
|
2484
|
-
*
|
|
2485
|
-
*
|
|
2486
|
-
*
|
|
2487
|
-
|
|
2488
|
-
*
|
|
2489
|
-
*
|
|
2490
|
-
*
|
|
2491
|
-
*
|
|
2492
|
-
*
|
|
2493
|
-
*
|
|
2494
|
-
*
|
|
2495
|
-
*
|
|
2496
|
-
*
|
|
2497
|
-
*
|
|
2498
|
-
|
|
2499
|
-
*
|
|
2500
|
-
*
|
|
2501
|
-
*
|
|
2502
|
-
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2505
|
-
*
|
|
2506
|
-
*
|
|
2507
|
-
*
|
|
2508
|
-
*
|
|
2509
|
-
*
|
|
2510
|
-
*
|
|
2511
|
-
*
|
|
2512
|
-
*
|
|
2513
|
-
*
|
|
2514
|
-
|
|
2515
|
-
*
|
|
2516
|
-
*
|
|
2517
|
-
*
|
|
2518
|
-
|
|
2519
|
-
*
|
|
2520
|
-
*
|
|
2521
|
-
|
|
2522
|
-
*
|
|
2523
|
-
*
|
|
2524
|
-
*
|
|
2525
|
-
*
|
|
2526
|
-
*
|
|
2527
|
-
*
|
|
2528
|
-
*
|
|
2529
|
-
*
|
|
2530
|
-
*
|
|
2531
|
-
*
|
|
2532
|
-
|
|
2533
|
-
*
|
|
2534
|
-
*
|
|
2535
|
-
*
|
|
2536
|
-
|
|
2537
|
-
*
|
|
2538
|
-
*
|
|
2539
|
-
*
|
|
2540
|
-
*
|
|
2541
|
-
*
|
|
2542
|
-
*
|
|
2543
|
-
*
|
|
2544
|
-
*
|
|
2545
|
-
*
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
*
|
|
2549
|
-
*
|
|
2550
|
-
|
|
2551
|
-
*
|
|
2552
|
-
|
|
2553
|
-
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2556
|
-
*
|
|
2557
|
-
*
|
|
2558
|
-
*
|
|
2559
|
-
*
|
|
2560
|
-
*
|
|
2561
|
-
|
|
2562
|
-
*
|
|
2563
|
-
*
|
|
2564
|
-
*
|
|
2565
|
-
|
|
2566
|
-
*
|
|
2567
|
-
*
|
|
2568
|
-
*
|
|
2569
|
-
*
|
|
2570
|
-
*
|
|
2571
|
-
*
|
|
2572
|
-
*
|
|
2573
|
-
*
|
|
2574
|
-
*
|
|
2575
|
-
*
|
|
2576
|
-
*
|
|
2577
|
-
*
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
*
|
|
2581
|
-
*
|
|
2582
|
-
*
|
|
2583
|
-
|
|
2584
|
-
*
|
|
2585
|
-
*
|
|
2586
|
-
*
|
|
2587
|
-
|
|
2588
|
-
*
|
|
2589
|
-
*
|
|
2590
|
-
*
|
|
2591
|
-
*
|
|
2592
|
-
*
|
|
2593
|
-
*
|
|
2594
|
-
*
|
|
2595
|
-
*
|
|
2596
|
-
*
|
|
2597
|
-
|
|
2598
|
-
*
|
|
2599
|
-
*
|
|
2600
|
-
*
|
|
2601
|
-
|
|
2602
|
-
*
|
|
2603
|
-
*
|
|
2604
|
-
*
|
|
2605
|
-
*
|
|
2606
|
-
*
|
|
2607
|
-
*
|
|
2608
|
-
*
|
|
2609
|
-
*
|
|
2610
|
-
|
|
2611
|
-
*
|
|
2612
|
-
*
|
|
2613
|
-
*
|
|
2614
|
-
|
|
2615
|
-
*
|
|
2616
|
-
*
|
|
2617
|
-
*
|
|
2618
|
-
*
|
|
2619
|
-
*
|
|
2620
|
-
*
|
|
2621
|
-
*
|
|
2622
|
-
*
|
|
2623
|
-
*
|
|
2624
|
-
|
|
2625
|
-
*
|
|
2626
|
-
*
|
|
2627
|
-
*
|
|
2628
|
-
|
|
2629
|
-
*
|
|
2630
|
-
*
|
|
2631
|
-
*
|
|
2632
|
-
*
|
|
2633
|
-
*
|
|
2634
|
-
*
|
|
2635
|
-
*
|
|
2636
|
-
*
|
|
2637
|
-
*
|
|
2638
|
-
*
|
|
2639
|
-
*
|
|
2640
|
-
*
|
|
2641
|
-
*
|
|
2642
|
-
*
|
|
2643
|
-
*
|
|
2644
|
-
*
|
|
2645
|
-
*
|
|
2646
|
-
*
|
|
2647
|
-
|
|
2648
|
-
*
|
|
2649
|
-
*
|
|
2650
|
-
*
|
|
2651
|
-
|
|
2652
|
-
*
|
|
2653
|
-
*
|
|
2654
|
-
*
|
|
2655
|
-
*
|
|
2656
|
-
*
|
|
2657
|
-
*
|
|
2658
|
-
*
|
|
2659
|
-
|
|
2660
|
-
*
|
|
2661
|
-
*
|
|
2662
|
-
*
|
|
2663
|
-
|
|
2664
|
-
*
|
|
2665
|
-
*
|
|
2666
|
-
*
|
|
2667
|
-
*
|
|
2668
|
-
*
|
|
2669
|
-
*
|
|
2670
|
-
|
|
2671
|
-
*
|
|
2672
|
-
*
|
|
2673
|
-
*
|
|
2489
|
+
* if (!result.success) {
|
|
2490
|
+
* console.error('Build failed:', result.logs);
|
|
2491
|
+
* process.exit(1);
|
|
2492
|
+
* }
|
|
2493
|
+
*```
|
|
2494
|
+
*
|
|
2495
|
+
* @example
|
|
2496
|
+
* Set up multiple entrypoints with code splitting enabled
|
|
2497
|
+
*```ts
|
|
2498
|
+
* await Bun.build({
|
|
2499
|
+
* entrypoints: ['./src/app.tsx', './src/admin.tsx'],
|
|
2500
|
+
* outdir: './dist',
|
|
2501
|
+
* splitting: true,
|
|
2502
|
+
* sourcemap: "external"
|
|
2503
|
+
* });
|
|
2504
|
+
*```
|
|
2505
|
+
*
|
|
2506
|
+
* @example
|
|
2507
|
+
* Configure minification and optimization settings
|
|
2508
|
+
*```ts
|
|
2509
|
+
* await Bun.build({
|
|
2510
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2511
|
+
* outdir: './dist',
|
|
2512
|
+
* minify: {
|
|
2513
|
+
* whitespace: true,
|
|
2514
|
+
* identifiers: true,
|
|
2515
|
+
* syntax: true
|
|
2516
|
+
* },
|
|
2517
|
+
* drop: ['console', 'debugger']
|
|
2518
|
+
* });
|
|
2519
|
+
*```
|
|
2520
|
+
*
|
|
2521
|
+
* @example
|
|
2522
|
+
* Set up custom loaders and mark packages as external
|
|
2523
|
+
*```ts
|
|
2524
|
+
* await Bun.build({
|
|
2525
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2526
|
+
* outdir: './dist',
|
|
2527
|
+
* loader: {
|
|
2528
|
+
* '.png': 'dataurl',
|
|
2529
|
+
* '.svg': 'file',
|
|
2530
|
+
* '.txt': 'text',
|
|
2531
|
+
* '.json': 'json'
|
|
2532
|
+
* },
|
|
2533
|
+
* external: ['react', 'react-dom']
|
|
2534
|
+
* });
|
|
2535
|
+
*```
|
|
2536
|
+
*
|
|
2537
|
+
* @example
|
|
2538
|
+
* Configure environment variable handling with different modes
|
|
2539
|
+
*```ts
|
|
2540
|
+
* // Inline all environment variables
|
|
2541
|
+
* await Bun.build({
|
|
2542
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2543
|
+
* outdir: './dist',
|
|
2544
|
+
* env: 'inline'
|
|
2545
|
+
* });
|
|
2546
|
+
*
|
|
2547
|
+
* // Only include specific env vars
|
|
2548
|
+
* await Bun.build({
|
|
2549
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2550
|
+
* outdir: './dist',
|
|
2551
|
+
* env: 'PUBLIC_*'
|
|
2552
|
+
* });
|
|
2553
|
+
*```
|
|
2554
|
+
*
|
|
2555
|
+
* @example
|
|
2556
|
+
* Set up custom naming patterns for all output types
|
|
2557
|
+
*```ts
|
|
2558
|
+
* await Bun.build({
|
|
2559
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2560
|
+
* outdir: './dist',
|
|
2561
|
+
* naming: {
|
|
2562
|
+
* entry: '[dir]/[name]-[hash].[ext]',
|
|
2563
|
+
* chunk: 'chunks/[name]-[hash].[ext]',
|
|
2564
|
+
* asset: 'assets/[name]-[hash].[ext]'
|
|
2565
|
+
* }
|
|
2566
|
+
* });
|
|
2567
|
+
*```
|
|
2568
|
+
*
|
|
2569
|
+
* @example
|
|
2570
|
+
* Work with build artifacts in different formats
|
|
2571
|
+
*```ts
|
|
2572
|
+
* const result = await Bun.build({
|
|
2573
|
+
* entrypoints: ['./src/index.tsx']
|
|
2574
|
+
* });
|
|
2575
|
+
* for (const artifact of result.outputs) {
|
|
2576
|
+
* const text = await artifact.text();
|
|
2577
|
+
* const buffer = await artifact.arrayBuffer();
|
|
2578
|
+
* const bytes = await artifact.bytes();
|
|
2579
|
+
* new Response(artifact);
|
|
2580
|
+
* await Bun.write(artifact.path, artifact);
|
|
2581
|
+
* }
|
|
2582
|
+
*```
|
|
2583
|
+
*
|
|
2584
|
+
* @example
|
|
2585
|
+
* Implement comprehensive error handling with position info
|
|
2586
|
+
*```ts
|
|
2587
|
+
* try {
|
|
2588
|
+
* const result = await Bun.build({
|
|
2589
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2590
|
+
* });
|
|
2591
|
+
* } catch (e) {
|
|
2592
|
+
* const error = e as AggregateError;
|
|
2593
|
+
* console.error('Build failed:');
|
|
2594
|
+
* for (const msg of error.errors) {
|
|
2595
|
+
* if ('position' in msg) {
|
|
2596
|
+
* console.error(
|
|
2597
|
+
* `${msg.message} at ${msg.position?.file}:${msg.position?.line}:${msg.position?.column}`
|
|
2598
|
+
* );
|
|
2599
|
+
* } else {
|
|
2600
|
+
* console.error(msg.message);
|
|
2601
|
+
* }
|
|
2602
|
+
* }
|
|
2603
|
+
* }
|
|
2604
|
+
*```
|
|
2605
|
+
*
|
|
2606
|
+
* @example
|
|
2607
|
+
* Set up Node.js target with specific configurations
|
|
2608
|
+
*```ts
|
|
2609
|
+
* await Bun.build({
|
|
2610
|
+
* entrypoints: ['./src/server.ts'],
|
|
2611
|
+
* outdir: './dist',
|
|
2612
|
+
* target: 'node',
|
|
2613
|
+
* format: 'cjs',
|
|
2614
|
+
* sourcemap: 'external',
|
|
2615
|
+
* minify: false,
|
|
2616
|
+
* packages: 'external'
|
|
2617
|
+
* });
|
|
2618
|
+
*```
|
|
2619
|
+
*
|
|
2620
|
+
* @example
|
|
2621
|
+
* Configure experimental CSS bundling with multiple themes
|
|
2622
|
+
*```ts
|
|
2623
|
+
* await Bun.build({
|
|
2624
|
+
* entrypoints: [
|
|
2625
|
+
* './src/styles.css',
|
|
2626
|
+
* './src/themes/dark.css',
|
|
2627
|
+
* './src/themes/light.css'
|
|
2628
|
+
* ],
|
|
2629
|
+
* outdir: './dist/css',
|
|
2630
|
+
* });
|
|
2631
|
+
*```
|
|
2632
|
+
*
|
|
2633
|
+
* @example
|
|
2634
|
+
* Define compile-time constants and version information
|
|
2635
|
+
*```ts
|
|
2636
|
+
* await Bun.build({
|
|
2637
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2638
|
+
* outdir: './dist',
|
|
2639
|
+
* define: {
|
|
2640
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
2641
|
+
* 'CONSTANTS.VERSION': JSON.stringify('1.0.0'),
|
|
2642
|
+
* 'CONSTANTS.BUILD_TIME': JSON.stringify(new Date().toISOString())
|
|
2643
|
+
* }
|
|
2644
|
+
* });
|
|
2645
|
+
*```
|
|
2646
|
+
*
|
|
2647
|
+
* @example
|
|
2648
|
+
* Create a custom plugin for handling special file types
|
|
2649
|
+
*```ts
|
|
2650
|
+
* await Bun.build({
|
|
2651
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2652
|
+
* outdir: './dist',
|
|
2653
|
+
* plugins: [
|
|
2654
|
+
* {
|
|
2655
|
+
* name: 'my-plugin',
|
|
2656
|
+
* setup(build) {
|
|
2657
|
+
* build.onLoad({ filter: /\.custom$/ }, async (args) => {
|
|
2658
|
+
* const content = await Bun.file(args.path).text();
|
|
2659
|
+
* return {
|
|
2660
|
+
* contents: `export default ${JSON.stringify(content)}`,
|
|
2661
|
+
* loader: 'js'
|
|
2662
|
+
* };
|
|
2663
|
+
* });
|
|
2664
|
+
* }
|
|
2665
|
+
* }
|
|
2666
|
+
* ]
|
|
2667
|
+
* });
|
|
2668
|
+
*```
|
|
2669
|
+
*
|
|
2670
|
+
* @example
|
|
2671
|
+
* Enable bytecode generation for faster startup
|
|
2672
|
+
*```ts
|
|
2673
|
+
* await Bun.build({
|
|
2674
|
+
* entrypoints: ['./src/server.ts'],
|
|
2675
|
+
* outdir: './dist',
|
|
2676
|
+
* target: 'bun',
|
|
2677
|
+
* format: 'cjs',
|
|
2678
|
+
* bytecode: true
|
|
2679
|
+
* });
|
|
2680
|
+
*```
|
|
2681
|
+
*
|
|
2682
|
+
* @example
|
|
2683
|
+
* Add custom banner and footer to output files
|
|
2684
|
+
*```ts
|
|
2685
|
+
* await Bun.build({
|
|
2686
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2687
|
+
* outdir: './dist',
|
|
2688
|
+
* banner: '"use client";\n// Built with Bun',
|
|
2689
|
+
* footer: '// Generated on ' + new Date().toISOString()
|
|
2690
|
+
* });
|
|
2691
|
+
*```
|
|
2692
|
+
*
|
|
2693
|
+
* @example
|
|
2694
|
+
* Configure CDN public path for asset loading
|
|
2695
|
+
*```ts
|
|
2696
|
+
* await Bun.build({
|
|
2697
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2698
|
+
* outdir: './dist',
|
|
2699
|
+
* publicPath: 'https://cdn.example.com/assets/',
|
|
2700
|
+
* loader: {
|
|
2701
|
+
* '.png': 'file',
|
|
2702
|
+
* '.svg': 'file'
|
|
2703
|
+
* }
|
|
2704
|
+
* });
|
|
2705
|
+
*```
|
|
2706
|
+
*
|
|
2707
|
+
* @example
|
|
2708
|
+
* Set up package export conditions for different environments
|
|
2709
|
+
*```ts
|
|
2710
|
+
* await Bun.build({
|
|
2711
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2712
|
+
* outdir: './dist',
|
|
2713
|
+
* conditions: ['production', 'browser', 'module'],
|
|
2714
|
+
* packages: 'external'
|
|
2715
|
+
* });
|
|
2716
|
+
*```
|
|
2674
2717
|
*/
|
|
2675
2718
|
function build(config: BuildConfig): Promise<BuildOutput>;
|
|
2719
|
+
|
|
2676
2720
|
/**
|
|
2677
2721
|
* A status that represents the outcome of a sent message.
|
|
2678
2722
|
*
|
|
@@ -2720,6 +2764,7 @@ declare module "bun" {
|
|
|
2720
2764
|
* Powered by [uWebSockets](https://github.com/uNetworking/uWebSockets).
|
|
2721
2765
|
*
|
|
2722
2766
|
* @example
|
|
2767
|
+
* ```ts
|
|
2723
2768
|
* Bun.serve({
|
|
2724
2769
|
* websocket: {
|
|
2725
2770
|
* open(ws) {
|
|
@@ -2734,6 +2779,7 @@ declare module "bun" {
|
|
|
2734
2779
|
* },
|
|
2735
2780
|
* }
|
|
2736
2781
|
* });
|
|
2782
|
+
* ```
|
|
2737
2783
|
*
|
|
2738
2784
|
* @category HTTP & Networking
|
|
2739
2785
|
*/
|
|
@@ -3219,13 +3265,15 @@ declare module "bun" {
|
|
|
3219
3265
|
/**
|
|
3220
3266
|
* Uniquely identify a server instance with an ID
|
|
3221
3267
|
*
|
|
3222
|
-
*
|
|
3268
|
+
* ---
|
|
3269
|
+
*
|
|
3270
|
+
* **When bun is started with the `--hot` flag**:
|
|
3223
3271
|
*
|
|
3224
3272
|
* This string will be used to hot reload the server without interrupting
|
|
3225
3273
|
* pending requests or websockets. If not provided, a value will be
|
|
3226
3274
|
* generated. To disable hot reloading, set this value to `null`.
|
|
3227
3275
|
*
|
|
3228
|
-
*
|
|
3276
|
+
* **When bun is not started with the `--hot` flag**:
|
|
3229
3277
|
*
|
|
3230
3278
|
* This string will currently do nothing. But in the future it could be useful for logs or metrics.
|
|
3231
3279
|
*/
|
|
@@ -4525,14 +4573,20 @@ declare module "bun" {
|
|
|
4525
4573
|
*/
|
|
4526
4574
|
function mmap(path: PathLike, opts?: MMapOptions): Uint8Array;
|
|
4527
4575
|
|
|
4528
|
-
/**
|
|
4576
|
+
/**
|
|
4577
|
+
* Write to stdout
|
|
4578
|
+
*/
|
|
4529
4579
|
const stdout: BunFile;
|
|
4530
|
-
|
|
4580
|
+
|
|
4581
|
+
/**
|
|
4582
|
+
* Write to stderr
|
|
4583
|
+
*/
|
|
4531
4584
|
const stderr: BunFile;
|
|
4585
|
+
|
|
4532
4586
|
/**
|
|
4533
4587
|
* Read from stdin
|
|
4534
4588
|
*
|
|
4535
|
-
* This is read-only
|
|
4589
|
+
* This is a read-only BunFile
|
|
4536
4590
|
*/
|
|
4537
4591
|
const stdin: BunFile;
|
|
4538
4592
|
|
|
@@ -4650,20 +4704,20 @@ declare module "bun" {
|
|
|
4650
4704
|
/**
|
|
4651
4705
|
* Bun.semver provides a fast way to parse and compare version numbers.
|
|
4652
4706
|
*/
|
|
4653
|
-
|
|
4707
|
+
namespace semver {
|
|
4654
4708
|
/**
|
|
4655
4709
|
* Test if the version satisfies the range. Stringifies both arguments. Returns `true` or `false`.
|
|
4656
4710
|
*/
|
|
4657
|
-
satisfies
|
|
4711
|
+
function satisfies(version: StringLike, range: StringLike): boolean;
|
|
4658
4712
|
|
|
4659
4713
|
/**
|
|
4660
4714
|
* Returns 0 if the versions are equal, 1 if `v1` is greater, or -1 if `v2` is greater.
|
|
4661
4715
|
* Throws an error if either version is invalid.
|
|
4662
4716
|
*/
|
|
4663
|
-
order
|
|
4664
|
-
}
|
|
4717
|
+
function order(v1: StringLike, v2: StringLike): -1 | 0 | 1;
|
|
4718
|
+
}
|
|
4665
4719
|
|
|
4666
|
-
|
|
4720
|
+
namespace unsafe {
|
|
4667
4721
|
/**
|
|
4668
4722
|
* Cast bytes to a `String` without copying. This is the fastest way to get a `String` from a `Uint8Array` or `ArrayBuffer`.
|
|
4669
4723
|
*
|
|
@@ -4671,7 +4725,7 @@ declare module "bun" {
|
|
|
4671
4725
|
*
|
|
4672
4726
|
* **The input buffer must not be garbage collected**. That means you will need to hold on to it for the duration of the string's lifetime.
|
|
4673
4727
|
*/
|
|
4674
|
-
arrayBufferToString(buffer: Uint8Array | ArrayBufferLike): string;
|
|
4728
|
+
function arrayBufferToString(buffer: Uint8Array | ArrayBufferLike): string;
|
|
4675
4729
|
|
|
4676
4730
|
/**
|
|
4677
4731
|
* Cast bytes to a `String` without copying. This is the fastest way to get a `String` from a `Uint16Array`
|
|
@@ -4681,7 +4735,7 @@ declare module "bun" {
|
|
|
4681
4735
|
* **The input buffer must not be garbage collected**. That means you will need to hold on to it for the duration of the string's lifetime.
|
|
4682
4736
|
*/
|
|
4683
4737
|
|
|
4684
|
-
arrayBufferToString(buffer: Uint16Array): string;
|
|
4738
|
+
function arrayBufferToString(buffer: Uint16Array): string;
|
|
4685
4739
|
|
|
4686
4740
|
/**
|
|
4687
4741
|
* Force the garbage collector to run extremely often,
|
|
@@ -4698,14 +4752,13 @@ declare module "bun" {
|
|
|
4698
4752
|
* @param level
|
|
4699
4753
|
* @returns The previous level
|
|
4700
4754
|
*/
|
|
4701
|
-
gcAggressionLevel(level?: 0 | 1 | 2): 0 | 1 | 2;
|
|
4755
|
+
function gcAggressionLevel(level?: 0 | 1 | 2): 0 | 1 | 2;
|
|
4702
4756
|
|
|
4703
4757
|
/**
|
|
4704
4758
|
* Dump the mimalloc heap to the console
|
|
4705
4759
|
*/
|
|
4706
|
-
mimallocDump(): void;
|
|
4760
|
+
function mimallocDump(): void;
|
|
4707
4761
|
}
|
|
4708
|
-
const unsafe: Unsafe;
|
|
4709
4762
|
|
|
4710
4763
|
type DigestEncoding = "utf8" | "ucs2" | "utf16le" | "latin1" | "ascii" | "base64" | "base64url" | "hex";
|
|
4711
4764
|
|
|
@@ -4797,6 +4850,8 @@ declare module "bun" {
|
|
|
4797
4850
|
|
|
4798
4851
|
/**
|
|
4799
4852
|
* The next time JavaScriptCore is idle, clear unused memory and attempt to reduce the heap size.
|
|
4853
|
+
*
|
|
4854
|
+
* @deprecated
|
|
4800
4855
|
*/
|
|
4801
4856
|
function shrink(): void;
|
|
4802
4857
|
|
|
@@ -5503,7 +5558,6 @@ declare module "bun" {
|
|
|
5503
5558
|
* @param specifier The module specifier to register the callback for
|
|
5504
5559
|
* @param callback The function to run when the module is imported or required
|
|
5505
5560
|
*
|
|
5506
|
-
* ### Example
|
|
5507
5561
|
* @example
|
|
5508
5562
|
* ```ts
|
|
5509
5563
|
* Bun.plugin({
|
|
@@ -5714,13 +5768,18 @@ declare module "bun" {
|
|
|
5714
5768
|
*/
|
|
5715
5769
|
shutdown(halfClose?: boolean): void;
|
|
5716
5770
|
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5771
|
+
/**
|
|
5772
|
+
* The ready state of the socket.
|
|
5773
|
+
*
|
|
5774
|
+
* You can assume that a positive value means the socket is open and usable
|
|
5775
|
+
*
|
|
5776
|
+
* - `-2` = Shutdown
|
|
5777
|
+
* - `-1` = Detached
|
|
5778
|
+
* - `0` = Closed
|
|
5779
|
+
* - `1` = Established
|
|
5780
|
+
* - `2` = Else
|
|
5781
|
+
*/
|
|
5782
|
+
readonly readyState: -2 | -1 | 0 | 1 | 2;
|
|
5724
5783
|
|
|
5725
5784
|
/**
|
|
5726
5785
|
* Allow Bun's process to exit even if this socket is still open
|
|
@@ -7069,13 +7128,13 @@ declare module "bun" {
|
|
|
7069
7128
|
/**
|
|
7070
7129
|
* The current version of Bun
|
|
7071
7130
|
* @example
|
|
7072
|
-
* "
|
|
7131
|
+
* "1.2.0"
|
|
7073
7132
|
*/
|
|
7074
7133
|
const version: string;
|
|
7075
7134
|
|
|
7076
7135
|
/**
|
|
7077
7136
|
* The current version of Bun with the shortened commit sha of the build
|
|
7078
|
-
* @example "v1.
|
|
7137
|
+
* @example "v1.2.0 (a1b2c3d4)"
|
|
7079
7138
|
*/
|
|
7080
7139
|
const version_with_sha: string;
|
|
7081
7140
|
|