bun-types 1.3.3 → 1.3.4-canary.20251123T140630
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/docs/pm/npmrc.mdx
CHANGED
|
@@ -6,7 +6,7 @@ description:
|
|
|
6
6
|
Bun supports loading configuration options from [`.npmrc`](https://docs.npmjs.com/cli/v10/configuring-npm/npmrc) files, allowing you to reuse existing registry/scope configurations.
|
|
7
7
|
|
|
8
8
|
<Note>
|
|
9
|
-
We recommend migrating your `.npmrc` file to Bun's [`bunfig.toml`](/runtime/bunfig) format, as it provides more
|
|
9
|
+
We recommend migrating your `.npmrc` file to Bun's [`bunfig.toml`](/docs/runtime/bunfig) format, as it provides more
|
|
10
10
|
flexible options and can let you configure Bun-specific options.
|
|
11
11
|
</Note>
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ To change it, you can set the `registry` option in `.npmrc`:
|
|
|
24
24
|
registry=http://localhost:4873/
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
The equivalent `bunfig.toml` option is [`install.registry`](/runtime/bunfig#install-registry):
|
|
27
|
+
The equivalent `bunfig.toml` option is [`install.registry`](/docs/runtime/bunfig#install-registry):
|
|
28
28
|
|
|
29
29
|
```toml bunfig.toml icon="settings"
|
|
30
30
|
install.registry = "http://localhost:4873/"
|
|
@@ -38,7 +38,7 @@ install.registry = "http://localhost:4873/"
|
|
|
38
38
|
@myorg:registry=http://localhost:4873/
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/runtime/bunfig#install-registry):
|
|
41
|
+
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/docs/runtime/bunfig#install-registry):
|
|
42
42
|
|
|
43
43
|
```toml bunfig.toml icon="settings"
|
|
44
44
|
[install.scopes]
|
|
@@ -73,7 +73,7 @@ The following options are supported:
|
|
|
73
73
|
- `_password` (base64 encoded password)
|
|
74
74
|
- `_auth` (base64 encoded username:password, e.g. `btoa(username + ":" + password)`)
|
|
75
75
|
|
|
76
|
-
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/runtime/bunfig#install-registry):
|
|
76
|
+
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/docs/runtime/bunfig#install-registry):
|
|
77
77
|
|
|
78
78
|
```toml bunfig.toml icon="settings"
|
|
79
79
|
[install.scopes]
|
|
@@ -88,7 +88,7 @@ Controls how workspace packages are installed when available locally:
|
|
|
88
88
|
link-workspace-packages=true
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
The equivalent `bunfig.toml` option is [`install.linkWorkspacePackages`](/runtime/bunfig#install-linkworkspacepackages):
|
|
91
|
+
The equivalent `bunfig.toml` option is [`install.linkWorkspacePackages`](/docs/runtime/bunfig#install-linkworkspacepackages):
|
|
92
92
|
|
|
93
93
|
```toml bunfig.toml icon="settings"
|
|
94
94
|
[install]
|
|
@@ -103,7 +103,7 @@ Always saves exact versions without the `^` prefix:
|
|
|
103
103
|
save-exact=true
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
The equivalent `bunfig.toml` option is [`install.exact`](/runtime/bunfig#install-exact):
|
|
106
|
+
The equivalent `bunfig.toml` option is [`install.exact`](/docs/runtime/bunfig#install-exact):
|
|
107
107
|
|
|
108
108
|
```toml bunfig.toml icon="settings"
|
|
109
109
|
[install]
|
|
@@ -90,6 +90,6 @@ For a complete example with tests and CI setup, see the official template:
|
|
|
90
90
|
|
|
91
91
|
## Related
|
|
92
92
|
|
|
93
|
-
- [Configuration (bunfig.toml)](/runtime/bunfig#install-security-scanner)
|
|
94
|
-
- [Package Manager](/installation)
|
|
93
|
+
- [Configuration (bunfig.toml)](/docs/runtime/bunfig#install-security-scanner)
|
|
94
|
+
- [Package Manager](/docs/installation)
|
|
95
95
|
- [Security Scanner Template](https://github.com/oven-sh/security-scanner-template)
|
package/docs/pm/workspaces.mdx
CHANGED
|
@@ -43,8 +43,7 @@ In the root `package.json`, the `"workspaces"` key is used to indicate which sub
|
|
|
43
43
|
|
|
44
44
|
<Note>
|
|
45
45
|
**Glob support** — Bun supports full glob syntax in `"workspaces"`, including negative patterns (e.g.
|
|
46
|
-
`!**/excluded/**`). See [here](
|
|
47
|
-
supported syntax.
|
|
46
|
+
`!**/excluded/**`). See [here](/docs/runtime/glob#supported-glob-patterns) for a comprehensive list of supported syntax.
|
|
48
47
|
</Note>
|
|
49
48
|
|
|
50
49
|
```json package.json icon="file-json"
|
|
@@ -95,7 +94,7 @@ Workspaces have a couple major benefits.
|
|
|
95
94
|
|
|
96
95
|
- **Code can be split into logical parts.** If one package relies on another, you can simply add it as a dependency in `package.json`. If package `b` depends on `a`, `bun install` will install your local `packages/a` directory into `node_modules` instead of downloading it from the npm registry.
|
|
97
96
|
- **Dependencies can be de-duplicated.** If `a` and `b` share a common dependency, it will be _hoisted_ to the root `node_modules` directory. This reduces redundant disk usage and minimizes "dependency hell" issues associated with having multiple versions of a package installed simultaneously.
|
|
98
|
-
- **Run scripts in multiple packages.** You can use the [`--filter` flag](/pm/filter) to easily run `package.json` scripts in multiple packages in your workspace, , or `--workspaces` to run scripts across all workspaces.
|
|
97
|
+
- **Run scripts in multiple packages.** You can use the [`--filter` flag](/docs/pm/filter) to easily run `package.json` scripts in multiple packages in your workspace, , or `--workspaces` to run scripts across all workspaces.
|
|
99
98
|
|
|
100
99
|
## Share versions with Catalogs
|
|
101
100
|
|
|
@@ -103,7 +102,7 @@ When many packages need the same dependency versions, catalogs let you define
|
|
|
103
102
|
those versions once in the root `package.json` and reference them from your
|
|
104
103
|
workspaces using the `catalog:` protocol. Updating the catalog automatically
|
|
105
104
|
updates every package that references it. See
|
|
106
|
-
[Catalogs](/pm/catalogs) for details.
|
|
105
|
+
[Catalogs](/docs/pm/catalogs) for details.
|
|
107
106
|
|
|
108
107
|
<Note>
|
|
109
108
|
⚡️ **Speed** — Installs are fast, even for big monorepos. Bun installs the [Remix](https://github.com/remix-run/remix) monorepo in about `500ms` on Linux.
|
|
@@ -185,7 +185,7 @@ Once imported, you should see something like this:
|
|
|
185
185
|
/>
|
|
186
186
|
</Frame>
|
|
187
187
|
|
|
188
|
-
> The [web debugger](/runtime/debugger#inspect) also offers the timeline feature which allows you to track and examine the memory usage of the running debug session.
|
|
188
|
+
> The [web debugger](/docs/runtime/debugger#inspect) also offers the timeline feature which allows you to track and examine the memory usage of the running debug session.
|
|
189
189
|
|
|
190
190
|
### Native heap stats
|
|
191
191
|
|
|
@@ -22,7 +22,7 @@ By default, running unverified scripts are blocked.
|
|
|
22
22
|
Bun v1.1 or later. We use Bun to run it's own code generators.
|
|
23
23
|
|
|
24
24
|
```ps1
|
|
25
|
-
> irm bun.
|
|
25
|
+
> irm bun.sh/install.ps1 | iex
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
[Visual Studio](https://visualstudio.microsoft.com) with the "Desktop Development with C++" workload. While installing, make sure to install Git as well, if Git for Windows is not already installed.
|
|
@@ -5,7 +5,7 @@ description: Contributing to Bun
|
|
|
5
5
|
|
|
6
6
|
Configuring a development environment for Bun can take 10-30 minutes depending on your internet connection and computer speed. You will need ~10GB of free disk space for the repository and build artifacts.
|
|
7
7
|
|
|
8
|
-
If you are using Windows, please refer to [this guide](/project/building-windows)
|
|
8
|
+
If you are using Windows, please refer to [this guide](/docs/project/building-windows)
|
|
9
9
|
|
|
10
10
|
## Using Nix (Alternative)
|
|
11
11
|
|
package/docs/project/license.mdx
CHANGED
|
@@ -11,7 +11,7 @@ Bun statically links JavaScriptCore (and WebKit) which is LGPL-2 licensed. WebCo
|
|
|
11
11
|
|
|
12
12
|
> (1) If you statically link against an LGPL'd library, you must also provide your application in an object (not necessarily source) format, so that a user has the opportunity to modify the library and relink the application.
|
|
13
13
|
|
|
14
|
-
You can find the patched version of WebKit used by Bun here:
|
|
14
|
+
You can find the patched version of WebKit used by Bun here: https://github.com/oven-sh/webkit. If you would like to relink Bun with changes:
|
|
15
15
|
|
|
16
16
|
- `git submodule update --init --recursive`
|
|
17
17
|
- `make jsc`
|
package/docs/quickstart.mdx
CHANGED
|
@@ -7,7 +7,7 @@ description: Build your first app with Bun
|
|
|
7
7
|
|
|
8
8
|
Build a minimal HTTP server with `Bun.serve`, run it locally, then evolve it by installing a package.
|
|
9
9
|
|
|
10
|
-
<Info>Prerequisites: Bun installed and available on your `PATH`. See [installation](/installation) for setup.</Info>
|
|
10
|
+
<Info>Prerequisites: Bun installed and available on your `PATH`. See [installation](/docs/installation) for setup.</Info>
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
@@ -92,7 +92,7 @@ Build a minimal HTTP server with `Bun.serve`, run it locally, then evolve it by
|
|
|
92
92
|
|
|
93
93
|
Then add the following to your `compilerOptions` in `tsconfig.json`:
|
|
94
94
|
|
|
95
|
-
```json tsconfig.json icon="file-
|
|
95
|
+
```json tsconfig.json icon="file-json"
|
|
96
96
|
{
|
|
97
97
|
"compilerOptions": {
|
|
98
98
|
"lib": ["ESNext"],
|
|
@@ -220,7 +220,7 @@ Build a minimal HTTP server with `Bun.serve`, run it locally, then evolve it by
|
|
|
220
220
|
Bun can also execute `"scripts"` from your `package.json`. Add the following script:
|
|
221
221
|
|
|
222
222
|
{/* prettier-ignore */}
|
|
223
|
-
```json package.json icon="file-
|
|
223
|
+
```json package.json icon="file-json"
|
|
224
224
|
{
|
|
225
225
|
"name": "quickstart",
|
|
226
226
|
"module": "index.ts",
|
|
@@ -5,7 +5,7 @@ description: "Bun's automatic package installation feature for standalone script
|
|
|
5
5
|
|
|
6
6
|
If no `node_modules` directory is found in the working directory or higher, Bun will abandon Node.js-style module resolution in favor of the **Bun module resolution algorithm**.
|
|
7
7
|
|
|
8
|
-
Under Bun-style module resolution, all imported packages are auto-installed on the fly into a [global module cache](/pm/global-cache) during execution (the same cache used by [`bun install`](/pm/cli/install)).
|
|
8
|
+
Under Bun-style module resolution, all imported packages are auto-installed on the fly into a [global module cache](/docs/pm/global-cache) during execution (the same cache used by [`bun install`](/docs/pm/cli/install)).
|
|
9
9
|
|
|
10
10
|
```ts index.ts icon="/icons/typescript.svg"
|
|
11
11
|
import { foo } from "foo"; // install `latest` version
|
|
@@ -378,7 +378,7 @@ for await (const chunk of stream) {
|
|
|
378
378
|
// => "world"
|
|
379
379
|
```
|
|
380
380
|
|
|
381
|
-
For a more complete discussion of streams in Bun, see [API > Streams](/runtime/streams).
|
|
381
|
+
For a more complete discussion of streams in Bun, see [API > Streams](/docs/runtime/streams).
|
|
382
382
|
|
|
383
383
|
---
|
|
384
384
|
|
|
@@ -20,40 +20,40 @@ Click the link in the right column to jump to the associated documentation.
|
|
|
20
20
|
|
|
21
21
|
| Topic | APIs |
|
|
22
22
|
| -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
-
| HTTP Server | [`Bun.serve`](/runtime/http/server) |
|
|
24
|
-
| Shell | [`$`](/runtime/shell) |
|
|
25
|
-
| Bundler | [`Bun.build`](/bundler) |
|
|
26
|
-
| File I/O | [`Bun.file`](/runtime/file-io#reading-files-bun-file), [`Bun.write`](/runtime/file-io#writing-files-bun-write), `Bun.stdin`, `Bun.stdout`, `Bun.stderr` |
|
|
27
|
-
| Child Processes | [`Bun.spawn`](/runtime/child-process#spawn-a-process-bun-spawn), [`Bun.spawnSync`](/runtime/child-process#blocking-api-bun-spawnsync) |
|
|
28
|
-
| TCP Sockets | [`Bun.listen`](/runtime/networking/tcp#start-a-server-bun-listen), [`Bun.connect`](/runtime/networking/tcp#start-a-server-bun-listen) |
|
|
29
|
-
| UDP Sockets | [`Bun.udpSocket`](/runtime/networking/udp) |
|
|
30
|
-
| WebSockets | `new WebSocket()` (client), [`Bun.serve`](/runtime/http/websockets) (server) |
|
|
31
|
-
| Transpiler | [`Bun.Transpiler`](/runtime/transpiler) |
|
|
32
|
-
| Routing | [`Bun.FileSystemRouter`](/runtime/file-system-router) |
|
|
33
|
-
| Streaming HTML | [`HTMLRewriter`](/runtime/html-rewriter) |
|
|
34
|
-
| Hashing | [`Bun.password`](/runtime/hashing#bun-password), [`Bun.hash`](/runtime/hashing#bun-hash), [`Bun.CryptoHasher`](/runtime/hashing#bun-cryptohasher), `Bun.sha` |
|
|
35
|
-
| SQLite | [`bun:sqlite`](/runtime/sqlite) |
|
|
36
|
-
| PostgreSQL Client | [`Bun.SQL`](/runtime/sql), `Bun.sql` |
|
|
37
|
-
| Redis (Valkey) Client | [`Bun.RedisClient`](/runtime/redis), `Bun.redis` |
|
|
38
|
-
| FFI (Foreign Function Interface) | [`bun:ffi`](/runtime/ffi) |
|
|
39
|
-
| DNS | [`Bun.dns.lookup`](/runtime/networking/dns), `Bun.dns.prefetch`, `Bun.dns.getCacheStats` |
|
|
40
|
-
| Testing | [`bun:test`](/test) |
|
|
41
|
-
| Workers | [`new Worker()`](/runtime/workers) |
|
|
42
|
-
| Module Loaders | [`Bun.plugin`](/bundler/plugins) |
|
|
43
|
-
| Glob | [`Bun.Glob`](/runtime/glob) |
|
|
44
|
-
| Cookies | [`Bun.Cookie`](/runtime/cookies), [`Bun.CookieMap`](/runtime/cookies) |
|
|
45
|
-
| Node-API | [`Node-API`](/runtime/node-api) |
|
|
46
|
-
| `import.meta` | [`import.meta`](/runtime/module-resolution#import-meta) |
|
|
47
|
-
| Utilities | [`Bun.version`](/runtime/utils#bun-version), [`Bun.revision`](/runtime/utils#bun-revision), [`Bun.env`](/runtime/utils#bun-env), [`Bun.main`](/runtime/utils#bun-main) |
|
|
48
|
-
| Sleep & Timing | [`Bun.sleep()`](/runtime/utils#bun-sleep), [`Bun.sleepSync()`](/runtime/utils#bun-sleepsync), [`Bun.nanoseconds()`](/runtime/utils#bun-nanoseconds) |
|
|
49
|
-
| Random & UUID | [`Bun.randomUUIDv7()`](/runtime/utils#bun-randomuuidv7) |
|
|
50
|
-
| System & Environment | [`Bun.which()`](/runtime/utils#bun-which) |
|
|
51
|
-
| Comparison & Inspection | [`Bun.peek()`](/runtime/utils#bun-peek), [`Bun.deepEquals()`](/runtime/utils#bun-deepequals), `Bun.deepMatch`, [`Bun.inspect()`](/runtime/utils#bun-inspect) |
|
|
52
|
-
| String & Text Processing | [`Bun.escapeHTML()`](/runtime/utils#bun-escapehtml), [`Bun.stringWidth()`](/runtime/utils#bun-stringwidth), `Bun.indexOfLine` |
|
|
53
|
-
| URL & Path Utilities | [`Bun.fileURLToPath()`](/runtime/utils#bun-fileurltopath), [`Bun.pathToFileURL()`](/runtime/utils#bun-pathtofileurl) |
|
|
54
|
-
| Compression | [`Bun.gzipSync()`](/runtime/utils#bun-gzipsync), [`Bun.gunzipSync()`](/runtime/utils#bun-gunzipsync), [`Bun.deflateSync()`](/runtime/utils#bun-deflatesync), [`Bun.inflateSync()`](/runtime/utils#bun-inflatesync), `Bun.zstdCompressSync()`, `Bun.zstdDecompressSync()`, `Bun.zstdCompress()`, `Bun.zstdDecompress()` |
|
|
55
|
-
| Stream Processing | [`Bun.readableStreamTo*()`](/runtime/utils#bun-readablestreamto), `Bun.readableStreamToBytes()`, `Bun.readableStreamToBlob()`, `Bun.readableStreamToFormData()`, `Bun.readableStreamToJSON()`, `Bun.readableStreamToArray()` |
|
|
23
|
+
| HTTP Server | [`Bun.serve`](/docs/runtime/http/server) |
|
|
24
|
+
| Shell | [`$`](/docs/runtime/shell) |
|
|
25
|
+
| Bundler | [`Bun.build`](/docs/bundler) |
|
|
26
|
+
| File I/O | [`Bun.file`](/docs/runtime/file-io#reading-files-bun-file), [`Bun.write`](/docs/runtime/file-io#writing-files-bun-write), `Bun.stdin`, `Bun.stdout`, `Bun.stderr` |
|
|
27
|
+
| Child Processes | [`Bun.spawn`](/docs/runtime/child-process#spawn-a-process-bun-spawn), [`Bun.spawnSync`](/docs/runtime/child-process#blocking-api-bun-spawnsync) |
|
|
28
|
+
| TCP Sockets | [`Bun.listen`](/docs/runtime/networking/tcp#start-a-server-bun-listen), [`Bun.connect`](/docs/runtime/networking/tcp#start-a-server-bun-listen) |
|
|
29
|
+
| UDP Sockets | [`Bun.udpSocket`](/docs/runtime/networking/udp) |
|
|
30
|
+
| WebSockets | `new WebSocket()` (client), [`Bun.serve`](/docs/runtime/http/websockets) (server) |
|
|
31
|
+
| Transpiler | [`Bun.Transpiler`](/docs/runtime/transpiler) |
|
|
32
|
+
| Routing | [`Bun.FileSystemRouter`](/docs/runtime/file-system-router) |
|
|
33
|
+
| Streaming HTML | [`HTMLRewriter`](/docs/runtime/html-rewriter) |
|
|
34
|
+
| Hashing | [`Bun.password`](/docs/runtime/hashing#bun-password), [`Bun.hash`](/docs/runtime/hashing#bun-hash), [`Bun.CryptoHasher`](/docs/runtime/hashing#bun-cryptohasher), `Bun.sha` |
|
|
35
|
+
| SQLite | [`bun:sqlite`](/docs/runtime/sqlite) |
|
|
36
|
+
| PostgreSQL Client | [`Bun.SQL`](/docs/runtime/sql), `Bun.sql` |
|
|
37
|
+
| Redis (Valkey) Client | [`Bun.RedisClient`](/docs/runtime/redis), `Bun.redis` |
|
|
38
|
+
| FFI (Foreign Function Interface) | [`bun:ffi`](/docs/runtime/ffi) |
|
|
39
|
+
| DNS | [`Bun.dns.lookup`](/docs/runtime/networking/dns), `Bun.dns.prefetch`, `Bun.dns.getCacheStats` |
|
|
40
|
+
| Testing | [`bun:test`](/docs/test) |
|
|
41
|
+
| Workers | [`new Worker()`](/docs/runtime/workers) |
|
|
42
|
+
| Module Loaders | [`Bun.plugin`](/docs/bundler/plugins) |
|
|
43
|
+
| Glob | [`Bun.Glob`](/docs/runtime/glob) |
|
|
44
|
+
| Cookies | [`Bun.Cookie`](/docs/runtime/cookies), [`Bun.CookieMap`](/docs/runtime/cookies) |
|
|
45
|
+
| Node-API | [`Node-API`](/docs/runtime/node-api) |
|
|
46
|
+
| `import.meta` | [`import.meta`](/docs/runtime/module-resolution#import-meta) |
|
|
47
|
+
| Utilities | [`Bun.version`](/docs/runtime/utils#bun-version), [`Bun.revision`](/docs/runtime/utils#bun-revision), [`Bun.env`](/docs/runtime/utils#bun-env), [`Bun.main`](/docs/runtime/utils#bun-main) |
|
|
48
|
+
| Sleep & Timing | [`Bun.sleep()`](/docs/runtime/utils#bun-sleep), [`Bun.sleepSync()`](/docs/runtime/utils#bun-sleepsync), [`Bun.nanoseconds()`](/docs/runtime/utils#bun-nanoseconds) |
|
|
49
|
+
| Random & UUID | [`Bun.randomUUIDv7()`](/docs/runtime/utils#bun-randomuuidv7) |
|
|
50
|
+
| System & Environment | [`Bun.which()`](/docs/runtime/utils#bun-which) |
|
|
51
|
+
| Comparison & Inspection | [`Bun.peek()`](/docs/runtime/utils#bun-peek), [`Bun.deepEquals()`](/docs/runtime/utils#bun-deepequals), `Bun.deepMatch`, [`Bun.inspect()`](/docs/runtime/utils#bun-inspect) |
|
|
52
|
+
| String & Text Processing | [`Bun.escapeHTML()`](/docs/runtime/utils#bun-escapehtml), [`Bun.stringWidth()`](/docs/runtime/utils#bun-stringwidth), `Bun.indexOfLine` |
|
|
53
|
+
| URL & Path Utilities | [`Bun.fileURLToPath()`](/docs/runtime/utils#bun-fileurltopath), [`Bun.pathToFileURL()`](/docs/runtime/utils#bun-pathtofileurl) |
|
|
54
|
+
| Compression | [`Bun.gzipSync()`](/docs/runtime/utils#bun-gzipsync), [`Bun.gunzipSync()`](/docs/runtime/utils#bun-gunzipsync), [`Bun.deflateSync()`](/docs/runtime/utils#bun-deflatesync), [`Bun.inflateSync()`](/docs/runtime/utils#bun-inflatesync), `Bun.zstdCompressSync()`, `Bun.zstdDecompressSync()`, `Bun.zstdCompress()`, `Bun.zstdDecompress()` |
|
|
55
|
+
| Stream Processing | [`Bun.readableStreamTo*()`](/docs/runtime/utils#bun-readablestreamto), `Bun.readableStreamToBytes()`, `Bun.readableStreamToBlob()`, `Bun.readableStreamToFormData()`, `Bun.readableStreamToJSON()`, `Bun.readableStreamToArray()` |
|
|
56
56
|
| Memory & Buffer Management | `Bun.ArrayBufferSink`, `Bun.allocUnsafe`, `Bun.concatArrayBuffers` |
|
|
57
|
-
| Module Resolution | [`Bun.resolveSync()`](/runtime/utils#bun-resolvesync) |
|
|
58
|
-
| Parsing & Formatting | [`Bun.semver`](/runtime/semver), `Bun.TOML.parse`, [`Bun.color`](/runtime/color) |
|
|
57
|
+
| Module Resolution | [`Bun.resolveSync()`](/docs/runtime/utils#bun-resolvesync) |
|
|
58
|
+
| Parsing & Formatting | [`Bun.semver`](/docs/runtime/semver), `Bun.TOML.parse`, [`Bun.color`](/docs/runtime/color) |
|
|
59
59
|
| Low-level / Internals | `Bun.mmap`, `Bun.gc`, `Bun.generateHeapSnapshot`, [`bun:jsc`](https://bun.com/reference/bun/jsc) |
|
package/docs/runtime/bunfig.mdx
CHANGED
|
@@ -452,8 +452,8 @@ To configure the directory where Bun installs globally installed binaries and CL
|
|
|
452
452
|
Environment variable: `BUN_INSTALL_BIN`
|
|
453
453
|
|
|
454
454
|
```toml title="bunfig.toml" icon="settings"
|
|
455
|
-
# where globally-installed package bins are linked
|
|
456
455
|
[install]
|
|
456
|
+
# where globally-installed package bins are linked
|
|
457
457
|
globalBinDir = "~/.bun/bin"
|
|
458
458
|
```
|
|
459
459
|
|
|
@@ -552,7 +552,7 @@ print = "yarn"
|
|
|
552
552
|
|
|
553
553
|
Configure the linker strategy for installing dependencies. Defaults to `"isolated"` for new workspaces, `"hoisted"` for new single-package projects and existing projects (made pre-v1.3.2).
|
|
554
554
|
|
|
555
|
-
For complete documentation refer to [Package manager > Isolated installs](/pm/isolated-installs).
|
|
555
|
+
For complete documentation refer to [Package manager > Isolated installs](/docs/pm/isolated-installs).
|
|
556
556
|
|
|
557
557
|
```toml title="bunfig.toml" icon="settings"
|
|
558
558
|
[install]
|
|
@@ -585,6 +585,32 @@ editor = "code"
|
|
|
585
585
|
# - "emacs"
|
|
586
586
|
```
|
|
587
587
|
|
|
588
|
+
### `install.security.scanner`
|
|
589
|
+
|
|
590
|
+
Configure a security scanner to scan packages for vulnerabilities before installation.
|
|
591
|
+
|
|
592
|
+
First, install a security scanner from npm:
|
|
593
|
+
|
|
594
|
+
```bash terminal icon="terminal"
|
|
595
|
+
bun add -d @acme/bun-security-scanner
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
Then configure it in your `bunfig.toml`:
|
|
599
|
+
|
|
600
|
+
```toml bunfig.toml icon="settings"
|
|
601
|
+
[install.security]
|
|
602
|
+
scanner = "@acme/bun-security-scanner"
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
When a security scanner is configured:
|
|
606
|
+
|
|
607
|
+
- Auto-install is automatically disabled for security
|
|
608
|
+
- Packages are scanned before installation
|
|
609
|
+
- Installation is cancelled if fatal issues are found
|
|
610
|
+
- Security warnings are displayed during installation
|
|
611
|
+
|
|
612
|
+
Learn more about [using and writing security scanners](/docs/pm/security-scanner-api).
|
|
613
|
+
|
|
588
614
|
### `install.minimumReleaseAge`
|
|
589
615
|
|
|
590
616
|
Configure a minimum age (in seconds) for npm package versions. Package versions published more recently than this threshold will be filtered out during installation. Default is `null` (disabled).
|
|
@@ -597,7 +623,7 @@ minimumReleaseAge = 259200
|
|
|
597
623
|
minimumReleaseAgeExcludes = ["@types/bun", "typescript"]
|
|
598
624
|
```
|
|
599
625
|
|
|
600
|
-
For more details see [Minimum release age](/pm/cli/install#minimum-release-age) in the install documentation.
|
|
626
|
+
For more details see [Minimum release age](/docs/pm/cli/install#minimum-release-age) in the install documentation.
|
|
601
627
|
|
|
602
628
|
## `bun run`
|
|
603
629
|
|
|
@@ -13,7 +13,7 @@ See the [introduction blog post](https://bun.com/blog/compile-and-run-c-in-js) f
|
|
|
13
13
|
|
|
14
14
|
JavaScript:
|
|
15
15
|
|
|
16
|
-
```ts hello.
|
|
16
|
+
```ts hello.ts icon="file-code"
|
|
17
17
|
import { cc } from "bun:ffi";
|
|
18
18
|
import source from "./hello.c" with { type: "file" };
|
|
19
19
|
|
|
@@ -51,7 +51,7 @@ Under the hood, `cc` uses [TinyCC](https://bellard.org/tcc/) to compile the C co
|
|
|
51
51
|
|
|
52
52
|
### Primitive types
|
|
53
53
|
|
|
54
|
-
The same `FFIType` values in [`dlopen`](/runtime/ffi) are supported in `cc`.
|
|
54
|
+
The same `FFIType` values in [`dlopen`](/docs/runtime/ffi) are supported in `cc`.
|
|
55
55
|
|
|
56
56
|
| `FFIType` | C Type | Aliases |
|
|
57
57
|
| ---------- | -------------- | --------------------------- |
|
|
@@ -87,7 +87,7 @@ You can also pass a `napi_env` to receive the N-API environment used to call the
|
|
|
87
87
|
|
|
88
88
|
For example, if you have a string in C, you can return it to JavaScript like this:
|
|
89
89
|
|
|
90
|
-
```ts hello.
|
|
90
|
+
```ts hello.ts
|
|
91
91
|
import { cc } from "bun:ffi";
|
|
92
92
|
import source from "./hello.c" with { type: "file" };
|
|
93
93
|
|
|
@@ -100,7 +100,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
100
100
|
```ts
|
|
101
101
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
102
102
|
const text = await proc.stdout.text();
|
|
103
|
-
console.log(text); // => "1.3.
|
|
103
|
+
console.log(text); // => "1.3.3\n"
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
|
@@ -289,7 +289,7 @@ childProc.disconnect();
|
|
|
289
289
|
|
|
290
290
|
To use IPC between a `bun` process and a Node.js process, set `serialization: "json"` in `Bun.spawn`. This is because Node.js and Bun use different JavaScript engines with different object serialization formats.
|
|
291
291
|
|
|
292
|
-
```
|
|
292
|
+
```js bun-node-ipc.js icon="file-code"
|
|
293
293
|
if (typeof Bun !== "undefined") {
|
|
294
294
|
const prefix = `[bun ${process.versions.bun} 🐇]`;
|
|
295
295
|
const node = Bun.spawn({
|
package/docs/runtime/cookies.mdx
CHANGED
|
@@ -9,7 +9,7 @@ Bun provides native APIs for working with HTTP cookies through `Bun.Cookie` and
|
|
|
9
9
|
|
|
10
10
|
`Bun.CookieMap` provides a Map-like interface for working with collections of cookies. It implements the `Iterable` interface, allowing you to use it with `for...of` loops and other iteration methods.
|
|
11
11
|
|
|
12
|
-
```ts
|
|
12
|
+
```ts title="cookies.ts" icon="/icons/typescript.svg"
|
|
13
13
|
// Empty cookie map
|
|
14
14
|
const cookies = new Bun.CookieMap();
|
|
15
15
|
|
|
@@ -33,7 +33,7 @@ const cookies3 = new Bun.CookieMap([
|
|
|
33
33
|
|
|
34
34
|
In Bun's HTTP server, the `cookies` property on the request object (in `routes`) is an instance of `CookieMap`:
|
|
35
35
|
|
|
36
|
-
```ts
|
|
36
|
+
```ts title="server.ts" icon="/icons/typescript.svg"
|
|
37
37
|
const server = Bun.serve({
|
|
38
38
|
routes: {
|
|
39
39
|
"/": req => {
|
|
@@ -68,7 +68,7 @@ console.log("Server listening at: " + server.url);
|
|
|
68
68
|
|
|
69
69
|
Retrieves a cookie by name. Returns `null` if the cookie doesn't exist.
|
|
70
70
|
|
|
71
|
-
```ts
|
|
71
|
+
```ts title="get-cookie.ts" icon="/icons/typescript.svg"
|
|
72
72
|
// Get by name
|
|
73
73
|
const cookie = cookies.get("session");
|
|
74
74
|
|
|
@@ -81,7 +81,7 @@ if (cookie != null) {
|
|
|
81
81
|
|
|
82
82
|
Checks if a cookie with the given name exists.
|
|
83
83
|
|
|
84
|
-
```ts
|
|
84
|
+
```ts title="has-cookie.ts" icon="/icons/typescript.svg"
|
|
85
85
|
// Check if cookie exists
|
|
86
86
|
if (cookies.has("session")) {
|
|
87
87
|
// Cookie exists
|
|
@@ -96,7 +96,7 @@ if (cookies.has("session")) {
|
|
|
96
96
|
|
|
97
97
|
Adds or updates a cookie in the map. Cookies default to `{ path: "/", sameSite: "lax" }`.
|
|
98
98
|
|
|
99
|
-
```ts
|
|
99
|
+
```ts title="set-cookie.ts" icon="/icons/typescript.svg"
|
|
100
100
|
// Set by name and value
|
|
101
101
|
cookies.set("session", "abc123");
|
|
102
102
|
|
|
@@ -119,7 +119,7 @@ cookies.set(cookie);
|
|
|
119
119
|
|
|
120
120
|
Removes a cookie from the map. When applied to a Response, this adds a cookie with an empty string value and an expiry date in the past. A cookie will only delete successfully on the browser if the domain and path is the same as it was when the cookie was created.
|
|
121
121
|
|
|
122
|
-
```ts
|
|
122
|
+
```ts title="delete-cookie.ts" icon="/icons/typescript.svg"
|
|
123
123
|
// Delete by name using default domain and path.
|
|
124
124
|
cookies.delete("session");
|
|
125
125
|
|
|
@@ -135,7 +135,7 @@ cookies.delete({
|
|
|
135
135
|
|
|
136
136
|
Converts the cookie map to a serializable format.
|
|
137
137
|
|
|
138
|
-
```ts
|
|
138
|
+
```ts title="cookie-to-json.ts" icon="/icons/typescript.svg"
|
|
139
139
|
const json = cookies.toJSON();
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -145,7 +145,7 @@ Returns an array of values for Set-Cookie headers that can be used to apply all
|
|
|
145
145
|
|
|
146
146
|
When using `Bun.serve()`, you don't need to call this method explicitly. Any changes made to the `req.cookies` map are automatically applied to the response headers. This method is primarily useful when working with other HTTP server implementations.
|
|
147
147
|
|
|
148
|
-
```
|
|
148
|
+
```js title="node-server.js" icon="file-code"
|
|
149
149
|
import { createServer } from "node:http";
|
|
150
150
|
import { CookieMap } from "bun";
|
|
151
151
|
|
|
@@ -172,7 +172,7 @@ server.listen(3000, () => {
|
|
|
172
172
|
|
|
173
173
|
`CookieMap` provides several methods for iteration:
|
|
174
174
|
|
|
175
|
-
```ts
|
|
175
|
+
```ts title="iterate-cookies.ts" icon="/icons/typescript.svg"
|
|
176
176
|
// Iterate over [name, cookie] entries
|
|
177
177
|
for (const [name, value] of cookies) {
|
|
178
178
|
console.log(`${name}: ${value}`);
|
|
@@ -205,7 +205,7 @@ cookies.forEach((value, name) => {
|
|
|
205
205
|
|
|
206
206
|
Returns the number of cookies in the map.
|
|
207
207
|
|
|
208
|
-
```ts
|
|
208
|
+
```ts title="cookie-size.ts" icon="/icons/typescript.svg"
|
|
209
209
|
console.log(cookies.size); // Number of cookies
|
|
210
210
|
```
|
|
211
211
|
|
|
@@ -213,7 +213,7 @@ console.log(cookies.size); // Number of cookies
|
|
|
213
213
|
|
|
214
214
|
`Bun.Cookie` represents an HTTP cookie with its name, value, and attributes.
|
|
215
215
|
|
|
216
|
-
```ts
|
|
216
|
+
```ts title="cookie-class.ts" icon="/icons/typescript.svg"
|
|
217
217
|
import { Cookie } from "bun";
|
|
218
218
|
|
|
219
219
|
// Create a basic cookie
|
|
@@ -243,7 +243,7 @@ const objCookie = new Bun.Cookie({
|
|
|
243
243
|
|
|
244
244
|
### Constructors
|
|
245
245
|
|
|
246
|
-
```ts
|
|
246
|
+
```ts title="constructors.ts" icon="/icons/typescript.svg"
|
|
247
247
|
// Basic constructor with name/value
|
|
248
248
|
new Bun.Cookie(name: string, value: string);
|
|
249
249
|
|
|
@@ -259,7 +259,7 @@ new Bun.Cookie(options: CookieInit);
|
|
|
259
259
|
|
|
260
260
|
### Properties
|
|
261
261
|
|
|
262
|
-
```ts
|
|
262
|
+
```ts title="cookie-properties.ts" icon="/icons/typescript.svg"
|
|
263
263
|
cookie.name; // string - Cookie name
|
|
264
264
|
cookie.value; // string - Cookie value
|
|
265
265
|
cookie.domain; // string | null - Domain scope (null if not specified)
|
|
@@ -278,7 +278,7 @@ cookie.httpOnly; // boolean - Accessible only via HTTP (not JavaScript)
|
|
|
278
278
|
|
|
279
279
|
Checks if the cookie has expired.
|
|
280
280
|
|
|
281
|
-
```ts
|
|
281
|
+
```ts title="is-expired.ts" icon="/icons/typescript.svg"
|
|
282
282
|
// Expired cookie (Date in the past)
|
|
283
283
|
const expiredCookie = new Bun.Cookie("name", "value", {
|
|
284
284
|
expires: new Date(Date.now() - 1000),
|
|
@@ -302,7 +302,7 @@ console.log(sessionCookie.isExpired()); // false
|
|
|
302
302
|
|
|
303
303
|
Returns a string representation of the cookie suitable for a `Set-Cookie` header.
|
|
304
304
|
|
|
305
|
-
```ts
|
|
305
|
+
```ts title="serialize-cookie.ts" icon="/icons/typescript.svg"
|
|
306
306
|
const cookie = new Bun.Cookie("session", "abc123", {
|
|
307
307
|
domain: "example.com",
|
|
308
308
|
path: "/admin",
|
|
@@ -322,7 +322,7 @@ console.log(cookie.toString());
|
|
|
322
322
|
|
|
323
323
|
Converts the cookie to a plain object suitable for JSON serialization.
|
|
324
324
|
|
|
325
|
-
```ts
|
|
325
|
+
```ts title="cookie-json.ts" icon="/icons/typescript.svg"
|
|
326
326
|
const cookie = new Bun.Cookie("session", "abc123", {
|
|
327
327
|
secure: true,
|
|
328
328
|
httpOnly: true,
|
|
@@ -349,7 +349,7 @@ const jsonString = JSON.stringify(cookie);
|
|
|
349
349
|
|
|
350
350
|
Parses a cookie string into a `Cookie` instance.
|
|
351
351
|
|
|
352
|
-
```ts
|
|
352
|
+
```ts title="parse-cookie.ts" icon="/icons/typescript.svg"
|
|
353
353
|
const cookie = Bun.Cookie.parse("name=value; Path=/; Secure; SameSite=Lax");
|
|
354
354
|
|
|
355
355
|
console.log(cookie.name); // "name"
|
|
@@ -363,7 +363,7 @@ console.log(cookie.sameSite); // "lax"
|
|
|
363
363
|
|
|
364
364
|
Factory method to create a cookie.
|
|
365
365
|
|
|
366
|
-
```ts
|
|
366
|
+
```ts title="cookie-from.ts" icon="/icons/typescript.svg"
|
|
367
367
|
const cookie = Bun.Cookie.from("session", "abc123", {
|
|
368
368
|
httpOnly: true,
|
|
369
369
|
secure: true,
|
|
@@ -373,7 +373,7 @@ const cookie = Bun.Cookie.from("session", "abc123", {
|
|
|
373
373
|
|
|
374
374
|
## Types
|
|
375
375
|
|
|
376
|
-
```ts
|
|
376
|
+
```ts title="types.ts" icon="/icons/typescript.svg"
|
|
377
377
|
interface CookieInit {
|
|
378
378
|
name?: string;
|
|
379
379
|
value?: string;
|
|
@@ -115,7 +115,7 @@ Here's a cheat sheet explaining the functions of the control flow buttons.
|
|
|
115
115
|
|
|
116
116
|
### Visual Studio Code Debugger
|
|
117
117
|
|
|
118
|
-
Experimental support for debugging Bun scripts is available in Visual Studio Code. To use it, you'll need to install the [Bun VSCode extension](
|
|
118
|
+
Experimental support for debugging Bun scripts is available in Visual Studio Code. To use it, you'll need to install the [Bun VSCode extension](/docs/guides/runtime/vscode-debugger).
|
|
119
119
|
|
|
120
120
|
---
|
|
121
121
|
|
|
@@ -146,11 +146,11 @@ await fetch("https://example.com", {
|
|
|
146
146
|
```
|
|
147
147
|
|
|
148
148
|
```txt
|
|
149
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.3.
|
|
149
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.3.3" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
150
150
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
151
151
|
[fetch] > content-type: application/json
|
|
152
152
|
[fetch] > Connection: keep-alive
|
|
153
|
-
[fetch] > User-Agent: Bun/1.3.
|
|
153
|
+
[fetch] > User-Agent: Bun/1.3.3
|
|
154
154
|
[fetch] > Accept: */*
|
|
155
155
|
[fetch] > Host: example.com
|
|
156
156
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -190,7 +190,7 @@ await fetch("https://example.com", {
|
|
|
190
190
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
191
191
|
[fetch] > content-type: application/json
|
|
192
192
|
[fetch] > Connection: keep-alive
|
|
193
|
-
[fetch] > User-Agent: Bun/1.3.
|
|
193
|
+
[fetch] > User-Agent: Bun/1.3.3
|
|
194
194
|
[fetch] > Accept: */*
|
|
195
195
|
[fetch] > Host: example.com
|
|
196
196
|
[fetch] > Accept-Encoding: gzip, deflate, br
|