bun-types 1.3.3 → 1.3.4-canary.20251125T140733
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/CLAUDE.md +3 -3
- package/docs/bundler/css.mdx +1 -1
- package/docs/bundler/executables.mdx +33 -4
- package/docs/bundler/fullstack.mdx +3 -3
- package/docs/bundler/hot-reloading.mdx +2 -2
- package/docs/bundler/html-static.mdx +10 -9
- package/docs/bundler/index.mdx +27 -18
- package/docs/bundler/loaders.mdx +2 -2
- package/docs/bundler/macros.mdx +1 -1
- package/docs/feedback.mdx +2 -12
- package/docs/guides/binary/arraybuffer-to-array.mdx +1 -1
- package/docs/guides/binary/arraybuffer-to-blob.mdx +1 -1
- package/docs/guides/binary/arraybuffer-to-buffer.mdx +1 -1
- package/docs/guides/binary/arraybuffer-to-string.mdx +1 -1
- package/docs/guides/binary/arraybuffer-to-typedarray.mdx +1 -1
- package/docs/guides/binary/blob-to-arraybuffer.mdx +1 -1
- package/docs/guides/binary/blob-to-dataview.mdx +1 -1
- package/docs/guides/binary/blob-to-stream.mdx +1 -1
- package/docs/guides/binary/blob-to-string.mdx +1 -1
- package/docs/guides/binary/blob-to-typedarray.mdx +1 -1
- package/docs/guides/binary/buffer-to-arraybuffer.mdx +1 -1
- package/docs/guides/binary/buffer-to-blob.mdx +1 -1
- package/docs/guides/binary/buffer-to-readablestream.mdx +1 -1
- package/docs/guides/binary/buffer-to-string.mdx +1 -1
- package/docs/guides/binary/buffer-to-typedarray.mdx +1 -1
- package/docs/guides/binary/dataview-to-string.mdx +1 -1
- package/docs/guides/binary/typedarray-to-arraybuffer.mdx +1 -1
- package/docs/guides/binary/typedarray-to-blob.mdx +1 -1
- package/docs/guides/binary/typedarray-to-buffer.mdx +1 -1
- package/docs/guides/binary/typedarray-to-dataview.mdx +1 -1
- package/docs/guides/binary/typedarray-to-readablestream.mdx +1 -1
- package/docs/guides/binary/typedarray-to-string.mdx +1 -1
- package/docs/guides/deployment/aws-lambda.mdx +6 -6
- package/docs/guides/deployment/digital-ocean.mdx +7 -7
- package/docs/guides/deployment/vercel.mdx +1 -3
- package/docs/guides/ecosystem/discordjs.mdx +2 -2
- package/docs/guides/ecosystem/express.mdx +2 -2
- package/docs/guides/ecosystem/mongoose.mdx +1 -1
- package/docs/guides/ecosystem/neon-drizzle.mdx +2 -2
- package/docs/guides/ecosystem/neon-serverless-postgres.mdx +2 -2
- package/docs/guides/ecosystem/nuxt.mdx +1 -1
- package/docs/guides/ecosystem/prisma-postgres.mdx +1 -1
- package/docs/guides/ecosystem/prisma.mdx +1 -1
- package/docs/guides/ecosystem/qwik.mdx +4 -4
- package/docs/guides/ecosystem/sentry.mdx +2 -2
- package/docs/guides/ecosystem/sveltekit.mdx +1 -1
- package/docs/guides/ecosystem/tanstack-start.mdx +0 -1
- package/docs/guides/ecosystem/upstash.mdx +2 -2
- package/docs/guides/ecosystem/vite.mdx +2 -2
- package/docs/guides/html-rewriter/extract-links.mdx +2 -2
- package/docs/guides/html-rewriter/extract-social-meta.mdx +1 -1
- package/docs/guides/http/file-uploads.mdx +1 -1
- package/docs/guides/http/hot.mdx +1 -1
- package/docs/guides/http/server.mdx +1 -1
- package/docs/guides/http/simple.mdx +1 -1
- package/docs/guides/http/stream-file.mdx +3 -3
- package/docs/guides/http/tls.mdx +1 -1
- package/docs/guides/install/add-dev.mdx +1 -1
- package/docs/guides/install/add-git.mdx +1 -1
- package/docs/guides/install/add-optional.mdx +1 -1
- package/docs/guides/install/add-peer.mdx +3 -3
- package/docs/guides/install/add-tarball.mdx +1 -1
- package/docs/guides/install/add.mdx +1 -1
- package/docs/guides/install/azure-artifacts.mdx +3 -3
- package/docs/guides/install/custom-registry.mdx +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.mdx +1 -1
- package/docs/guides/install/git-diff-bun-lockfile.mdx +2 -1
- package/docs/guides/install/npm-alias.mdx +1 -1
- package/docs/guides/install/registry-scope.mdx +3 -3
- package/docs/guides/install/trusted.mdx +1 -1
- package/docs/guides/install/workspaces.mdx +1 -1
- package/docs/guides/install/yarnlock.mdx +4 -3
- package/docs/guides/process/ctrl-c.mdx +1 -1
- package/docs/guides/process/ipc.mdx +2 -2
- package/docs/guides/process/nanoseconds.mdx +1 -1
- package/docs/guides/process/os-signals.mdx +1 -1
- package/docs/guides/process/spawn-stderr.mdx +2 -2
- package/docs/guides/process/spawn-stdout.mdx +2 -2
- package/docs/guides/process/spawn.mdx +2 -2
- package/docs/guides/process/stdin.mdx +1 -1
- package/docs/guides/read-file/arraybuffer.mdx +2 -2
- package/docs/guides/read-file/buffer.mdx +1 -1
- package/docs/guides/read-file/exists.mdx +1 -1
- package/docs/guides/read-file/mime.mdx +1 -1
- package/docs/guides/read-file/stream.mdx +1 -1
- package/docs/guides/read-file/uint8array.mdx +1 -1
- package/docs/guides/read-file/watch.mdx +1 -1
- package/docs/guides/runtime/build-time-constants.mdx +3 -3
- package/docs/guides/runtime/cicd.mdx +1 -1
- package/docs/guides/runtime/codesign-macos-executable.mdx +1 -1
- package/docs/guides/runtime/delete-directory.mdx +1 -1
- package/docs/guides/runtime/delete-file.mdx +1 -1
- package/docs/guides/runtime/heap-snapshot.mdx +1 -1
- package/docs/guides/runtime/import-json.mdx +1 -1
- package/docs/guides/runtime/import-toml.mdx +1 -1
- package/docs/guides/runtime/import-yaml.mdx +1 -1
- package/docs/guides/runtime/read-env.mdx +1 -1
- package/docs/guides/runtime/set-env.mdx +2 -2
- package/docs/guides/runtime/shell.mdx +1 -1
- package/docs/guides/runtime/tsconfig-paths.mdx +1 -1
- package/docs/guides/runtime/typescript.mdx +1 -1
- package/docs/guides/runtime/vscode-debugger.mdx +1 -2
- package/docs/guides/runtime/web-debugger.mdx +1 -1
- package/docs/guides/streams/to-array.mdx +1 -1
- package/docs/guides/streams/to-arraybuffer.mdx +1 -1
- package/docs/guides/streams/to-blob.mdx +1 -1
- package/docs/guides/streams/to-buffer.mdx +1 -1
- package/docs/guides/streams/to-json.mdx +1 -1
- package/docs/guides/streams/to-string.mdx +1 -1
- package/docs/guides/streams/to-typedarray.mdx +1 -1
- package/docs/guides/test/bail.mdx +1 -1
- package/docs/guides/test/concurrent-test-glob.mdx +5 -2
- package/docs/guides/test/coverage-threshold.mdx +1 -1
- package/docs/guides/test/coverage.mdx +1 -1
- package/docs/guides/test/happy-dom.mdx +1 -1
- package/docs/guides/test/migrate-from-jest.mdx +7 -7
- package/docs/guides/test/mock-clock.mdx +2 -2
- package/docs/guides/test/mock-functions.mdx +1 -1
- package/docs/guides/test/rerun-each.mdx +1 -1
- package/docs/guides/test/run-tests.mdx +2 -2
- package/docs/guides/test/skip-tests.mdx +2 -2
- package/docs/guides/test/snapshot.mdx +4 -4
- package/docs/guides/test/spy-on.mdx +1 -1
- package/docs/guides/test/svelte-test.mdx +4 -4
- package/docs/guides/test/testing-library.mdx +3 -3
- package/docs/guides/test/timeout.mdx +1 -1
- package/docs/guides/test/todo-tests.mdx +2 -2
- package/docs/guides/test/update-snapshots.mdx +1 -1
- package/docs/guides/test/watch-mode.mdx +1 -1
- package/docs/guides/util/base64.mdx +1 -1
- package/docs/guides/util/deep-equals.mdx +3 -3
- package/docs/guides/util/deflate.mdx +1 -1
- package/docs/guides/util/entrypoint.mdx +2 -2
- package/docs/guides/util/escape-html.mdx +1 -1
- package/docs/guides/util/file-url-to-path.mdx +1 -1
- package/docs/guides/util/gzip.mdx +1 -1
- package/docs/guides/util/hash-a-password.mdx +1 -1
- package/docs/guides/util/import-meta-dir.mdx +2 -2
- package/docs/guides/util/import-meta-file.mdx +2 -2
- package/docs/guides/util/import-meta-path.mdx +2 -2
- package/docs/guides/util/javascript-uuid.mdx +2 -2
- package/docs/guides/util/main.mdx +1 -1
- package/docs/guides/util/path-to-file-url.mdx +1 -1
- package/docs/guides/util/sleep.mdx +1 -1
- package/docs/guides/util/version.mdx +2 -2
- package/docs/guides/util/which-path-to-executable-bin.mdx +1 -1
- package/docs/guides/websocket/context.mdx +1 -1
- package/docs/guides/websocket/simple.mdx +1 -1
- package/docs/guides/write-file/basic.mdx +2 -2
- package/docs/guides/write-file/blob.mdx +2 -2
- package/docs/guides/write-file/cat.mdx +2 -2
- package/docs/guides/write-file/file-cp.mdx +2 -2
- package/docs/guides/write-file/filesink.mdx +1 -1
- package/docs/guides/write-file/response.mdx +2 -2
- package/docs/guides/write-file/stdout.mdx +2 -2
- package/docs/guides/write-file/stream.mdx +2 -2
- package/docs/guides/write-file/unlink.mdx +1 -1
- package/docs/index.mdx +2 -2
- package/docs/installation.mdx +3 -3
- package/docs/pm/bunx.mdx +2 -2
- package/docs/pm/cli/install.mdx +8 -8
- package/docs/pm/cli/link.mdx +2 -2
- package/docs/pm/cli/outdated.mdx +3 -3
- package/docs/pm/cli/patch.mdx +2 -2
- package/docs/pm/cli/pm.mdx +1 -1
- package/docs/pm/cli/publish.mdx +1 -1
- package/docs/pm/filter.mdx +2 -2
- package/docs/pm/isolated-installs.mdx +3 -3
- package/docs/pm/npmrc.mdx +6 -6
- package/docs/pm/scopes-registries.mdx +1 -1
- package/docs/pm/security-scanner-api.mdx +2 -2
- package/docs/pm/workspaces.mdx +3 -4
- package/docs/project/benchmarking.mdx +1 -1
- package/docs/project/building-windows.mdx +1 -1
- package/docs/project/contributing.mdx +1 -1
- package/docs/project/license.mdx +1 -1
- package/docs/quickstart.mdx +3 -3
- package/docs/runtime/auto-install.mdx +1 -1
- package/docs/runtime/binary-data.mdx +1 -1
- package/docs/runtime/bun-apis.mdx +35 -35
- package/docs/runtime/bunfig.mdx +29 -3
- package/docs/runtime/c-compiler.mdx +3 -3
- package/docs/runtime/child-process.mdx +2 -2
- package/docs/runtime/cookies.mdx +19 -19
- package/docs/runtime/debugger.mdx +4 -4
- package/docs/runtime/environment-variables.mdx +24 -7
- package/docs/runtime/ffi.mdx +2 -2
- package/docs/runtime/file-io.mdx +2 -2
- package/docs/runtime/file-types.mdx +5 -5
- package/docs/runtime/globals.mdx +4 -4
- package/docs/runtime/http/error-handling.mdx +2 -2
- package/docs/runtime/http/routing.mdx +1 -1
- package/docs/runtime/http/server.mdx +5 -9
- package/docs/runtime/http/websockets.mdx +1 -1
- package/docs/runtime/index.mdx +2 -2
- package/docs/runtime/jsx.mdx +1 -1
- package/docs/runtime/module-resolution.mdx +2 -2
- package/docs/runtime/networking/fetch.mdx +4 -4
- package/docs/runtime/nodejs-compat.mdx +3 -3
- package/docs/runtime/plugins.mdx +1 -1
- package/docs/runtime/s3.mdx +4 -4
- package/docs/runtime/secrets.mdx +10 -7
- package/docs/runtime/sql.mdx +10 -10
- package/docs/runtime/sqlite.mdx +15 -4
- package/docs/runtime/templating/create.mdx +4 -4
- package/docs/runtime/transpiler.mdx +1 -1
- package/docs/runtime/utils.mdx +3 -3
- package/docs/runtime/watch-mode.mdx +1 -1
- package/docs/runtime/workers.mdx +5 -17
- package/docs/snippets/cli/publish.mdx +2 -2
- package/docs/test/configuration.mdx +1 -1
- package/docs/test/dom.mdx +1 -1
- package/docs/test/index.mdx +8 -8
- package/docs/test/reporters.mdx +1 -1
- package/docs/test/snapshots.mdx +3 -3
- package/docs/test/writing-tests.mdx +37 -0
- package/docs/typescript.mdx +2 -2
- package/package.json +3 -4
- package/docs/snippets/product-card.mdx +0 -32
- package/docs/snippets/product-tiles.mdx +0 -94
package/CLAUDE.md
CHANGED
|
@@ -5,6 +5,7 @@ Default to using Bun instead of Node.js.
|
|
|
5
5
|
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
|
|
6
6
|
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
|
|
7
7
|
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
|
|
8
|
+
- Use `bunx <package> <command>` instead of `npx <package> <command>`
|
|
8
9
|
- Bun automatically loads .env, so don't use dotenv.
|
|
9
10
|
|
|
10
11
|
## APIs
|
|
@@ -81,12 +82,11 @@ With the following `frontend.tsx`:
|
|
|
81
82
|
|
|
82
83
|
```tsx#frontend.tsx
|
|
83
84
|
import React from "react";
|
|
85
|
+
import { createRoot } from "react-dom/client";
|
|
84
86
|
|
|
85
87
|
// import .css files directly and it works
|
|
86
88
|
import './index.css';
|
|
87
89
|
|
|
88
|
-
import { createRoot } from "react-dom/client";
|
|
89
|
-
|
|
90
90
|
const root = createRoot(document.body);
|
|
91
91
|
|
|
92
92
|
export default function Frontend() {
|
|
@@ -102,4 +102,4 @@ Then, run index.ts
|
|
|
102
102
|
bun --hot ./index.ts
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
For more information, read the Bun API docs in `docs/**.
|
|
105
|
+
For more information, read the Bun API docs in `docs/**.mdx`.
|
package/docs/bundler/css.mdx
CHANGED
|
@@ -72,7 +72,7 @@ Bun's CSS bundler automatically converts this nested syntax into traditional fla
|
|
|
72
72
|
|
|
73
73
|
You can also nest media queries and other at-rules inside selectors, eliminating the need to repeat selector patterns:
|
|
74
74
|
|
|
75
|
-
```
|
|
75
|
+
```scss title="styles.css" icon="file-code"
|
|
76
76
|
.responsive-element {
|
|
77
77
|
display: block;
|
|
78
78
|
|
|
@@ -118,7 +118,7 @@ These constants are embedded directly into your compiled binary at build time, p
|
|
|
118
118
|
|
|
119
119
|
<Note>
|
|
120
120
|
For comprehensive examples and advanced patterns, see the [Build-time constants
|
|
121
|
-
guide](
|
|
121
|
+
guide](/docs/guides/runtime/build-time-constants).
|
|
122
122
|
</Note>
|
|
123
123
|
|
|
124
124
|
---
|
|
@@ -183,6 +183,35 @@ console.log(process.execArgv); // ["--smol", "--user-agent=MyBot"]
|
|
|
183
183
|
|
|
184
184
|
---
|
|
185
185
|
|
|
186
|
+
## Disabling automatic config loading
|
|
187
|
+
|
|
188
|
+
By default, standalone executables look for `.env` and `bunfig.toml` files in the directory where the executable is run. You can disable this behavior at build time for deterministic execution regardless of the user's working directory.
|
|
189
|
+
|
|
190
|
+
```bash icon="terminal" terminal
|
|
191
|
+
# Disable .env loading
|
|
192
|
+
bun build --compile --no-compile-autoload-dotenv ./app.ts --outfile myapp
|
|
193
|
+
|
|
194
|
+
# Disable bunfig.toml loading
|
|
195
|
+
bun build --compile --no-compile-autoload-bunfig ./app.ts --outfile myapp
|
|
196
|
+
|
|
197
|
+
# Disable both
|
|
198
|
+
bun build --compile --no-compile-autoload-dotenv --no-compile-autoload-bunfig ./app.ts --outfile myapp
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
You can also configure this via the JavaScript API:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
await Bun.build({
|
|
205
|
+
entrypoints: ["./app.ts"],
|
|
206
|
+
compile: {
|
|
207
|
+
autoloadDotenv: false, // Disable .env loading
|
|
208
|
+
autoloadBunfig: false, // Disable bunfig.toml loading
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
186
215
|
## Act as the Bun CLI
|
|
187
216
|
|
|
188
217
|
<Note>New in Bun v1.2.16</Note>
|
|
@@ -259,12 +288,12 @@ console.log(`Server running at http://localhost:${server.port}`);
|
|
|
259
288
|
</head>
|
|
260
289
|
<body>
|
|
261
290
|
<h1>Hello World</h1>
|
|
262
|
-
<script src="./app.
|
|
291
|
+
<script src="./app.ts"></script>
|
|
263
292
|
</body>
|
|
264
293
|
</html>
|
|
265
294
|
```
|
|
266
295
|
|
|
267
|
-
```ts app.
|
|
296
|
+
```ts app.ts icon="file-code"
|
|
268
297
|
console.log("Hello from the client!");
|
|
269
298
|
```
|
|
270
299
|
|
|
@@ -297,7 +326,7 @@ The result is a single file that can be deployed anywhere without needing Node.j
|
|
|
297
326
|
|
|
298
327
|
Bun automatically handles serving the frontend assets with proper MIME types and cache headers. The HTML import is replaced with a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets.
|
|
299
328
|
|
|
300
|
-
For more details on building full-stack applications with Bun, see the [full-stack guide](/bundler/fullstack).
|
|
329
|
+
For more details on building full-stack applications with Bun, see the [full-stack guide](/docs/bundler/fullstack).
|
|
301
330
|
|
|
302
331
|
---
|
|
303
332
|
|
|
@@ -632,7 +632,7 @@ const server = serve({
|
|
|
632
632
|
console.log(`🚀 Server running on ${server.url}`);
|
|
633
633
|
```
|
|
634
634
|
|
|
635
|
-
```html title="public/index.html"
|
|
635
|
+
```html title="public/index.html" icon="file-code"
|
|
636
636
|
<!DOCTYPE html>
|
|
637
637
|
<html>
|
|
638
638
|
<head>
|
|
@@ -757,7 +757,7 @@ export function App() {
|
|
|
757
757
|
}
|
|
758
758
|
```
|
|
759
759
|
|
|
760
|
-
```css title="src/styles.css"
|
|
760
|
+
```css title="src/styles.css" icon="file-code"
|
|
761
761
|
* {
|
|
762
762
|
margin: 0;
|
|
763
763
|
padding: 0;
|
|
@@ -999,7 +999,7 @@ CMD ["bun", "index.js"]
|
|
|
999
999
|
|
|
1000
1000
|
### Environment Variables
|
|
1001
1001
|
|
|
1002
|
-
```
|
|
1002
|
+
```ini title=".env.production" icon="file-code"
|
|
1003
1003
|
NODE_ENV=production
|
|
1004
1004
|
PORT=3000
|
|
1005
1005
|
DATABASE_URL=postgresql://user:pass@localhost:5432/myapp
|
|
@@ -9,7 +9,7 @@ Hot Module Replacement (HMR) allows you to update modules in a running applicati
|
|
|
9
9
|
|
|
10
10
|
## `import.meta.hot` API Reference
|
|
11
11
|
|
|
12
|
-
Bun implements a client-side HMR API modeled after [Vite's `import.meta.hot` API](https://
|
|
12
|
+
Bun implements a client-side HMR API modeled after [Vite's `import.meta.hot` API](https://vite.dev/guide/api-hmr). It can be checked for with `if (import.meta.hot)`, tree-shaking it in production.
|
|
13
13
|
|
|
14
14
|
```ts title="index.ts" icon="/icons/typescript.svg"
|
|
15
15
|
if (import.meta.hot) {
|
|
@@ -144,7 +144,7 @@ Indicates that multiple dependencies' modules can be accepted. This variant acce
|
|
|
144
144
|
|
|
145
145
|
`import.meta.hot.data` maintains state between module instances during hot replacement, enabling data transfer from previous to new versions. When `import.meta.hot.data` is written into, Bun will also mark this module as capable of self-accepting (equivalent of calling `import.meta.hot.accept()`).
|
|
146
146
|
|
|
147
|
-
```
|
|
147
|
+
```tsx title="index.tsx" icon="/icons/typescript.svg"
|
|
148
148
|
import { createRoot } from "react-dom/client";
|
|
149
149
|
import { App } from "./app";
|
|
150
150
|
|
|
@@ -25,7 +25,7 @@ bun ./index.html
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
```
|
|
28
|
-
Bun v1.3.
|
|
28
|
+
Bun v1.3.3
|
|
29
29
|
ready in 6.62ms
|
|
30
30
|
→ http://localhost:3000/
|
|
31
31
|
Press h + Enter to show shortcuts
|
|
@@ -51,7 +51,7 @@ bun index.html
|
|
|
51
51
|
```
|
|
52
52
|
|
|
53
53
|
```
|
|
54
|
-
Bun v1.3.
|
|
54
|
+
Bun v1.3.3
|
|
55
55
|
ready in 6.62ms
|
|
56
56
|
→ http://localhost:3000/
|
|
57
57
|
Press h + Enter to show shortcuts
|
|
@@ -81,7 +81,7 @@ bun ./index.html ./about.html
|
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
```txt
|
|
84
|
-
Bun v1.3.
|
|
84
|
+
Bun v1.3.3
|
|
85
85
|
ready in 6.62ms
|
|
86
86
|
→ http://localhost:3000/
|
|
87
87
|
Routes:
|
|
@@ -104,7 +104,7 @@ bun ./**/*.html
|
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
```
|
|
107
|
-
Bun v1.3.
|
|
107
|
+
Bun v1.3.3
|
|
108
108
|
ready in 6.62ms
|
|
109
109
|
→ http://localhost:3000/
|
|
110
110
|
Routes:
|
|
@@ -122,7 +122,7 @@ bun ./index.html ./about/index.html ./about/foo/index.html
|
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
```
|
|
125
|
-
Bun v1.3.
|
|
125
|
+
Bun v1.3.3
|
|
126
126
|
ready in 6.62ms
|
|
127
127
|
→ http://localhost:3000/
|
|
128
128
|
Routes:
|
|
@@ -164,7 +164,7 @@ For example:
|
|
|
164
164
|
}
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
```css abc.css
|
|
167
|
+
```css abc.css icon="file-code"
|
|
168
168
|
body {
|
|
169
169
|
background-color: red;
|
|
170
170
|
}
|
|
@@ -174,7 +174,7 @@ body {
|
|
|
174
174
|
|
|
175
175
|
This outputs:
|
|
176
176
|
|
|
177
|
-
```css
|
|
177
|
+
```css styles.css icon="file-code"
|
|
178
178
|
body {
|
|
179
179
|
background-color: red;
|
|
180
180
|
}
|
|
@@ -273,7 +273,7 @@ bun ./index.html --console
|
|
|
273
273
|
```
|
|
274
274
|
|
|
275
275
|
```
|
|
276
|
-
Bun v1.3.
|
|
276
|
+
Bun v1.3.3
|
|
277
277
|
ready in 6.62ms
|
|
278
278
|
→ http://localhost:3000/
|
|
279
279
|
Press h + Enter to show shortcuts
|
|
@@ -385,7 +385,8 @@ All paths are resolved relative to your HTML file, making it easy to organize yo
|
|
|
385
385
|
- Need more configuration options for things like asset handling
|
|
386
386
|
- Need a way to configure CORS, headers, etc.
|
|
387
387
|
|
|
388
|
-
|
|
388
|
+
{/* todo: find the correct link to link to as this 404's and there isn't any similar files */}
|
|
389
|
+
{/* If you want to submit a PR, most of the code is [here](https://github.com/oven-sh/bun/blob/main/src/bun.js/api/bun/html-rewriter.ts). You could even copy paste that file into your project and use it as a starting point. */}
|
|
389
390
|
|
|
390
391
|
</Warning>
|
|
391
392
|
|
package/docs/bundler/index.mdx
CHANGED
|
@@ -106,7 +106,7 @@ For each file specified in `entrypoints`, Bun will generate a new bundle. This b
|
|
|
106
106
|
|
|
107
107
|
The contents of `out/index.js` will look something like this:
|
|
108
108
|
|
|
109
|
-
```
|
|
109
|
+
```js title="out/index.js" icon="/icons/javascript.svg"
|
|
110
110
|
// out/index.js
|
|
111
111
|
// ...
|
|
112
112
|
// ~20k lines of code
|
|
@@ -154,7 +154,7 @@ bun build ./index.tsx --outdir ./out --watch
|
|
|
154
154
|
|
|
155
155
|
## Content types
|
|
156
156
|
|
|
157
|
-
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](/bundler/loaders) for full documentation.
|
|
157
|
+
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](/docs/bundler/loaders) for full documentation.
|
|
158
158
|
|
|
159
159
|
| Extensions | Details |
|
|
160
160
|
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
@@ -190,11 +190,11 @@ console.log(logo);
|
|
|
190
190
|
|
|
191
191
|
The exact behavior of the file loader is also impacted by [`naming`](#naming) and [`publicPath`](#publicpath).
|
|
192
192
|
|
|
193
|
-
<Info>Refer to the [Bundler > Loaders](/bundler/loaders) page for more complete documentation on the file loader.</Info>
|
|
193
|
+
<Info>Refer to the [Bundler > Loaders](/docs/bundler/loaders) page for more complete documentation on the file loader.</Info>
|
|
194
194
|
|
|
195
195
|
### Plugins
|
|
196
196
|
|
|
197
|
-
The behavior described in this table can be overridden or extended with plugins. Refer to the [Bundler > Loaders](/bundler/loaders) page for complete documentation.
|
|
197
|
+
The behavior described in this table can be overridden or extended with plugins. Refer to the [Bundler > Loaders](/docs/bundler/loaders) page for complete documentation.
|
|
198
198
|
|
|
199
199
|
## API
|
|
200
200
|
|
|
@@ -498,7 +498,7 @@ await Bun.build({
|
|
|
498
498
|
});
|
|
499
499
|
```
|
|
500
500
|
|
|
501
|
-
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](/bundler/plugins) for complete documentation.
|
|
501
|
+
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](/docs/bundler/plugins) for complete documentation.
|
|
502
502
|
|
|
503
503
|
### env
|
|
504
504
|
|
|
@@ -527,7 +527,7 @@ Injects environment variables into the bundled output by converting `process.env
|
|
|
527
527
|
|
|
528
528
|
For the input below:
|
|
529
529
|
|
|
530
|
-
```
|
|
530
|
+
```js title="input.js" icon="/icons/javascript.svg"
|
|
531
531
|
// input.js
|
|
532
532
|
console.log(process.env.FOO);
|
|
533
533
|
console.log(process.env.BAZ);
|
|
@@ -535,7 +535,7 @@ console.log(process.env.BAZ);
|
|
|
535
535
|
|
|
536
536
|
The generated bundle will contain the following code:
|
|
537
537
|
|
|
538
|
-
```
|
|
538
|
+
```js title="output.js" icon="/icons/javascript.svg"
|
|
539
539
|
// output.js
|
|
540
540
|
console.log("bar");
|
|
541
541
|
console.log("123");
|
|
@@ -580,7 +580,7 @@ console.log(process.env.BAZ);
|
|
|
580
580
|
|
|
581
581
|
The generated bundle will contain the following code:
|
|
582
582
|
|
|
583
|
-
```
|
|
583
|
+
```js title="output.js" icon="/icons/javascript.svg"
|
|
584
584
|
console.log(process.env.FOO);
|
|
585
585
|
console.log("https://acme.com");
|
|
586
586
|
console.log(process.env.BAZ);
|
|
@@ -722,7 +722,7 @@ Normally, bundling `index.tsx` would generate a bundle containing the entire sou
|
|
|
722
722
|
|
|
723
723
|
The generated bundle will look something like this:
|
|
724
724
|
|
|
725
|
-
```
|
|
725
|
+
```js title="out/index.js" icon="/icons/javascript.svg"
|
|
726
726
|
import { z } from "zod";
|
|
727
727
|
|
|
728
728
|
// ...
|
|
@@ -1026,7 +1026,7 @@ Setting `publicPath` will prefix all file paths with the specified value.
|
|
|
1026
1026
|
|
|
1027
1027
|
The output file would now look something like this.
|
|
1028
1028
|
|
|
1029
|
-
```
|
|
1029
|
+
```js title="out/index.js" icon="/icons/javascript.svg"
|
|
1030
1030
|
var logo = "https://cdn.example.com/logo-a7305bdef.svg";
|
|
1031
1031
|
```
|
|
1032
1032
|
|
|
@@ -1181,7 +1181,7 @@ Each artifact also contains the following properties:
|
|
|
1181
1181
|
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1182
1182
|
| `kind` | What kind of build output this file is. A build generates bundled entrypoints, code-split "chunks", sourcemaps, bytecode, and copied assets (like images). |
|
|
1183
1183
|
| `path` | Absolute path to the file on disk |
|
|
1184
|
-
| `loader` | The loader was used to interpret the file. See [Bundler > Loaders](/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader. |
|
|
1184
|
+
| `loader` | The loader was used to interpret the file. See [Bundler > Loaders](/docs/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader. |
|
|
1185
1185
|
| `hash` | The hash of the file contents. Always defined for assets. |
|
|
1186
1186
|
| `sourcemap` | The sourcemap file corresponding to this file, if generated. Only defined for entrypoints and chunks. |
|
|
1187
1187
|
|
|
@@ -1268,7 +1268,7 @@ bun build ./cli.tsx --outfile mycli --compile
|
|
|
1268
1268
|
./mycli
|
|
1269
1269
|
```
|
|
1270
1270
|
|
|
1271
|
-
Refer to [Bundler > Executables](/bundler/executables) for complete documentation.
|
|
1271
|
+
Refer to [Bundler > Executables](/docs/bundler/executables) for complete documentation.
|
|
1272
1272
|
|
|
1273
1273
|
## Logs and errors
|
|
1274
1274
|
|
|
@@ -1356,10 +1356,12 @@ interface BuildConfig {
|
|
|
1356
1356
|
* JSX configuration object for controlling JSX transform behavior
|
|
1357
1357
|
*/
|
|
1358
1358
|
jsx?: {
|
|
1359
|
+
runtime?: "automatic" | "classic";
|
|
1360
|
+
importSource?: string;
|
|
1359
1361
|
factory?: string;
|
|
1360
1362
|
fragment?: string;
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
+
sideEffects?: boolean;
|
|
1364
|
+
development?: boolean;
|
|
1363
1365
|
};
|
|
1364
1366
|
naming?:
|
|
1365
1367
|
| string
|
|
@@ -1443,13 +1445,20 @@ interface BuildConfig {
|
|
|
1443
1445
|
drop?: string[];
|
|
1444
1446
|
|
|
1445
1447
|
/**
|
|
1446
|
-
* When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
|
|
1447
|
-
* When set to `false`,
|
|
1448
|
+
* - When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
|
|
1449
|
+
* - When set to `false`, returns a {@link BuildOutput} with `{success: false}`
|
|
1448
1450
|
*
|
|
1449
|
-
*
|
|
1450
|
-
* as most usage of `Bun.build` forgets to check for errors.
|
|
1451
|
+
* @default true
|
|
1451
1452
|
*/
|
|
1452
1453
|
throw?: boolean;
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* Custom tsconfig.json file path to use for path resolution.
|
|
1457
|
+
* Equivalent to `--tsconfig-override` in the CLI.
|
|
1458
|
+
*/
|
|
1459
|
+
tsconfig?: string;
|
|
1460
|
+
|
|
1461
|
+
outdir?: string;
|
|
1453
1462
|
}
|
|
1454
1463
|
|
|
1455
1464
|
interface BuildOutput {
|
package/docs/bundler/loaders.mdx
CHANGED
|
@@ -312,7 +312,7 @@ The `html` loader processes HTML files and bundles any referenced assets. It wil
|
|
|
312
312
|
|
|
313
313
|
For example, given this HTML file:
|
|
314
314
|
|
|
315
|
-
```html title="src/index.html"
|
|
315
|
+
```html title="src/index.html" icon="file-code"
|
|
316
316
|
<!DOCTYPE html>
|
|
317
317
|
<html>
|
|
318
318
|
<body>
|
|
@@ -325,7 +325,7 @@ For example, given this HTML file:
|
|
|
325
325
|
|
|
326
326
|
It will output a new HTML file with the bundled assets:
|
|
327
327
|
|
|
328
|
-
```html title="dist/index.html"
|
|
328
|
+
```html title="dist/index.html" icon="file-code"
|
|
329
329
|
<!DOCTYPE html>
|
|
330
330
|
<html>
|
|
331
331
|
<body>
|
package/docs/bundler/macros.mdx
CHANGED
|
@@ -87,7 +87,7 @@ macro();
|
|
|
87
87
|
|
|
88
88
|
When shipping a library containing a macro to npm or another package registry, use the `"macro"` export condition to provide a special version of your package exclusively for the macro environment.
|
|
89
89
|
|
|
90
|
-
```json title="package.json" icon="file-
|
|
90
|
+
```json title="package.json" icon="file-json"
|
|
91
91
|
{
|
|
92
92
|
"name": "my-package",
|
|
93
93
|
"exports": {
|
package/docs/feedback.mdx
CHANGED
|
@@ -4,13 +4,9 @@ description: Share feedback, bug reports, and feature requests
|
|
|
4
4
|
mode: center
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
import Feedback from "/snippets/cli/feedback.mdx";
|
|
8
|
-
|
|
9
7
|
Whether you've found a bug, have a performance issue, or just want to suggest an improvement, here's how you can open a helpful issue:
|
|
10
8
|
|
|
11
|
-
<Callout icon="discord">
|
|
12
|
-
For general questions, please join our [Discord](https://discord.com/invite/CXdq2DP29u).
|
|
13
|
-
</Callout>
|
|
9
|
+
<Callout icon="discord">For general questions, please join our [Discord](https://bun.com/discord).</Callout>
|
|
14
10
|
|
|
15
11
|
## Reporting Issues
|
|
16
12
|
|
|
@@ -56,9 +52,7 @@ Whether you've found a bug, have a performance issue, or just want to suggest an
|
|
|
56
52
|
<Note>
|
|
57
53
|
- For MacOS and Linux: copy the output of `uname -mprs`
|
|
58
54
|
- For Windows: copy the output of this command in the powershell console:
|
|
59
|
-
|
|
60
|
-
"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"
|
|
61
|
-
```
|
|
55
|
+
`"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"`
|
|
62
56
|
</Note>
|
|
63
57
|
</Step>
|
|
64
58
|
|
|
@@ -79,7 +73,3 @@ echo "please document X" | bun feedback --email you@example.com
|
|
|
79
73
|
```
|
|
80
74
|
|
|
81
75
|
You can provide feedback as text arguments, file paths, or piped input.
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
<Feedback />
|
|
@@ -26,4 +26,4 @@ const regularArr = Array.from(uintArr);
|
|
|
26
26
|
|
|
27
27
|
---
|
|
28
28
|
|
|
29
|
-
See [Docs > API > Binary Data](
|
|
29
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -23,4 +23,4 @@ blob.type; // => "application/octet-stream"
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
See [Docs > API > Binary Data](
|
|
26
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -24,4 +24,4 @@ const nodeBuffer = Buffer.from(arrBuffer, 0, 16); // view first 16 bytes
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
See [Docs > API > Binary Data](
|
|
27
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -14,4 +14,4 @@ const str = decoder.decode(buf);
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
See [Docs > API > Binary Data](
|
|
17
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const buf = await blob.arrayBuffer();
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const arr = new DataView(await blob.arrayBuffer());
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const stream = await blob.stream();
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -14,4 +14,4 @@ const str = await blob.text();
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
See [Docs > API > Binary Data](
|
|
17
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const arr = new Uint8Array(await blob.arrayBuffer());
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const arrBuf = nodeBuf.buffer;
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const blob = new Blob([buf]);
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -40,4 +40,4 @@ const stream = blob.stream(1024);
|
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
43
|
-
See [Docs > API > Binary Data](
|
|
43
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -24,4 +24,4 @@ const str = buf.toString("utf8", 0, 5);
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
See [Docs > API > Binary Data](
|
|
27
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ buf instanceof Uint8Array; // => true
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -14,4 +14,4 @@ const str = decoder.decode(dv);
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
See [Docs > API > Binary Data](
|
|
17
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -24,4 +24,4 @@ arr.byteLength; // => 32
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
See [Docs > API > Binary Data](
|
|
27
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -15,4 +15,4 @@ console.log(await blob.text());
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
See [Docs > API > Binary Data](
|
|
18
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const buf = Buffer.from(arr);
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -13,4 +13,4 @@ const dv = new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
See [Docs > API > Binary Data](
|
|
16
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -40,4 +40,4 @@ const stream = blob.stream(1024);
|
|
|
40
40
|
|
|
41
41
|
---
|
|
42
42
|
|
|
43
|
-
See [Docs > API > Binary Data](
|
|
43
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
|
@@ -15,4 +15,4 @@ const str = decoder.decode(arr);
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
See [Docs > API > Binary Data](
|
|
18
|
+
See [Docs > API > Binary Data](/docs/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|