bun-types 1.2.8-canary.20250327T140605 → 1.2.8-canary.20250329T140548
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 +335 -233
- package/docs/api/fetch.md +1 -1
- package/docs/api/spawn.md +1 -1
- package/docs/api/sql.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/project/contributing.md +10 -0
- package/docs/runtime/debugger.md +3 -3
- package/docs/runtime/nodejs-apis.md +1 -2
- package/docs/test/dom.md +1 -1
- package/ffi.d.ts +8 -1
- package/globals.d.ts +140 -73
- package/html-rewriter.d.ts +2 -0
- package/package.json +1 -1
- package/s3.d.ts +6 -0
- package/sqlite.d.ts +4 -0
- package/test.d.ts +6 -0
package/bun.d.ts
CHANGED
|
@@ -40,7 +40,6 @@ declare module "bun" {
|
|
|
40
40
|
type SignalsListener = (signal: NodeJS.Signals) => void;
|
|
41
41
|
type BlobPart = string | Blob | BufferSource;
|
|
42
42
|
type TimerHandler = (...args: any[]) => void;
|
|
43
|
-
|
|
44
43
|
type DOMHighResTimeStamp = number;
|
|
45
44
|
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
46
45
|
type BlobOrStringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike | Blob;
|
|
@@ -537,9 +536,11 @@ declare module "bun" {
|
|
|
537
536
|
/**
|
|
538
537
|
* Find the path to an executable, similar to typing which in your terminal. Reads the `PATH` environment variable unless overridden with `options.PATH`.
|
|
539
538
|
*
|
|
540
|
-
* @
|
|
541
|
-
*
|
|
542
|
-
* @param
|
|
539
|
+
* @category Utilities
|
|
540
|
+
*
|
|
541
|
+
* @param command The name of the executable or script
|
|
542
|
+
* @param options.PATH Overrides the PATH environment variable
|
|
543
|
+
* @param options.cwd When given a relative path, use this path to join it.
|
|
543
544
|
*/
|
|
544
545
|
function which(command: string, options?: { PATH?: string; cwd?: string }): string | null;
|
|
545
546
|
|
|
@@ -945,19 +946,24 @@ declare module "bun" {
|
|
|
945
946
|
blob(): Blob;
|
|
946
947
|
}
|
|
947
948
|
|
|
949
|
+
/**
|
|
950
|
+
* The Bun shell
|
|
951
|
+
*
|
|
952
|
+
* @category Process Management
|
|
953
|
+
*/
|
|
948
954
|
const $: Shell;
|
|
949
955
|
|
|
950
|
-
|
|
956
|
+
const TOML: {
|
|
951
957
|
/**
|
|
952
958
|
* Parse a TOML string into a JavaScript object.
|
|
953
959
|
*
|
|
954
|
-
* @
|
|
955
|
-
*
|
|
956
|
-
* @param
|
|
960
|
+
* @category Utilities
|
|
961
|
+
*
|
|
962
|
+
* @param input The TOML string to parse
|
|
963
|
+
* @returns A JavaScript object
|
|
957
964
|
*/
|
|
958
965
|
parse(input: string): object;
|
|
959
|
-
}
|
|
960
|
-
const TOML: TOML;
|
|
966
|
+
};
|
|
961
967
|
|
|
962
968
|
/**
|
|
963
969
|
* Synchronously resolve a `moduleId` as though it were imported from `parent`
|
|
@@ -980,6 +986,8 @@ declare module "bun" {
|
|
|
980
986
|
*
|
|
981
987
|
* 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
988
|
*
|
|
989
|
+
* @category File System
|
|
990
|
+
*
|
|
983
991
|
* @param destination The file or file path to write to
|
|
984
992
|
* @param input The data to copy into `destination`.
|
|
985
993
|
* @returns A promise that resolves with the number of bytes written.
|
|
@@ -1271,6 +1279,8 @@ declare module "bun" {
|
|
|
1271
1279
|
/**
|
|
1272
1280
|
* Escape the following characters in a string:
|
|
1273
1281
|
*
|
|
1282
|
+
* @category Security
|
|
1283
|
+
*
|
|
1274
1284
|
* - `"` becomes `"""`
|
|
1275
1285
|
* - `&` becomes `"&"`
|
|
1276
1286
|
* - `'` becomes `"'"`
|
|
@@ -1291,6 +1301,8 @@ declare module "bun" {
|
|
|
1291
1301
|
* @param path The path to convert.
|
|
1292
1302
|
* @returns A {@link URL} with the file:// scheme.
|
|
1293
1303
|
*
|
|
1304
|
+
* @category File System
|
|
1305
|
+
*
|
|
1294
1306
|
* @example
|
|
1295
1307
|
* ```js
|
|
1296
1308
|
* const url = Bun.pathToFileURL("/foo/bar.txt");
|
|
@@ -1313,9 +1325,13 @@ declare module "bun" {
|
|
|
1313
1325
|
|
|
1314
1326
|
/**
|
|
1315
1327
|
* Convert a {@link URL} to a filesystem path.
|
|
1328
|
+
*
|
|
1316
1329
|
* @param url The URL to convert.
|
|
1317
1330
|
* @returns A filesystem path.
|
|
1318
1331
|
* @throws If the URL is not a URL.
|
|
1332
|
+
*
|
|
1333
|
+
* @category File System
|
|
1334
|
+
*
|
|
1319
1335
|
* @example
|
|
1320
1336
|
* ```js
|
|
1321
1337
|
* const path = Bun.fileURLToPath(new URL("file:///foo/bar.txt"));
|
|
@@ -1523,6 +1539,8 @@ declare module "bun" {
|
|
|
1523
1539
|
* - `size` will not be valid until the contents of the file are read at least once.
|
|
1524
1540
|
* - `type` is auto-set based on the file extension when possible
|
|
1525
1541
|
*
|
|
1542
|
+
* @category File System
|
|
1543
|
+
*
|
|
1526
1544
|
* @example
|
|
1527
1545
|
* ```js
|
|
1528
1546
|
* const file = Bun.file("./hello.json");
|
|
@@ -1558,7 +1576,7 @@ declare module "bun" {
|
|
|
1558
1576
|
*
|
|
1559
1577
|
* 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
1578
|
*
|
|
1561
|
-
* If `begin` > 0, {@link Bun.write()
|
|
1579
|
+
* If `begin` > 0, {@link Bun.write}() will be slower on macOS
|
|
1562
1580
|
*
|
|
1563
1581
|
* @param begin - start offset in bytes
|
|
1564
1582
|
* @param contentType - MIME type for the new BunFile
|
|
@@ -2040,10 +2058,32 @@ declare module "bun" {
|
|
|
2040
2058
|
verify(token: string, options?: CSRFVerifyOptions): boolean;
|
|
2041
2059
|
}
|
|
2042
2060
|
|
|
2061
|
+
/**
|
|
2062
|
+
* SQL client
|
|
2063
|
+
*
|
|
2064
|
+
* @category Database
|
|
2065
|
+
*/
|
|
2043
2066
|
var sql: SQL;
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* SQL client for PostgreSQL
|
|
2070
|
+
*
|
|
2071
|
+
* @category Database
|
|
2072
|
+
*/
|
|
2044
2073
|
var postgres: SQL;
|
|
2074
|
+
|
|
2075
|
+
/**
|
|
2076
|
+
* The SQL constructor
|
|
2077
|
+
*
|
|
2078
|
+
* @category Database
|
|
2079
|
+
*/
|
|
2045
2080
|
var SQL: SQL;
|
|
2046
2081
|
|
|
2082
|
+
/**
|
|
2083
|
+
* Generate and verify CSRF tokens
|
|
2084
|
+
*
|
|
2085
|
+
* @category Security
|
|
2086
|
+
*/
|
|
2047
2087
|
var CSRF: CSRF;
|
|
2048
2088
|
|
|
2049
2089
|
/**
|
|
@@ -2510,6 +2550,15 @@ declare module "bun" {
|
|
|
2510
2550
|
throw?: boolean;
|
|
2511
2551
|
}
|
|
2512
2552
|
|
|
2553
|
+
/**
|
|
2554
|
+
* Hash and verify passwords using argon2 or bcrypt
|
|
2555
|
+
*
|
|
2556
|
+
* These are fast APIs that can run in a worker thread if used asynchronously.
|
|
2557
|
+
*
|
|
2558
|
+
* @see [Bun.password API docs](https://bun.sh/guides/util/hash-a-password)
|
|
2559
|
+
*
|
|
2560
|
+
* @category Security
|
|
2561
|
+
*/
|
|
2513
2562
|
namespace Password {
|
|
2514
2563
|
type AlgorithmLabel = "bcrypt" | "argon2id" | "argon2d" | "argon2i";
|
|
2515
2564
|
|
|
@@ -2540,6 +2589,10 @@ declare module "bun" {
|
|
|
2540
2589
|
* Password hashing functions are necessarily slow, and this object will
|
|
2541
2590
|
* automatically run in a worker thread.
|
|
2542
2591
|
*
|
|
2592
|
+
* @see [Bun.password API docs](https://bun.sh/guides/util/hash-a-password)
|
|
2593
|
+
*
|
|
2594
|
+
* @category Security
|
|
2595
|
+
*
|
|
2543
2596
|
* The underlying implementation of these functions are provided by the Zig
|
|
2544
2597
|
* Standard Library. Thanks to @jedisct1 and other Zig contributors for their
|
|
2545
2598
|
* work on this.
|
|
@@ -2724,6 +2777,11 @@ declare module "bun" {
|
|
|
2724
2777
|
): string;
|
|
2725
2778
|
};
|
|
2726
2779
|
|
|
2780
|
+
/**
|
|
2781
|
+
* A build artifact represents a file that was generated by the bundler @see {@link Bun.build}
|
|
2782
|
+
*
|
|
2783
|
+
* @category Bundler
|
|
2784
|
+
*/
|
|
2727
2785
|
interface BuildArtifact extends Blob {
|
|
2728
2786
|
path: string;
|
|
2729
2787
|
loader: Loader;
|
|
@@ -2732,6 +2790,11 @@ declare module "bun" {
|
|
|
2732
2790
|
sourcemap: BuildArtifact | null;
|
|
2733
2791
|
}
|
|
2734
2792
|
|
|
2793
|
+
/**
|
|
2794
|
+
* The output of a build
|
|
2795
|
+
*
|
|
2796
|
+
* @category Bundler
|
|
2797
|
+
*/
|
|
2735
2798
|
interface BuildOutput {
|
|
2736
2799
|
outputs: BuildArtifact[];
|
|
2737
2800
|
success: boolean;
|
|
@@ -2745,220 +2808,222 @@ declare module "bun" {
|
|
|
2745
2808
|
* @returns {Promise<BuildOutput>} Promise that resolves to build output containing generated artifacts and build status
|
|
2746
2809
|
* @throws {AggregateError} When build fails and config.throw is true (default in Bun 1.2+)
|
|
2747
2810
|
*
|
|
2811
|
+
* @category Bundler
|
|
2812
|
+
*
|
|
2748
2813
|
* @example Basic usage - Bundle a single entrypoint and check results
|
|
2749
|
-
```ts
|
|
2750
|
-
const result = await Bun.build({
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
});
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
```
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2814
|
+
* ```ts
|
|
2815
|
+
* const result = await Bun.build({
|
|
2816
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2817
|
+
* outdir: './dist'
|
|
2818
|
+
* });
|
|
2819
|
+
*
|
|
2820
|
+
* if (!result.success) {
|
|
2821
|
+
* console.error('Build failed:', result.logs);
|
|
2822
|
+
* process.exit(1);
|
|
2823
|
+
* }
|
|
2824
|
+
* ```
|
|
2825
|
+
* *
|
|
2826
|
+
* * @example Set up multiple entrypoints with code splitting enabled
|
|
2827
|
+
* ```ts
|
|
2828
|
+
* await Bun.build({
|
|
2829
|
+
* entrypoints: ['./src/app.tsx', './src/admin.tsx'],
|
|
2830
|
+
* outdir: './dist',
|
|
2831
|
+
* splitting: true,
|
|
2832
|
+
* sourcemap: "external"
|
|
2833
|
+
* });
|
|
2834
|
+
* ```
|
|
2835
|
+
* *
|
|
2836
|
+
* * @example Configure minification and optimization settings
|
|
2837
|
+
* ```ts
|
|
2838
|
+
* await Bun.build({
|
|
2839
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2840
|
+
* outdir: './dist',
|
|
2841
|
+
* minify: {
|
|
2842
|
+
* whitespace: true,
|
|
2843
|
+
* identifiers: true,
|
|
2844
|
+
* syntax: true
|
|
2845
|
+
* },
|
|
2846
|
+
* drop: ['console', 'debugger']
|
|
2847
|
+
* });
|
|
2848
|
+
* ```
|
|
2849
|
+
* *
|
|
2850
|
+
* * @example Set up custom loaders and mark packages as external
|
|
2851
|
+
* ```ts
|
|
2852
|
+
* await Bun.build({
|
|
2853
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2854
|
+
* outdir: './dist',
|
|
2855
|
+
* loader: {
|
|
2856
|
+
* '.png': 'dataurl',
|
|
2857
|
+
* '.svg': 'file',
|
|
2858
|
+
* '.txt': 'text',
|
|
2859
|
+
* '.json': 'json'
|
|
2860
|
+
* },
|
|
2861
|
+
* external: ['react', 'react-dom']
|
|
2862
|
+
* });
|
|
2863
|
+
* ```
|
|
2864
|
+
* *
|
|
2865
|
+
* * @example Configure environment variable handling with different modes
|
|
2866
|
+
* ```ts
|
|
2867
|
+
* // Inline all environment variables
|
|
2868
|
+
* await Bun.build({
|
|
2869
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2870
|
+
* outdir: './dist',
|
|
2871
|
+
* env: 'inline'
|
|
2872
|
+
* });
|
|
2873
|
+
|
|
2874
|
+
* // Only include specific env vars
|
|
2875
|
+
* await Bun.build({
|
|
2876
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2877
|
+
* outdir: './dist',
|
|
2878
|
+
* env: 'PUBLIC_*'
|
|
2879
|
+
* });
|
|
2880
|
+
* ```
|
|
2881
|
+
* *
|
|
2882
|
+
* * @example Set up custom naming patterns for all output types
|
|
2883
|
+
* ```ts
|
|
2884
|
+
* await Bun.build({
|
|
2885
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2886
|
+
* outdir: './dist',
|
|
2887
|
+
* naming: {
|
|
2888
|
+
* entry: '[dir]/[name]-[hash].[ext]',
|
|
2889
|
+
* chunk: 'chunks/[name]-[hash].[ext]',
|
|
2890
|
+
* asset: 'assets/[name]-[hash].[ext]'
|
|
2891
|
+
* }
|
|
2892
|
+
* });
|
|
2893
|
+
* ```
|
|
2894
|
+
* @example Work with build artifacts in different formats
|
|
2895
|
+
* ```ts
|
|
2896
|
+
* const result = await Bun.build({
|
|
2897
|
+
* entrypoints: ['./src/index.tsx']
|
|
2898
|
+
* });
|
|
2899
|
+
|
|
2900
|
+
* for (const artifact of result.outputs) {
|
|
2901
|
+
* const text = await artifact.text();
|
|
2902
|
+
* const buffer = await artifact.arrayBuffer();
|
|
2903
|
+
* const bytes = await artifact.bytes();
|
|
2904
|
+
|
|
2905
|
+
* new Response(artifact);
|
|
2906
|
+
* await Bun.write(artifact.path, artifact);
|
|
2907
|
+
* }
|
|
2908
|
+
* ```
|
|
2909
|
+
* @example Implement comprehensive error handling with position info
|
|
2910
|
+
* ```ts
|
|
2911
|
+
* try {
|
|
2912
|
+
* const result = await Bun.build({
|
|
2913
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2914
|
+
* });
|
|
2915
|
+
* } catch (e) {
|
|
2916
|
+
* const error = e as AggregateError;
|
|
2917
|
+
* console.error('Build failed:');
|
|
2918
|
+
* for (const msg of error.errors) {
|
|
2919
|
+
* if ('position' in msg) {
|
|
2920
|
+
* console.error(
|
|
2921
|
+
* `${msg.message} at ${msg.position?.file}:${msg.position?.line}:${msg.position?.column}`
|
|
2922
|
+
* );
|
|
2923
|
+
* } else {
|
|
2924
|
+
* console.error(msg.message);
|
|
2925
|
+
* }
|
|
2926
|
+
* }
|
|
2927
|
+
* }
|
|
2928
|
+
* ```
|
|
2929
|
+
* @example Set up Node.js target with specific configurations
|
|
2930
|
+
* ```ts
|
|
2931
|
+
* await Bun.build({
|
|
2932
|
+
* entrypoints: ['./src/server.ts'],
|
|
2933
|
+
* outdir: './dist',
|
|
2934
|
+
* target: 'node',
|
|
2935
|
+
* format: 'cjs',
|
|
2936
|
+
* sourcemap: 'external',
|
|
2937
|
+
* minify: false,
|
|
2938
|
+
* packages: 'external'
|
|
2939
|
+
* });
|
|
2940
|
+
* ```
|
|
2941
|
+
* *
|
|
2942
|
+
* * @example Configure experimental CSS bundling with multiple themes
|
|
2943
|
+
* ```ts
|
|
2944
|
+
* await Bun.build({
|
|
2945
|
+
* entrypoints: [
|
|
2946
|
+
* './src/styles.css',
|
|
2947
|
+
* './src/themes/dark.css',
|
|
2948
|
+
* './src/themes/light.css'
|
|
2949
|
+
* ],
|
|
2950
|
+
* outdir: './dist/css',
|
|
2951
|
+
* });
|
|
2952
|
+
* ```
|
|
2953
|
+
* @example Define compile-time constants and version information
|
|
2954
|
+
* ```ts
|
|
2955
|
+
* await Bun.build({
|
|
2956
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2957
|
+
* outdir: './dist',
|
|
2958
|
+
* define: {
|
|
2959
|
+
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
2960
|
+
* 'CONSTANTS.VERSION': JSON.stringify('1.0.0'),
|
|
2961
|
+
* 'CONSTANTS.BUILD_TIME': JSON.stringify(new Date().toISOString())
|
|
2962
|
+
* }
|
|
2963
|
+
* });
|
|
2964
|
+
* ```
|
|
2965
|
+
* @example Create a custom plugin for handling special file types
|
|
2966
|
+
* ```ts
|
|
2967
|
+
* await Bun.build({
|
|
2968
|
+
* entrypoints: ['./src/index.tsx'],
|
|
2969
|
+
* outdir: './dist',
|
|
2970
|
+
* plugins: [
|
|
2971
|
+
* {
|
|
2972
|
+
* name: 'my-plugin',
|
|
2973
|
+
* setup(build) {
|
|
2974
|
+
* build.onLoad({ filter: /\.custom$/ }, async (args) => {
|
|
2975
|
+
* const content = await Bun.file(args.path).text();
|
|
2976
|
+
* return {
|
|
2977
|
+
* contents: `export default ${JSON.stringify(content)}`,
|
|
2978
|
+
* loader: 'js'
|
|
2979
|
+
* };
|
|
2980
|
+
* });
|
|
2981
|
+
* }
|
|
2982
|
+
* }
|
|
2983
|
+
* ]
|
|
2984
|
+
* });
|
|
2985
|
+
* ```
|
|
2986
|
+
* @example Enable bytecode generation for faster startup
|
|
2987
|
+
* ```ts
|
|
2988
|
+
* await Bun.build({
|
|
2989
|
+
* entrypoints: ['./src/server.ts'],
|
|
2990
|
+
* outdir: './dist',
|
|
2991
|
+
* target: 'bun',
|
|
2992
|
+
* format: 'cjs',
|
|
2993
|
+
* bytecode: true
|
|
2994
|
+
* });
|
|
2995
|
+
* ```
|
|
2996
|
+
* @example Add custom banner and footer to output files
|
|
2997
|
+
* ```ts
|
|
2998
|
+
* await Bun.build({
|
|
2999
|
+
* entrypoints: ['./src/index.tsx'],
|
|
3000
|
+
* outdir: './dist',
|
|
3001
|
+
* banner: '"use client";\n// Built with Bun',
|
|
3002
|
+
* footer: '// Generated on ' + new Date().toISOString()
|
|
3003
|
+
* });
|
|
3004
|
+
* ```
|
|
3005
|
+
* @example Configure CDN public path for asset loading
|
|
3006
|
+
* ```ts
|
|
3007
|
+
* await Bun.build({
|
|
3008
|
+
* entrypoints: ['./src/index.tsx'],
|
|
3009
|
+
* outdir: './dist',
|
|
3010
|
+
* publicPath: 'https://cdn.example.com/assets/',
|
|
3011
|
+
* loader: {
|
|
3012
|
+
* '.png': 'file',
|
|
3013
|
+
* '.svg': 'file'
|
|
3014
|
+
* }
|
|
3015
|
+
* });
|
|
3016
|
+
* ```
|
|
3017
|
+
* @example Set up package export conditions for different environments
|
|
3018
|
+
* ```ts
|
|
3019
|
+
* await Bun.build({
|
|
3020
|
+
* entrypoints: ['./src/index.tsx'],
|
|
3021
|
+
* outdir: './dist',
|
|
3022
|
+
* conditions: ['production', 'browser', 'module'],
|
|
3023
|
+
* packages: 'external'
|
|
3024
|
+
* });
|
|
3025
|
+
* ```
|
|
3026
|
+
*/
|
|
2962
3027
|
function build(config: BuildConfig): Promise<BuildOutput>;
|
|
2963
3028
|
/**
|
|
2964
3029
|
* A status that represents the outcome of a sent message.
|
|
@@ -2996,6 +3061,8 @@ declare module "bun" {
|
|
|
2996
3061
|
/**
|
|
2997
3062
|
* A fast WebSocket designed for servers.
|
|
2998
3063
|
*
|
|
3064
|
+
* @category HTTP & Networking
|
|
3065
|
+
*
|
|
2999
3066
|
* Features:
|
|
3000
3067
|
* - **Message compression** - Messages can be compressed
|
|
3001
3068
|
* - **Backpressure** - If the client is not ready to receive data, the server will tell you.
|
|
@@ -3264,6 +3331,8 @@ declare module "bun" {
|
|
|
3264
3331
|
/**
|
|
3265
3332
|
* Create a server-side {@link ServerWebSocket} handler for use with {@link Bun.serve}
|
|
3266
3333
|
*
|
|
3334
|
+
* @category HTTP & Networking
|
|
3335
|
+
*
|
|
3267
3336
|
* @example
|
|
3268
3337
|
* ```ts
|
|
3269
3338
|
* import { websocket, serve } from "bun";
|
|
@@ -3743,6 +3812,14 @@ declare module "bun" {
|
|
|
3743
3812
|
tls?: TLSOptions | TLSOptions[];
|
|
3744
3813
|
}
|
|
3745
3814
|
|
|
3815
|
+
interface TLSServeOptions extends ServeOptions, TLSOptionsAsDeprecated {
|
|
3816
|
+
tls?: TLSOptions | TLSOptions[];
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
interface UnixTLSServeOptions extends UnixServeOptions, TLSOptionsAsDeprecated {
|
|
3820
|
+
tls?: TLSOptions | TLSOptions[];
|
|
3821
|
+
}
|
|
3822
|
+
|
|
3746
3823
|
interface ErrorLike extends Error {
|
|
3747
3824
|
code?: string;
|
|
3748
3825
|
errno?: number;
|
|
@@ -3943,14 +4020,6 @@ declare module "bun" {
|
|
|
3943
4020
|
secureOptions?: number | undefined; // Value is a numeric bitmask of the `SSL_OP_*` options
|
|
3944
4021
|
}
|
|
3945
4022
|
|
|
3946
|
-
interface TLSServeOptions extends ServeOptions, TLSOptionsAsDeprecated {
|
|
3947
|
-
tls?: TLSOptions | TLSOptions[];
|
|
3948
|
-
}
|
|
3949
|
-
|
|
3950
|
-
interface UnixTLSServeOptions extends UnixServeOptions, TLSOptionsAsDeprecated {
|
|
3951
|
-
tls?: TLSOptions | TLSOptions[];
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
4023
|
interface SocketAddress {
|
|
3955
4024
|
/**
|
|
3956
4025
|
* The IP address of the client.
|
|
@@ -3971,6 +4040,8 @@ declare module "bun" {
|
|
|
3971
4040
|
*
|
|
3972
4041
|
* To start the server, see {@link serve}
|
|
3973
4042
|
*
|
|
4043
|
+
* @category HTTP & Networking
|
|
4044
|
+
*
|
|
3974
4045
|
* For performance, Bun pre-allocates most of the data for 2048 concurrent requests.
|
|
3975
4046
|
* That means starting a new server allocates about 500 KB of memory. Try to
|
|
3976
4047
|
* avoid starting and stopping the server often (unless it's a new instance of bun).
|
|
@@ -4270,6 +4341,8 @@ declare module "bun" {
|
|
|
4270
4341
|
*
|
|
4271
4342
|
* @param options - Server configuration options
|
|
4272
4343
|
*
|
|
4344
|
+
* @category HTTP & Networking
|
|
4345
|
+
*
|
|
4273
4346
|
* @example Basic Usage
|
|
4274
4347
|
* ```ts
|
|
4275
4348
|
* Bun.serve({
|
|
@@ -4600,6 +4673,11 @@ declare module "bun" {
|
|
|
4600
4673
|
|
|
4601
4674
|
type StringLike = string | { toString(): string };
|
|
4602
4675
|
|
|
4676
|
+
/**
|
|
4677
|
+
* Valid inputs for {@link color}
|
|
4678
|
+
*
|
|
4679
|
+
* @category Utilities
|
|
4680
|
+
*/
|
|
4603
4681
|
type ColorInput =
|
|
4604
4682
|
| { r: number; g: number; b: number; a?: number }
|
|
4605
4683
|
| [number, number, number]
|
|
@@ -4614,6 +4692,9 @@ declare module "bun" {
|
|
|
4614
4692
|
|
|
4615
4693
|
/**
|
|
4616
4694
|
* Converts formats of colors
|
|
4695
|
+
*
|
|
4696
|
+
* @category Utilities
|
|
4697
|
+
*
|
|
4617
4698
|
* @param input A value that could possibly be a color
|
|
4618
4699
|
* @param outputFormat An optional output format
|
|
4619
4700
|
*/
|
|
@@ -5033,6 +5114,8 @@ declare module "bun" {
|
|
|
5033
5114
|
* Resolve a `Promise` after milliseconds. This is like
|
|
5034
5115
|
* {@link setTimeout} except it returns a `Promise`.
|
|
5035
5116
|
*
|
|
5117
|
+
* @category Utilities
|
|
5118
|
+
*
|
|
5036
5119
|
* @param ms milliseconds to delay resolving the promise. This is a minimum
|
|
5037
5120
|
* number. It may take longer. If a {@link Date} is passed, it will sleep until the
|
|
5038
5121
|
* {@link Date} is reached.
|
|
@@ -5075,6 +5158,8 @@ declare module "bun" {
|
|
|
5075
5158
|
/**
|
|
5076
5159
|
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
5077
5160
|
*
|
|
5161
|
+
* @category Utilities
|
|
5162
|
+
*
|
|
5078
5163
|
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
5079
5164
|
* @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
|
|
5080
5165
|
*
|
|
@@ -5094,6 +5179,8 @@ declare module "bun" {
|
|
|
5094
5179
|
/**
|
|
5095
5180
|
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
5096
5181
|
*
|
|
5182
|
+
* @category Utilities
|
|
5183
|
+
*
|
|
5097
5184
|
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
5098
5185
|
* @param encoding `DigestEncoding` to return the hash in
|
|
5099
5186
|
*
|
|
@@ -5471,6 +5558,11 @@ declare module "bun" {
|
|
|
5471
5558
|
readonly __ffi_function_callable: typeof import("bun:ffi").FFIFunctionCallableSymbol;
|
|
5472
5559
|
};
|
|
5473
5560
|
|
|
5561
|
+
/**
|
|
5562
|
+
* The builder object passed to `Bun.plugin`
|
|
5563
|
+
*
|
|
5564
|
+
* @category Bundler
|
|
5565
|
+
*/
|
|
5474
5566
|
interface PluginBuilder {
|
|
5475
5567
|
/**
|
|
5476
5568
|
* Register a callback which will be invoked when bundling starts. When
|
|
@@ -5571,6 +5663,11 @@ declare module "bun" {
|
|
|
5571
5663
|
module(specifier: string, callback: () => OnLoadResult | Promise<OnLoadResult>): this;
|
|
5572
5664
|
}
|
|
5573
5665
|
|
|
5666
|
+
/**
|
|
5667
|
+
* A Bun plugin. Used for extending Bun's behavior at runtime, or with {@link Bun.build}
|
|
5668
|
+
*
|
|
5669
|
+
* @category Bundler
|
|
5670
|
+
*/
|
|
5574
5671
|
interface BunPlugin {
|
|
5575
5672
|
/**
|
|
5576
5673
|
* Human-readable name of the plugin
|
|
@@ -5587,9 +5684,10 @@ declare module "bun" {
|
|
|
5587
5684
|
*
|
|
5588
5685
|
* If unspecified, it is assumed that the plugin is compatible with all targets.
|
|
5589
5686
|
*
|
|
5590
|
-
* This field is not read by {@link Bun.plugin}
|
|
5687
|
+
* This field is not read by {@link Bun.plugin}, only {@link Bun.build} and `bun build`
|
|
5591
5688
|
*/
|
|
5592
5689
|
target?: Target;
|
|
5690
|
+
|
|
5593
5691
|
/**
|
|
5594
5692
|
* A function that will be called when the plugin is loaded.
|
|
5595
5693
|
*
|
|
@@ -6736,6 +6834,8 @@ declare module "bun" {
|
|
|
6736
6834
|
/**
|
|
6737
6835
|
* Spawn a new process
|
|
6738
6836
|
*
|
|
6837
|
+
* @category Process Management
|
|
6838
|
+
*
|
|
6739
6839
|
* ```js
|
|
6740
6840
|
* const subprocess = Bun.spawn({
|
|
6741
6841
|
* cmd: ["echo", "hello"],
|
|
@@ -6800,6 +6900,8 @@ declare module "bun" {
|
|
|
6800
6900
|
/**
|
|
6801
6901
|
* Spawn a new process
|
|
6802
6902
|
*
|
|
6903
|
+
* @category Process Management
|
|
6904
|
+
*
|
|
6803
6905
|
* ```js
|
|
6804
6906
|
* const {stdout} = Bun.spawnSync({
|
|
6805
6907
|
* cmd: ["echo", "hello"],
|