bun-types 1.3.4-canary.20251126T140720 → 1.3.4-canary.20251128T140630
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 +18 -13
- package/docs/bundler/fullstack.mdx +22 -0
- package/docs/bundler/html-static.mdx +87 -0
- package/docs/guides/http/proxy.mdx +27 -3
- package/docs/guides/test/testing-library.mdx +1 -1
- package/docs/runtime/networking/fetch.mdx +17 -1
- package/globals.d.ts +32 -2
- package/package.json +1 -1
- package/wasm.d.ts +2 -2
package/bun.d.ts
CHANGED
|
@@ -1740,10 +1740,9 @@ declare module "bun" {
|
|
|
1740
1740
|
* @default "esm"
|
|
1741
1741
|
*/
|
|
1742
1742
|
format?: /**
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
| "esm"
|
|
1743
|
+
* ECMAScript Module format
|
|
1744
|
+
*/
|
|
1745
|
+
| "esm"
|
|
1747
1746
|
/**
|
|
1748
1747
|
* CommonJS format
|
|
1749
1748
|
* **Experimental**
|
|
@@ -3317,10 +3316,10 @@ declare module "bun" {
|
|
|
3317
3316
|
function color(
|
|
3318
3317
|
input: ColorInput,
|
|
3319
3318
|
outputFormat?: /**
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3319
|
+
* True color ANSI color string, for use in terminals
|
|
3320
|
+
* @example \x1b[38;2;100;200;200m
|
|
3321
|
+
*/
|
|
3322
|
+
| "ansi"
|
|
3324
3323
|
| "ansi-16"
|
|
3325
3324
|
| "ansi-16m"
|
|
3326
3325
|
/**
|
|
@@ -5651,11 +5650,17 @@ declare module "bun" {
|
|
|
5651
5650
|
maxBuffer?: number;
|
|
5652
5651
|
}
|
|
5653
5652
|
|
|
5654
|
-
interface SpawnSyncOptions<In extends Writable, Out extends Readable, Err extends Readable>
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5653
|
+
interface SpawnSyncOptions<In extends Writable, Out extends Readable, Err extends Readable> extends BaseOptions<
|
|
5654
|
+
In,
|
|
5655
|
+
Out,
|
|
5656
|
+
Err
|
|
5657
|
+
> {}
|
|
5658
|
+
|
|
5659
|
+
interface SpawnOptions<In extends Writable, Out extends Readable, Err extends Readable> extends BaseOptions<
|
|
5660
|
+
In,
|
|
5661
|
+
Out,
|
|
5662
|
+
Err
|
|
5663
|
+
> {
|
|
5659
5664
|
/**
|
|
5660
5665
|
* If true, stdout and stderr pipes will not automatically start reading
|
|
5661
5666
|
* data. Reading will only begin when you access the `stdout` or `stderr`
|
|
@@ -492,6 +492,28 @@ Bun will lazily resolve and load each plugin and use them to bundle your routes.
|
|
|
492
492
|
the CLI.
|
|
493
493
|
</Note>
|
|
494
494
|
|
|
495
|
+
## Inline Environment Variables
|
|
496
|
+
|
|
497
|
+
Bun can replace `process.env.*` references in your frontend JavaScript and TypeScript with their actual values at build time. Configure the `env` option in your `bunfig.toml`:
|
|
498
|
+
|
|
499
|
+
```toml title="bunfig.toml" icon="settings"
|
|
500
|
+
[serve.static]
|
|
501
|
+
env = "PUBLIC_*" # only inline env vars starting with PUBLIC_ (recommended)
|
|
502
|
+
# env = "inline" # inline all environment variables
|
|
503
|
+
# env = "disable" # disable env var replacement (default)
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
<Note>
|
|
507
|
+
This only works with literal `process.env.FOO` references, not `import.meta.env` or indirect access like `const env =
|
|
508
|
+
process.env; env.FOO`.
|
|
509
|
+
|
|
510
|
+
If an environment variable is not set, you may see runtime errors like `ReferenceError: process
|
|
511
|
+
is not defined` in the browser.
|
|
512
|
+
|
|
513
|
+
</Note>
|
|
514
|
+
|
|
515
|
+
See the [HTML & static sites documentation](/docs/bundler/html-static#inline-environment-variables) for more details on build-time configuration and examples.
|
|
516
|
+
|
|
495
517
|
## How It Works
|
|
496
518
|
|
|
497
519
|
Bun uses `HTMLRewriter` to scan for `<script>` and `<link>` tags in HTML files, uses them as entrypoints for Bun's bundler, generates an optimized bundle for the JavaScript/TypeScript/TSX/JSX and CSS files, and serves the result.
|
|
@@ -262,6 +262,93 @@ Then, reference TailwindCSS in your HTML via `<link>` tag, `@import` in CSS, or
|
|
|
262
262
|
|
|
263
263
|
<Info>Only one of those are necessary, not all three.</Info>
|
|
264
264
|
|
|
265
|
+
## Inline environment variables
|
|
266
|
+
|
|
267
|
+
Bun can replace `process.env.*` references in your JavaScript and TypeScript with their actual values at build time. This is useful for injecting configuration like API URLs or feature flags into your frontend code.
|
|
268
|
+
|
|
269
|
+
### Dev server (runtime)
|
|
270
|
+
|
|
271
|
+
To inline environment variables when using `bun ./index.html`, configure the `env` option in your `bunfig.toml`:
|
|
272
|
+
|
|
273
|
+
```toml title="bunfig.toml" icon="settings"
|
|
274
|
+
[serve.static]
|
|
275
|
+
env = "PUBLIC_*" # only inline env vars starting with PUBLIC_ (recommended)
|
|
276
|
+
# env = "inline" # inline all environment variables
|
|
277
|
+
# env = "disable" # disable env var replacement (default)
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
<Note>
|
|
281
|
+
This only works with literal `process.env.FOO` references, not `import.meta.env` or indirect access like `const env =
|
|
282
|
+
process.env; env.FOO`.
|
|
283
|
+
|
|
284
|
+
If an environment variable is not set, you may see runtime errors like `ReferenceError: process
|
|
285
|
+
is not defined` in the browser.
|
|
286
|
+
|
|
287
|
+
</Note>
|
|
288
|
+
|
|
289
|
+
Then run the dev server:
|
|
290
|
+
|
|
291
|
+
```bash terminal icon="terminal"
|
|
292
|
+
PUBLIC_API_URL=https://api.example.com bun ./index.html
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Build for production
|
|
296
|
+
|
|
297
|
+
When building static HTML for production, use the `env` option to inline environment variables:
|
|
298
|
+
|
|
299
|
+
<Tabs>
|
|
300
|
+
<Tab title="CLI">
|
|
301
|
+
```bash terminal icon="terminal"
|
|
302
|
+
# Inline all environment variables
|
|
303
|
+
bun build ./index.html --outdir=dist --env=inline
|
|
304
|
+
|
|
305
|
+
# Only inline env vars with a specific prefix (recommended)
|
|
306
|
+
bun build ./index.html --outdir=dist --env=PUBLIC_*
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
</Tab>
|
|
310
|
+
<Tab title="API">
|
|
311
|
+
```ts title="build.ts" icon="/icons/typescript.svg"
|
|
312
|
+
// Inline all environment variables
|
|
313
|
+
await Bun.build({
|
|
314
|
+
entrypoints: ["./index.html"],
|
|
315
|
+
outdir: "./dist",
|
|
316
|
+
env: "inline", // [!code highlight]
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Only inline env vars with a specific prefix (recommended)
|
|
320
|
+
await Bun.build({
|
|
321
|
+
entrypoints: ["./index.html"],
|
|
322
|
+
outdir: "./dist",
|
|
323
|
+
env: "PUBLIC_*", // [!code highlight]
|
|
324
|
+
});
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
</Tab>
|
|
328
|
+
</Tabs>
|
|
329
|
+
|
|
330
|
+
### Example
|
|
331
|
+
|
|
332
|
+
Given this source file:
|
|
333
|
+
|
|
334
|
+
```ts title="app.ts" icon="/icons/typescript.svg"
|
|
335
|
+
const apiUrl = process.env.PUBLIC_API_URL;
|
|
336
|
+
console.log(`API URL: ${apiUrl}`);
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
And running with `PUBLIC_API_URL=https://api.example.com`:
|
|
340
|
+
|
|
341
|
+
```bash terminal icon="terminal"
|
|
342
|
+
PUBLIC_API_URL=https://api.example.com bun build ./index.html --outdir=dist --env=PUBLIC_*
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
The bundled output will contain:
|
|
346
|
+
|
|
347
|
+
```js title="dist/app.js" icon="/icons/javascript.svg"
|
|
348
|
+
const apiUrl = "https://api.example.com";
|
|
349
|
+
console.log(`API URL: ${apiUrl}`);
|
|
350
|
+
```
|
|
351
|
+
|
|
265
352
|
## Echo console logs from browser to terminal
|
|
266
353
|
|
|
267
354
|
Bun's dev server supports streaming console logs from the browser to the terminal.
|
|
@@ -9,18 +9,42 @@ In Bun, `fetch` supports sending requests through an HTTP or HTTPS proxy. This i
|
|
|
9
9
|
```ts proxy.ts icon="/icons/typescript.svg"
|
|
10
10
|
await fetch("https://example.com", {
|
|
11
11
|
// The URL of the proxy server
|
|
12
|
-
proxy: "https://
|
|
12
|
+
proxy: "https://username:password@proxy.example.com:8080",
|
|
13
13
|
});
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
The `proxy` option
|
|
18
|
+
The `proxy` option can be a URL string or an object with `url` and optional `headers`. The URL can include the username and password if the proxy requires authentication. It can be `http://` or `https://`.
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
|
+
## Custom proxy headers
|
|
23
|
+
|
|
24
|
+
To send custom headers to the proxy server (useful for proxy authentication tokens, custom routing, etc.), use the object format:
|
|
25
|
+
|
|
26
|
+
```ts proxy-headers.ts icon="/icons/typescript.svg"
|
|
27
|
+
await fetch("https://example.com", {
|
|
28
|
+
proxy: {
|
|
29
|
+
url: "https://proxy.example.com:8080",
|
|
30
|
+
headers: {
|
|
31
|
+
"Proxy-Authorization": "Bearer my-token",
|
|
32
|
+
"X-Proxy-Region": "us-east-1",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The `headers` property accepts a plain object or a `Headers` instance. These headers are sent directly to the proxy server in `CONNECT` requests (for HTTPS targets) or in the proxy request (for HTTP targets).
|
|
39
|
+
|
|
40
|
+
If you provide a `Proxy-Authorization` header, it will override any credentials specified in the proxy URL.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Environment variables
|
|
45
|
+
|
|
22
46
|
You can also set the `$HTTP_PROXY` or `$HTTPS_PROXY` environment variable to the proxy URL. This is useful when you want to use the same proxy for all requests.
|
|
23
47
|
|
|
24
48
|
```sh terminal icon="terminal"
|
|
25
|
-
HTTPS_PROXY=https://
|
|
49
|
+
HTTPS_PROXY=https://username:password@proxy.example.com:8080 bun run index.ts
|
|
26
50
|
```
|
|
@@ -76,7 +76,7 @@ declare module "bun:test" {
|
|
|
76
76
|
|
|
77
77
|
You should now be able to use Testing Library in your tests
|
|
78
78
|
|
|
79
|
-
```
|
|
79
|
+
```tsx myComponent.test.tsx icon="/icons/typescript.svg"
|
|
80
80
|
import { test, expect } from "bun:test";
|
|
81
81
|
import { screen, render } from "@testing-library/react";
|
|
82
82
|
import { MyComponent } from "./myComponent";
|
|
@@ -51,7 +51,7 @@ const response = await fetch("http://example.com", {
|
|
|
51
51
|
|
|
52
52
|
### Proxying requests
|
|
53
53
|
|
|
54
|
-
To proxy a request, pass an object with the `proxy` property set to a URL
|
|
54
|
+
To proxy a request, pass an object with the `proxy` property set to a URL string:
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
const response = await fetch("http://example.com", {
|
|
@@ -59,6 +59,22 @@ const response = await fetch("http://example.com", {
|
|
|
59
59
|
});
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
You can also use an object format to send custom headers to the proxy server:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const response = await fetch("http://example.com", {
|
|
66
|
+
proxy: {
|
|
67
|
+
url: "http://proxy.com",
|
|
68
|
+
headers: {
|
|
69
|
+
"Proxy-Authorization": "Bearer my-token",
|
|
70
|
+
"X-Custom-Proxy-Header": "value",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The `headers` are sent directly to the proxy in `CONNECT` requests (for HTTPS targets) or in the proxy request (for HTTP targets). If you provide a `Proxy-Authorization` header, it overrides any credentials in the proxy URL.
|
|
77
|
+
|
|
62
78
|
### Custom headers
|
|
63
79
|
|
|
64
80
|
To set custom headers, pass an object with the `headers` property set to an object.
|
package/globals.d.ts
CHANGED
|
@@ -1920,14 +1920,44 @@ interface BunFetchRequestInit extends RequestInit {
|
|
|
1920
1920
|
* Override http_proxy or HTTPS_PROXY
|
|
1921
1921
|
* This is a custom property that is not part of the Fetch API specification.
|
|
1922
1922
|
*
|
|
1923
|
+
* Can be a string URL or an object with `url` and optional `headers`.
|
|
1924
|
+
*
|
|
1923
1925
|
* @example
|
|
1924
1926
|
* ```js
|
|
1927
|
+
* // String format
|
|
1925
1928
|
* const response = await fetch("http://example.com", {
|
|
1926
1929
|
* proxy: "https://username:password@127.0.0.1:8080"
|
|
1927
1930
|
* });
|
|
1931
|
+
*
|
|
1932
|
+
* // Object format with custom headers sent to the proxy
|
|
1933
|
+
* const response = await fetch("http://example.com", {
|
|
1934
|
+
* proxy: {
|
|
1935
|
+
* url: "https://127.0.0.1:8080",
|
|
1936
|
+
* headers: {
|
|
1937
|
+
* "Proxy-Authorization": "Bearer token",
|
|
1938
|
+
* "X-Custom-Proxy-Header": "value"
|
|
1939
|
+
* }
|
|
1940
|
+
* }
|
|
1941
|
+
* });
|
|
1928
1942
|
* ```
|
|
1929
|
-
|
|
1930
|
-
|
|
1943
|
+
*
|
|
1944
|
+
* If a `Proxy-Authorization` header is provided in `proxy.headers`, it takes
|
|
1945
|
+
* precedence over credentials parsed from the proxy URL.
|
|
1946
|
+
*/
|
|
1947
|
+
proxy?:
|
|
1948
|
+
| string
|
|
1949
|
+
| {
|
|
1950
|
+
/**
|
|
1951
|
+
* The proxy URL
|
|
1952
|
+
*/
|
|
1953
|
+
url: string;
|
|
1954
|
+
/**
|
|
1955
|
+
* Custom headers to send to the proxy server.
|
|
1956
|
+
* These headers are sent in the CONNECT request (for HTTPS targets)
|
|
1957
|
+
* or in the proxy request (for HTTP targets).
|
|
1958
|
+
*/
|
|
1959
|
+
headers?: Bun.HeadersInit;
|
|
1960
|
+
};
|
|
1931
1961
|
|
|
1932
1962
|
/**
|
|
1933
1963
|
* Override the default S3 options
|
package/package.json
CHANGED
package/wasm.d.ts
CHANGED
|
@@ -100,8 +100,8 @@ declare module "bun" {
|
|
|
100
100
|
|
|
101
101
|
declare namespace WebAssembly {
|
|
102
102
|
interface ValueTypeMap extends Bun.WebAssembly.ValueTypeMap {}
|
|
103
|
-
interface GlobalDescriptor<T extends keyof ValueTypeMap = keyof ValueTypeMap>
|
|
104
|
-
|
|
103
|
+
interface GlobalDescriptor<T extends keyof ValueTypeMap = keyof ValueTypeMap> extends Bun.WebAssembly
|
|
104
|
+
.GlobalDescriptor<T> {}
|
|
105
105
|
interface MemoryDescriptor extends Bun.WebAssembly.MemoryDescriptor {}
|
|
106
106
|
interface ModuleExportDescriptor extends Bun.WebAssembly.ModuleExportDescriptor {}
|
|
107
107
|
interface ModuleImportDescriptor extends Bun.WebAssembly.ModuleImportDescriptor {}
|