bun-types 1.3.3-canary.20251112T140644 → 1.3.3-canary.20251114T140703

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
 
@@ -5,14 +5,16 @@ description: "File types and loaders supported by Bun's bundler and runtime"
5
5
 
6
6
  The Bun bundler implements a set of default loaders out of the box. As a rule of thumb, the bundler and the runtime both support the same set of file types out of the box.
7
7
 
8
- `.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.toml` `.json` `.txt` `.wasm` `.node` `.html`
8
+ `.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.css` `.json` `.jsonc` `.toml` `.yaml` `.yml` `.txt` `.wasm` `.node` `.html` `.sh`
9
9
 
10
10
  Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](/bundler/plugins) that extend Bun with custom loaders.
11
11
 
12
- You can explicitly specify which loader to use using the 'loader' import attribute.
12
+ You can explicitly specify which loader to use using the `'type'` import attribute.
13
13
 
14
14
  ```ts
15
- import my_toml from "./my_file" with { loader: "toml" };
15
+ import my_toml from "./my_file" with { type: "toml" };
16
+ // or with dynamic imports
17
+ const { default: my_toml } = await import("./my_file", { with: { type: "toml" } });
16
18
  ```
17
19
 
18
20
  ---
@@ -84,6 +86,29 @@ export default {
84
86
 
85
87
  </CodeGroup>
86
88
 
89
+ ### `jsonc`
90
+
91
+ **JSON with Comments loader**. Default for `.jsonc`.
92
+
93
+ JSONC (JSON with Comments) files can be directly imported. Bun will parse them, stripping out comments and trailing commas.
94
+
95
+ ```ts
96
+ import config from "./config.jsonc";
97
+ console.log(config);
98
+ ```
99
+
100
+ During bundling, the parsed JSONC is inlined into the bundle as a JavaScript object, identical to the `json` loader.
101
+
102
+ ```ts
103
+ var config = {
104
+ option: "value",
105
+ };
106
+ ```
107
+
108
+ <Note>
109
+ Bun automatically uses the `jsonc` loader for `tsconfig.json`, `jsconfig.json`, `package.json`, and `bun.lock` files.
110
+ </Note>
111
+
87
112
  ### `toml`
88
113
 
89
114
  **TOML loader**. Default for `.toml`.
@@ -128,6 +153,50 @@ export default {
128
153
 
129
154
  </CodeGroup>
130
155
 
156
+ ### `yaml`
157
+
158
+ **YAML loader**. Default for `.yaml` and `.yml`.
159
+
160
+ YAML files can be directly imported. Bun will parse them with its fast native YAML parser.
161
+
162
+ ```ts
163
+ import config from "./config.yaml";
164
+ console.log(config);
165
+
166
+ // via import attribute:
167
+ import data from "./data.txt" with { type: "yaml" };
168
+ ```
169
+
170
+ During bundling, the parsed YAML is inlined into the bundle as a JavaScript object.
171
+
172
+ ```ts
173
+ var config = {
174
+ name: "my-app",
175
+ version: "1.0.0",
176
+ // ...other fields
177
+ };
178
+ ```
179
+
180
+ If a `.yaml` or `.yml` file is passed as an entrypoint, it will be converted to a `.js` module that `export default`s the parsed object.
181
+
182
+ <CodeGroup>
183
+
184
+ ```yaml Input
185
+ name: John Doe
186
+ age: 35
187
+ email: johndoe@example.com
188
+ ```
189
+
190
+ ```ts Output
191
+ export default {
192
+ name: "John Doe",
193
+ age: 35,
194
+ email: "johndoe@example.com",
195
+ };
196
+ ```
197
+
198
+ </CodeGroup>
199
+
131
200
  ### `text`
132
201
 
133
202
  **Text loader**. Default for `.txt`.
@@ -283,6 +352,18 @@ The `html` loader behaves differently depending on how it's used:
283
352
 
284
353
  </Note>
285
354
 
355
+ ### `css`
356
+
357
+ **CSS loader**. Default for `.css`.
358
+
359
+ CSS files can be directly imported. This is primarily useful for [full-stack applications](/bundler/html-static) where CSS is bundled alongside HTML.
360
+
361
+ ```ts
362
+ import "./styles.css";
363
+ ```
364
+
365
+ There isn't any value returned from the import, it's only used for side effects.
366
+
286
367
  ### `sh` loader
287
368
 
288
369
  **Bun Shell loader**. Default for `.sh` files
@@ -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
 
@@ -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",
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.3-canary.20251112T140644",
2
+ "version": "1.3.3-canary.20251114T140703",
3
3
  "name": "bun-types",
4
4
  "license": "MIT",
5
5
  "types": "./index.d.ts",