bun-types 1.3.3-canary.20251111T140653 → 1.3.3-canary.20251113T140630

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.
@@ -12,198 +12,204 @@ Build a minimal HTTP server with `Bun.serve`, run it locally, then evolve it by
12
12
  ---
13
13
 
14
14
  <Steps>
15
- <Step title="Step 1">
16
- Initialize a new project with `bun init`.
17
-
18
- ```bash terminal icon="terminal"
19
- bun init my-app
20
- ```
21
-
22
- It'll prompt you to pick a template, either `Blank`, `React`, or `Library`. For this guide, we'll pick `Blank`.
23
-
24
- ```bash terminal icon="terminal"
25
- bun init my-app
26
- ```
27
- ```txt
28
- ✓ Select a project template: Blank
29
-
30
- - .gitignore
31
- - CLAUDE.md
32
- - .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc -> CLAUDE.md
33
- - index.ts
34
- - tsconfig.json (for editor autocomplete)
35
- - README.md
36
-
37
- ````
38
-
39
- This automatically creates a `my-app` directory with a basic Bun app.
40
- </Step>
41
- <Step title="Step 2">
42
-
43
- Run the `index.ts` file using `bun run index.ts`.
44
-
45
- ```bash terminal icon="terminal"
46
- cd my-app
47
- bun run index.ts
48
- ```
49
- ```txt
50
- Hello via Bun!
51
- ```
52
-
53
- You should see a console output saying `"Hello via Bun!"`.
54
- </Step>
55
- <Step title="Step 3">
56
- Replace the contents of `index.ts` with the following code:
57
-
58
- ```ts index.ts icon="/icons/typescript.svg"
59
- const server = Bun.serve({
60
- port: 3000,
61
- routes: {
62
- "/": () => new Response('Bun!'),
63
- }
64
- });
65
-
66
- console.log(`Listening on ${server.url}`);
67
- ```
68
-
69
- Run the `index.ts` file again using `bun run index.ts`.
70
-
71
- ```bash terminal icon="terminal"
72
- bun run index.ts
73
- ```
74
- ```txt
75
- Listening on http://localhost:3000
76
- ```
77
-
78
- Visit [`http://localhost:3000`](http://localhost:3000) to test the server. You should see a simple page that says `"Bun!"`.
79
-
80
-
81
- <Accordion title="Seeing TypeScript errors on Bun?">
82
- If you used `bun init`, Bun will have automatically installed Bun's TypeScript declarations and configured your `tsconfig.json`. If you're trying out Bun in an existing project, you may see a type error on the `Bun` global.
83
-
84
- To fix this, first install `@types/bun` as a dev dependency.
85
-
86
- ```bash terminal icon="terminal"
87
- bun add -d @types/bun
88
- ```
89
-
90
- Then add the following to your `compilerOptions` in `tsconfig.json`:
91
-
92
- ```json tsconfig.json icon="file-code"
93
- {
94
- "compilerOptions": {
95
- "lib": ["ESNext"],
96
- "target": "ESNext",
97
- "module": "Preserve",
98
- "moduleDetection": "force",
99
- "moduleResolution": "bundler",
100
- "allowImportingTsExtensions": true,
101
- "verbatimModuleSyntax": true,
102
- "noEmit": true
103
- }
104
- }
105
- ```
106
-
107
- </Accordion>
108
-
109
- </Step>
110
- <Step title="Step 4">
111
- Install the `figlet` package and its type declarations. Figlet is a utility for converting strings into ASCII art.
112
-
113
- ```bash terminal icon="terminal"
114
- bun add figlet
115
- bun add -d @types/figlet # TypeScript users only
116
- ```
117
-
118
- Update `index.ts` to use `figlet` in `routes`.
119
-
120
- ```ts index.ts icon="/icons/typescript.svg"
121
- import figlet from 'figlet'; // [!code ++]
122
-
123
- const server = Bun.serve({
124
- port: 3000,
125
- routes: {
126
- "/": () => new Response('Bun!'),
127
- "/figlet": () => { // [!code ++]
128
- const body = figlet.textSync('Bun!'); // [!code ++]
129
- return new Response(body); // [!code ++]
130
- } // [!code ++]
131
- }
132
- });
133
-
134
- console.log(`Listening on ${server.url}`);
135
- ```
136
-
137
- Run the `index.ts` file again using `bun run index.ts`.
138
-
139
- ```bash terminal icon="terminal"
140
- bun run index.ts
141
- ```
142
- ```txt
143
- Listening on http://localhost:3000
144
- ```
145
-
146
- Visit [`http://localhost:3000/figlet`](http://localhost:3000/figlet) to test the server. You should see a simple page that says `"Bun!"` in ASCII art.
147
-
148
- ```txt
149
- ____ _
150
- | __ ) _ _ _ __ | |
151
- | _ \| | | | '_ \| |
152
- | |_) | |_| | | | |_|
153
- |____/ \__,_|_| |_(_)
154
- ```
155
- </Step>
156
- <Step title="Step 5">
157
- Let's add some HTML. Create a new file called `index.html` and add the following code:
158
-
159
- ```html index.html icon="file-code"
160
- <!DOCTYPE html>
161
- <html lang="en">
162
- <head>
163
- <meta charset="UTF-8">
164
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
165
- <title>Bun</title>
166
- </head>
167
- <body>
168
- <h1>Bun!</h1>
169
- </body>
170
- </html>
171
- ```
172
-
173
- Then, import this file in `index.ts` and serve it from the root `/` route.
174
-
175
- ```ts index.ts icon="/icons/typescript.svg"
176
- import figlet from 'figlet';
177
- import index from './index.html'; // [!code ++]
178
-
179
- const server = Bun.serve({
180
- port: 3000,
181
- routes: {
182
- "/": index, // [!code ++]
183
- "/figlet": () => {
184
- const body = figlet.textSync('Bun!');
185
- return new Response(body);
186
- }
187
- }
188
- });
189
-
190
- console.log(`Listening on ${server.url}`);
191
- ```
192
-
193
- Run the `index.ts` file again using `bun run index.ts`.
194
-
195
- ```bash terminal icon="terminal"
196
- bun run index.ts
197
- ```
198
- ```txt
199
- Listening on http://localhost:3000
200
- ```
201
-
202
- Visit [`http://localhost:3000`](http://localhost:3000) to test the server. You should see the static HTML page.
203
- </Step>
204
-
205
- </Steps>
206
- ````
15
+ <Step title="Step 1">
16
+
17
+ Initialize a new project with `bun init`.
18
+
19
+ ```bash terminal icon="terminal"
20
+ bun init my-app
21
+ ```
22
+
23
+ It'll prompt you to pick a template, either `Blank`, `React`, or `Library`. For this guide, we'll pick `Blank`.
24
+
25
+ ```bash terminal icon="terminal"
26
+ bun init my-app
27
+ ```
28
+ ```txt
29
+ ✓ Select a project template: Blank
30
+
31
+ - .gitignore
32
+ - CLAUDE.md
33
+ - .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc -> CLAUDE.md
34
+ - index.ts
35
+ - tsconfig.json (for editor autocomplete)
36
+ - README.md
37
+ ```
38
+
39
+ This automatically creates a `my-app` directory with a basic Bun app.
40
+
41
+ </Step>
42
+ <Step title="Step 2">
43
+
44
+ Run the `index.ts` file using `bun run index.ts`.
45
+
46
+ ```bash terminal icon="terminal"
47
+ cd my-app
48
+ bun run index.ts
49
+ ```
50
+ ```txt
51
+ Hello via Bun!
52
+ ```
53
+
54
+ You should see a console output saying `"Hello via Bun!"`.
55
+
56
+ </Step>
57
+ <Step title="Step 3">
58
+
59
+ Replace the contents of `index.ts` with the following code:
60
+
61
+ ```ts index.ts icon="/icons/typescript.svg"
62
+ const server = Bun.serve({
63
+ port: 3000,
64
+ routes: {
65
+ "/": () => new Response('Bun!'),
66
+ }
67
+ });
68
+
69
+ console.log(`Listening on ${server.url}`);
70
+ ```
71
+
72
+ Run the `index.ts` file again using `bun run index.ts`.
73
+
74
+ ```bash terminal icon="terminal"
75
+ bun run index.ts
76
+ ```
77
+ ```txt
78
+ Listening on http://localhost:3000
79
+ ```
80
+
81
+ Visit [`http://localhost:3000`](http://localhost:3000) to test the server. You should see a simple page that says `"Bun!"`.
82
+
83
+ <Accordion title="Seeing TypeScript errors on Bun?">
84
+
85
+ If you used `bun init`, Bun will have automatically installed Bun's TypeScript declarations and configured your `tsconfig.json`. If you're trying out Bun in an existing project, you may see a type error on the `Bun` global.
86
+
87
+ To fix this, first install `@types/bun` as a dev dependency.
88
+
89
+ ```bash terminal icon="terminal"
90
+ bun add -d @types/bun
91
+ ```
92
+
93
+ Then add the following to your `compilerOptions` in `tsconfig.json`:
94
+
95
+ ```json tsconfig.json icon="file-code"
96
+ {
97
+ "compilerOptions": {
98
+ "lib": ["ESNext"],
99
+ "target": "ESNext",
100
+ "module": "Preserve",
101
+ "moduleDetection": "force",
102
+ "moduleResolution": "bundler",
103
+ "allowImportingTsExtensions": true,
104
+ "verbatimModuleSyntax": true,
105
+ "noEmit": true
106
+ }
107
+ }
108
+ ```
109
+
110
+ </Accordion>
111
+
112
+ </Step>
113
+ <Step title="Step 4">
114
+
115
+ Install the `figlet` package and its type declarations. Figlet is a utility for converting strings into ASCII art.
116
+
117
+ ```bash terminal icon="terminal"
118
+ bun add figlet
119
+ bun add -d @types/figlet # TypeScript users only
120
+ ```
121
+
122
+ Update `index.ts` to use `figlet` in `routes`.
123
+
124
+ ```ts index.ts icon="/icons/typescript.svg"
125
+ import figlet from 'figlet'; // [!code ++]
126
+
127
+ const server = Bun.serve({
128
+ port: 3000,
129
+ routes: {
130
+ "/": () => new Response('Bun!'),
131
+ "/figlet": () => { // [!code ++]
132
+ const body = figlet.textSync('Bun!'); // [!code ++]
133
+ return new Response(body); // [!code ++]
134
+ } // [!code ++]
135
+ }
136
+ });
137
+
138
+ console.log(`Listening on ${server.url}`);
139
+ ```
140
+
141
+ Run the `index.ts` file again using `bun run index.ts`.
142
+
143
+ ```bash terminal icon="terminal"
144
+ bun run index.ts
145
+ ```
146
+ ```txt
147
+ Listening on http://localhost:3000
148
+ ```
149
+
150
+ Visit [`http://localhost:3000/figlet`](http://localhost:3000/figlet) to test the server. You should see a simple page that says `"Bun!"` in ASCII art.
151
+
152
+ ```txt
153
+ ____ _
154
+ | __ ) _ _ _ __ | |
155
+ | _ \| | | | '_ \| |
156
+ | |_) | |_| | | | |_|
157
+ |____/ \__,_|_| |_(_)
158
+ ```
159
+
160
+ </Step>
161
+ <Step title="Step 5">
162
+
163
+ Let's add some HTML. Create a new file called `index.html` and add the following code:
164
+
165
+ ```html index.html icon="file-code"
166
+ <!DOCTYPE html>
167
+ <html lang="en">
168
+ <head>
169
+ <meta charset="UTF-8">
170
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
171
+ <title>Bun</title>
172
+ </head>
173
+ <body>
174
+ <h1>Bun!</h1>
175
+ </body>
176
+ </html>
177
+ ```
178
+
179
+ Then, import this file in `index.ts` and serve it from the root `/` route.
180
+
181
+ ```ts index.ts icon="/icons/typescript.svg"
182
+ import figlet from 'figlet';
183
+ import index from './index.html'; // [!code ++]
184
+
185
+ const server = Bun.serve({
186
+ port: 3000,
187
+ routes: {
188
+ "/": index, // [!code ++]
189
+ "/figlet": () => {
190
+ const body = figlet.textSync('Bun!');
191
+ return new Response(body);
192
+ }
193
+ }
194
+ });
195
+
196
+ console.log(`Listening on ${server.url}`);
197
+ ```
198
+
199
+ Run the `index.ts` file again using `bun run index.ts`.
200
+
201
+ ```bash terminal icon="terminal"
202
+ bun run index.ts
203
+ ```
204
+ ```txt
205
+ Listening on http://localhost:3000
206
+ ```
207
+
208
+ Visit [`http://localhost:3000`](http://localhost:3000) to test the server. You should see the static HTML page.
209
+
210
+ </Step>
211
+
212
+ </Steps>
207
213
 
208
214
  🎉 Congratulations! You've built a simple HTTP server with Bun and installed a package.
209
215
 
@@ -234,7 +240,7 @@ bun run start
234
240
  ```
235
241
 
236
242
  ```txt
237
- Listening on http://localhost:3000
243
+ Listening on http://localhost:3000
238
244
  ```
239
245
 
240
246
  <Note>⚡️ **Performance** — `bun run` is roughly 28x faster than `npm run` (6ms vs 170ms of overhead).</Note>
@@ -401,6 +401,7 @@ Environment variable: `BUN_INSTALL_BIN`
401
401
 
402
402
  ```toml title="bunfig.toml" icon="settings"
403
403
  # where globally-installed package bins are linked
404
+ [install]
404
405
  globalBinDir = "~/.bun/bin"
405
406
  ```
406
407
 
@@ -276,7 +276,7 @@ await Bun.build({
276
276
 
277
277
  ## Path re-mapping
278
278
 
279
- In the spirit of treating TypeScript as a first-class citizen, the Bun runtime will re-map import paths according to the [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) field in `tsconfig.json`. This is a major divergence from Node.js, which doesn't support any form of import path re-mapping.
279
+ Bun supports import path re-mapping through TypeScript's [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) in `tsconfig.json`, which works well with editors. If you aren't a TypeScript user, you can achieve the same behavior by using a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root.
280
280
 
281
281
  ```json tsconfig.json icon="file-json"
282
282
  {
@@ -289,7 +289,16 @@ In the spirit of treating TypeScript as a first-class citizen, the Bun runtime w
289
289
  }
290
290
  ```
291
291
 
292
- If you aren't a TypeScript user, you can create a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in your project root to achieve the same behavior.
292
+ Bun also supports [Node.js-style subpath imports](https://nodejs.org/api/packages.html#subpath-imports) in `package.json`, where mapped paths must start with `#`. This approach doesn’t work as well with editors, but both options can be used together.
293
+
294
+ ```json package.json icon="file-json"
295
+ {
296
+ "imports": {
297
+ "#config": "./config.ts", // map specifier to file
298
+ "#components/*": "./components/*" // wildcard matching
299
+ }
300
+ }
301
+ ```
293
302
 
294
303
  <Accordion title="Low-level details of CommonJS interop in Bun">
295
304
 
@@ -23,7 +23,7 @@ dns.prefetch("bun.com", 443);
23
23
 
24
24
  ## DNS caching in Bun
25
25
 
26
- In Bun v1.1.9, we added support for DNS caching. This cache makes repeated connections to the same hosts faster.
26
+ Bun supports DNS caching. This cache makes repeated connections to the same hosts faster.
27
27
 
28
28
  At the time of writing, we cache up to 255 entries for a maximum of 30 seconds (each). If any connections to a host fail, we remove the entry from the cache. When multiple connections are made to the same host simultaneously, DNS lookups are deduplicated to avoid making multiple requests for the same host.
29
29
 
@@ -42,7 +42,21 @@ type PluginBuilder = {
42
42
  config: BuildConfig;
43
43
  };
44
44
 
45
- type Loader = "js" | "jsx" | "ts" | "tsx" | "css" | "json" | "toml";
45
+ type Loader =
46
+ | "js"
47
+ | "jsx"
48
+ | "ts"
49
+ | "tsx"
50
+ | "json"
51
+ | "jsonc"
52
+ | "toml"
53
+ | "yaml"
54
+ | "file"
55
+ | "napi"
56
+ | "wasm"
57
+ | "text"
58
+ | "css"
59
+ | "html";
46
60
  ```
47
61
 
48
62
  ## Usage
@@ -697,7 +697,7 @@ To list some or all (up to 1,000) objects in a bucket, you can use the `S3Client
697
697
  ```ts s3.ts icon="/icons/typescript.svg" highlight={12, 15-20, 24-29}
698
698
  import { S3Client } from "bun";
699
699
 
700
- const credentials = { ... }
700
+ const credentials = {
701
701
  accessKeyId: "your-access-key",
702
702
  secretAccessKey: "your-secret-key",
703
703
  bucket: "my-bucket",
@@ -359,8 +359,6 @@ for (const row of query) {
359
359
  }
360
360
  ```
361
361
 
362
- This feature was added in Bun v1.1.31.
363
-
364
362
  ### `.values()`
365
363
 
366
364
  Use `values()` to run a query and get back all results as an array of arrays.
@@ -76,11 +76,9 @@ const worker = new Worker("./worker.ts", {
76
76
  });
77
77
  ```
78
78
 
79
- This feature was added in Bun v1.1.35.
80
-
81
79
  ### `blob:` URLs
82
80
 
83
- As of Bun v1.1.13, you can also pass a `blob:` URL to `Worker`. This is useful for creating workers from strings or other sources.
81
+ You can also pass a `blob:` URL to `Worker`. This is useful for creating workers from strings or other sources.
84
82
 
85
83
  ```js
86
84
  const blob = new Blob(
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.3-canary.20251111T140653",
2
+ "version": "1.3.3-canary.20251113T140630",
3
3
  "name": "bun-types",
4
4
  "license": "MIT",
5
5
  "types": "./index.d.ts",