bun-types 1.2.11-canary.20250418T140557 → 1.2.11-canary.20250419T140546

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
@@ -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
- const origin: string;
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.PATH Overrides the PATH environment variable
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?: { PATH?: string; cwd?: string }): string | null;
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
- /** If writing to a PathLike, set the permissions of the file. */
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 Multipart form data 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
- * @example URL-encoded form data example
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
- const peek: Peek;
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
- * ## Example
1018
- *
1037
+ * @example
1038
+ * ## Basic usage
1019
1039
  * ```js
1020
1040
  * const [{ address }] = await Bun.dns.lookup('example.com');
1021
1041
  * ```
1022
1042
  *
1023
- * ### Filter results to IPv4:
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
- * ### Filter results to IPv6:
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
- * #### DNS resolver client
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
- var CSRF: {
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
- * ### Example with argon2
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
- * ### Example with bcrypt
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
- * ## Example with argon2
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
- * ## Example with bcrypt
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
- * ### Example with argon2
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
- * ### Example with bcrypt
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
- * ### Example with argon2
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
- * ### Example with bcrypt
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 {Object} config - Build configuration options
2456
- * @returns {Promise<BuildOutput>} Promise that resolves to build output containing generated artifacts and build status
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 Basic usage - Bundle a single entrypoint and check results
2462
- * ```ts
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
- * if (!result.success) {
2469
- * console.error('Build failed:', result.logs);
2470
- * process.exit(1);
2471
- * }
2472
- * ```
2473
- * *
2474
- * * @example Set up multiple entrypoints with code splitting enabled
2475
- * ```ts
2476
- * await Bun.build({
2477
- * entrypoints: ['./src/app.tsx', './src/admin.tsx'],
2478
- * outdir: './dist',
2479
- * splitting: true,
2480
- * sourcemap: "external"
2481
- * });
2482
- * ```
2483
- * *
2484
- * * @example Configure minification and optimization settings
2485
- * ```ts
2486
- * await Bun.build({
2487
- * entrypoints: ['./src/index.tsx'],
2488
- * outdir: './dist',
2489
- * minify: {
2490
- * whitespace: true,
2491
- * identifiers: true,
2492
- * syntax: true
2493
- * },
2494
- * drop: ['console', 'debugger']
2495
- * });
2496
- * ```
2497
- * *
2498
- * * @example Set up custom loaders and mark packages as external
2499
- * ```ts
2500
- * await Bun.build({
2501
- * entrypoints: ['./src/index.tsx'],
2502
- * outdir: './dist',
2503
- * loader: {
2504
- * '.png': 'dataurl',
2505
- * '.svg': 'file',
2506
- * '.txt': 'text',
2507
- * '.json': 'json'
2508
- * },
2509
- * external: ['react', 'react-dom']
2510
- * });
2511
- * ```
2512
- * *
2513
- * * @example Configure environment variable handling with different modes
2514
- * ```ts
2515
- * // Inline all environment variables
2516
- * await Bun.build({
2517
- * entrypoints: ['./src/index.tsx'],
2518
- * outdir: './dist',
2519
- * env: 'inline'
2520
- * });
2521
-
2522
- * // Only include specific env vars
2523
- * await Bun.build({
2524
- * entrypoints: ['./src/index.tsx'],
2525
- * outdir: './dist',
2526
- * env: 'PUBLIC_*'
2527
- * });
2528
- * ```
2529
- * *
2530
- * * @example Set up custom naming patterns for all output types
2531
- * ```ts
2532
- * await Bun.build({
2533
- * entrypoints: ['./src/index.tsx'],
2534
- * outdir: './dist',
2535
- * naming: {
2536
- * entry: '[dir]/[name]-[hash].[ext]',
2537
- * chunk: 'chunks/[name]-[hash].[ext]',
2538
- * asset: 'assets/[name]-[hash].[ext]'
2539
- * }
2540
- * });
2541
- * ```
2542
- * @example Work with build artifacts in different formats
2543
- * ```ts
2544
- * const result = await Bun.build({
2545
- * entrypoints: ['./src/index.tsx']
2546
- * });
2547
-
2548
- * for (const artifact of result.outputs) {
2549
- * const text = await artifact.text();
2550
- * const buffer = await artifact.arrayBuffer();
2551
- * const bytes = await artifact.bytes();
2552
-
2553
- * new Response(artifact);
2554
- * await Bun.write(artifact.path, artifact);
2555
- * }
2556
- * ```
2557
- * @example Implement comprehensive error handling with position info
2558
- * ```ts
2559
- * try {
2560
- * const result = await Bun.build({
2561
- * entrypoints: ['./src/index.tsx'],
2562
- * });
2563
- * } catch (e) {
2564
- * const error = e as AggregateError;
2565
- * console.error('Build failed:');
2566
- * for (const msg of error.errors) {
2567
- * if ('position' in msg) {
2568
- * console.error(
2569
- * `${msg.message} at ${msg.position?.file}:${msg.position?.line}:${msg.position?.column}`
2570
- * );
2571
- * } else {
2572
- * console.error(msg.message);
2573
- * }
2574
- * }
2575
- * }
2576
- * ```
2577
- * @example Set up Node.js target with specific configurations
2578
- * ```ts
2579
- * await Bun.build({
2580
- * entrypoints: ['./src/server.ts'],
2581
- * outdir: './dist',
2582
- * target: 'node',
2583
- * format: 'cjs',
2584
- * sourcemap: 'external',
2585
- * minify: false,
2586
- * packages: 'external'
2587
- * });
2588
- * ```
2589
- * *
2590
- * * @example Configure experimental CSS bundling with multiple themes
2591
- * ```ts
2592
- * await Bun.build({
2593
- * entrypoints: [
2594
- * './src/styles.css',
2595
- * './src/themes/dark.css',
2596
- * './src/themes/light.css'
2597
- * ],
2598
- * outdir: './dist/css',
2599
- * });
2600
- * ```
2601
- * @example Define compile-time constants and version information
2602
- * ```ts
2603
- * await Bun.build({
2604
- * entrypoints: ['./src/index.tsx'],
2605
- * outdir: './dist',
2606
- * define: {
2607
- * 'process.env.NODE_ENV': JSON.stringify('production'),
2608
- * 'CONSTANTS.VERSION': JSON.stringify('1.0.0'),
2609
- * 'CONSTANTS.BUILD_TIME': JSON.stringify(new Date().toISOString())
2610
- * }
2611
- * });
2612
- * ```
2613
- * @example Create a custom plugin for handling special file types
2614
- * ```ts
2615
- * await Bun.build({
2616
- * entrypoints: ['./src/index.tsx'],
2617
- * outdir: './dist',
2618
- * plugins: [
2619
- * {
2620
- * name: 'my-plugin',
2621
- * setup(build) {
2622
- * build.onLoad({ filter: /\.custom$/ }, async (args) => {
2623
- * const content = await Bun.file(args.path).text();
2624
- * return {
2625
- * contents: `export default ${JSON.stringify(content)}`,
2626
- * loader: 'js'
2627
- * };
2628
- * });
2629
- * }
2630
- * }
2631
- * ]
2632
- * });
2633
- * ```
2634
- * @example Enable bytecode generation for faster startup
2635
- * ```ts
2636
- * await Bun.build({
2637
- * entrypoints: ['./src/server.ts'],
2638
- * outdir: './dist',
2639
- * target: 'bun',
2640
- * format: 'cjs',
2641
- * bytecode: true
2642
- * });
2643
- * ```
2644
- * @example Add custom banner and footer to output files
2645
- * ```ts
2646
- * await Bun.build({
2647
- * entrypoints: ['./src/index.tsx'],
2648
- * outdir: './dist',
2649
- * banner: '"use client";\n// Built with Bun',
2650
- * footer: '// Generated on ' + new Date().toISOString()
2651
- * });
2652
- * ```
2653
- * @example Configure CDN public path for asset loading
2654
- * ```ts
2655
- * await Bun.build({
2656
- * entrypoints: ['./src/index.tsx'],
2657
- * outdir: './dist',
2658
- * publicPath: 'https://cdn.example.com/assets/',
2659
- * loader: {
2660
- * '.png': 'file',
2661
- * '.svg': 'file'
2662
- * }
2663
- * });
2664
- * ```
2665
- * @example Set up package export conditions for different environments
2666
- * ```ts
2667
- * await Bun.build({
2668
- * entrypoints: ['./src/index.tsx'],
2669
- * outdir: './dist',
2670
- * conditions: ['production', 'browser', 'module'],
2671
- * packages: 'external'
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
- * ### When bun is started with the `--hot` flag
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
- * ### When bun is not started with the `--hot` flag
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
- /** Write to stdout */
4576
+ /**
4577
+ * Write to stdout
4578
+ */
4529
4579
  const stdout: BunFile;
4530
- /** Write to stderr */
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
- var semver: {
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: (version: StringLike, range: StringLike) => boolean;
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: (v1: StringLike, v2: StringLike) => -1 | 0 | 1;
4664
- };
4717
+ function order(v1: StringLike, v2: StringLike): -1 | 0 | 1;
4718
+ }
4665
4719
 
4666
- interface Unsafe {
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
- // -1 = detached
5718
- // 0 = closed
5719
- // 1 = open
5720
- // -2 = closing
5721
- // 2 = everything else
5722
- // positive = open
5723
- readonly readyState: "open" | "closing" | "closed";
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
- * "0.2.0"
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.1.30 (d09df1af)"
7137
+ * @example "v1.2.0 (a1b2c3d4)"
7079
7138
  */
7080
7139
  const version_with_sha: string;
7081
7140