bun-types 1.3.4-canary.20251127T140647 → 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/test/testing-library.mdx +1 -1
- 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.
|
|
@@ -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";
|
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 {}
|