bun-types 1.1.37-canary.20241123T140655 → 1.1.37-canary.20241125T140601
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/docs/api/binary-data.md +1028 -0
- package/docs/api/cc.md +197 -0
- package/docs/api/color.md +262 -0
- package/docs/api/console.md +38 -0
- package/docs/api/dns.md +113 -0
- package/docs/api/fetch.md +308 -0
- package/docs/api/ffi.md +536 -0
- package/docs/api/file-io.md +358 -0
- package/docs/api/file-system-router.md +112 -0
- package/docs/api/file.md +19 -0
- package/docs/api/glob.md +157 -0
- package/docs/api/globals.md +387 -0
- package/docs/api/hashing.md +314 -0
- package/docs/api/html-rewriter.md +31 -0
- package/docs/api/http.md +661 -0
- package/docs/api/import-meta.md +69 -0
- package/docs/api/node-api.md +16 -0
- package/docs/api/semver.md +52 -0
- package/docs/api/spawn.md +441 -0
- package/docs/api/sqlite.md +692 -0
- package/docs/api/streams.md +214 -0
- package/docs/api/tcp.md +221 -0
- package/docs/api/test.md +1 -0
- package/docs/api/transpiler.md +274 -0
- package/docs/api/udp.md +125 -0
- package/docs/api/utils.md +773 -0
- package/docs/api/websockets.md +547 -0
- package/docs/api/workers.md +230 -0
- package/docs/benchmarks.md +120 -0
- package/docs/bun-flavored-toml.md +42 -0
- package/docs/bundler/executables.md +291 -0
- package/docs/bundler/index.md +1543 -0
- package/docs/bundler/intro.md +75 -0
- package/docs/bundler/loaders.md +288 -0
- package/docs/bundler/macros.md +327 -0
- package/docs/bundler/plugins.md +30 -0
- package/docs/bundler/vs-esbuild.md +1127 -0
- package/docs/cli/add.md +163 -0
- package/docs/cli/bun-completions.md +3 -0
- package/docs/cli/bun-create.md +254 -0
- package/docs/cli/bun-dev.md +21 -0
- package/docs/cli/bun-install.md +255 -0
- package/docs/cli/bun-upgrade.md +39 -0
- package/docs/cli/bunx.md +80 -0
- package/docs/cli/filter.md +57 -0
- package/docs/cli/init.md +40 -0
- package/docs/cli/install.md +205 -0
- package/docs/cli/link.md +38 -0
- package/docs/cli/outdated.md +61 -0
- package/docs/cli/patch-commit.md +9 -0
- package/docs/cli/pm.md +150 -0
- package/docs/cli/publish.md +107 -0
- package/docs/cli/remove.md +5 -0
- package/docs/cli/run.md +196 -0
- package/docs/cli/test.md +247 -0
- package/docs/cli/unlink.md +7 -0
- package/docs/cli/update.md +34 -0
- package/docs/contributing/upgrading-webkit.md +57 -0
- package/docs/ecosystem/elysia.md +24 -0
- package/docs/ecosystem/express.md +37 -0
- package/docs/ecosystem/hono.md +18 -0
- package/docs/ecosystem/react.md +65 -0
- package/docs/ecosystem/stric.md +37 -0
- package/docs/guides/binary/arraybuffer-to-array.md +27 -0
- package/docs/guides/binary/arraybuffer-to-blob.md +24 -0
- package/docs/guides/binary/arraybuffer-to-buffer.md +25 -0
- package/docs/guides/binary/arraybuffer-to-string.md +15 -0
- package/docs/guides/binary/arraybuffer-to-typedarray.md +39 -0
- package/docs/guides/binary/blob-to-arraybuffer.md +14 -0
- package/docs/guides/binary/blob-to-dataview.md +14 -0
- package/docs/guides/binary/blob-to-stream.md +14 -0
- package/docs/guides/binary/blob-to-string.md +15 -0
- package/docs/guides/binary/blob-to-typedarray.md +14 -0
- package/docs/guides/binary/buffer-to-arraybuffer.md +14 -0
- package/docs/guides/binary/buffer-to-blob.md +14 -0
- package/docs/guides/binary/buffer-to-readablestream.md +41 -0
- package/docs/guides/binary/buffer-to-string.md +25 -0
- package/docs/guides/binary/buffer-to-typedarray.md +14 -0
- package/docs/guides/binary/dataview-to-string.md +15 -0
- package/docs/guides/binary/typedarray-to-arraybuffer.md +25 -0
- package/docs/guides/binary/typedarray-to-blob.md +16 -0
- package/docs/guides/binary/typedarray-to-buffer.md +14 -0
- package/docs/guides/binary/typedarray-to-dataview.md +14 -0
- package/docs/guides/binary/typedarray-to-readablestream.md +41 -0
- package/docs/guides/binary/typedarray-to-string.md +16 -0
- package/docs/guides/ecosystem/astro.md +72 -0
- package/docs/guides/ecosystem/discordjs.md +77 -0
- package/docs/guides/ecosystem/docker.md +140 -0
- package/docs/guides/ecosystem/drizzle.md +185 -0
- package/docs/guides/ecosystem/edgedb.md +228 -0
- package/docs/guides/ecosystem/elysia.md +31 -0
- package/docs/guides/ecosystem/express.md +40 -0
- package/docs/guides/ecosystem/hono.md +39 -0
- package/docs/guides/ecosystem/mongoose.md +87 -0
- package/docs/guides/ecosystem/neon-drizzle.md +220 -0
- package/docs/guides/ecosystem/neon-serverless-postgres.md +55 -0
- package/docs/guides/ecosystem/nextjs.md +38 -0
- package/docs/guides/ecosystem/nuxt.md +56 -0
- package/docs/guides/ecosystem/pm2.md +57 -0
- package/docs/guides/ecosystem/prisma.md +140 -0
- package/docs/guides/ecosystem/qwik.md +107 -0
- package/docs/guides/ecosystem/react.md +49 -0
- package/docs/guides/ecosystem/remix.md +78 -0
- package/docs/guides/ecosystem/render.md +79 -0
- package/docs/guides/ecosystem/sentry.md +52 -0
- package/docs/guides/ecosystem/solidstart.md +58 -0
- package/docs/guides/ecosystem/ssr-react.md +51 -0
- package/docs/guides/ecosystem/stric.md +55 -0
- package/docs/guides/ecosystem/sveltekit.md +125 -0
- package/docs/guides/ecosystem/systemd.md +113 -0
- package/docs/guides/ecosystem/vite.md +70 -0
- package/docs/guides/http/cluster.md +66 -0
- package/docs/guides/http/fetch-unix.md +33 -0
- package/docs/guides/http/fetch.md +24 -0
- package/docs/guides/http/file-uploads.md +94 -0
- package/docs/guides/http/hot.md +22 -0
- package/docs/guides/http/proxy.md +24 -0
- package/docs/guides/http/server.md +46 -0
- package/docs/guides/http/simple.md +18 -0
- package/docs/guides/http/stream-file.md +48 -0
- package/docs/guides/http/stream-iterator.md +47 -0
- package/docs/guides/http/stream-node-streams-in-bun.md +20 -0
- package/docs/guides/http/tls.md +30 -0
- package/docs/guides/install/add-dev.md +26 -0
- package/docs/guides/install/add-git.md +36 -0
- package/docs/guides/install/add-optional.md +25 -0
- package/docs/guides/install/add-peer.md +17 -0
- package/docs/guides/install/add-tarball.md +33 -0
- package/docs/guides/install/add.md +42 -0
- package/docs/guides/install/azure-artifacts.md +73 -0
- package/docs/guides/install/cicd.md +41 -0
- package/docs/guides/install/custom-registry.md +30 -0
- package/docs/guides/install/from-npm-install-to-bun-install.md +214 -0
- package/docs/guides/install/git-diff-bun-lockfile.md +38 -0
- package/docs/guides/install/jfrog-artifactory.md +28 -0
- package/docs/guides/install/npm-alias.md +23 -0
- package/docs/guides/install/registry-scope.md +36 -0
- package/docs/guides/install/trusted.md +48 -0
- package/docs/guides/install/workspaces.md +70 -0
- package/docs/guides/install/yarnlock.md +42 -0
- package/docs/guides/process/argv.md +57 -0
- package/docs/guides/process/ctrl-c.md +16 -0
- package/docs/guides/process/ipc.md +66 -0
- package/docs/guides/process/nanoseconds.md +13 -0
- package/docs/guides/process/os-signals.md +39 -0
- package/docs/guides/process/spawn-stderr.md +31 -0
- package/docs/guides/process/spawn-stdout.md +26 -0
- package/docs/guides/process/spawn.md +41 -0
- package/docs/guides/process/stdin.md +54 -0
- package/docs/guides/read-file/arraybuffer.md +28 -0
- package/docs/guides/read-file/buffer.md +19 -0
- package/docs/guides/read-file/exists.md +16 -0
- package/docs/guides/read-file/json.md +17 -0
- package/docs/guides/read-file/mime.md +20 -0
- package/docs/guides/read-file/stream.md +26 -0
- package/docs/guides/read-file/string.md +22 -0
- package/docs/guides/read-file/uint8array.md +21 -0
- package/docs/guides/read-file/watch.md +68 -0
- package/docs/guides/runtime/cicd.md +43 -0
- package/docs/guides/runtime/define-constant.md +145 -0
- package/docs/guides/runtime/import-html.md +15 -0
- package/docs/guides/runtime/import-json.md +44 -0
- package/docs/guides/runtime/import-toml.md +30 -0
- package/docs/guides/runtime/read-env.md +32 -0
- package/docs/guides/runtime/set-env.md +37 -0
- package/docs/guides/runtime/shell.md +40 -0
- package/docs/guides/runtime/timezone.md +35 -0
- package/docs/guides/runtime/tsconfig-paths.md +29 -0
- package/docs/guides/runtime/typescript.md +47 -0
- package/docs/guides/runtime/vscode-debugger.md +47 -0
- package/docs/guides/runtime/web-debugger.md +82 -0
- package/docs/guides/streams/node-readable-to-arraybuffer.md +11 -0
- package/docs/guides/streams/node-readable-to-blob.md +11 -0
- package/docs/guides/streams/node-readable-to-json.md +12 -0
- package/docs/guides/streams/node-readable-to-string.md +12 -0
- package/docs/guides/streams/node-readable-to-uint8array.md +11 -0
- package/docs/guides/streams/to-array.md +14 -0
- package/docs/guides/streams/to-arraybuffer.md +14 -0
- package/docs/guides/streams/to-blob.md +14 -0
- package/docs/guides/streams/to-buffer.md +15 -0
- package/docs/guides/streams/to-json.md +14 -0
- package/docs/guides/streams/to-string.md +14 -0
- package/docs/guides/streams/to-typedarray.md +22 -0
- package/docs/guides/test/bail.md +22 -0
- package/docs/guides/test/coverage-threshold.md +60 -0
- package/docs/guides/test/coverage.md +44 -0
- package/docs/guides/test/happy-dom.md +68 -0
- package/docs/guides/test/migrate-from-jest.md +110 -0
- package/docs/guides/test/mock-clock.md +48 -0
- package/docs/guides/test/mock-functions.md +68 -0
- package/docs/guides/test/rerun-each.md +14 -0
- package/docs/guides/test/run-tests.md +111 -0
- package/docs/guides/test/skip-tests.md +39 -0
- package/docs/guides/test/snapshot.md +99 -0
- package/docs/guides/test/spy-on.md +46 -0
- package/docs/guides/test/testing-library.md +87 -0
- package/docs/guides/test/timeout.md +15 -0
- package/docs/guides/test/todo-tests.md +67 -0
- package/docs/guides/test/update-snapshots.md +50 -0
- package/docs/guides/test/watch-mode.md +19 -0
- package/docs/guides/util/base64.md +15 -0
- package/docs/guides/util/deep-equals.md +39 -0
- package/docs/guides/util/deflate.md +18 -0
- package/docs/guides/util/detect-bun.md +23 -0
- package/docs/guides/util/entrypoint.md +17 -0
- package/docs/guides/util/escape-html.md +22 -0
- package/docs/guides/util/file-url-to-path.md +14 -0
- package/docs/guides/util/gzip.md +18 -0
- package/docs/guides/util/hash-a-password.md +54 -0
- package/docs/guides/util/import-meta-dir.md +13 -0
- package/docs/guides/util/import-meta-file.md +13 -0
- package/docs/guides/util/import-meta-path.md +13 -0
- package/docs/guides/util/main.md +32 -0
- package/docs/guides/util/path-to-file-url.md +14 -0
- package/docs/guides/util/sleep.md +22 -0
- package/docs/guides/util/version.md +21 -0
- package/docs/guides/util/which-path-to-executable-bin.md +15 -0
- package/docs/guides/websocket/compression.md +31 -0
- package/docs/guides/websocket/context.md +72 -0
- package/docs/guides/websocket/pubsub.md +38 -0
- package/docs/guides/websocket/simple.md +33 -0
- package/docs/guides/write-file/append.md +52 -0
- package/docs/guides/write-file/basic.md +44 -0
- package/docs/guides/write-file/blob.md +28 -0
- package/docs/guides/write-file/cat.md +17 -0
- package/docs/guides/write-file/file-cp.md +16 -0
- package/docs/guides/write-file/filesink.md +52 -0
- package/docs/guides/write-file/response.md +17 -0
- package/docs/guides/write-file/stdout.md +21 -0
- package/docs/guides/write-file/stream.md +17 -0
- package/docs/guides/write-file/unlink.md +23 -0
- package/docs/index.md +77 -0
- package/docs/install/cache.md +57 -0
- package/docs/install/index.md +202 -0
- package/docs/install/lifecycle.md +46 -0
- package/docs/install/lockfile.md +90 -0
- package/docs/install/npmrc.md +75 -0
- package/docs/install/overrides.md +73 -0
- package/docs/install/patch.md +57 -0
- package/docs/install/registries.md +30 -0
- package/docs/install/workspaces.md +70 -0
- package/docs/installation.md +289 -0
- package/docs/project/benchmarking.md +203 -0
- package/docs/project/building-windows.md +162 -0
- package/docs/project/internals/build-process-for-ci.md +75 -0
- package/docs/project/roadmap.md +87 -0
- package/docs/quickstart.md +144 -0
- package/docs/runtime/autoimport.md +94 -0
- package/docs/runtime/bun-apis.md +129 -0
- package/docs/runtime/bunfig.md +532 -0
- package/docs/runtime/debugger.md +325 -0
- package/docs/runtime/env.md +214 -0
- package/docs/runtime/hot.md +139 -0
- package/docs/runtime/index.md +309 -0
- package/docs/runtime/jsx.md +326 -0
- package/docs/runtime/loaders.md +127 -0
- package/docs/runtime/modules.md +298 -0
- package/docs/runtime/nodejs-apis.md +456 -0
- package/docs/runtime/plugins.md +605 -0
- package/docs/runtime/shell.md +537 -0
- package/docs/runtime/typescript.md +60 -0
- package/docs/runtime/web-apis.md +128 -0
- package/docs/test/coverage.md +91 -0
- package/docs/test/dom.md +75 -0
- package/docs/test/hot.md +15 -0
- package/docs/test/lifecycle.md +81 -0
- package/docs/test/mocks.md +236 -0
- package/docs/test/snapshots.md +15 -0
- package/docs/test/time.md +106 -0
- package/docs/test/writing.md +547 -0
- package/docs/typescript.md +51 -0
- package/package.json +5 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Using bun install with Artifactory
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
[JFrog Artifactory](https://jfrog.com/artifactory/) is a package management system for npm, Docker, Maven, NuGet, Ruby, Helm, and more. It allows you to host your own private npm registry, npm packages, and other types of packages as well.
|
|
6
|
+
|
|
7
|
+
To use it with `bun install`, add a `bunfig.toml` file to your project with the following contents:
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### Configure with bunfig.toml
|
|
12
|
+
|
|
13
|
+
Make sure to replace `MY_SUBDOMAIN` with your JFrog Artifactory subdomain, such as `jarred1234` and MY_TOKEN with your JFrog Artifactory token.
|
|
14
|
+
|
|
15
|
+
```toml#bunfig.toml
|
|
16
|
+
[install.registry]
|
|
17
|
+
url = "https://MY_SUBDOMAIN.jfrog.io/artifactory/api/npm/npm/_auth=MY_TOKEN"
|
|
18
|
+
# Bun v1.0.3+ supports using an environment variable here
|
|
19
|
+
# url = "$NPM_CONFIG_REGISTRY"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
### Configure with `$NPM_CONFIG_REGISTRY`
|
|
25
|
+
|
|
26
|
+
Like with npm, you can use the `NPM_CONFIG_REGISTRY` environment variable to configure JFrog Artifactory with bun install.
|
|
27
|
+
|
|
28
|
+
---
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Install a package under a different name
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
To install an npm package under an alias:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
$ bun add my-custom-name@npm:zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
The `zod` package can now be imported as `my-custom-name`.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { z } from "my-custom-name";
|
|
17
|
+
|
|
18
|
+
z.string();
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Configure a private registry for an organization scope with bun install
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Bun does not read `.npmrc` files; instead private registries are configured via `bunfig.toml`. To configure a registry for a particular npm scope:
|
|
6
|
+
|
|
7
|
+
```toml#bunfig.toml
|
|
8
|
+
[install.scopes]
|
|
9
|
+
# as a string
|
|
10
|
+
"@myorg1" = "https://username:password@registry.myorg.com/"
|
|
11
|
+
|
|
12
|
+
# as an object with username/password
|
|
13
|
+
# you can reference environment variables
|
|
14
|
+
"@myorg2" = {
|
|
15
|
+
username = "myusername",
|
|
16
|
+
password = "$npm_pass",
|
|
17
|
+
url = "https://registry.myorg.com/"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
# as an object with token
|
|
21
|
+
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](https://bun.sh/docs/runtime/env) for more information.
|
|
28
|
+
|
|
29
|
+
```toml#bunfig.toml
|
|
30
|
+
[install.scopes]
|
|
31
|
+
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Add a trusted dependency
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Unlike other npm clients, Bun does not execute arbitrary lifecycle scripts for installed dependencies, such as `postinstall` and `node-gyp` builds. These scripts represent a potential security risk, as they can execute arbitrary code on your machine.
|
|
6
|
+
|
|
7
|
+
{% callout %}
|
|
8
|
+
Bun includes a default allowlist of popular packages containing `postinstall` scripts that are known to be safe. You can see this list [here](https://github.com/oven-sh/bun/blob/main/src/install/default-trusted-dependencies.txt).
|
|
9
|
+
{% /callout %}
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
If you are seeing one of the following errors, you are probably trying to use a package that uses `postinstall` to work properly:
|
|
14
|
+
|
|
15
|
+
- `error: could not determine executable to run for package`
|
|
16
|
+
- `InvalidExe`
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
To allow Bun to execute lifecycle scripts for a specific package, add the package to `trustedDependencies` in your package.json file. You can do this automatically by running the command `bun pm trust <pkg>`.
|
|
21
|
+
|
|
22
|
+
{% callout %}
|
|
23
|
+
Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!
|
|
24
|
+
{% /callout %}
|
|
25
|
+
|
|
26
|
+
<!-- Bun maintains an allow-list of popular packages containing `postinstall` scripts that are known to be safe. To run lifecycle scripts for packages that aren't on this list, add the package to `trustedDependencies` in your package.json. -->
|
|
27
|
+
|
|
28
|
+
```json-diff
|
|
29
|
+
{
|
|
30
|
+
"name": "my-app",
|
|
31
|
+
"version": "1.0.0",
|
|
32
|
+
+ "trustedDependencies": ["my-trusted-package"]
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
Once this is added, run a fresh install. Bun will re-install your dependencies and properly install
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
$ rm -rf node_modules
|
|
42
|
+
$ rm bun.lockb
|
|
43
|
+
$ bun install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
See [Docs > Package manager > Trusted dependencies](https://bun.sh/docs/install/lifecycle) for complete documentation of trusted dependencies.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Configuring a monorepo using workspaces
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Bun's package manager supports npm `"workspaces"`. This allows you to split a codebase into multiple distinct "packages" that live in the same repository, can depend on each other, and (when possible) share a `node_modules` directory.
|
|
6
|
+
|
|
7
|
+
Clone [this sample project](https://github.com/colinhacks/bun-workspaces) to experiment with workspaces.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
The root `package.json` should not contain any `"dependencies"`, `"devDependencies"`, etc. Each individual package should be self-contained and declare its own dependencies. Similarly, it's conventional to declare `"private": true` to avoid accidentally publishing the root package to `npm`.
|
|
12
|
+
|
|
13
|
+
```json#package.json
|
|
14
|
+
{
|
|
15
|
+
"name": "my-monorepo",
|
|
16
|
+
"private": true,
|
|
17
|
+
"workspaces": [
|
|
18
|
+
"packages/*"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
It's common to place all packages in a `packages` directory. The `"workspaces"` field in package.json supports glob patterns, so you can use `packages/*` to indicate that each subdirectory of `packages` should be considered separate _package_ (also known as a workspace).
|
|
26
|
+
|
|
27
|
+
```txt
|
|
28
|
+
.
|
|
29
|
+
├── package.json
|
|
30
|
+
├── node_modules
|
|
31
|
+
└── packages
|
|
32
|
+
├── stuff-a
|
|
33
|
+
│ └── package.json
|
|
34
|
+
└── stuff-b
|
|
35
|
+
└── package.json
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
To add dependencies between workspaces, use the `"workspace:*"` syntax. Here we're adding `stuff-a` as a dependency of `stuff-b`.
|
|
41
|
+
|
|
42
|
+
```json-diff#packages/stuff-b/package.json
|
|
43
|
+
{
|
|
44
|
+
"name": "stuff-b",
|
|
45
|
+
"dependencies": {
|
|
46
|
+
+ "stuff-a": "workspace:*"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
Once added, run `bun install` from the project root to install dependencies for all workspaces.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
$ bun install
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
To add npm dependencies to a particular workspace, just `cd` to the appropriate directory and run `bun add` commands as you would normally. Bun will detect that you are in a workspace and hoist the dependency as needed.
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
$ cd packages/stuff-a
|
|
65
|
+
$ bun add zod
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Generate a human-readable lockfile
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
By default Bun generates a binary `bun.lockb` file when you run `bun install`. In some cases, it's preferable to generate a human-readable lockfile instead.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
Use the `--yarn` flag to generate a Yarn-compatible `yarn.lock` file (in addition to `bun.lockb`).
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ bun install --yarn
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
To set this as the default behavior, add the following to your `bunfig.toml` file.
|
|
18
|
+
|
|
19
|
+
```toml#bunfig.toml
|
|
20
|
+
[install.lockfile]
|
|
21
|
+
print = "yarn"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
To print a Yarn lockfile to your console without writing it to disk, just "run" your `bun.lockb` with `bun`.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
$ bun bun.lockb
|
|
30
|
+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
|
31
|
+
# yarn lockfile v1
|
|
32
|
+
# bun ./bun.lockb --hash: 9BFBF11D86084AAB-9418b03ff880c569-390CE6459EACEC9A...
|
|
33
|
+
|
|
34
|
+
abab@^2.0.6:
|
|
35
|
+
version "2.0.6"
|
|
36
|
+
resolved "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz"
|
|
37
|
+
integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvH...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Parse command-line arguments
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The _argument vector_ is the list of arguments passed to the program when it is run. It is available as `Bun.argv`.
|
|
6
|
+
|
|
7
|
+
```ts#cli.ts
|
|
8
|
+
console.log(Bun.argv);
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Running this file with arguments results in the following:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
$ bun run cli.ts --flag1 --flag2 value
|
|
17
|
+
[ '/path/to/bun', '/path/to/cli.ts', '--flag1', '--flag2', 'value' ]
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
To parse `argv` into a more useful format, `util.parseArgs` would be helpful.
|
|
23
|
+
|
|
24
|
+
Example:
|
|
25
|
+
|
|
26
|
+
```ts#cli.ts
|
|
27
|
+
import { parseArgs } from "util";
|
|
28
|
+
|
|
29
|
+
const { values, positionals } = parseArgs({
|
|
30
|
+
args: Bun.argv,
|
|
31
|
+
options: {
|
|
32
|
+
flag1: {
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
},
|
|
35
|
+
flag2: {
|
|
36
|
+
type: 'string',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
strict: true,
|
|
40
|
+
allowPositionals: true,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
console.log(values);
|
|
44
|
+
console.log(positionals);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
then it outputs
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
$ bun run cli.ts --flag1 --flag2 value
|
|
51
|
+
{
|
|
52
|
+
flag1: true,
|
|
53
|
+
flag2: "value",
|
|
54
|
+
}
|
|
55
|
+
[ "/path/to/bun", "/path/to/cli.ts" ]
|
|
56
|
+
```
|
|
57
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Listen for CTRL+C
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `ctrl+c` shortcut sends an _interrupt signal_ to the running process. This signal can be intercepted by listening for the `SIGINT` event. If you want to close the process, you must explicitly call `process.exit()`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
process.on("SIGINT", () => {
|
|
9
|
+
console.log("Ctrl-C was pressed");
|
|
10
|
+
process.exit();
|
|
11
|
+
});
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
See [Docs > API > Utils](https://bun.sh/docs/api/utils) for more useful utilities.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Spawn a child process and communicate using IPC
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Use [`Bun.spawn()`](https://bun.sh/docs/api/spawn) to spawn a child process. When spawning a second `bun` process, you can open a direct inter-process communication (IPC) channel between the two processes.
|
|
6
|
+
|
|
7
|
+
{%callout%}
|
|
8
|
+
**Note** — This API is only compatible with other `bun` processes. Use `process.execPath` to get a path to the currently running `bun` executable.
|
|
9
|
+
{%/callout%}
|
|
10
|
+
|
|
11
|
+
```ts#parent.ts
|
|
12
|
+
const child = Bun.spawn(["bun", "child.ts"], {
|
|
13
|
+
ipc(message) {
|
|
14
|
+
/**
|
|
15
|
+
* The message received from the sub process
|
|
16
|
+
**/
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
The parent process can send messages to the subprocess using the `.send()` method on the returned `Subprocess` instance. A reference to the sending subprocess is also available as the second argument in the `ipc` handler.
|
|
24
|
+
|
|
25
|
+
```ts#parent.ts
|
|
26
|
+
const childProc = Bun.spawn(["bun", "child.ts"], {
|
|
27
|
+
ipc(message, childProc) {
|
|
28
|
+
/**
|
|
29
|
+
* The message received from the sub process
|
|
30
|
+
**/
|
|
31
|
+
childProc.send("Respond to child")
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
childProc.send("I am your father"); // The parent can send messages to the child as well
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
Meanwhile the child process can send messages to its parent using with `process.send()` and receive messages with `process.on("message")`. This is the same API used for `child_process.fork()` in Node.js.
|
|
41
|
+
|
|
42
|
+
```ts#child.ts
|
|
43
|
+
process.send("Hello from child as string");
|
|
44
|
+
process.send({ message: "Hello from child as object" });
|
|
45
|
+
|
|
46
|
+
process.on("message", (message) => {
|
|
47
|
+
// print message from parent
|
|
48
|
+
console.log(message);
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
All messages are serialized using the JSC `serialize` API, which allows for the same set of [transferrable types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects) supported by `postMessage` and `structuredClone`, including strings, typed arrays, streams, and objects.
|
|
55
|
+
|
|
56
|
+
```ts#child.ts
|
|
57
|
+
// send a string
|
|
58
|
+
process.send("Hello from child as string");
|
|
59
|
+
|
|
60
|
+
// send an object
|
|
61
|
+
process.send({ message: "Hello from child as object" });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
See [Docs > API > Child processes](https://bun.sh/docs/api/spawn) for complete documentation.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Get the process uptime in nanoseconds
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Use `Bun.nanoseconds()` to get the total number of nanoseconds the `bun` process has been alive.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
Bun.nanoseconds();
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
See [Docs > API > Utils](https://bun.sh/docs/api/utils) for more useful utilities.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Listen to OS signals
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Bun supports the Node.js `process` global, including the `process.on()` method for listening to OS signals.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
process.on("SIGINT", () => {
|
|
9
|
+
console.log("Received SIGINT");
|
|
10
|
+
});
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
If you don't know which signal to listen for, you listen to the umbrella `"exit"` event.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
process.on("exit", code => {
|
|
19
|
+
console.log(`Process exited with code ${code}`);
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
If you don't know which signal to listen for, you listen to the [`"beforeExit"`](https://nodejs.org/api/process.html#event-beforeexit) and [`"exit"`](https://nodejs.org/api/process.html#event-exit) events.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
process.on("beforeExit", code => {
|
|
29
|
+
console.log(`Event loop is empty!`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
process.on("exit", code => {
|
|
33
|
+
console.log(`Process is exiting with code ${code}`);
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
See [Docs > API > Utils](https://bun.sh/docs/api/utils) for more useful utilities.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read stderr from a child process
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
When using [`Bun.spawn()`](https://bun.sh/docs/api/spawn), the child process inherits the `stderr` of the spawning process. If instead you'd prefer to read and handle `stderr`, set the `stderr` option to `"pipe"`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const proc = Bun.spawn(["echo", "hello"], {
|
|
9
|
+
stderr: "pipe",
|
|
10
|
+
});
|
|
11
|
+
proc.stderr; // => ReadableStream
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
To read `stderr` until the child process exits, use the [`Bun.readableStreamToText()`](https://bun.sh/docs/api/utils#bun-readablestreamto) convenience function.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const proc = Bun.spawn(["echo", "hello"], {
|
|
20
|
+
stderr: "pipe",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const errors: string = await Bun.readableStreamToText(proc.stderr);
|
|
24
|
+
if (errors) {
|
|
25
|
+
// handle errors
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
See [Docs > API > Child processes](https://bun.sh/docs/api/spawn) for complete documentation.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read stdout from a child process
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
When using [`Bun.spawn()`](https://bun.sh/docs/api/spawn), the `stdout` of the child process can be consumed as a `ReadableStream` via `proc.stdout`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const proc = Bun.spawn(["echo", "hello"]);
|
|
9
|
+
|
|
10
|
+
const output = await new Response(proc.stdout).text();
|
|
11
|
+
output; // => "hello"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
To instead pipe the `stdout` of the child process to `stdout` of the parent process, set "inherit".
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const proc = Bun.spawn(["echo", "hello"], {
|
|
20
|
+
stdout: "inherit",
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
See [Docs > API > Child processes](https://bun.sh/docs/api/spawn) for complete documentation.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Spawn a child process
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Use [`Bun.spawn()`](https://bun.sh/docs/api/spawn) to spawn a child process.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const proc = Bun.spawn(["echo", "hello"]);
|
|
9
|
+
|
|
10
|
+
// await completion
|
|
11
|
+
await proc.exited;
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
The second argument accepts a configuration object.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const proc = Bun.spawn(["echo", "Hello, world!"], {
|
|
20
|
+
cwd: "/tmp",
|
|
21
|
+
env: { FOO: "bar" },
|
|
22
|
+
onExit(proc, exitCode, signalCode, error) {
|
|
23
|
+
// exit handler
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
By default, the `stdout` of the child process can be consumed as a `ReadableStream` using `proc.stdout`.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
const proc = Bun.spawn(["echo", "hello"]);
|
|
34
|
+
|
|
35
|
+
const output = await new Response(proc.stdout).text();
|
|
36
|
+
output; // => "hello"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
See [Docs > API > Child processes](https://bun.sh/docs/api/spawn) for complete documentation.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read from stdin
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
For CLI tools, it's often useful to read from `stdin`. In Bun, the `console` object is an `AsyncIterable` that yields lines from `stdin`.
|
|
6
|
+
|
|
7
|
+
```ts#index.ts
|
|
8
|
+
const prompt = "Type something: ";
|
|
9
|
+
process.stdout.write(prompt);
|
|
10
|
+
for await (const line of console) {
|
|
11
|
+
console.log(`You typed: ${line}`);
|
|
12
|
+
process.stdout.write(prompt);
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
Running this file results in a never-ending interactive prompt that echoes whatever the user types.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
$ bun run index.ts
|
|
22
|
+
Type something: hello
|
|
23
|
+
You typed: hello
|
|
24
|
+
Type something: hello again
|
|
25
|
+
You typed: hello again
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
Bun also exposes stdin as a `BunFile` via `Bun.stdin`. This is useful for incrementally reading large inputs that are piped into the `bun` process.
|
|
31
|
+
|
|
32
|
+
There is no guarantee that the chunks will be split line-by-line.
|
|
33
|
+
|
|
34
|
+
```ts#stdin.ts
|
|
35
|
+
for await (const chunk of Bun.stdin.stream()) {
|
|
36
|
+
// chunk is Uint8Array
|
|
37
|
+
// this converts it to text (assumes ASCII encoding)
|
|
38
|
+
const chunkText = Buffer.from(chunk).toString();
|
|
39
|
+
console.log(`Chunk: ${chunkText}`);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
This will print the input that is piped into the `bun` process.
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
$ echo "hello" | bun run stdin.ts
|
|
49
|
+
Chunk: hello
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
See [Docs > API > Utils](https://bun.sh/docs/api/utils) for more useful utilities.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read a file to an ArrayBuffer
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `BunFile` class extends `Blob` and allows you to lazily read the file in a variety of formats. Use `.arrayBuffer()` to read the file as an `ArrayBuffer`.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const path = "/path/to/package.json";
|
|
9
|
+
const file = Bun.file(path);
|
|
10
|
+
|
|
11
|
+
const buffer = await file.arrayBuffer();
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
The binary content in the `ArrayBuffer` can then be read as a typed array, such as `Int8Array`. For `Uint8Array`, use [`.bytes()`](./uint8array).
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
const buffer = await file.arrayBuffer();
|
|
20
|
+
const bytes = new Int8Array(buffer);
|
|
21
|
+
|
|
22
|
+
bytes[0];
|
|
23
|
+
bytes.length;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
Refer to the [Typed arrays](https://bun.sh/docs/api/binary-data#typedarray) docs for more information on working with typed arrays in Bun.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read a file to a Buffer
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `BunFile` class extends `Blob` and allows you to lazily read the file in a variety of formats.
|
|
6
|
+
|
|
7
|
+
To read the file into a `Buffer` instance, first use `.arrayBuffer()` to consume the file as an `ArrayBuffer`, then use `Buffer.from()` to create a `Buffer` from the `ArrayBuffer`.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const path = "/path/to/package.json";
|
|
11
|
+
const file = Bun.file(path);
|
|
12
|
+
|
|
13
|
+
const arrbuf = await file.arrayBuffer();
|
|
14
|
+
const buffer = Buffer.from(arrbuf);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
Refer to [Binary data > Buffer](https://bun.sh/docs/api/binary-data#buffer) for more information on working with `Buffer` and other binary data formats in Bun.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Check if a file exists
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `Bun.file()` function accepts a path and returns a `BunFile` instance. Use the `.exists()` method to check if a file exists at the given path.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
const path = "/path/to/package.json";
|
|
9
|
+
const file = Bun.file(path);
|
|
10
|
+
|
|
11
|
+
await file.exists(); // boolean;
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
Refer to [API > File I/O](https://bun.sh/docs/api/file-io) for more information on working with `BunFile`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Read a JSON file
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `BunFile` class extends `Blob` and allows you to lazily read the file in a variety of formats. Use `.json()` to read and parse the contents of a `.json` file as a plain object.
|
|
6
|
+
|
|
7
|
+
The MIME type of the `BunFile` will be set accordingly.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const path = "/path/to/package.json";
|
|
11
|
+
const file = Bun.file(path);
|
|
12
|
+
|
|
13
|
+
const contents = await file.json();
|
|
14
|
+
// { name: "my-package" }
|
|
15
|
+
|
|
16
|
+
file.type; // => "application/json;charset=utf-8";
|
|
17
|
+
```
|