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.
- package/bun.d.ts +25 -1
- package/docs/bundler/css.mdx +2 -2
- package/docs/bundler/esbuild.mdx +52 -8
- package/docs/bundler/executables.mdx +4 -4
- package/docs/bundler/html-static.mdx +17 -3
- package/docs/bundler/index.mdx +19 -1
- package/docs/bundler/loaders.mdx +105 -11
- package/docs/bundler/minifier.mdx +343 -363
- package/docs/bundler/plugins.mdx +15 -1
- package/docs/guides/deployment/google-cloud-run.mdx +2 -5
- package/docs/guides/ecosystem/{edgedb.mdx → gel.mdx} +42 -38
- package/docs/guides/install/azure-artifacts.mdx +1 -1
- package/docs/guides/install/jfrog-artifactory.mdx +1 -1
- package/docs/guides/runtime/define-constant.mdx +1 -1
- package/docs/guides/runtime/import-html.mdx +0 -2
- package/docs/guides/runtime/typescript.mdx +1 -1
- package/docs/guides/test/snapshot.mdx +2 -2
- package/docs/pm/cli/pm.mdx +1 -1
- package/docs/pm/lifecycle.mdx +1 -1
- package/docs/pm/workspaces.mdx +1 -2
- package/docs/quickstart.mdx +199 -193
- package/docs/runtime/bunfig.mdx +1 -0
- package/docs/runtime/module-resolution.mdx +11 -2
- package/docs/runtime/networking/dns.mdx +1 -1
- package/docs/runtime/plugins.mdx +15 -1
- package/docs/runtime/s3.mdx +1 -1
- package/docs/runtime/sqlite.mdx +0 -2
- package/docs/runtime/workers.mdx +1 -3
- package/package.json +1 -1
package/docs/quickstart.mdx
CHANGED
|
@@ -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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
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>
|
package/docs/runtime/bunfig.mdx
CHANGED
|
@@ -276,7 +276,7 @@ await Bun.build({
|
|
|
276
276
|
|
|
277
277
|
## Path re-mapping
|
|
278
278
|
|
|
279
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
package/docs/runtime/plugins.mdx
CHANGED
|
@@ -42,7 +42,21 @@ type PluginBuilder = {
|
|
|
42
42
|
config: BuildConfig;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
type Loader =
|
|
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
|
package/docs/runtime/s3.mdx
CHANGED
|
@@ -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",
|
package/docs/runtime/sqlite.mdx
CHANGED
package/docs/runtime/workers.mdx
CHANGED
|
@@ -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
|
-
|
|
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