@depup/bun-types 1.3.11-depup.0
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 +105 -0
- package/README.md +25 -0
- package/bun.d.ts +8712 -0
- package/bun.ns.d.ts +5 -0
- package/bundle.d.ts +74 -0
- package/changes.json +5 -0
- package/deprecated.d.ts +184 -0
- package/devserver.d.ts +187 -0
- package/docs/README.md +28 -0
- package/docs/bundler/bytecode.mdx +447 -0
- package/docs/bundler/css.mdx +1024 -0
- package/docs/bundler/esbuild.mdx +304 -0
- package/docs/bundler/executables.mdx +1318 -0
- package/docs/bundler/fullstack.mdx +1086 -0
- package/docs/bundler/hot-reloading.mdx +229 -0
- package/docs/bundler/html-static.mdx +498 -0
- package/docs/bundler/index.mdx +1840 -0
- package/docs/bundler/loaders.mdx +451 -0
- package/docs/bundler/macros.mdx +328 -0
- package/docs/bundler/minifier.mdx +1286 -0
- package/docs/bundler/plugins.mdx +477 -0
- package/docs/bundler/standalone-html.mdx +314 -0
- package/docs/feedback.mdx +75 -0
- package/docs/guides/binary/arraybuffer-to-array.mdx +29 -0
- package/docs/guides/binary/arraybuffer-to-blob.mdx +26 -0
- package/docs/guides/binary/arraybuffer-to-buffer.mdx +27 -0
- package/docs/guides/binary/arraybuffer-to-string.mdx +17 -0
- package/docs/guides/binary/arraybuffer-to-typedarray.mdx +41 -0
- package/docs/guides/binary/blob-to-arraybuffer.mdx +16 -0
- package/docs/guides/binary/blob-to-dataview.mdx +16 -0
- package/docs/guides/binary/blob-to-stream.mdx +16 -0
- package/docs/guides/binary/blob-to-string.mdx +17 -0
- package/docs/guides/binary/blob-to-typedarray.mdx +16 -0
- package/docs/guides/binary/buffer-to-arraybuffer.mdx +16 -0
- package/docs/guides/binary/buffer-to-blob.mdx +16 -0
- package/docs/guides/binary/buffer-to-readablestream.mdx +43 -0
- package/docs/guides/binary/buffer-to-string.mdx +27 -0
- package/docs/guides/binary/buffer-to-typedarray.mdx +16 -0
- package/docs/guides/binary/dataview-to-string.mdx +17 -0
- package/docs/guides/binary/typedarray-to-arraybuffer.mdx +27 -0
- package/docs/guides/binary/typedarray-to-blob.mdx +18 -0
- package/docs/guides/binary/typedarray-to-buffer.mdx +16 -0
- package/docs/guides/binary/typedarray-to-dataview.mdx +16 -0
- package/docs/guides/binary/typedarray-to-readablestream.mdx +43 -0
- package/docs/guides/binary/typedarray-to-string.mdx +18 -0
- package/docs/guides/deployment/aws-lambda.mdx +204 -0
- package/docs/guides/deployment/digital-ocean.mdx +161 -0
- package/docs/guides/deployment/google-cloud-run.mdx +194 -0
- package/docs/guides/deployment/railway.mdx +145 -0
- package/docs/guides/deployment/render.mdx +82 -0
- package/docs/guides/deployment/vercel.mdx +97 -0
- package/docs/guides/ecosystem/astro.mdx +82 -0
- package/docs/guides/ecosystem/discordjs.mdx +80 -0
- package/docs/guides/ecosystem/docker.mdx +151 -0
- package/docs/guides/ecosystem/drizzle.mdx +195 -0
- package/docs/guides/ecosystem/elysia.mdx +31 -0
- package/docs/guides/ecosystem/express.mdx +43 -0
- package/docs/guides/ecosystem/gel.mdx +261 -0
- package/docs/guides/ecosystem/hono.mdx +47 -0
- package/docs/guides/ecosystem/mongoose.mdx +92 -0
- package/docs/guides/ecosystem/neon-drizzle.mdx +234 -0
- package/docs/guides/ecosystem/neon-serverless-postgres.mdx +60 -0
- package/docs/guides/ecosystem/nextjs.mdx +103 -0
- package/docs/guides/ecosystem/nuxt.mdx +96 -0
- package/docs/guides/ecosystem/pm2.mdx +55 -0
- package/docs/guides/ecosystem/prisma-postgres.mdx +169 -0
- package/docs/guides/ecosystem/prisma.mdx +164 -0
- package/docs/guides/ecosystem/qwik.mdx +114 -0
- package/docs/guides/ecosystem/react.mdx +52 -0
- package/docs/guides/ecosystem/remix.mdx +97 -0
- package/docs/guides/ecosystem/sentry.mdx +54 -0
- package/docs/guides/ecosystem/solidstart.mdx +62 -0
- package/docs/guides/ecosystem/ssr-react.mdx +49 -0
- package/docs/guides/ecosystem/stric.mdx +54 -0
- package/docs/guides/ecosystem/sveltekit.mdx +138 -0
- package/docs/guides/ecosystem/systemd.mdx +114 -0
- package/docs/guides/ecosystem/tanstack-start.mdx +791 -0
- package/docs/guides/ecosystem/upstash.mdx +87 -0
- package/docs/guides/ecosystem/vite.mdx +77 -0
- package/docs/guides/html-rewriter/extract-links.mdx +71 -0
- package/docs/guides/html-rewriter/extract-social-meta.mdx +97 -0
- package/docs/guides/http/cluster.mdx +69 -0
- package/docs/guides/http/fetch-unix.mdx +35 -0
- package/docs/guides/http/fetch.mdx +26 -0
- package/docs/guides/http/file-uploads.mdx +97 -0
- package/docs/guides/http/hot.mdx +28 -0
- package/docs/guides/http/proxy.mdx +50 -0
- package/docs/guides/http/server.mdx +48 -0
- package/docs/guides/http/simple.mdx +20 -0
- package/docs/guides/http/sse.mdx +91 -0
- package/docs/guides/http/stream-file.mdx +50 -0
- package/docs/guides/http/stream-iterator.mdx +49 -0
- package/docs/guides/http/stream-node-streams-in-bun.mdx +22 -0
- package/docs/guides/http/tls.mdx +32 -0
- package/docs/guides/index.mdx +10 -0
- package/docs/guides/install/add-dev.mdx +28 -0
- package/docs/guides/install/add-git.mdx +40 -0
- package/docs/guides/install/add-optional.mdx +27 -0
- package/docs/guides/install/add-peer.mdx +45 -0
- package/docs/guides/install/add-tarball.mdx +35 -0
- package/docs/guides/install/add.mdx +44 -0
- package/docs/guides/install/azure-artifacts.mdx +76 -0
- package/docs/guides/install/cicd.mdx +43 -0
- package/docs/guides/install/custom-registry.mdx +32 -0
- package/docs/guides/install/from-npm-install-to-bun-install.mdx +230 -0
- package/docs/guides/install/git-diff-bun-lockfile.mdx +48 -0
- package/docs/guides/install/jfrog-artifactory.mdx +28 -0
- package/docs/guides/install/npm-alias.mdx +25 -0
- package/docs/guides/install/registry-scope.mdx +40 -0
- package/docs/guides/install/trusted.mdx +52 -0
- package/docs/guides/install/workspaces.mdx +70 -0
- package/docs/guides/install/yarnlock.mdx +51 -0
- package/docs/guides/process/argv.mdx +66 -0
- package/docs/guides/process/ctrl-c.mdx +18 -0
- package/docs/guides/process/ipc.mdx +69 -0
- package/docs/guides/process/nanoseconds.mdx +15 -0
- package/docs/guides/process/os-signals.mdx +31 -0
- package/docs/guides/process/spawn-stderr.mdx +34 -0
- package/docs/guides/process/spawn-stdout.mdx +28 -0
- package/docs/guides/process/spawn.mdx +43 -0
- package/docs/guides/process/stdin.mdx +62 -0
- package/docs/guides/read-file/arraybuffer.mdx +30 -0
- package/docs/guides/read-file/buffer.mdx +21 -0
- package/docs/guides/read-file/exists.mdx +18 -0
- package/docs/guides/read-file/json.mdx +19 -0
- package/docs/guides/read-file/mime.mdx +22 -0
- package/docs/guides/read-file/stream.mdx +28 -0
- package/docs/guides/read-file/string.mdx +24 -0
- package/docs/guides/read-file/uint8array.mdx +23 -0
- package/docs/guides/read-file/watch.mdx +66 -0
- package/docs/guides/runtime/build-time-constants.mdx +295 -0
- package/docs/guides/runtime/cicd.mdx +45 -0
- package/docs/guides/runtime/codesign-macos-executable.mdx +61 -0
- package/docs/guides/runtime/define-constant.mdx +149 -0
- package/docs/guides/runtime/delete-directory.mdx +39 -0
- package/docs/guides/runtime/delete-file.mdx +21 -0
- package/docs/guides/runtime/heap-snapshot.mdx +28 -0
- package/docs/guides/runtime/import-html.mdx +15 -0
- package/docs/guides/runtime/import-json.mdx +46 -0
- package/docs/guides/runtime/import-json5.mdx +74 -0
- package/docs/guides/runtime/import-toml.mdx +32 -0
- package/docs/guides/runtime/import-yaml.mdx +104 -0
- package/docs/guides/runtime/read-env.mdx +37 -0
- package/docs/guides/runtime/set-env.mdx +51 -0
- package/docs/guides/runtime/shell.mdx +42 -0
- package/docs/guides/runtime/timezone.mdx +38 -0
- package/docs/guides/runtime/tsconfig-paths.mdx +31 -0
- package/docs/guides/runtime/typescript.mdx +51 -0
- package/docs/guides/runtime/vscode-debugger.mdx +47 -0
- package/docs/guides/runtime/web-debugger.mdx +103 -0
- package/docs/guides/streams/node-readable-to-arraybuffer.mdx +13 -0
- package/docs/guides/streams/node-readable-to-blob.mdx +13 -0
- package/docs/guides/streams/node-readable-to-json.mdx +14 -0
- package/docs/guides/streams/node-readable-to-string.mdx +14 -0
- package/docs/guides/streams/node-readable-to-uint8array.mdx +13 -0
- package/docs/guides/streams/to-array.mdx +16 -0
- package/docs/guides/streams/to-arraybuffer.mdx +16 -0
- package/docs/guides/streams/to-blob.mdx +16 -0
- package/docs/guides/streams/to-buffer.mdx +17 -0
- package/docs/guides/streams/to-json.mdx +16 -0
- package/docs/guides/streams/to-string.mdx +16 -0
- package/docs/guides/streams/to-typedarray.mdx +24 -0
- package/docs/guides/test/bail.mdx +24 -0
- package/docs/guides/test/concurrent-test-glob.mdx +146 -0
- package/docs/guides/test/coverage-threshold.mdx +67 -0
- package/docs/guides/test/coverage.mdx +49 -0
- package/docs/guides/test/happy-dom.mdx +73 -0
- package/docs/guides/test/migrate-from-jest.mdx +125 -0
- package/docs/guides/test/mock-clock.mdx +50 -0
- package/docs/guides/test/mock-functions.mdx +70 -0
- package/docs/guides/test/rerun-each.mdx +16 -0
- package/docs/guides/test/run-tests.mdx +116 -0
- package/docs/guides/test/skip-tests.mdx +43 -0
- package/docs/guides/test/snapshot.mdx +102 -0
- package/docs/guides/test/spy-on.mdx +49 -0
- package/docs/guides/test/svelte-test.mdx +113 -0
- package/docs/guides/test/testing-library.mdx +93 -0
- package/docs/guides/test/timeout.mdx +17 -0
- package/docs/guides/test/todo-tests.mdx +74 -0
- package/docs/guides/test/update-snapshots.mdx +49 -0
- package/docs/guides/test/watch-mode.mdx +24 -0
- package/docs/guides/util/base64.mdx +17 -0
- package/docs/guides/util/deep-equals.mdx +41 -0
- package/docs/guides/util/deflate.mdx +20 -0
- package/docs/guides/util/detect-bun.mdx +28 -0
- package/docs/guides/util/entrypoint.mdx +19 -0
- package/docs/guides/util/escape-html.mdx +24 -0
- package/docs/guides/util/file-url-to-path.mdx +16 -0
- package/docs/guides/util/gzip.mdx +20 -0
- package/docs/guides/util/hash-a-password.mdx +56 -0
- package/docs/guides/util/import-meta-dir.mdx +15 -0
- package/docs/guides/util/import-meta-file.mdx +15 -0
- package/docs/guides/util/import-meta-path.mdx +15 -0
- package/docs/guides/util/javascript-uuid.mdx +25 -0
- package/docs/guides/util/main.mdx +43 -0
- package/docs/guides/util/path-to-file-url.mdx +16 -0
- package/docs/guides/util/sleep.mdx +24 -0
- package/docs/guides/util/upgrade.mdx +93 -0
- package/docs/guides/util/version.mdx +23 -0
- package/docs/guides/util/which-path-to-executable-bin.mdx +17 -0
- package/docs/guides/websocket/compression.mdx +33 -0
- package/docs/guides/websocket/context.mdx +79 -0
- package/docs/guides/websocket/pubsub.mdx +43 -0
- package/docs/guides/websocket/simple.mdx +38 -0
- package/docs/guides/write-file/append.mdx +54 -0
- package/docs/guides/write-file/basic.mdx +46 -0
- package/docs/guides/write-file/blob.mdx +30 -0
- package/docs/guides/write-file/cat.mdx +19 -0
- package/docs/guides/write-file/file-cp.mdx +18 -0
- package/docs/guides/write-file/filesink.mdx +54 -0
- package/docs/guides/write-file/response.mdx +19 -0
- package/docs/guides/write-file/stdout.mdx +23 -0
- package/docs/guides/write-file/stream.mdx +19 -0
- package/docs/guides/write-file/unlink.mdx +18 -0
- package/docs/index.mdx +133 -0
- package/docs/installation.mdx +372 -0
- package/docs/pm/bunx.mdx +91 -0
- package/docs/pm/catalogs.mdx +292 -0
- package/docs/pm/cli/add.mdx +179 -0
- package/docs/pm/cli/audit.mdx +60 -0
- package/docs/pm/cli/info.mdx +70 -0
- package/docs/pm/cli/install.mdx +591 -0
- package/docs/pm/cli/link.mdx +61 -0
- package/docs/pm/cli/outdated.mdx +197 -0
- package/docs/pm/cli/patch.mdx +69 -0
- package/docs/pm/cli/pm.mdx +323 -0
- package/docs/pm/cli/publish.mdx +131 -0
- package/docs/pm/cli/remove.mdx +16 -0
- package/docs/pm/cli/update.mdx +140 -0
- package/docs/pm/cli/why.mdx +84 -0
- package/docs/pm/filter.mdx +127 -0
- package/docs/pm/global-cache.mdx +72 -0
- package/docs/pm/isolated-installs.mdx +220 -0
- package/docs/pm/lifecycle.mdx +64 -0
- package/docs/pm/lockfile.mdx +64 -0
- package/docs/pm/npmrc.mdx +245 -0
- package/docs/pm/overrides.mdx +83 -0
- package/docs/pm/scopes-registries.mdx +35 -0
- package/docs/pm/security-scanner-api.mdx +95 -0
- package/docs/pm/workspaces.mdx +115 -0
- package/docs/project/benchmarking.mdx +296 -0
- package/docs/project/bindgen.mdx +223 -0
- package/docs/project/building-windows.mdx +143 -0
- package/docs/project/contributing.mdx +366 -0
- package/docs/project/feedback.mdx +20 -0
- package/docs/project/license.mdx +78 -0
- package/docs/project/roadmap.mdx +8 -0
- package/docs/quickstart.mdx +251 -0
- package/docs/runtime/archive.mdx +452 -0
- package/docs/runtime/auto-install.mdx +97 -0
- package/docs/runtime/binary-data.mdx +846 -0
- package/docs/runtime/bun-apis.mdx +60 -0
- package/docs/runtime/bunfig.mdx +765 -0
- package/docs/runtime/c-compiler.mdx +204 -0
- package/docs/runtime/child-process.mdx +659 -0
- package/docs/runtime/color.mdx +267 -0
- package/docs/runtime/console.mdx +67 -0
- package/docs/runtime/cookies.mdx +454 -0
- package/docs/runtime/cron.mdx +358 -0
- package/docs/runtime/csrf.mdx +171 -0
- package/docs/runtime/debugger.mdx +335 -0
- package/docs/runtime/environment-variables.mdx +231 -0
- package/docs/runtime/ffi.mdx +567 -0
- package/docs/runtime/file-io.mdx +306 -0
- package/docs/runtime/file-system-router.mdx +118 -0
- package/docs/runtime/file-types.mdx +482 -0
- package/docs/runtime/glob.mdx +181 -0
- package/docs/runtime/globals.mdx +72 -0
- package/docs/runtime/hashing.mdx +315 -0
- package/docs/runtime/html-rewriter.mdx +333 -0
- package/docs/runtime/http/cookies.mdx +79 -0
- package/docs/runtime/http/error-handling.mdx +40 -0
- package/docs/runtime/http/metrics.mdx +36 -0
- package/docs/runtime/http/routing.mdx +289 -0
- package/docs/runtime/http/server.mdx +672 -0
- package/docs/runtime/http/tls.mdx +101 -0
- package/docs/runtime/http/websockets.mdx +414 -0
- package/docs/runtime/index.mdx +223 -0
- package/docs/runtime/json5.mdx +271 -0
- package/docs/runtime/jsonl.mdx +188 -0
- package/docs/runtime/jsx.mdx +115 -0
- package/docs/runtime/markdown.mdx +381 -0
- package/docs/runtime/module-resolution.mdx +374 -0
- package/docs/runtime/networking/dns.mdx +111 -0
- package/docs/runtime/networking/fetch.mdx +484 -0
- package/docs/runtime/networking/tcp.mdx +239 -0
- package/docs/runtime/networking/udp.mdx +180 -0
- package/docs/runtime/node-api.mdx +19 -0
- package/docs/runtime/nodejs-compat.mdx +468 -0
- package/docs/runtime/plugins.mdx +419 -0
- package/docs/runtime/redis.mdx +583 -0
- package/docs/runtime/repl.mdx +176 -0
- package/docs/runtime/s3.mdx +881 -0
- package/docs/runtime/secrets.mdx +340 -0
- package/docs/runtime/semver.mdx +57 -0
- package/docs/runtime/shell.mdx +637 -0
- package/docs/runtime/sql.mdx +1404 -0
- package/docs/runtime/sqlite.mdx +721 -0
- package/docs/runtime/streams.mdx +232 -0
- package/docs/runtime/templating/create.mdx +269 -0
- package/docs/runtime/templating/init.mdx +58 -0
- package/docs/runtime/toml.mdx +238 -0
- package/docs/runtime/transpiler.mdx +288 -0
- package/docs/runtime/typescript.mdx +58 -0
- package/docs/runtime/utils.mdx +1010 -0
- package/docs/runtime/watch-mode.mdx +161 -0
- package/docs/runtime/web-apis.mdx +29 -0
- package/docs/runtime/workers.mdx +314 -0
- package/docs/runtime/yaml.mdx +470 -0
- package/docs/snippets/cli/add.mdx +166 -0
- package/docs/snippets/cli/build.mdx +197 -0
- package/docs/snippets/cli/bunx.mdx +49 -0
- package/docs/snippets/cli/feedback.mdx +17 -0
- package/docs/snippets/cli/init.mdx +84 -0
- package/docs/snippets/cli/install.mdx +173 -0
- package/docs/snippets/cli/link.mdx +163 -0
- package/docs/snippets/cli/outdated.mdx +140 -0
- package/docs/snippets/cli/patch.mdx +171 -0
- package/docs/snippets/cli/publish.mdx +198 -0
- package/docs/snippets/cli/remove.mdx +146 -0
- package/docs/snippets/cli/run.mdx +305 -0
- package/docs/snippets/cli/test.mdx +105 -0
- package/docs/snippets/cli/update.mdx +144 -0
- package/docs/test/code-coverage.mdx +409 -0
- package/docs/test/configuration.mdx +574 -0
- package/docs/test/dates-times.mdx +129 -0
- package/docs/test/discovery.mdx +90 -0
- package/docs/test/dom.mdx +226 -0
- package/docs/test/index.mdx +409 -0
- package/docs/test/lifecycle.mdx +366 -0
- package/docs/test/mocks.mdx +637 -0
- package/docs/test/reporters.mdx +126 -0
- package/docs/test/runtime-behavior.mdx +342 -0
- package/docs/test/snapshots.mdx +434 -0
- package/docs/test/writing-tests.mdx +672 -0
- package/docs/typescript.mdx +54 -0
- package/extensions.d.ts +40 -0
- package/fetch.d.ts +79 -0
- package/ffi.d.ts +1154 -0
- package/globals.d.ts +2067 -0
- package/html-rewriter.d.ts +186 -0
- package/index.d.ts +32 -0
- package/jsc.d.ts +233 -0
- package/jsx.d.ts +11 -0
- package/overrides.d.ts +376 -0
- package/package.json +53 -0
- package/redis.d.ts +3352 -0
- package/s3.d.ts +1354 -0
- package/security.d.ts +101 -0
- package/serve.d.ts +1296 -0
- package/shell.d.ts +380 -0
- package/sql.d.ts +887 -0
- package/sqlite.d.ts +1322 -0
- package/test-globals.d.ts +22 -0
- package/test.d.ts +2392 -0
- package/vendor/expect-type/branding.d.ts +283 -0
- package/vendor/expect-type/index.d.ts +1207 -0
- package/vendor/expect-type/messages.d.ts +395 -0
- package/vendor/expect-type/overloads.d.ts +669 -0
- package/vendor/expect-type/utils.d.ts +431 -0
- package/wasm.d.ts +193 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Update snapshots in `bun test`
|
|
3
|
+
sidebarTitle: Update snapshots
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun's test runner supports Jest-style snapshot testing via `.toMatchSnapshot()`.
|
|
8
|
+
|
|
9
|
+
```ts snap.test.ts icon="/icons/typescript.svg"
|
|
10
|
+
import { test, expect } from "bun:test";
|
|
11
|
+
|
|
12
|
+
test("snapshot", () => {
|
|
13
|
+
expect({ foo: "bar" }).toMatchSnapshot();
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
The first time this test is executed, Bun will write a snapshot file to disk in a directory called `__snapshots__` that lives alongside the test file.
|
|
20
|
+
|
|
21
|
+
```txt File Tree icon="folder-tree"
|
|
22
|
+
test
|
|
23
|
+
├── __snapshots__
|
|
24
|
+
│ └── snap.test.ts.snap
|
|
25
|
+
└── snap.test.ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
To regenerate snapshots, use the `--update-snapshots` flag.
|
|
31
|
+
|
|
32
|
+
```sh terminal icon="terminal"
|
|
33
|
+
bun test --update-snapshots
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```txt
|
|
37
|
+
test/snap.test.ts:
|
|
38
|
+
✓ snapshot [0.86ms]
|
|
39
|
+
|
|
40
|
+
1 pass
|
|
41
|
+
0 fail
|
|
42
|
+
snapshots: +1 added # the snapshot was regenerated
|
|
43
|
+
1 expect() calls
|
|
44
|
+
Ran 1 tests across 1 files. [102.00ms]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
See [Docs > Test Runner > Snapshots](/docs/test/snapshots) for complete documentation on snapshots with the Bun test runner.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Run tests in watch mode with Bun
|
|
3
|
+
sidebarTitle: Watch mode
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use the `--watch` flag to run your tests in watch mode.
|
|
8
|
+
|
|
9
|
+
```sh terminal icon="terminal"
|
|
10
|
+
bun test --watch
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
This will restart the running Bun process whenever a file change is detected. It's fast. In this example, the editor is configured to save the file on every keystroke.
|
|
16
|
+
|
|
17
|
+
<Frame>
|
|
18
|
+

|
|
20
|
+
</Frame>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
See [Docs > Test Runner](/docs/test) for complete documentation on the test runner.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Encode and decode base64 strings
|
|
3
|
+
sidebarTitle: Base64 encoding
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun implements the Web-standard [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/atob) and [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/btoa) functions for encoding and decoding base64 strings.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const data = "hello world";
|
|
11
|
+
const encoded = btoa(data); // => "aGVsbG8gd29ybGQ="
|
|
12
|
+
const decoded = atob(encoded); // => "hello world"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
See [Docs > Web APIs](/docs/runtime/web-apis) for a complete breakdown of the Web APIs implemented in Bun.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Check if two objects are deeply equal
|
|
3
|
+
sidebarTitle: Deep equality
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Check if two objects are deeply equal. This is used internally by `expect().toEqual()` in Bun's [test runner](/docs/test/writing-tests).
|
|
8
|
+
|
|
9
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
10
|
+
const a = { a: 1, b: 2, c: { d: 3 } };
|
|
11
|
+
const b = { a: 1, b: 2, c: { d: 3 } };
|
|
12
|
+
|
|
13
|
+
Bun.deepEquals(a, b); // true
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
Pass `true` as a third argument to enable strict mode. This is used internally by `expect().toStrictEqual()` in Bun's [test runner](/docs/test/writing-tests).
|
|
19
|
+
|
|
20
|
+
The following examples would return `true` in non-strict mode but `false` in strict mode.
|
|
21
|
+
|
|
22
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
23
|
+
// undefined values
|
|
24
|
+
Bun.deepEquals({}, { a: undefined }, true); // false
|
|
25
|
+
|
|
26
|
+
// undefined in arrays
|
|
27
|
+
Bun.deepEquals(["asdf"], ["asdf", undefined], true); // false
|
|
28
|
+
|
|
29
|
+
// sparse arrays
|
|
30
|
+
Bun.deepEquals([, 1], [undefined, 1], true); // false
|
|
31
|
+
|
|
32
|
+
// object literals vs instances w/ same properties
|
|
33
|
+
class Foo {
|
|
34
|
+
a = 1;
|
|
35
|
+
}
|
|
36
|
+
Bun.deepEquals(new Foo(), { a: 1 }, true); // false
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Compress and decompress data with DEFLATE
|
|
3
|
+
sidebarTitle: DEFLATE compression
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use `Bun.deflateSync()` to compress a `Uint8Array` with DEFLATE.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const data = Buffer.from("Hello, world!");
|
|
11
|
+
const compressed = Bun.deflateSync("Hello, world!");
|
|
12
|
+
// => Uint8Array
|
|
13
|
+
|
|
14
|
+
const decompressed = Bun.inflateSync(compressed);
|
|
15
|
+
// => Uint8Array
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Detect when code is executed with Bun
|
|
3
|
+
sidebarTitle: Detect Bun
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The recommended way to detect when code is being executed with Bun is to check `process.versions.bun`. This works in both JavaScript and TypeScript without requiring any additional type definitions.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
if (process.versions.bun) {
|
|
11
|
+
// this code will only run when the file is run with Bun
|
|
12
|
+
}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
Alternatively, you can check for the existence of the `Bun` global. This is similar to how you'd check for the existence of the `window` variable to detect when code is being executed in a browser.
|
|
18
|
+
|
|
19
|
+
<Note>
|
|
20
|
+
This approach will result in a type error in TypeScript unless `@types/bun` is installed. You can install it with `bun
|
|
21
|
+
add -d @types/bun`.
|
|
22
|
+
</Note>
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
if (typeof Bun !== "undefined") {
|
|
26
|
+
// this code will only run when the file is run with Bun
|
|
27
|
+
}
|
|
28
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Check if the current file is the entrypoint
|
|
3
|
+
sidebarTitle: Check entrypoint
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun provides a handful of module-specific utilities on the [`import.meta`](/docs/runtime/module-resolution#import-meta) object. Use `import.meta.main` to check if the current file is the entrypoint of the current process.
|
|
8
|
+
|
|
9
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
10
|
+
if (import.meta.main) {
|
|
11
|
+
// this file is directly executed with `bun run`
|
|
12
|
+
} else {
|
|
13
|
+
// this file is being imported by another file
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
See [Docs > API > import.meta](/docs/runtime/module-resolution#import-meta) for complete documentation.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Escape an HTML string
|
|
3
|
+
sidebarTitle: Escape HTML
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `Bun.escapeHTML()` utility can be used to escape HTML characters in a string. The following replacements are made.
|
|
8
|
+
|
|
9
|
+
- `"` becomes `"""`
|
|
10
|
+
- `&` becomes `"&"`
|
|
11
|
+
- `'` becomes `"'"`
|
|
12
|
+
- `<` becomes `"<"`
|
|
13
|
+
- `>` becomes `">"`
|
|
14
|
+
|
|
15
|
+
This function is optimized for large input. Non-string types will be converted to a string before escaping.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
Bun.escapeHTML("<script>alert('Hello World!')</script>");
|
|
19
|
+
// <script>alert('Hello World!')</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert a file URL to an absolute path
|
|
3
|
+
sidebarTitle: File URL to path
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use `Bun.fileURLToPath()` to convert a `file://` URL to an absolute path.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
Bun.fileURLToPath("file:///path/to/file.txt");
|
|
11
|
+
// => "/path/to/file.txt"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Compress and decompress data with gzip
|
|
3
|
+
sidebarTitle: Gzip compression
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use `Bun.gzipSync()` to compress a `Uint8Array` with gzip.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const data = Buffer.from("Hello, world!");
|
|
11
|
+
const compressed = Bun.gzipSync(data);
|
|
12
|
+
// => Uint8Array
|
|
13
|
+
|
|
14
|
+
const decompressed = Bun.gunzipSync(compressed);
|
|
15
|
+
// => Uint8Array
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Hash a password
|
|
3
|
+
sidebarTitle: Hash password
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `Bun.password.hash()` function provides a fast, built-in mechanism for securely hashing passwords in Bun. No third-party dependencies are required.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const password = "super-secure-pa$$word";
|
|
11
|
+
|
|
12
|
+
const hash = await Bun.password.hash(password);
|
|
13
|
+
// => $argon2id$v=19$m=65536,t=2,p=1$tFq+9AVr1bfPxQdh6E8DQRhEXg/M/...
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
By default, this uses the [Argon2id](https://en.wikipedia.org/wiki/Argon2) algorithm. Pass a second argument to `Bun.password.hash()` to use a different algorithm or configure the hashing parameters.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
const password = "super-secure-pa$$word";
|
|
22
|
+
|
|
23
|
+
// use argon2 (default)
|
|
24
|
+
const argonHash = await Bun.password.hash(password, {
|
|
25
|
+
memoryCost: 4, // memory usage in kibibytes
|
|
26
|
+
timeCost: 3, // the number of iterations
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
Bun also implements the [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Specify `algorithm: "bcrypt"` to use it.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
// use bcrypt
|
|
36
|
+
const bcryptHash = await Bun.password.hash(password, {
|
|
37
|
+
algorithm: "bcrypt",
|
|
38
|
+
cost: 4, // number between 4-31
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
Use `Bun.password.verify()` to verify a password. The algorithm and its parameters are stored in the hash itself, so re-specifying configuration is unnecessary.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
const password = "super-secure-pa$$word";
|
|
48
|
+
const hash = await Bun.password.hash(password);
|
|
49
|
+
|
|
50
|
+
const isMatch = await Bun.password.verify(password, hash);
|
|
51
|
+
// => true
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
See [Docs > API > Hashing](/docs/runtime/hashing#bun-password) for complete documentation.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the directory of the current file
|
|
3
|
+
sidebarTitle: import.meta.dir
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun provides a handful of module-specific utilities on the [`import.meta`](/docs/runtime/module-resolution#import-meta) object.
|
|
8
|
+
|
|
9
|
+
```ts /a/b/c.ts icon="/icons/typescript.svg"
|
|
10
|
+
import.meta.dir; // => "/a/b"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
See [Docs > API > import.meta](/docs/runtime/module-resolution#import-meta) for complete documentation.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the file name of the current file
|
|
3
|
+
sidebarTitle: import.meta.file
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun provides a handful of module-specific utilities on the [`import.meta`](/docs/runtime/module-resolution#import-meta) object. Use `import.meta.file` to retrieve the name of the current file.
|
|
8
|
+
|
|
9
|
+
```ts /a/b/c.ts icon="/icons/typescript.svg"
|
|
10
|
+
import.meta.file; // => "c.ts"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
See [Docs > API > import.meta](/docs/runtime/module-resolution#import-meta) for complete documentation.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the absolute path of the current file
|
|
3
|
+
sidebarTitle: import.meta.path
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun provides a handful of module-specific utilities on the [`import.meta`](/docs/runtime/module-resolution#import-meta) object. Use `import.meta.path` to retrieve the absolute path of the current file.
|
|
8
|
+
|
|
9
|
+
```ts /a/b/c.ts icon="/icons/typescript.svg"
|
|
10
|
+
import.meta.path; // => "/a/b/c.ts"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
See [Docs > API > import.meta](/docs/runtime/module-resolution#import-meta) for complete documentation.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Generate a UUID
|
|
3
|
+
sidebarTitle: Generate UUID
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use `crypto.randomUUID()` to generate a UUID v4. This API works in Bun, Node.js, and browsers. It requires no dependencies.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
crypto.randomUUID();
|
|
11
|
+
// => "123e4567-e89b-42d3-a456-426614174000"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
In Bun, you can also use `Bun.randomUUIDv7()` to generate a [UUID v7](https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-01.html).
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
Bun.randomUUIDv7();
|
|
20
|
+
// => "0196a000-bb12-7000-905e-8039f5d5b206"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the absolute path to the current entrypoint
|
|
3
|
+
sidebarTitle: Get entrypoint path
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `Bun.main` property contains the absolute path to the current entrypoint.
|
|
8
|
+
|
|
9
|
+
<CodeGroup>
|
|
10
|
+
|
|
11
|
+
```ts foo.ts icon="/icons/typescript.svg"
|
|
12
|
+
console.log(Bun.main);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
16
|
+
import "./foo.ts";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
</CodeGroup>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
The printed path corresponds to the file that is executed with `bun run`.
|
|
24
|
+
|
|
25
|
+
```sh terminal icon="terminal"
|
|
26
|
+
bun run index.ts
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```txt
|
|
30
|
+
/path/to/index.ts
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```sh terminal icon="terminal"
|
|
34
|
+
bun run foo.ts
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```txt
|
|
38
|
+
/path/to/foo.ts
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Convert an absolute path to a file URL
|
|
3
|
+
sidebarTitle: Path to file URL
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Use `Bun.pathToFileURL()` to convert an absolute path to a `file://` URL.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
Bun.pathToFileURL("/path/to/file.txt");
|
|
11
|
+
// => "file:///path/to/file.txt"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Sleep for a fixed number of milliseconds
|
|
3
|
+
sidebarTitle: Sleep
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
The `Bun.sleep` method provides a convenient way to create a void `Promise` that resolves in a fixed number of milliseconds.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// sleep for 1 second
|
|
11
|
+
await Bun.sleep(1000);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
Internally, this is equivalent to the following snippet that uses [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Upgrade Bun to the latest version
|
|
3
|
+
sidebarTitle: Upgrade Bun
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Bun can upgrade itself using the built-in `bun upgrade` command. This is the fastest way to get the latest features and bug fixes.
|
|
8
|
+
|
|
9
|
+
```bash terminal icon="terminal"
|
|
10
|
+
bun upgrade
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This downloads and installs the latest stable version of Bun, replacing the currently installed version.
|
|
14
|
+
|
|
15
|
+
<Note>To see the current version of Bun, run `bun --version`.</Note>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Verify the upgrade
|
|
20
|
+
|
|
21
|
+
After upgrading, verify the new version:
|
|
22
|
+
|
|
23
|
+
```bash terminal icon="terminal"
|
|
24
|
+
bun --version
|
|
25
|
+
# Output: 1.x.y
|
|
26
|
+
|
|
27
|
+
# See the exact commit of the Bun binary
|
|
28
|
+
bun --revision
|
|
29
|
+
# Output: 1.x.y+abc123def
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Upgrade to canary builds
|
|
35
|
+
|
|
36
|
+
Canary builds are automatically released on every commit to the `main` branch. These are untested but useful for trying new features or verifying bug fixes before they're released.
|
|
37
|
+
|
|
38
|
+
```bash terminal icon="terminal"
|
|
39
|
+
bun upgrade --canary
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
<Warning>Canary builds are not recommended for production use. They may contain bugs or breaking changes.</Warning>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Switch back to stable
|
|
47
|
+
|
|
48
|
+
If you're on a canary build and want to return to the latest stable release:
|
|
49
|
+
|
|
50
|
+
```bash terminal icon="terminal"
|
|
51
|
+
bun upgrade --stable
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Install a specific version
|
|
57
|
+
|
|
58
|
+
To install a specific version of Bun, use the install script with a version tag:
|
|
59
|
+
|
|
60
|
+
<Tabs>
|
|
61
|
+
<Tab title="macOS & Linux">
|
|
62
|
+
```bash terminal icon="terminal"
|
|
63
|
+
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.3"
|
|
64
|
+
```
|
|
65
|
+
</Tab>
|
|
66
|
+
<Tab title="Windows">
|
|
67
|
+
```powershell PowerShell icon="windows"
|
|
68
|
+
iex "& {$(irm https://bun.sh/install.ps1)} -Version 1.3.3"
|
|
69
|
+
```
|
|
70
|
+
</Tab>
|
|
71
|
+
</Tabs>
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Package manager users
|
|
76
|
+
|
|
77
|
+
If you installed Bun via a package manager, use that package manager to upgrade instead of `bun upgrade` to avoid conflicts.
|
|
78
|
+
|
|
79
|
+
<Tip>
|
|
80
|
+
**Homebrew users** <br />
|
|
81
|
+
To avoid conflicts with Homebrew, use `brew upgrade bun` instead.
|
|
82
|
+
|
|
83
|
+
**Scoop users** <br />
|
|
84
|
+
To avoid conflicts with Scoop, use `scoop update bun` instead.
|
|
85
|
+
|
|
86
|
+
</Tip>
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## See also
|
|
91
|
+
|
|
92
|
+
- [Installation](/docs/installation) — Install Bun for the first time
|
|
93
|
+
- [Update packages](/docs/pm/cli/update) — Update dependencies to latest versions
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the current Bun version
|
|
3
|
+
sidebarTitle: Get Bun version
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Get the current version of Bun in a semver format.
|
|
8
|
+
|
|
9
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
10
|
+
Bun.version; // => "1.3.3"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
Get the exact `git` commit of [`oven-sh/bun`](https://github.com/oven-sh/bun) that was compiled to produce this Bun binary.
|
|
16
|
+
|
|
17
|
+
```ts index.ts icon="/icons/typescript.svg"
|
|
18
|
+
Bun.revision; // => "49231b2cb9aa48497ab966fc0bb6b742dacc4994"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
See [Docs > API > Utils](/docs/runtime/utils) for more useful utilities.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Get the path to an executable bin file
|
|
3
|
+
sidebarTitle: Find executable path
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`Bun.which` is a utility function to find the absolute path of an executable file. It is similar to the `which` command in Unix-like systems.
|
|
8
|
+
|
|
9
|
+
```ts foo.ts icon="/icons/typescript.svg"
|
|
10
|
+
Bun.which("sh"); // => "/bin/sh"
|
|
11
|
+
Bun.which("notfound"); // => null
|
|
12
|
+
Bun.which("bun"); // => "/home/user/.bun/bin/bun"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
See [Docs > API > Utils](/docs/runtime/utils#bun-which) for complete documentation.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Enable compression for WebSocket messages
|
|
3
|
+
sidebarTitle: Enable compression
|
|
4
|
+
mode: center
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Per-message compression can be enabled with the `perMessageDeflate` parameter. When set, all messages will be compressed using the [permessage-deflate](https://tools.ietf.org/html/rfc7692) WebSocket extension.
|
|
8
|
+
|
|
9
|
+
```ts server.ts icon="/icons/typescript.svg"
|
|
10
|
+
Bun.serve({
|
|
11
|
+
// ...
|
|
12
|
+
websocket: {
|
|
13
|
+
// enable compression
|
|
14
|
+
perMessageDeflate: true,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
To enable compression for individual messages, pass `true` as the second parameter to `ws.send()`.
|
|
22
|
+
|
|
23
|
+
```ts server.ts icon="/icons/typescript.svg"
|
|
24
|
+
Bun.serve({
|
|
25
|
+
// ...
|
|
26
|
+
websocket: {
|
|
27
|
+
async message(ws, message) {
|
|
28
|
+
// send a compressed message
|
|
29
|
+
ws.send(message, true);
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|