bun-types 1.2.8-canary.20250327T140605 → 1.2.8-canary.20250328T140605

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
@@ -537,9 +537,11 @@ declare module "bun" {
537
537
  /**
538
538
  * Find the path to an executable, similar to typing which in your terminal. Reads the `PATH` environment variable unless overridden with `options.PATH`.
539
539
  *
540
- * @param {string} command The name of the executable or script
541
- * @param {string} options.PATH Overrides the PATH environment variable
542
- * @param {string} options.cwd When given a relative path, use this path to join it.
540
+ * @category Utilities
541
+ *
542
+ * @param command The name of the executable or script
543
+ * @param options.PATH Overrides the PATH environment variable
544
+ * @param options.cwd When given a relative path, use this path to join it.
543
545
  */
544
546
  function which(command: string, options?: { PATH?: string; cwd?: string }): string | null;
545
547
 
@@ -945,19 +947,24 @@ declare module "bun" {
945
947
  blob(): Blob;
946
948
  }
947
949
 
950
+ /**
951
+ * The Bun shell
952
+ *
953
+ * @category Process Management
954
+ */
948
955
  const $: Shell;
949
956
 
950
- interface TOML {
957
+ const TOML: {
951
958
  /**
952
959
  * Parse a TOML string into a JavaScript object.
953
960
  *
954
- * @param {string} command The name of the executable or script
955
- * @param {string} options.PATH Overrides the PATH environment variable
956
- * @param {string} options.cwd Limits the search to a particular directory in which to searc
961
+ * @category Utilities
962
+ *
963
+ * @param input The TOML string to parse
964
+ * @returns A JavaScript object
957
965
  */
958
966
  parse(input: string): object;
959
- }
960
- const TOML: TOML;
967
+ };
961
968
 
962
969
  /**
963
970
  * Synchronously resolve a `moduleId` as though it were imported from `parent`
@@ -980,6 +987,8 @@ declare module "bun" {
980
987
  *
981
988
  * If `destination` exists, it must be a regular file or symlink to a file. If `destination`'s directory does not exist, it will be created by default.
982
989
  *
990
+ * @category File System
991
+ *
983
992
  * @param destination The file or file path to write to
984
993
  * @param input The data to copy into `destination`.
985
994
  * @returns A promise that resolves with the number of bytes written.
@@ -1271,6 +1280,8 @@ declare module "bun" {
1271
1280
  /**
1272
1281
  * Escape the following characters in a string:
1273
1282
  *
1283
+ * @category Security
1284
+ *
1274
1285
  * - `"` becomes `"""`
1275
1286
  * - `&` becomes `"&"`
1276
1287
  * - `'` becomes `"'"`
@@ -1291,6 +1302,8 @@ declare module "bun" {
1291
1302
  * @param path The path to convert.
1292
1303
  * @returns A {@link URL} with the file:// scheme.
1293
1304
  *
1305
+ * @category File System
1306
+ *
1294
1307
  * @example
1295
1308
  * ```js
1296
1309
  * const url = Bun.pathToFileURL("/foo/bar.txt");
@@ -1313,9 +1326,13 @@ declare module "bun" {
1313
1326
 
1314
1327
  /**
1315
1328
  * Convert a {@link URL} to a filesystem path.
1329
+ *
1316
1330
  * @param url The URL to convert.
1317
1331
  * @returns A filesystem path.
1318
1332
  * @throws If the URL is not a URL.
1333
+ *
1334
+ * @category File System
1335
+ *
1319
1336
  * @example
1320
1337
  * ```js
1321
1338
  * const path = Bun.fileURLToPath(new URL("file:///foo/bar.txt"));
@@ -1523,6 +1540,8 @@ declare module "bun" {
1523
1540
  * - `size` will not be valid until the contents of the file are read at least once.
1524
1541
  * - `type` is auto-set based on the file extension when possible
1525
1542
  *
1543
+ * @category File System
1544
+ *
1526
1545
  * @example
1527
1546
  * ```js
1528
1547
  * const file = Bun.file("./hello.json");
@@ -1558,7 +1577,7 @@ declare module "bun" {
1558
1577
  *
1559
1578
  * Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). Does not copy the file, open the file, or modify the file.
1560
1579
  *
1561
- * If `begin` > 0, {@link Bun.write()} will be slower on macOS
1580
+ * If `begin` > 0, {@link Bun.write}() will be slower on macOS
1562
1581
  *
1563
1582
  * @param begin - start offset in bytes
1564
1583
  * @param contentType - MIME type for the new BunFile
@@ -2040,10 +2059,32 @@ declare module "bun" {
2040
2059
  verify(token: string, options?: CSRFVerifyOptions): boolean;
2041
2060
  }
2042
2061
 
2062
+ /**
2063
+ * SQL client
2064
+ *
2065
+ * @category Database
2066
+ */
2043
2067
  var sql: SQL;
2068
+
2069
+ /**
2070
+ * SQL client for PostgreSQL
2071
+ *
2072
+ * @category Database
2073
+ */
2044
2074
  var postgres: SQL;
2075
+
2076
+ /**
2077
+ * The SQL constructor
2078
+ *
2079
+ * @category Database
2080
+ */
2045
2081
  var SQL: SQL;
2046
2082
 
2083
+ /**
2084
+ * Generate and verify CSRF tokens
2085
+ *
2086
+ * @category Security
2087
+ */
2047
2088
  var CSRF: CSRF;
2048
2089
 
2049
2090
  /**
@@ -2510,6 +2551,15 @@ declare module "bun" {
2510
2551
  throw?: boolean;
2511
2552
  }
2512
2553
 
2554
+ /**
2555
+ * Hash and verify passwords using argon2 or bcrypt
2556
+ *
2557
+ * These are fast APIs that can run in a worker thread if used asynchronously.
2558
+ *
2559
+ * @see [Bun.password API docs](https://bun.sh/guides/util/hash-a-password)
2560
+ *
2561
+ * @category Security
2562
+ */
2513
2563
  namespace Password {
2514
2564
  type AlgorithmLabel = "bcrypt" | "argon2id" | "argon2d" | "argon2i";
2515
2565
 
@@ -2540,6 +2590,10 @@ declare module "bun" {
2540
2590
  * Password hashing functions are necessarily slow, and this object will
2541
2591
  * automatically run in a worker thread.
2542
2592
  *
2593
+ * @see [Bun.password API docs](https://bun.sh/guides/util/hash-a-password)
2594
+ *
2595
+ * @category Security
2596
+ *
2543
2597
  * The underlying implementation of these functions are provided by the Zig
2544
2598
  * Standard Library. Thanks to @jedisct1 and other Zig contributors for their
2545
2599
  * work on this.
@@ -2724,6 +2778,11 @@ declare module "bun" {
2724
2778
  ): string;
2725
2779
  };
2726
2780
 
2781
+ /**
2782
+ * A build artifact represents a file that was generated by the bundler @see {@link Bun.build}
2783
+ *
2784
+ * @category Bundler
2785
+ */
2727
2786
  interface BuildArtifact extends Blob {
2728
2787
  path: string;
2729
2788
  loader: Loader;
@@ -2732,6 +2791,11 @@ declare module "bun" {
2732
2791
  sourcemap: BuildArtifact | null;
2733
2792
  }
2734
2793
 
2794
+ /**
2795
+ * The output of a build
2796
+ *
2797
+ * @category Bundler
2798
+ */
2735
2799
  interface BuildOutput {
2736
2800
  outputs: BuildArtifact[];
2737
2801
  success: boolean;
@@ -2745,220 +2809,222 @@ declare module "bun" {
2745
2809
  * @returns {Promise<BuildOutput>} Promise that resolves to build output containing generated artifacts and build status
2746
2810
  * @throws {AggregateError} When build fails and config.throw is true (default in Bun 1.2+)
2747
2811
  *
2812
+ * @category Bundler
2813
+ *
2748
2814
  * @example Basic usage - Bundle a single entrypoint and check results
2749
- ```ts
2750
- const result = await Bun.build({
2751
- entrypoints: ['./src/index.tsx'],
2752
- outdir: './dist'
2753
- });
2754
-
2755
- if (!result.success) {
2756
- console.error('Build failed:', result.logs);
2757
- process.exit(1);
2758
- }
2759
- ```
2760
- *
2761
- * @example Set up multiple entrypoints with code splitting enabled
2762
- ```ts
2763
- await Bun.build({
2764
- entrypoints: ['./src/app.tsx', './src/admin.tsx'],
2765
- outdir: './dist',
2766
- splitting: true,
2767
- sourcemap: "external"
2768
- });
2769
- ```
2770
- *
2771
- * @example Configure minification and optimization settings
2772
- ```ts
2773
- await Bun.build({
2774
- entrypoints: ['./src/index.tsx'],
2775
- outdir: './dist',
2776
- minify: {
2777
- whitespace: true,
2778
- identifiers: true,
2779
- syntax: true
2780
- },
2781
- drop: ['console', 'debugger']
2782
- });
2783
- ```
2784
- *
2785
- * @example Set up custom loaders and mark packages as external
2786
- ```ts
2787
- await Bun.build({
2788
- entrypoints: ['./src/index.tsx'],
2789
- outdir: './dist',
2790
- loader: {
2791
- '.png': 'dataurl',
2792
- '.svg': 'file',
2793
- '.txt': 'text',
2794
- '.json': 'json'
2795
- },
2796
- external: ['react', 'react-dom']
2797
- });
2798
- ```
2799
- *
2800
- * @example Configure environment variable handling with different modes
2801
- ```ts
2802
- // Inline all environment variables
2803
- await Bun.build({
2804
- entrypoints: ['./src/index.tsx'],
2805
- outdir: './dist',
2806
- env: 'inline'
2807
- });
2808
-
2809
- // Only include specific env vars
2810
- await Bun.build({
2811
- entrypoints: ['./src/index.tsx'],
2812
- outdir: './dist',
2813
- env: 'PUBLIC_*'
2814
- });
2815
- ```
2816
- *
2817
- * @example Set up custom naming patterns for all output types
2818
- ```ts
2819
- await Bun.build({
2820
- entrypoints: ['./src/index.tsx'],
2821
- outdir: './dist',
2822
- naming: {
2823
- entry: '[dir]/[name]-[hash].[ext]',
2824
- chunk: 'chunks/[name]-[hash].[ext]',
2825
- asset: 'assets/[name]-[hash].[ext]'
2826
- }
2827
- });
2828
- ```
2829
- @example Work with build artifacts in different formats
2830
- ```ts
2831
- const result = await Bun.build({
2832
- entrypoints: ['./src/index.tsx']
2833
- });
2834
-
2835
- for (const artifact of result.outputs) {
2836
- const text = await artifact.text();
2837
- const buffer = await artifact.arrayBuffer();
2838
- const bytes = await artifact.bytes();
2839
-
2840
- new Response(artifact);
2841
- await Bun.write(artifact.path, artifact);
2842
- }
2843
- ```
2844
- @example Implement comprehensive error handling with position info
2845
- ```ts
2846
- try {
2847
- const result = await Bun.build({
2848
- entrypoints: ['./src/index.tsx'],
2849
- });
2850
- } catch (e) {
2851
- const error = e as AggregateError;
2852
- console.error('Build failed:');
2853
- for (const msg of error.errors) {
2854
- if ('position' in msg) {
2855
- console.error(
2856
- `${msg.message} at ${msg.position?.file}:${msg.position?.line}:${msg.position?.column}`
2857
- );
2858
- } else {
2859
- console.error(msg.message);
2860
- }
2861
- }
2862
- }
2863
- ```
2864
- @example Set up Node.js target with specific configurations
2865
- ```ts
2866
- await Bun.build({
2867
- entrypoints: ['./src/server.ts'],
2868
- outdir: './dist',
2869
- target: 'node',
2870
- format: 'cjs',
2871
- sourcemap: 'external',
2872
- minify: false,
2873
- packages: 'external'
2874
- });
2875
- ```
2876
- *
2877
- * @example Configure experimental CSS bundling with multiple themes
2878
- ```ts
2879
- await Bun.build({
2880
- entrypoints: [
2881
- './src/styles.css',
2882
- './src/themes/dark.css',
2883
- './src/themes/light.css'
2884
- ],
2885
- outdir: './dist/css',
2886
- });
2887
- ```
2888
- @example Define compile-time constants and version information
2889
- ```ts
2890
- await Bun.build({
2891
- entrypoints: ['./src/index.tsx'],
2892
- outdir: './dist',
2893
- define: {
2894
- 'process.env.NODE_ENV': JSON.stringify('production'),
2895
- 'CONSTANTS.VERSION': JSON.stringify('1.0.0'),
2896
- 'CONSTANTS.BUILD_TIME': JSON.stringify(new Date().toISOString())
2897
- }
2898
- });
2899
- ```
2900
- @example Create a custom plugin for handling special file types
2901
- ```ts
2902
- await Bun.build({
2903
- entrypoints: ['./src/index.tsx'],
2904
- outdir: './dist',
2905
- plugins: [
2906
- {
2907
- name: 'my-plugin',
2908
- setup(build) {
2909
- build.onLoad({ filter: /\.custom$/ }, async (args) => {
2910
- const content = await Bun.file(args.path).text();
2911
- return {
2912
- contents: `export default ${JSON.stringify(content)}`,
2913
- loader: 'js'
2914
- };
2915
- });
2916
- }
2917
- }
2918
- ]
2919
- });
2920
- ```
2921
- @example Enable bytecode generation for faster startup
2922
- ```ts
2923
- await Bun.build({
2924
- entrypoints: ['./src/server.ts'],
2925
- outdir: './dist',
2926
- target: 'bun',
2927
- format: 'cjs',
2928
- bytecode: true
2929
- });
2930
- ```
2931
- @example Add custom banner and footer to output files
2932
- ```ts
2933
- await Bun.build({
2934
- entrypoints: ['./src/index.tsx'],
2935
- outdir: './dist',
2936
- banner: '"use client";\n// Built with Bun',
2937
- footer: '// Generated on ' + new Date().toISOString()
2938
- });
2939
- ```
2940
- @example Configure CDN public path for asset loading
2941
- ```ts
2942
- await Bun.build({
2943
- entrypoints: ['./src/index.tsx'],
2944
- outdir: './dist',
2945
- publicPath: 'https://cdn.example.com/assets/',
2946
- loader: {
2947
- '.png': 'file',
2948
- '.svg': 'file'
2949
- }
2950
- });
2951
- ```
2952
- @example Set up package export conditions for different environments
2953
- ```ts
2954
- await Bun.build({
2955
- entrypoints: ['./src/index.tsx'],
2956
- outdir: './dist',
2957
- conditions: ['production', 'browser', 'module'],
2958
- packages: 'external'
2959
- });
2960
- ```
2961
- */
2815
+ * ```ts
2816
+ * const result = await Bun.build({
2817
+ * entrypoints: ['./src/index.tsx'],
2818
+ * outdir: './dist'
2819
+ * });
2820
+ *
2821
+ * if (!result.success) {
2822
+ * console.error('Build failed:', result.logs);
2823
+ * process.exit(1);
2824
+ * }
2825
+ * ```
2826
+ * *
2827
+ * * @example Set up multiple entrypoints with code splitting enabled
2828
+ * ```ts
2829
+ * await Bun.build({
2830
+ * entrypoints: ['./src/app.tsx', './src/admin.tsx'],
2831
+ * outdir: './dist',
2832
+ * splitting: true,
2833
+ * sourcemap: "external"
2834
+ * });
2835
+ * ```
2836
+ * *
2837
+ * * @example Configure minification and optimization settings
2838
+ * ```ts
2839
+ * await Bun.build({
2840
+ * entrypoints: ['./src/index.tsx'],
2841
+ * outdir: './dist',
2842
+ * minify: {
2843
+ * whitespace: true,
2844
+ * identifiers: true,
2845
+ * syntax: true
2846
+ * },
2847
+ * drop: ['console', 'debugger']
2848
+ * });
2849
+ * ```
2850
+ * *
2851
+ * * @example Set up custom loaders and mark packages as external
2852
+ * ```ts
2853
+ * await Bun.build({
2854
+ * entrypoints: ['./src/index.tsx'],
2855
+ * outdir: './dist',
2856
+ * loader: {
2857
+ * '.png': 'dataurl',
2858
+ * '.svg': 'file',
2859
+ * '.txt': 'text',
2860
+ * '.json': 'json'
2861
+ * },
2862
+ * external: ['react', 'react-dom']
2863
+ * });
2864
+ * ```
2865
+ * *
2866
+ * * @example Configure environment variable handling with different modes
2867
+ * ```ts
2868
+ * // Inline all environment variables
2869
+ * await Bun.build({
2870
+ * entrypoints: ['./src/index.tsx'],
2871
+ * outdir: './dist',
2872
+ * env: 'inline'
2873
+ * });
2874
+
2875
+ * // Only include specific env vars
2876
+ * await Bun.build({
2877
+ * entrypoints: ['./src/index.tsx'],
2878
+ * outdir: './dist',
2879
+ * env: 'PUBLIC_*'
2880
+ * });
2881
+ * ```
2882
+ * *
2883
+ * * @example Set up custom naming patterns for all output types
2884
+ * ```ts
2885
+ * await Bun.build({
2886
+ * entrypoints: ['./src/index.tsx'],
2887
+ * outdir: './dist',
2888
+ * naming: {
2889
+ * entry: '[dir]/[name]-[hash].[ext]',
2890
+ * chunk: 'chunks/[name]-[hash].[ext]',
2891
+ * asset: 'assets/[name]-[hash].[ext]'
2892
+ * }
2893
+ * });
2894
+ * ```
2895
+ * @example Work with build artifacts in different formats
2896
+ * ```ts
2897
+ * const result = await Bun.build({
2898
+ * entrypoints: ['./src/index.tsx']
2899
+ * });
2900
+
2901
+ * for (const artifact of result.outputs) {
2902
+ * const text = await artifact.text();
2903
+ * const buffer = await artifact.arrayBuffer();
2904
+ * const bytes = await artifact.bytes();
2905
+
2906
+ * new Response(artifact);
2907
+ * await Bun.write(artifact.path, artifact);
2908
+ * }
2909
+ * ```
2910
+ * @example Implement comprehensive error handling with position info
2911
+ * ```ts
2912
+ * try {
2913
+ * const result = await Bun.build({
2914
+ * entrypoints: ['./src/index.tsx'],
2915
+ * });
2916
+ * } catch (e) {
2917
+ * const error = e as AggregateError;
2918
+ * console.error('Build failed:');
2919
+ * for (const msg of error.errors) {
2920
+ * if ('position' in msg) {
2921
+ * console.error(
2922
+ * `${msg.message} at ${msg.position?.file}:${msg.position?.line}:${msg.position?.column}`
2923
+ * );
2924
+ * } else {
2925
+ * console.error(msg.message);
2926
+ * }
2927
+ * }
2928
+ * }
2929
+ * ```
2930
+ * @example Set up Node.js target with specific configurations
2931
+ * ```ts
2932
+ * await Bun.build({
2933
+ * entrypoints: ['./src/server.ts'],
2934
+ * outdir: './dist',
2935
+ * target: 'node',
2936
+ * format: 'cjs',
2937
+ * sourcemap: 'external',
2938
+ * minify: false,
2939
+ * packages: 'external'
2940
+ * });
2941
+ * ```
2942
+ * *
2943
+ * * @example Configure experimental CSS bundling with multiple themes
2944
+ * ```ts
2945
+ * await Bun.build({
2946
+ * entrypoints: [
2947
+ * './src/styles.css',
2948
+ * './src/themes/dark.css',
2949
+ * './src/themes/light.css'
2950
+ * ],
2951
+ * outdir: './dist/css',
2952
+ * });
2953
+ * ```
2954
+ * @example Define compile-time constants and version information
2955
+ * ```ts
2956
+ * await Bun.build({
2957
+ * entrypoints: ['./src/index.tsx'],
2958
+ * outdir: './dist',
2959
+ * define: {
2960
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
2961
+ * 'CONSTANTS.VERSION': JSON.stringify('1.0.0'),
2962
+ * 'CONSTANTS.BUILD_TIME': JSON.stringify(new Date().toISOString())
2963
+ * }
2964
+ * });
2965
+ * ```
2966
+ * @example Create a custom plugin for handling special file types
2967
+ * ```ts
2968
+ * await Bun.build({
2969
+ * entrypoints: ['./src/index.tsx'],
2970
+ * outdir: './dist',
2971
+ * plugins: [
2972
+ * {
2973
+ * name: 'my-plugin',
2974
+ * setup(build) {
2975
+ * build.onLoad({ filter: /\.custom$/ }, async (args) => {
2976
+ * const content = await Bun.file(args.path).text();
2977
+ * return {
2978
+ * contents: `export default ${JSON.stringify(content)}`,
2979
+ * loader: 'js'
2980
+ * };
2981
+ * });
2982
+ * }
2983
+ * }
2984
+ * ]
2985
+ * });
2986
+ * ```
2987
+ * @example Enable bytecode generation for faster startup
2988
+ * ```ts
2989
+ * await Bun.build({
2990
+ * entrypoints: ['./src/server.ts'],
2991
+ * outdir: './dist',
2992
+ * target: 'bun',
2993
+ * format: 'cjs',
2994
+ * bytecode: true
2995
+ * });
2996
+ * ```
2997
+ * @example Add custom banner and footer to output files
2998
+ * ```ts
2999
+ * await Bun.build({
3000
+ * entrypoints: ['./src/index.tsx'],
3001
+ * outdir: './dist',
3002
+ * banner: '"use client";\n// Built with Bun',
3003
+ * footer: '// Generated on ' + new Date().toISOString()
3004
+ * });
3005
+ * ```
3006
+ * @example Configure CDN public path for asset loading
3007
+ * ```ts
3008
+ * await Bun.build({
3009
+ * entrypoints: ['./src/index.tsx'],
3010
+ * outdir: './dist',
3011
+ * publicPath: 'https://cdn.example.com/assets/',
3012
+ * loader: {
3013
+ * '.png': 'file',
3014
+ * '.svg': 'file'
3015
+ * }
3016
+ * });
3017
+ * ```
3018
+ * @example Set up package export conditions for different environments
3019
+ * ```ts
3020
+ * await Bun.build({
3021
+ * entrypoints: ['./src/index.tsx'],
3022
+ * outdir: './dist',
3023
+ * conditions: ['production', 'browser', 'module'],
3024
+ * packages: 'external'
3025
+ * });
3026
+ * ```
3027
+ */
2962
3028
  function build(config: BuildConfig): Promise<BuildOutput>;
2963
3029
  /**
2964
3030
  * A status that represents the outcome of a sent message.
@@ -2996,6 +3062,8 @@ declare module "bun" {
2996
3062
  /**
2997
3063
  * A fast WebSocket designed for servers.
2998
3064
  *
3065
+ * @category HTTP & Networking
3066
+ *
2999
3067
  * Features:
3000
3068
  * - **Message compression** - Messages can be compressed
3001
3069
  * - **Backpressure** - If the client is not ready to receive data, the server will tell you.
@@ -3264,6 +3332,8 @@ declare module "bun" {
3264
3332
  /**
3265
3333
  * Create a server-side {@link ServerWebSocket} handler for use with {@link Bun.serve}
3266
3334
  *
3335
+ * @category HTTP & Networking
3336
+ *
3267
3337
  * @example
3268
3338
  * ```ts
3269
3339
  * import { websocket, serve } from "bun";
@@ -3971,6 +4041,8 @@ declare module "bun" {
3971
4041
  *
3972
4042
  * To start the server, see {@link serve}
3973
4043
  *
4044
+ * @category HTTP & Networking
4045
+ *
3974
4046
  * For performance, Bun pre-allocates most of the data for 2048 concurrent requests.
3975
4047
  * That means starting a new server allocates about 500 KB of memory. Try to
3976
4048
  * avoid starting and stopping the server often (unless it's a new instance of bun).
@@ -4270,6 +4342,8 @@ declare module "bun" {
4270
4342
  *
4271
4343
  * @param options - Server configuration options
4272
4344
  *
4345
+ * @category HTTP & Networking
4346
+ *
4273
4347
  * @example Basic Usage
4274
4348
  * ```ts
4275
4349
  * Bun.serve({
@@ -4600,6 +4674,11 @@ declare module "bun" {
4600
4674
 
4601
4675
  type StringLike = string | { toString(): string };
4602
4676
 
4677
+ /**
4678
+ * Valid inputs for {@link color}
4679
+ *
4680
+ * @category Utilities
4681
+ */
4603
4682
  type ColorInput =
4604
4683
  | { r: number; g: number; b: number; a?: number }
4605
4684
  | [number, number, number]
@@ -4614,6 +4693,9 @@ declare module "bun" {
4614
4693
 
4615
4694
  /**
4616
4695
  * Converts formats of colors
4696
+ *
4697
+ * @category Utilities
4698
+ *
4617
4699
  * @param input A value that could possibly be a color
4618
4700
  * @param outputFormat An optional output format
4619
4701
  */
@@ -5033,6 +5115,8 @@ declare module "bun" {
5033
5115
  * Resolve a `Promise` after milliseconds. This is like
5034
5116
  * {@link setTimeout} except it returns a `Promise`.
5035
5117
  *
5118
+ * @category Utilities
5119
+ *
5036
5120
  * @param ms milliseconds to delay resolving the promise. This is a minimum
5037
5121
  * number. It may take longer. If a {@link Date} is passed, it will sleep until the
5038
5122
  * {@link Date} is reached.
@@ -5075,6 +5159,8 @@ declare module "bun" {
5075
5159
  /**
5076
5160
  * Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
5077
5161
  *
5162
+ * @category Utilities
5163
+ *
5078
5164
  * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
5079
5165
  * @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
5080
5166
  *
@@ -5094,6 +5180,8 @@ declare module "bun" {
5094
5180
  /**
5095
5181
  * Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
5096
5182
  *
5183
+ * @category Utilities
5184
+ *
5097
5185
  * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
5098
5186
  * @param encoding `DigestEncoding` to return the hash in
5099
5187
  *
@@ -5471,6 +5559,11 @@ declare module "bun" {
5471
5559
  readonly __ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
5472
5560
  };
5473
5561
 
5562
+ /**
5563
+ * The builder object passed to `Bun.plugin`
5564
+ *
5565
+ * @category Bundler
5566
+ */
5474
5567
  interface PluginBuilder {
5475
5568
  /**
5476
5569
  * Register a callback which will be invoked when bundling starts. When
@@ -5571,6 +5664,11 @@ declare module "bun" {
5571
5664
  module(specifier: string, callback: () => OnLoadResult | Promise<OnLoadResult>): this;
5572
5665
  }
5573
5666
 
5667
+ /**
5668
+ * A Bun plugin. Used for extending Bun's behavior at runtime, or with {@link Bun.build}
5669
+ *
5670
+ * @category Bundler
5671
+ */
5574
5672
  interface BunPlugin {
5575
5673
  /**
5576
5674
  * Human-readable name of the plugin
@@ -5587,9 +5685,10 @@ declare module "bun" {
5587
5685
  *
5588
5686
  * If unspecified, it is assumed that the plugin is compatible with all targets.
5589
5687
  *
5590
- * This field is not read by {@link Bun.plugin}
5688
+ * This field is not read by {@link Bun.plugin}, only {@link Bun.build} and `bun build`
5591
5689
  */
5592
5690
  target?: Target;
5691
+
5593
5692
  /**
5594
5693
  * A function that will be called when the plugin is loaded.
5595
5694
  *
@@ -6736,6 +6835,8 @@ declare module "bun" {
6736
6835
  /**
6737
6836
  * Spawn a new process
6738
6837
  *
6838
+ * @category Process Management
6839
+ *
6739
6840
  * ```js
6740
6841
  * const subprocess = Bun.spawn({
6741
6842
  * cmd: ["echo", "hello"],
@@ -6800,6 +6901,8 @@ declare module "bun" {
6800
6901
  /**
6801
6902
  * Spawn a new process
6802
6903
  *
6904
+ * @category Process Management
6905
+ *
6803
6906
  * ```js
6804
6907
  * const {stdout} = Bun.spawnSync({
6805
6908
  * cmd: ["echo", "hello"],
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.8-canary.20250327T140605
340
+ [fetch] > User-Agent: Bun/1.2.8-canary.20250328T140605
341
341
  [fetch] > Accept: */*
342
342
  [fetch] > Host: example.com
343
343
  [fetch] > Accept-Encoding: gzip, deflate, br
package/docs/api/spawn.md CHANGED
@@ -120,7 +120,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
120
120
  ```ts
121
121
  const proc = Bun.spawn(["bun", "--version"]);
122
122
  const text = await new Response(proc.stdout).text();
123
- console.log(text); // => "1.2.8-canary.20250327T140605"
123
+ console.log(text); // => "1.2.8-canary.20250328T140605"
124
124
  ```
125
125
 
126
126
  Configure the output stream by passing one of the following values to `stdout/stderr`:
package/docs/api/sql.md CHANGED
@@ -240,7 +240,7 @@ const result = await sql.unsafe(
240
240
 
241
241
  ### Execute and Cancelling Queries
242
242
 
243
- Bun's SQL is lazy that means its will only start executing when awaited or executed with `.execute()`.
243
+ Bun's SQL is lazy, which means it will only start executing when awaited or executed with `.execute()`.
244
244
  You can cancel a query that is currently executing by calling the `cancel()` method on the query object.
245
245
 
246
246
  ```ts
@@ -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.8-canary.20250327T140605 (ca7428e9)
10
+ bun publish v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (16b4bf34)
12
+ bun install v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605"
19
+ + "@types/bun": "^1.2.8-canary.20250328T140605"
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.8-canary.20250327T140605"
31
+ "@types/bun": "^1.2.8-canary.20250328T140605"
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.8-canary.20250327T140605
100
+ $ bun update @types/bun@1.2.8-canary.20250328T140605
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.8-canary.20250327T140605 (9c68abdb)
24
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
50
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
88
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
21
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
64
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
81
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605 (9c68abdb)
32
+ bun test v1.2.8-canary.20250328T140605 (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.8-canary.20250327T140605"
8
+ Bun.version; // => "1.2.8-canary.20250328T140605"
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.8-canary.20250327T140605"
17
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.8-canary.20250328T140605"
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.8-canary.20250327T140605`.
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.8-canary.20250328T140605`.
193
193
 
194
194
  ```sh
195
- $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.8-canary.20250327T140605"
195
+ $ curl -fsSL https://bun.sh/install | bash -s "bun-v1.2.8-canary.20250328T140605"
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.8-canary.20250327T140605"
204
+ $ iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.2.8-canary.20250328T140605"
205
205
  ```
206
206
 
207
207
  ## Downloading Bun binaries directly
@@ -134,6 +134,16 @@ We recommend adding `./build/debug` to your `$PATH` so that you can run `bun-deb
134
134
  $ bun-debug
135
135
  ```
136
136
 
137
+ ## Running debug builds
138
+
139
+ The `bd` package.json script compiles and runs a debug build of Bun, only printing the output of the build process if it fails.
140
+
141
+ ```sh
142
+ $ bun bd <args>
143
+ $ bun bd test foo.test.ts
144
+ $ bun bd ./foo.ts
145
+ ```
146
+
137
147
  ## Code generation scripts
138
148
 
139
149
  Several code generation scripts are used during Bun's build process. These are run automatically when changes are made to certain files.
@@ -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.8-canary.20250327T140605" -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.8-canary.20250328T140605" -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.8-canary.20250327T140605
131
+ [fetch] > User-Agent: Bun/1.2.8-canary.20250328T140605
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.8-canary.20250327T140605
173
+ [fetch] > User-Agent: Bun/1.2.8-canary.20250328T140605
174
174
  [fetch] > Accept: */*
175
175
  [fetch] > Host: example.com
176
176
  [fetch] > Accept-Encoding: gzip, deflate, br
@@ -378,8 +378,7 @@ The table below lists all globals implemented by Node.js and Bun's current compa
378
378
 
379
379
  ### [`require()`](https://nodejs.org/api/globals.html#require)
380
380
 
381
- 🟢 Fully implemented, including [`require.main`](https://nodejs.org/api/modules.html#requiremain), [`require.cache`](https://nodejs.org/api/modules.html#requirecache), [`require.resolve`](https://nodejs.org/api/modules.html#requireresolverequest-options). `require.extensions` is a stub.
382
-
381
+ 🟢 Fully implemented, including [`require.main`](https://nodejs.org/api/modules.html#requiremain), [`require.cache`](https://nodejs.org/api/modules.html#requirecache), [`require.resolve`](https://nodejs.org/api/modules.html#requireresolverequest-options).
383
382
  ### [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
384
383
 
385
384
  🟢 Fully implemented.
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.8-canary.20250327T140605
58
+ bun test v1.2.8-canary.20250328T140605
59
59
 
60
60
  dom.test.ts:
61
61
  ✓ dom test [0.82ms]
package/ffi.d.ts CHANGED
@@ -13,6 +13,8 @@
13
13
  * that convert JavaScript types to C types and back. Internally,
14
14
  * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
15
15
  * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
16
+ *
17
+ * @category FFI
16
18
  */
17
19
  declare module "bun:ffi" {
18
20
  enum FFIType {
@@ -600,6 +602,8 @@ declare module "bun:ffi" {
600
602
  * that convert JavaScript types to C types and back. Internally,
601
603
  * bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
602
604
  * goes to Fabrice Bellard and TinyCC maintainers for making this possible.
605
+ *
606
+ * @category FFI
603
607
  */
604
608
  function dlopen<Fns extends Record<string, FFIFunction>>(
605
609
  name: string | import("bun").BunFile | URL,
@@ -1018,6 +1022,8 @@ declare module "bun:ffi" {
1018
1022
  * // Do something with rawPtr
1019
1023
  * }
1020
1024
  * ```
1025
+ *
1026
+ * @category FFI
1021
1027
  */
1022
1028
  function ptr(view: NodeJS.TypedArray | ArrayBufferLike | DataView, byteOffset?: number): Pointer;
1023
1029
 
@@ -1042,8 +1048,9 @@ declare module "bun:ffi" {
1042
1048
  * thing to do safely. Passing an invalid pointer can crash the program and
1043
1049
  * reading beyond the bounds of the pointer will crash the program or cause
1044
1050
  * undefined behavior. Use with care!
1051
+ *
1052
+ * @category FFI
1045
1053
  */
1046
-
1047
1054
  class CString extends String {
1048
1055
  /**
1049
1056
  * Get a string from a UTF-8 encoded C string
package/globals.d.ts CHANGED
@@ -1384,7 +1384,7 @@ interface Uint8ArrayConstructor {
1384
1384
  interface BroadcastChannel {}
1385
1385
  declare var BroadcastChannel: Bun.__internal.UseLibDomIfAvailable<
1386
1386
  "BroadcastChannel",
1387
- import("node:worker_threads").BroadcastChannel
1387
+ typeof import("node:worker_threads").BroadcastChannel
1388
1388
  >;
1389
1389
 
1390
1390
  declare var URL: Bun.__internal.UseLibDomIfAvailable<
@@ -1434,6 +1434,24 @@ declare var AbortSignal: Bun.__internal.UseLibDomIfAvailable<
1434
1434
  {
1435
1435
  prototype: AbortSignal;
1436
1436
  new (): AbortSignal;
1437
+ /**
1438
+ * Create an AbortSignal that will be aborted after a timeout
1439
+ * @param ms The timeout in milliseconds
1440
+ * @returns An AbortSignal that will be aborted after the timeout
1441
+ */
1442
+ timeout(ms: number): AbortSignal;
1443
+ /**
1444
+ * Create an immediately-aborted AbortSignal
1445
+ * @param reason The reason for the abort
1446
+ * @returns An AbortSignal that is already aborted
1447
+ */
1448
+ abort(reason?: any): AbortSignal;
1449
+ /**
1450
+ * Create an AbortSignal that will be aborted if any of the signals are aborted
1451
+ * @param signals The signals to combine
1452
+ * @returns An AbortSignal that will be aborted if any of the signals are aborted
1453
+ */
1454
+ any(signals: AbortSignal[]): AbortSignal;
1437
1455
  }
1438
1456
  >;
1439
1457
 
@@ -147,6 +147,8 @@ declare namespace HTMLRewriterTypes {
147
147
  * });
148
148
  * rewriter.transform(await fetch("https://remix.run"));
149
149
  * ```
150
+ *
151
+ * @category HTML Manipulation
150
152
  */
151
153
  declare class HTMLRewriter {
152
154
  constructor();
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.8-canary.20250327T140605",
2
+ "version": "1.2.8-canary.20250328T140605",
3
3
  "name": "bun-types",
4
4
  "license": "MIT",
5
5
  "types": "./index.d.ts",
package/s3.d.ts CHANGED
@@ -340,6 +340,8 @@ declare module "bun" {
340
340
  /**
341
341
  * Represents a file in an S3-compatible storage service.
342
342
  * Extends the Blob interface for compatibility with web APIs.
343
+ *
344
+ * @category Cloud Storage
343
345
  */
344
346
  interface S3File extends Blob {
345
347
  /**
@@ -635,6 +637,8 @@ declare module "bun" {
635
637
  * await bucket.write("data.json", JSON.stringify({hello: "world"}));
636
638
  * const url = bucket.presign("file.pdf");
637
639
  * await bucket.unlink("old.txt");
640
+ *
641
+ * @category Cloud Storage
638
642
  */
639
643
  class S3Client {
640
644
  prototype: S3Client;
@@ -820,6 +824,8 @@ declare module "bun" {
820
824
  * A default instance of S3Client
821
825
  *
822
826
  * Pulls credentials from environment variables. Use `new Bun.S3Client()` if you need to explicitly set credentials.
827
+ *
828
+ * @category Cloud Storage
823
829
  */
824
830
  var s3: S3Client;
825
831
  }
package/sqlite.d.ts CHANGED
@@ -58,6 +58,8 @@ declare module "bun:sqlite" {
58
58
  * ```ts
59
59
  * const db = new Database("mydb.sqlite", {readonly: true});
60
60
  * ```
61
+ *
62
+ * @category Database
61
63
  */
62
64
  constructor(
63
65
  filename?: string,
@@ -567,6 +569,8 @@ declare module "bun:sqlite" {
567
569
  *
568
570
  * This is returned by {@link Database.prepare} and {@link Database.query}.
569
571
  *
572
+ * @category Database
573
+ *
570
574
  * @example
571
575
  * ```ts
572
576
  * const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
package/test.d.ts CHANGED
@@ -16,6 +16,8 @@
16
16
  declare module "bun:test" {
17
17
  /**
18
18
  * -- Mocks --
19
+ *
20
+ * @category Testing
19
21
  */
20
22
  export type Mock<T extends (...args: any[]) => any> = JestMock.Mock<T>;
21
23
 
@@ -168,6 +170,8 @@ declare module "bun:test" {
168
170
  *
169
171
  * @param label the label for the tests
170
172
  * @param fn the function that defines the tests
173
+ *
174
+ * @category Testing
171
175
  */
172
176
  export interface Describe {
173
177
  (fn: () => void): void;
@@ -352,6 +356,8 @@ declare module "bun:test" {
352
356
  * @param label the label for the test
353
357
  * @param fn the test function
354
358
  * @param options the test timeout or options
359
+ *
360
+ * @category Testing
355
361
  */
356
362
  export interface Test {
357
363
  (