bun-types 1.3.2-canary.20251106T140813 → 1.3.2
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/bun.d.ts +102 -6
- package/docs/bundler/bytecode.mdx +465 -0
- package/docs/bundler/css.mdx +1024 -0
- package/docs/bundler/esbuild.mdx +253 -0
- package/docs/bundler/executables.mdx +535 -0
- package/docs/bundler/fullstack.mdx +1064 -0
- package/docs/bundler/hot-reloading.mdx +229 -0
- package/docs/bundler/html-static.mdx +386 -0
- package/docs/bundler/index.mdx +1499 -0
- package/docs/bundler/loaders.mdx +356 -0
- package/docs/bundler/macros.mdx +328 -0
- package/docs/bundler/minifier.mdx +1306 -0
- package/docs/bundler/plugins.mdx +411 -0
- package/docs/feedback.mdx +85 -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 +197 -0
- package/docs/guides/deployment/railway.mdx +145 -0
- package/docs/guides/deployment/render.mdx +82 -0
- package/docs/guides/deployment/vercel.mdx +99 -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/edgedb.mdx +257 -0
- package/docs/guides/ecosystem/elysia.mdx +31 -0
- package/docs/guides/ecosystem/express.mdx +43 -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 +57 -0
- package/docs/guides/ecosystem/nuxt.mdx +90 -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 +66 -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/upstash.mdx +87 -0
- package/docs/guides/ecosystem/vite.mdx +77 -0
- package/docs/guides/html-rewriter/extract-links.mdx +72 -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 +26 -0
- package/docs/guides/http/server.mdx +48 -0
- package/docs/guides/http/simple.mdx +20 -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 +38 -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 +47 -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 +50 -0
- package/docs/guides/install/workspaces.mdx +70 -0
- package/docs/guides/install/yarnlock.mdx +50 -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 +41 -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 +17 -0
- package/docs/guides/runtime/import-json.mdx +46 -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 +48 -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/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 +25 -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/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 +74 -0
- package/docs/guides/websocket/pubsub.mdx +40 -0
- package/docs/guides/websocket/simple.mdx +35 -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 +365 -0
- package/docs/pm/bunx.mdx +83 -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/install.mdx +471 -0
- package/docs/pm/cli/link.mdx +48 -0
- package/docs/pm/cli/outdated.mdx +197 -0
- package/docs/pm/cli/patch.mdx +69 -0
- package/docs/pm/cli/pm.mdx +319 -0
- package/docs/pm/cli/publish.mdx +123 -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 +102 -0
- package/docs/pm/global-cache.mdx +72 -0
- package/docs/pm/isolated-installs.mdx +205 -0
- package/docs/pm/lifecycle.mdx +57 -0
- package/docs/pm/lockfile.mdx +64 -0
- package/docs/pm/npmrc.mdx +111 -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 +109 -0
- package/docs/project/benchmarking.mdx +218 -0
- package/docs/project/bindgen.mdx +223 -0
- package/docs/project/building-windows.mdx +133 -0
- package/docs/project/contributing.mdx +343 -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 +240 -0
- package/docs/runtime/auto-install.mdx +97 -0
- package/docs/runtime/binary-data.mdx +846 -0
- package/docs/runtime/bun-apis.mdx +59 -0
- package/docs/runtime/bunfig.mdx +642 -0
- package/docs/runtime/c-compiler.mdx +204 -0
- package/docs/runtime/child-process.mdx +532 -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/debugger.mdx +335 -0
- package/docs/runtime/environment-variables.mdx +214 -0
- package/docs/runtime/ffi.mdx +565 -0
- package/docs/runtime/file-io.mdx +306 -0
- package/docs/runtime/file-system-router.mdx +118 -0
- package/docs/runtime/file-types.mdx +354 -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 +340 -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 +647 -0
- package/docs/runtime/http/tls.mdx +101 -0
- package/docs/runtime/http/websockets.mdx +404 -0
- package/docs/runtime/index.mdx +223 -0
- package/docs/runtime/jsx.mdx +115 -0
- package/docs/runtime/module-resolution.mdx +342 -0
- package/docs/runtime/networking/dns.mdx +111 -0
- package/docs/runtime/networking/fetch.mdx +468 -0
- package/docs/runtime/networking/tcp.mdx +239 -0
- package/docs/runtime/networking/udp.mdx +129 -0
- package/docs/runtime/node-api.mdx +19 -0
- package/docs/runtime/nodejs-compat.mdx +468 -0
- package/docs/runtime/plugins.mdx +405 -0
- package/docs/runtime/redis.mdx +582 -0
- package/docs/runtime/s3.mdx +863 -0
- package/docs/runtime/secrets.mdx +336 -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 +699 -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/transpiler.mdx +288 -0
- package/docs/runtime/typescript.mdx +58 -0
- package/docs/runtime/utils.mdx +922 -0
- package/docs/runtime/watch-mode.mdx +161 -0
- package/docs/runtime/web-apis.mdx +29 -0
- package/docs/runtime/workers.mdx +328 -0
- package/docs/runtime/yaml.mdx +469 -0
- package/docs/snippets/cli/add.mdx +166 -0
- package/docs/snippets/cli/build.mdx +196 -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 +293 -0
- package/docs/snippets/cli/test.mdx +100 -0
- package/docs/snippets/cli/update.mdx +144 -0
- package/docs/snippets/product-card.mdx +32 -0
- package/docs/snippets/product-tiles.mdx +94 -0
- package/docs/test/code-coverage.mdx +409 -0
- package/docs/test/configuration.mdx +467 -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 +380 -0
- package/docs/test/lifecycle.mdx +348 -0
- package/docs/test/mocks.mdx +637 -0
- package/docs/test/reporters.mdx +117 -0
- package/docs/test/runtime-behavior.mdx +342 -0
- package/docs/test/snapshots.mdx +434 -0
- package/docs/test/writing-tests.mdx +635 -0
- package/docs/typescript.mdx +54 -0
- package/package.json +8 -6
- package/test.d.ts +2 -2
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Isolated installs"
|
|
3
|
+
description: "Strict dependency isolation similar to pnpm's approach"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Bun provides an alternative package installation strategy called **isolated installs** that creates strict dependency isolation similar to pnpm's approach. This mode prevents phantom dependencies and ensures reproducible, deterministic builds.
|
|
7
|
+
|
|
8
|
+
This is the default installation strategy for monorepo projects.
|
|
9
|
+
|
|
10
|
+
## What are isolated installs?
|
|
11
|
+
|
|
12
|
+
Isolated installs create a non-hoisted dependency structure where packages can only access their explicitly declared dependencies. This differs from the traditional "hoisted" installation strategy used by npm and Yarn, where dependencies are flattened into a shared `node_modules` directory.
|
|
13
|
+
|
|
14
|
+
### Key benefits
|
|
15
|
+
|
|
16
|
+
- **Prevents phantom dependencies** — Packages cannot accidentally import dependencies they haven't declared
|
|
17
|
+
- **Deterministic resolution** — Same dependency tree regardless of what else is installed
|
|
18
|
+
- **Better for monorepos** — Workspace isolation prevents cross-contamination between packages
|
|
19
|
+
- **Reproducible builds** — More predictable resolution behavior across environments
|
|
20
|
+
|
|
21
|
+
## Using isolated installs
|
|
22
|
+
|
|
23
|
+
### Command line
|
|
24
|
+
|
|
25
|
+
Use the `--linker` flag to specify the installation strategy:
|
|
26
|
+
|
|
27
|
+
```bash terminal icon="terminal"
|
|
28
|
+
# Use isolated installs
|
|
29
|
+
bun install --linker isolated
|
|
30
|
+
|
|
31
|
+
# Use traditional hoisted installs
|
|
32
|
+
bun install --linker hoisted
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Configuration file
|
|
36
|
+
|
|
37
|
+
Set the default linker strategy in your `bunfig.toml` or globally in `$HOME/.bunfig.toml`:
|
|
38
|
+
|
|
39
|
+
```toml bunfig.toml icon="settings"
|
|
40
|
+
[install]
|
|
41
|
+
linker = "isolated"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Default behavior
|
|
45
|
+
|
|
46
|
+
- For monorepo projects, Bun uses the **isolated** installation strategy by default.
|
|
47
|
+
- For single-project projects, Bun uses the **hoisted** installation strategy by default.
|
|
48
|
+
|
|
49
|
+
You can override the default behavior by explicitly specifying the `--linker` flag or setting it in your configuration file.
|
|
50
|
+
|
|
51
|
+
## How isolated installs work
|
|
52
|
+
|
|
53
|
+
### Directory structure
|
|
54
|
+
|
|
55
|
+
Instead of hoisting dependencies, isolated installs create a two-tier structure:
|
|
56
|
+
|
|
57
|
+
```bash tree layout of node_modules icon="list-tree"
|
|
58
|
+
node_modules/
|
|
59
|
+
├── .bun/ # Central package store
|
|
60
|
+
│ ├── package@1.0.0/ # Versioned package installations
|
|
61
|
+
│ │ └── node_modules/
|
|
62
|
+
│ │ └── package/ # Actual package files
|
|
63
|
+
│ ├── @scope+package@2.1.0/ # Scoped packages (+ replaces /)
|
|
64
|
+
│ │ └── node_modules/
|
|
65
|
+
│ │ └── @scope/
|
|
66
|
+
│ │ └── package/
|
|
67
|
+
│ └── ...
|
|
68
|
+
└── package-name -> .bun/package@1.0.0/node_modules/package # Symlinks
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Resolution algorithm
|
|
72
|
+
|
|
73
|
+
1. **Central store** — All packages are installed in `node_modules/.bun/package@version/` directories
|
|
74
|
+
2. **Symlinks** — Top-level `node_modules` contains symlinks pointing to the central store
|
|
75
|
+
3. **Peer resolution** — Complex peer dependencies create specialized directory names
|
|
76
|
+
4. **Deduplication** — Packages with identical package IDs and peer dependency sets are shared
|
|
77
|
+
|
|
78
|
+
### Workspace handling
|
|
79
|
+
|
|
80
|
+
In monorepos, workspace dependencies are handled specially:
|
|
81
|
+
|
|
82
|
+
- **Workspace packages** — Symlinked directly to their source directories, not the store
|
|
83
|
+
- **Workspace dependencies** — Can access other workspace packages in the monorepo
|
|
84
|
+
- **External dependencies** — Installed in the isolated store with proper isolation
|
|
85
|
+
|
|
86
|
+
## Comparison with hoisted installs
|
|
87
|
+
|
|
88
|
+
| Aspect | Hoisted (npm/Yarn) | Isolated (pnpm-like) |
|
|
89
|
+
| ------------------------- | ------------------------------------------ | --------------------------------------- |
|
|
90
|
+
| **Dependency access** | Packages can access any hoisted dependency | Packages only see declared dependencies |
|
|
91
|
+
| **Phantom dependencies** | ❌ Possible | ✅ Prevented |
|
|
92
|
+
| **Disk usage** | ✅ Lower (shared installs) | ✅ Similar (uses symlinks) |
|
|
93
|
+
| **Determinism** | ❌ Less deterministic | ✅ More deterministic |
|
|
94
|
+
| **Node.js compatibility** | ✅ Standard behavior | ✅ Compatible via symlinks |
|
|
95
|
+
| **Best for** | Single projects, legacy code | Monorepos, strict dependency management |
|
|
96
|
+
|
|
97
|
+
## Advanced features
|
|
98
|
+
|
|
99
|
+
### Peer dependency handling
|
|
100
|
+
|
|
101
|
+
Isolated installs handle peer dependencies through sophisticated resolution:
|
|
102
|
+
|
|
103
|
+
```bash tree layout of node_modules icon="list-tree"
|
|
104
|
+
# Package with peer dependencies creates specialized paths
|
|
105
|
+
node_modules/.bun/package@1.0.0_react@18.2.0/
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The directory name encodes both the package version and its peer dependency versions, ensuring each unique combination gets its own installation.
|
|
109
|
+
|
|
110
|
+
### Backend strategies
|
|
111
|
+
|
|
112
|
+
Bun uses different file operation strategies for performance:
|
|
113
|
+
|
|
114
|
+
- **Clonefile** (macOS) — Copy-on-write filesystem clones for maximum efficiency
|
|
115
|
+
- **Hardlink** (Linux/Windows) — Hardlinks to save disk space
|
|
116
|
+
- **Copyfile** (fallback) — Full file copies when other methods aren't available
|
|
117
|
+
|
|
118
|
+
### Debugging isolated installs
|
|
119
|
+
|
|
120
|
+
Enable verbose logging to understand the installation process:
|
|
121
|
+
|
|
122
|
+
```bash terminal icon="terminal"
|
|
123
|
+
bun install --linker isolated --verbose
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This shows:
|
|
127
|
+
|
|
128
|
+
- Store entry creation
|
|
129
|
+
- Symlink operations
|
|
130
|
+
- Peer dependency resolution
|
|
131
|
+
- Deduplication decisions
|
|
132
|
+
|
|
133
|
+
## Troubleshooting
|
|
134
|
+
|
|
135
|
+
### Compatibility issues
|
|
136
|
+
|
|
137
|
+
Some packages may not work correctly with isolated installs due to:
|
|
138
|
+
|
|
139
|
+
- **Hardcoded paths** — Packages that assume a flat `node_modules` structure
|
|
140
|
+
- **Dynamic imports** — Runtime imports that don't follow Node.js resolution
|
|
141
|
+
- **Build tools** — Tools that scan `node_modules` directly
|
|
142
|
+
|
|
143
|
+
If you encounter issues, you can:
|
|
144
|
+
|
|
145
|
+
1. **Switch to hoisted mode** for specific projects:
|
|
146
|
+
|
|
147
|
+
```bash terminal icon="terminal"
|
|
148
|
+
bun install --linker hoisted
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **Report compatibility issues** to help improve isolated install support
|
|
152
|
+
|
|
153
|
+
### Performance considerations
|
|
154
|
+
|
|
155
|
+
- **Install time** — May be slightly slower due to symlink operations
|
|
156
|
+
- **Disk usage** — Similar to hoisted (uses symlinks, not file copies)
|
|
157
|
+
- **Memory usage** — Higher during install due to complex peer resolution
|
|
158
|
+
|
|
159
|
+
## Migration guide
|
|
160
|
+
|
|
161
|
+
### From npm/Yarn
|
|
162
|
+
|
|
163
|
+
```bash terminal icon="terminal"
|
|
164
|
+
# Remove existing node_modules and lockfiles
|
|
165
|
+
rm -rf node_modules package-lock.json yarn.lock
|
|
166
|
+
|
|
167
|
+
# Install with isolated linker
|
|
168
|
+
bun install --linker isolated
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### From pnpm
|
|
172
|
+
|
|
173
|
+
Isolated installs are conceptually similar to pnpm, so migration should be straightforward:
|
|
174
|
+
|
|
175
|
+
```bash terminal icon="terminal"
|
|
176
|
+
# Remove pnpm files
|
|
177
|
+
$ rm -rf node_modules pnpm-lock.yaml
|
|
178
|
+
|
|
179
|
+
# Install with Bun's isolated linker
|
|
180
|
+
bun install --linker isolated
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The main difference is that Bun uses symlinks in `node_modules` while pnpm uses a global store with symlinks.
|
|
184
|
+
|
|
185
|
+
## When to use isolated installs
|
|
186
|
+
|
|
187
|
+
**Use isolated installs when:**
|
|
188
|
+
|
|
189
|
+
- Working in monorepos with multiple packages
|
|
190
|
+
- Strict dependency management is required
|
|
191
|
+
- Preventing phantom dependencies is important
|
|
192
|
+
- Building libraries that need deterministic dependencies
|
|
193
|
+
|
|
194
|
+
**Use hoisted installs when:**
|
|
195
|
+
|
|
196
|
+
- Working with legacy code that assumes flat `node_modules`
|
|
197
|
+
- Compatibility with existing build tools is required
|
|
198
|
+
- Working in environments where symlinks aren't well supported
|
|
199
|
+
- You prefer the simpler traditional npm behavior
|
|
200
|
+
|
|
201
|
+
## Related documentation
|
|
202
|
+
|
|
203
|
+
- [Package manager > Workspaces](/pm/workspaces) — Monorepo workspace management
|
|
204
|
+
- [Package manager > Lockfile](/pm/lockfile) — Understanding Bun's lockfile format
|
|
205
|
+
- [CLI > install](/pm/cli/install) — Complete `bun install` command reference
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Lifecycle scripts"
|
|
3
|
+
description: "How Bun handles package lifecycle scripts securely"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Packages on `npm` can define _lifecycle scripts_ in their `package.json`. Some of the most common are below, but there are [many others](https://docs.npmjs.com/cli/v10/using-npm/scripts).
|
|
7
|
+
|
|
8
|
+
- `preinstall`: Runs before the package is installed
|
|
9
|
+
- `postinstall`: Runs after the package is installed
|
|
10
|
+
- `preuninstall`: Runs before the package is uninstalled
|
|
11
|
+
- `prepublishOnly`: Runs before the package is published
|
|
12
|
+
|
|
13
|
+
These scripts are arbitrary shell commands that the package manager is expected to read and execute at the appropriate time. But executing arbitrary scripts represents a potential security risk, so—unlike other `npm` clients—Bun does not execute arbitrary lifecycle scripts by default.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## `postinstall`
|
|
18
|
+
|
|
19
|
+
The `postinstall` script is particularly important. It's widely used to build or install platform-specific binaries for packages that are implemented as [native Node.js add-ons](https://nodejs.org/api/addons.html). For example, `node-sass` is a popular package that uses `postinstall` to build a native binary for Sass.
|
|
20
|
+
|
|
21
|
+
```json package.json icon="file-json"
|
|
22
|
+
{
|
|
23
|
+
"name": "my-app",
|
|
24
|
+
"version": "1.0.0",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"node-sass": "^6.0.1"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## `trustedDependencies`
|
|
34
|
+
|
|
35
|
+
Instead of executing arbitrary scripts, Bun uses a "default-secure" approach. You can add certain packages to an allow list, and Bun will execute lifecycle scripts for those packages. To tell Bun to allow lifecycle scripts for a particular package, add the package name to `trustedDependencies` array in your `package.json`.
|
|
36
|
+
|
|
37
|
+
```json package.json icon="file-json"
|
|
38
|
+
{
|
|
39
|
+
"name": "my-app",
|
|
40
|
+
"version": "1.0.0",
|
|
41
|
+
"trustedDependencies": ["node-sass"] // [!code ++]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Once added to `trustedDependencies`, install/re-install the package. Bun will read this field and run lifecycle scripts for `my-trusted-package`.
|
|
46
|
+
|
|
47
|
+
As of Bun v1.0.16, the top 500 npm packages with lifecycle scripts are allowed by default. You can see the full list [here](https://github.com/oven-sh/bun/blob/main/src/install/default-trusted-dependencies.txt).
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## `--ignore-scripts`
|
|
52
|
+
|
|
53
|
+
To disable lifecycle scripts for all packages, use the `--ignore-scripts` flag.
|
|
54
|
+
|
|
55
|
+
```bash terminal icon="terminal"
|
|
56
|
+
bun install --ignore-scripts
|
|
57
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Lockfile"
|
|
3
|
+
description: "Bun's lockfile format and configuration"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Running `bun install` will create a lockfile called `bun.lock`.
|
|
7
|
+
|
|
8
|
+
#### Should it be committed to git?
|
|
9
|
+
|
|
10
|
+
Yes
|
|
11
|
+
|
|
12
|
+
#### Generate a lockfile without installing?
|
|
13
|
+
|
|
14
|
+
To generate a lockfile without installing to `node_modules` you can use the `--lockfile-only` flag. The lockfile will always be saved to disk, even if it is up-to-date with the `package.json`(s) for your project.
|
|
15
|
+
|
|
16
|
+
```bash terminal icon="terminal"
|
|
17
|
+
bun install --lockfile-only
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
<Note>
|
|
21
|
+
Using `--lockfile-only` will still populate the global install cache with registry metadata and git/tarball
|
|
22
|
+
dependencies.
|
|
23
|
+
</Note>
|
|
24
|
+
|
|
25
|
+
#### Can I opt out?
|
|
26
|
+
|
|
27
|
+
To install without creating a lockfile:
|
|
28
|
+
|
|
29
|
+
```bash terminal icon="terminal"
|
|
30
|
+
bun install --no-save
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
To install a Yarn lockfile _in addition_ to `bun.lock`.
|
|
34
|
+
|
|
35
|
+
<CodeGroup>
|
|
36
|
+
|
|
37
|
+
```bash terminal icon="terminal"
|
|
38
|
+
bun install --yarn
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```toml bunfig.toml icon="settings"
|
|
42
|
+
[install.lockfile]
|
|
43
|
+
# whether to save a non-Bun lockfile alongside bun.lock
|
|
44
|
+
# only "yarn" is supported
|
|
45
|
+
print = "yarn"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
</CodeGroup>
|
|
49
|
+
|
|
50
|
+
#### Text-based lockfile
|
|
51
|
+
|
|
52
|
+
Bun v1.2 changed the default lockfile format to the text-based `bun.lock`. Existing binary `bun.lockb` lockfiles can be migrated to the new format by running `bun install --save-text-lockfile --frozen-lockfile --lockfile-only` and deleting `bun.lockb`.
|
|
53
|
+
|
|
54
|
+
More information about the new lockfile format can be found on [our blogpost](https://bun.com/blog/bun-lock-text-lockfile).
|
|
55
|
+
|
|
56
|
+
#### Automatic lockfile migration
|
|
57
|
+
|
|
58
|
+
When running `bun install` in a project without a `bun.lock`, Bun automatically migrates existing lockfiles:
|
|
59
|
+
|
|
60
|
+
- `yarn.lock` (v1)
|
|
61
|
+
- `package-lock.json` (npm)
|
|
62
|
+
- `pnpm-lock.yaml` (pnpm)
|
|
63
|
+
|
|
64
|
+
The original lockfile is preserved and can be removed manually after verification.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: .npmrc support
|
|
3
|
+
description:
|
|
4
|
+
---
|
|
5
|
+
|
|
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
|
+
|
|
8
|
+
<Note>
|
|
9
|
+
We recommend migrating your `.npmrc` file to Bun's [`bunfig.toml`](/runtime/bunfig) format, as it provides more
|
|
10
|
+
flexible options and can let you configure Bun-specific options.
|
|
11
|
+
</Note>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Supported options
|
|
16
|
+
|
|
17
|
+
### Set the default registry
|
|
18
|
+
|
|
19
|
+
The default registry is used to resolve packages, its default value is `npm`'s official registry (`https://registry.npmjs.org/`).
|
|
20
|
+
|
|
21
|
+
To change it, you can set the `registry` option in `.npmrc`:
|
|
22
|
+
|
|
23
|
+
```ini .npmrc icon="npm"
|
|
24
|
+
registry=http://localhost:4873/
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The equivalent `bunfig.toml` option is [`install.registry`](/runtime/bunfig#install-registry):
|
|
28
|
+
|
|
29
|
+
```toml bunfig.toml icon="settings"
|
|
30
|
+
install.registry = "http://localhost:4873/"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Set the registry for a specific scope
|
|
34
|
+
|
|
35
|
+
`@<scope>:registry` allows you to set the registry for a specific scope:
|
|
36
|
+
|
|
37
|
+
```ini .npmrc icon="npm"
|
|
38
|
+
@myorg:registry=http://localhost:4873/
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/runtime/bunfig#install-registry):
|
|
42
|
+
|
|
43
|
+
```toml bunfig.toml icon="settings"
|
|
44
|
+
[install.scopes]
|
|
45
|
+
myorg = "http://localhost:4873/"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Configure options for a specific registry
|
|
49
|
+
|
|
50
|
+
`//<registry_url>/:<key>=<value>` allows you to set options for a specific registry:
|
|
51
|
+
|
|
52
|
+
```ini .npmrc icon="npm"
|
|
53
|
+
# set an auth token for the registry
|
|
54
|
+
# ${...} is a placeholder for environment variables
|
|
55
|
+
//http://localhost:4873/:_authToken=${NPM_TOKEN}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# or you could set a username and password
|
|
59
|
+
# note that the password is base64 encoded
|
|
60
|
+
//http://localhost:4873/:username=myusername
|
|
61
|
+
|
|
62
|
+
//http://localhost:4873/:_password=${NPM_PASSWORD}
|
|
63
|
+
|
|
64
|
+
# or use _auth, which is your username and password
|
|
65
|
+
# combined into a single string, which is then base 64 encoded
|
|
66
|
+
//http://localhost:4873/:_auth=${NPM_AUTH}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The following options are supported:
|
|
70
|
+
|
|
71
|
+
- `_authToken`
|
|
72
|
+
- `username`
|
|
73
|
+
- `_password` (base64 encoded password)
|
|
74
|
+
- `_auth` (base64 encoded username:password, e.g. `btoa(username + ":" + password)`)
|
|
75
|
+
|
|
76
|
+
The equivalent `bunfig.toml` option is to add a key in [`install.scopes`](/runtime/bunfig#install-registry):
|
|
77
|
+
|
|
78
|
+
```toml bunfig.toml icon="settings"
|
|
79
|
+
[install.scopes]
|
|
80
|
+
myorg = { url = "http://localhost:4873/", username = "myusername", password = "$NPM_PASSWORD" }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### `link-workspace-packages`: Control workspace package installation
|
|
84
|
+
|
|
85
|
+
Controls how workspace packages are installed when available locally:
|
|
86
|
+
|
|
87
|
+
```ini .npmrc icon="npm"
|
|
88
|
+
link-workspace-packages=true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The equivalent `bunfig.toml` option is [`install.linkWorkspacePackages`](/runtime/bunfig#install-linkworkspacepackages):
|
|
92
|
+
|
|
93
|
+
```toml bunfig.toml icon="settings"
|
|
94
|
+
[install]
|
|
95
|
+
linkWorkspacePackages = true
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### `save-exact`: Save exact versions
|
|
99
|
+
|
|
100
|
+
Always saves exact versions without the `^` prefix:
|
|
101
|
+
|
|
102
|
+
```ini .npmrc icon="npm"
|
|
103
|
+
save-exact=true
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The equivalent `bunfig.toml` option is [`install.exact`](/runtime/bunfig#install-exact):
|
|
107
|
+
|
|
108
|
+
```toml bunfig.toml icon="settings"
|
|
109
|
+
[install]
|
|
110
|
+
exact = true
|
|
111
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Overrides and resolutions"
|
|
3
|
+
description: "Control metadependency versions with npm overrides and Yarn resolutions"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies.
|
|
7
|
+
|
|
8
|
+
```json package.json icon="file-json"
|
|
9
|
+
{
|
|
10
|
+
"name": "my-app",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"foo": "^2.0.0"
|
|
13
|
+
},
|
|
14
|
+
"overrides": {
|
|
15
|
+
// [!code ++]
|
|
16
|
+
"bar": "~4.4.0" // [!code ++]
|
|
17
|
+
} // [!code ++]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
By default, Bun will install the latest version of all dependencies and metadependencies, according to the ranges specified in each package's `package.json`. Let's say you have a project with one dependency, `foo`, which in turn has a dependency on `bar`. This means `bar` is a _metadependency_ of our project.
|
|
22
|
+
|
|
23
|
+
```json package.json icon="file-json"
|
|
24
|
+
{
|
|
25
|
+
"name": "my-app",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"foo": "^2.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
When you run `bun install`, Bun will install the latest versions of each package.
|
|
33
|
+
|
|
34
|
+
```txt tree layout of node_modules icon="list-tree"
|
|
35
|
+
node_modules
|
|
36
|
+
├── foo@1.2.3
|
|
37
|
+
└── bar@4.5.6
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
But what if a security vulnerability was introduced in `bar@4.5.6`? We may want a way to pin `bar` to an older version that doesn't have the vulnerability. This is where `"overrides"`/`"resolutions"` come in.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## `"overrides"`
|
|
45
|
+
|
|
46
|
+
Add `bar` to the `"overrides"` field in `package.json`. Bun will defer to the specified version range when determining which version of `bar` to install, whether it's a dependency or a metadependency.
|
|
47
|
+
|
|
48
|
+
<Note>
|
|
49
|
+
Bun currently only supports top-level `"overrides"`. [Nested
|
|
50
|
+
overrides](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides) are not supported.
|
|
51
|
+
</Note>
|
|
52
|
+
|
|
53
|
+
```json package.json icon="file-json"
|
|
54
|
+
{
|
|
55
|
+
"name": "my-app",
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"foo": "^2.0.0"
|
|
58
|
+
},
|
|
59
|
+
"overrides": {
|
|
60
|
+
// [!code ++]
|
|
61
|
+
"bar": "~4.4.0" // [!code ++]
|
|
62
|
+
} // [!code ++]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## `"resolutions"`
|
|
67
|
+
|
|
68
|
+
The syntax is similar for `"resolutions"`, which is Yarn's alternative to `"overrides"`. Bun supports this feature to make migration from Yarn easier.
|
|
69
|
+
|
|
70
|
+
As with `"overrides"`, _nested resolutions_ are not currently supported.
|
|
71
|
+
|
|
72
|
+
```json package.json icon="file-json"
|
|
73
|
+
{
|
|
74
|
+
"name": "my-app",
|
|
75
|
+
"dependencies": {
|
|
76
|
+
"foo": "^2.0.0"
|
|
77
|
+
},
|
|
78
|
+
"resolutions": {
|
|
79
|
+
// [!code ++]
|
|
80
|
+
"bar": "~4.4.0" // [!code ++]
|
|
81
|
+
} // [!code ++]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Scopes and registries"
|
|
3
|
+
description: "Configure private registries and scoped packages"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The default registry is `registry.npmjs.org`. This can be globally configured in `bunfig.toml`:
|
|
7
|
+
|
|
8
|
+
```toml bunfig.toml icon="settings"
|
|
9
|
+
[install]
|
|
10
|
+
# set default registry as a string
|
|
11
|
+
registry = "https://registry.npmjs.org"
|
|
12
|
+
# set a token
|
|
13
|
+
registry = { url = "https://registry.npmjs.org", token = "123456" }
|
|
14
|
+
# set a username/password
|
|
15
|
+
registry = "https://username:password@registry.npmjs.org"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
To configure a private registry scoped to a particular organization:
|
|
19
|
+
|
|
20
|
+
```toml bunfig.toml icon="settings"
|
|
21
|
+
[install.scopes]
|
|
22
|
+
# registry as string
|
|
23
|
+
"@myorg1" = "https://username:password@registry.myorg.com/"
|
|
24
|
+
|
|
25
|
+
# registry with username/password
|
|
26
|
+
# you can reference environment variables
|
|
27
|
+
"@myorg2" = { username = "myusername", password = "$NPM_PASS", url = "https://registry.myorg.com/" }
|
|
28
|
+
|
|
29
|
+
# registry with token
|
|
30
|
+
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### `.npmrc`
|
|
34
|
+
|
|
35
|
+
Bun also reads `.npmrc` files, [learn more](/pm/npmrc).
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Security Scanner API
|
|
3
|
+
description:
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Bun's package manager can scan packages for security vulnerabilities before installation, helping protect your applications from supply chain attacks and known vulnerabilities.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Quick Start
|
|
11
|
+
|
|
12
|
+
Configure a security scanner in your `bunfig.toml`:
|
|
13
|
+
|
|
14
|
+
```toml bunfig.toml icon="settings"
|
|
15
|
+
[install.security]
|
|
16
|
+
scanner = "@acme/bun-security-scanner"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
When configured, Bun will:
|
|
20
|
+
|
|
21
|
+
- Scan all packages before installation
|
|
22
|
+
- Display security warnings and advisories
|
|
23
|
+
- Cancel installation if critical vulnerabilities are found
|
|
24
|
+
- Automatically disable auto-install for security
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## How It Works
|
|
29
|
+
|
|
30
|
+
Security scanners analyze packages during `bun install`, `bun add`, and other package operations. They can detect:
|
|
31
|
+
|
|
32
|
+
- Known security vulnerabilities (CVEs)
|
|
33
|
+
- Malicious packages
|
|
34
|
+
- License compliance issues
|
|
35
|
+
- ...and more!
|
|
36
|
+
|
|
37
|
+
### Security Levels
|
|
38
|
+
|
|
39
|
+
Scanners report issues at two severity levels:
|
|
40
|
+
|
|
41
|
+
- **`fatal`** - Installation stops immediately, exits with non-zero code
|
|
42
|
+
- **`warn`** - In interactive terminals, prompts to continue; in CI, exits immediately
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Using Pre-built Scanners
|
|
47
|
+
|
|
48
|
+
Many security companies publish Bun security scanners as npm packages that you can install and use immediately.
|
|
49
|
+
|
|
50
|
+
### Installing a Scanner
|
|
51
|
+
|
|
52
|
+
Install a security scanner from npm:
|
|
53
|
+
|
|
54
|
+
```bash terminal icon="terminal"
|
|
55
|
+
bun add -d @acme/bun-security-scanner
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
<Note>
|
|
59
|
+
Consult your security scanner's documentation for their specific package name and installation instructions. Most
|
|
60
|
+
scanners will be installed with `bun add`.
|
|
61
|
+
</Note>
|
|
62
|
+
|
|
63
|
+
### Configuring the Scanner
|
|
64
|
+
|
|
65
|
+
After installation, configure it in your `bunfig.toml`:
|
|
66
|
+
|
|
67
|
+
```toml bunfig.toml icon="settings"
|
|
68
|
+
[install.security]
|
|
69
|
+
scanner = "@acme/bun-security-scanner"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Enterprise Configuration
|
|
73
|
+
|
|
74
|
+
Some enterprise scanners might support authentication and/or configuration through environment variables:
|
|
75
|
+
|
|
76
|
+
```bash terminal icon="terminal"
|
|
77
|
+
# This might go in ~/.bashrc, for example
|
|
78
|
+
export SECURITY_API_KEY="your-api-key"
|
|
79
|
+
|
|
80
|
+
# The scanner will now use these credentials automatically
|
|
81
|
+
bun install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Consult your security scanner's documentation to learn which environment variables to set and if any additional configuration is required.
|
|
85
|
+
|
|
86
|
+
### Authoring your own scanner
|
|
87
|
+
|
|
88
|
+
For a complete example with tests and CI setup, see the official template:
|
|
89
|
+
[github.com/oven-sh/security-scanner-template](https://github.com/oven-sh/security-scanner-template)
|
|
90
|
+
|
|
91
|
+
## Related
|
|
92
|
+
|
|
93
|
+
- [Configuration (bunfig.toml)](/runtime/bunfig#install-security-scanner)
|
|
94
|
+
- [Package Manager](/installation)
|
|
95
|
+
- [Security Scanner Template](https://github.com/oven-sh/security-scanner-template)
|