bun-types 1.1.37-canary.20241124T140524 → 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
package/docs/cli/add.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
To add a particular package:
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
$ bun add preact
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
To specify a version, version range, or tag:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ bun add zod@3.20.0
|
|
11
|
+
$ bun add zod@^3.0.0
|
|
12
|
+
$ bun add zod@latest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## `--dev`
|
|
16
|
+
|
|
17
|
+
{% callout %}
|
|
18
|
+
**Alias** — `--development`, `-d`, `-D`
|
|
19
|
+
{% /callout %}
|
|
20
|
+
|
|
21
|
+
To add a package as a dev dependency (`"devDependencies"`):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
$ bun add --dev @types/react
|
|
25
|
+
$ bun add -d @types/react
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## `--optional`
|
|
29
|
+
|
|
30
|
+
To add a package as an optional dependency (`"optionalDependencies"`):
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
$ bun add --optional lodash
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## `--exact`
|
|
37
|
+
|
|
38
|
+
{% callout %}
|
|
39
|
+
**Alias** — `-E`
|
|
40
|
+
{% /callout %}
|
|
41
|
+
|
|
42
|
+
To add a package and pin to the resolved version, use `--exact`. This will resolve the version of the package and add it to your `package.json` with an exact version number instead of a version range.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
$ bun add react --exact
|
|
46
|
+
$ bun add react -E
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This will add the following to your `package.json`:
|
|
50
|
+
|
|
51
|
+
```jsonc
|
|
52
|
+
{
|
|
53
|
+
"dependencies": {
|
|
54
|
+
// without --exact
|
|
55
|
+
"react": "^18.2.0", // this matches >= 18.2.0 < 19.0.0
|
|
56
|
+
|
|
57
|
+
// with --exact
|
|
58
|
+
"react": "18.2.0" // this matches only 18.2.0 exactly
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To view a complete list of options for this command:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
$ bun add --help
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## `--global`
|
|
70
|
+
|
|
71
|
+
{% callout %}
|
|
72
|
+
**Note** — This would not modify package.json of your current project folder.
|
|
73
|
+
**Alias** - `bun add --global`, `bun add -g`, `bun install --global` and `bun install -g`
|
|
74
|
+
{% /callout %}
|
|
75
|
+
|
|
76
|
+
To install a package globally, use the `-g`/`--global` flag. This will not modify the `package.json` of your current project. Typically this is used for installing command-line tools.
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
$ bun add --global cowsay # or `bun add -g cowsay`
|
|
80
|
+
$ cowsay "Bun!"
|
|
81
|
+
______
|
|
82
|
+
< Bun! >
|
|
83
|
+
------
|
|
84
|
+
\ ^__^
|
|
85
|
+
\ (oo)\_______
|
|
86
|
+
(__)\ )\/\
|
|
87
|
+
||----w |
|
|
88
|
+
|| ||
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
{% details summary="Configuring global installation behavior" %}
|
|
92
|
+
|
|
93
|
+
```toml
|
|
94
|
+
[install]
|
|
95
|
+
# where `bun add --global` installs packages
|
|
96
|
+
globalDir = "~/.bun/install/global"
|
|
97
|
+
|
|
98
|
+
# where globally-installed package bins are linked
|
|
99
|
+
globalBinDir = "~/.bun/bin"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
{% /details %}
|
|
103
|
+
|
|
104
|
+
## Trusted dependencies
|
|
105
|
+
|
|
106
|
+
Unlike other npm clients, Bun does not execute arbitrary lifecycle scripts for installed dependencies, such as `postinstall`. These scripts represent a potential security risk, as they can execute arbitrary code on your machine.
|
|
107
|
+
|
|
108
|
+
To tell Bun to allow lifecycle scripts for a particular package, add the package to `trustedDependencies` in your package.json.
|
|
109
|
+
|
|
110
|
+
```json-diff
|
|
111
|
+
{
|
|
112
|
+
"name": "my-app",
|
|
113
|
+
"version": "1.0.0",
|
|
114
|
+
+ "trustedDependencies": ["my-trusted-package"]
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Bun reads this field and will run lifecycle scripts for `my-trusted-package`.
|
|
119
|
+
|
|
120
|
+
<!-- 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. -->
|
|
121
|
+
|
|
122
|
+
## Git dependencies
|
|
123
|
+
|
|
124
|
+
To add a dependency from a public or private git repository:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
$ bun add git@github.com:moment/moment.git
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
{% callout %}
|
|
131
|
+
**Note** — To install private repositories, your system needs the appropriate SSH credentials to access the repository.
|
|
132
|
+
{% /callout %}
|
|
133
|
+
|
|
134
|
+
Bun supports a variety of protocols, including [`github`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#github-urls), [`git`](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#git-urls-as-dependencies), `git+ssh`, `git+https`, and many more.
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"dependencies": {
|
|
139
|
+
"dayjs": "git+https://github.com/iamkun/dayjs.git",
|
|
140
|
+
"lodash": "git+ssh://github.com/lodash/lodash.git#4.17.21",
|
|
141
|
+
"moment": "git@github.com:moment/moment.git",
|
|
142
|
+
"zod": "github:colinhacks/zod"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Tarball dependencies
|
|
148
|
+
|
|
149
|
+
A package name can correspond to a publicly hosted `.tgz` file. During installation, Bun will download and install the package from the specified tarball URL, rather than from the package registry.
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
$ bun add zod@https://registry.npmjs.org/zod/-/zod-3.21.4.tgz
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
This will add the following line to your `package.json`:
|
|
156
|
+
|
|
157
|
+
```json#package.json
|
|
158
|
+
{
|
|
159
|
+
"dependencies": {
|
|
160
|
+
"zod": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz"
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
This command installs completions for `zsh` and/or `fish`. It runs automatically on every `bun upgrade` and on install. It reads from `$SHELL` to determine which shell to install for. It tries several common shell completion directories for your shell and OS.
|
|
2
|
+
|
|
3
|
+
If you want to copy the completions manually, run `bun completions > path-to-file`. If you know the completions directory to install them to, run `bun completions /path/to/directory`.
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
{% callout %}
|
|
2
|
+
**Note** — You don’t need `bun create` to use Bun. You don’t need any configuration at all. This command exists to make getting started a bit quicker and easier.
|
|
3
|
+
{% /callout %}
|
|
4
|
+
|
|
5
|
+
Template a new Bun project with `bun create`. This is a flexible command that can be used to create a new project with a `create-<template>` npm package, a GitHub repo, or a local template.
|
|
6
|
+
|
|
7
|
+
If you're looking to create a brand new empty project, use [`bun init`](https://bun.sh/docs/cli/init).
|
|
8
|
+
|
|
9
|
+
## From `npm`
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ bun create <template> [<destination>]
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Assuming you don't have a [local template](#from-a-local-template) with the same name, this command will download and execute the `create-<template>` package from npm. The following two commands will behave identically:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ bun create remix
|
|
19
|
+
$ bunx create-remix
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Refer to the documentation of the associated `create-<template>` package for complete documentation and usage instructions.
|
|
23
|
+
|
|
24
|
+
## From GitHub
|
|
25
|
+
|
|
26
|
+
This will download the contents of the GitHub repo to disk.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
$ bun create <user>/<repo>
|
|
30
|
+
$ bun create github.com/<user>/<repo>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Optionally specify a name for the destination folder. If no destination is specified, the repo name will be used.
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
$ bun create <user>/<repo> mydir
|
|
37
|
+
$ bun create github.com/<user>/<repo> mydir
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Bun will perform the following steps:
|
|
41
|
+
|
|
42
|
+
- Download the template
|
|
43
|
+
- Copy all template files into the destination folder
|
|
44
|
+
- Install dependencies with `bun install`.
|
|
45
|
+
- Initialize a fresh Git repo. Opt out with the `--no-git` flag.
|
|
46
|
+
- Run the template's configured `start` script, if defined.
|
|
47
|
+
|
|
48
|
+
{% callout %}
|
|
49
|
+
By default Bun will _not overwrite_ any existing files. Use the `--force` flag to overwrite existing files.
|
|
50
|
+
{% /callout %}
|
|
51
|
+
|
|
52
|
+
<!-- ### Official templates
|
|
53
|
+
|
|
54
|
+
The following official templates are available.
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
bun create next ./myapp
|
|
58
|
+
bun create react ./myapp
|
|
59
|
+
bun create svelte-kit ./myapp
|
|
60
|
+
bun create elysia ./myapp
|
|
61
|
+
bun create hono ./myapp
|
|
62
|
+
bun create kingworld ./myapp
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Each of these corresponds to a directory in the [bun-community/create-templates](https://github.com/bun-community/create-templates) repo. If you think a major framework is missing, please open a PR there. This list will change over time as additional examples are added. To see an up-to-date list, run `bun create` with no arguments.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
$ bun create
|
|
69
|
+
Welcome to bun! Create a new project by pasting any of the following:
|
|
70
|
+
<list of templates>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
{% callout %}
|
|
74
|
+
⚡️ **Speed** — At the time of writing, `bun create react app` runs ~11x faster on a M1 Macbook Pro than `yarn create react-app app`.
|
|
75
|
+
{% /callout %} -->
|
|
76
|
+
|
|
77
|
+
<!-- ### GitHub repos
|
|
78
|
+
|
|
79
|
+
A template of the form `<username>/<repo>` will be downloaded from GitHub.
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
$ bun create ahfarmer/calculator ./myapp
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Complete GitHub URLs will also work:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
$ bun create github.com/ahfarmer/calculator ./myapp
|
|
89
|
+
$ bun create https://github.com/ahfarmer/calculator ./myapp
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Bun installs the files as they currently exist current default branch (usually `main` or `master`). Unlike `git clone` it doesn't download the commit history or configure a remote. -->
|
|
93
|
+
|
|
94
|
+
## From a local template
|
|
95
|
+
|
|
96
|
+
{% callout %}
|
|
97
|
+
**⚠️ Warning** — Unlike remote templates, running `bun create` with a local template will delete the entire destination folder if it already exists! Be careful.
|
|
98
|
+
{% /callout %}
|
|
99
|
+
Bun's templater can be extended to support custom templates defined on your local file system. These templates should live in one of the following directories:
|
|
100
|
+
|
|
101
|
+
- `$HOME/.bun-create/<name>`: global templates
|
|
102
|
+
- `<project root>/.bun-create/<name>`: project-specific templates
|
|
103
|
+
|
|
104
|
+
{% callout %}
|
|
105
|
+
**Note** — You can customize the global template path by setting the `BUN_CREATE_DIR` environment variable.
|
|
106
|
+
{% /callout %}
|
|
107
|
+
|
|
108
|
+
To create a local template, navigate to `$HOME/.bun-create` and create a new directory with the desired name of your template.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ cd $HOME/.bun-create
|
|
112
|
+
$ mkdir foo
|
|
113
|
+
$ cd foo
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then, create a `package.json` file in that directory with the following contents:
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"name": "foo"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
You can run `bun create foo` elsewhere on your file system to verify that Bun is correctly finding your local template.
|
|
125
|
+
|
|
126
|
+
#### Setup logic
|
|
127
|
+
|
|
128
|
+
You can specify pre- and post-install setup scripts in the `"bun-create"` section of your local template's `package.json`.
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"name": "@bun-examples/simplereact",
|
|
133
|
+
"version": "0.0.1",
|
|
134
|
+
"main": "index.js",
|
|
135
|
+
"dependencies": {
|
|
136
|
+
"react": "^17.0.2",
|
|
137
|
+
"react-dom": "^17.0.2"
|
|
138
|
+
},
|
|
139
|
+
"bun-create": {
|
|
140
|
+
"preinstall": "echo 'Installing...'", // a single command
|
|
141
|
+
"postinstall": ["echo 'Done!'"], // an array of commands
|
|
142
|
+
"start": "bun run echo 'Hello world!'"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The following fields are supported. Each of these can correspond to a string or array of strings. An array of commands will be executed in order.
|
|
148
|
+
|
|
149
|
+
{% table %}
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
- `postinstall`
|
|
154
|
+
- runs after installing dependencies
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
- `preinstall`
|
|
159
|
+
- runs before installing dependencies
|
|
160
|
+
|
|
161
|
+
{% /table %}
|
|
162
|
+
|
|
163
|
+
After cloning a template, `bun create` will automatically remove the `"bun-create"` section from `package.json` before writing it to the destination folder.
|
|
164
|
+
|
|
165
|
+
## Reference
|
|
166
|
+
|
|
167
|
+
### CLI flags
|
|
168
|
+
|
|
169
|
+
{% table %}
|
|
170
|
+
|
|
171
|
+
- Flag
|
|
172
|
+
- Description
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
- `--force`
|
|
177
|
+
- Overwrite existing files
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
- `--no-install`
|
|
182
|
+
- Skip installing `node_modules` & tasks
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
- `--no-git`
|
|
187
|
+
- Don’t initialize a git repository
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
- `--open`
|
|
192
|
+
- Start & open in-browser after finish
|
|
193
|
+
|
|
194
|
+
{% /table %}
|
|
195
|
+
|
|
196
|
+
### Environment variables
|
|
197
|
+
|
|
198
|
+
{% table %}
|
|
199
|
+
|
|
200
|
+
- Name
|
|
201
|
+
- Description
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
- `GITHUB_API_DOMAIN`
|
|
206
|
+
- If you’re using a GitHub enterprise or a proxy, you can customize the GitHub domain Bun pings for downloads
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
- `GITHUB_TOKEN` (or `GITHUB_ACCESS_TOKEN`)
|
|
211
|
+
- This lets `bun create` work with private repositories or if you get rate-limited. `GITHUB_TOKEN` is chosen over `GITHUB_ACCESS_TOKEN` if both exist.
|
|
212
|
+
|
|
213
|
+
{% /table %}
|
|
214
|
+
|
|
215
|
+
{% details summary="How `bun create` works" %}
|
|
216
|
+
|
|
217
|
+
When you run `bun create ${template} ${destination}`, here’s what happens:
|
|
218
|
+
|
|
219
|
+
IF remote template
|
|
220
|
+
|
|
221
|
+
1. GET `registry.npmjs.org/@bun-examples/${template}/latest` and parse it
|
|
222
|
+
2. GET `registry.npmjs.org/@bun-examples/${template}/-/${template}-${latestVersion}.tgz`
|
|
223
|
+
3. Decompress & extract `${template}-${latestVersion}.tgz` into `${destination}`
|
|
224
|
+
|
|
225
|
+
- If there are files that would overwrite, warn and exit unless `--force` is passed
|
|
226
|
+
|
|
227
|
+
IF GitHub repo
|
|
228
|
+
|
|
229
|
+
1. Download the tarball from GitHub’s API
|
|
230
|
+
2. Decompress & extract into `${destination}`
|
|
231
|
+
|
|
232
|
+
- If there are files that would overwrite, warn and exit unless `--force` is passed
|
|
233
|
+
|
|
234
|
+
ELSE IF local template
|
|
235
|
+
|
|
236
|
+
1. Open local template folder
|
|
237
|
+
2. Delete destination directory recursively
|
|
238
|
+
3. Copy files recursively using the fastest system calls available (on macOS `fcopyfile` and Linux, `copy_file_range`). Do not copy or traverse into `node_modules` folder if exists (this alone makes it faster than `cp`)
|
|
239
|
+
|
|
240
|
+
4. Parse the `package.json` (again!), update `name` to be `${basename(destination)}`, remove the `bun-create` section from the `package.json` and save the updated `package.json` to disk.
|
|
241
|
+
- IF Next.js is detected, add `bun-framework-next` to the list of dependencies
|
|
242
|
+
- IF Create React App is detected, add the entry point in /src/index.{js,jsx,ts,tsx} to `public/index.html`
|
|
243
|
+
- IF Relay is detected, add `bun-macro-relay` so that Relay works
|
|
244
|
+
5. Auto-detect the npm client, preferring `pnpm`, `yarn` (v1), and lastly `npm`
|
|
245
|
+
6. Run any tasks defined in `"bun-create": { "preinstall" }` with the npm client
|
|
246
|
+
7. Run `${npmClient} install` unless `--no-install` is passed OR no dependencies are in package.json
|
|
247
|
+
8. Run any tasks defined in `"bun-create": { "postinstall" }` with the npm client
|
|
248
|
+
9. Run `git init; git add -A .; git commit -am "Initial Commit";`
|
|
249
|
+
|
|
250
|
+
- Rename `gitignore` to `.gitignore`. NPM automatically removes `.gitignore` files from appearing in packages.
|
|
251
|
+
- If there are dependencies, this runs in a separate thread concurrently while node_modules are being installed
|
|
252
|
+
- Using libgit2 if available was tested and performed 3x slower in microbenchmarks
|
|
253
|
+
|
|
254
|
+
{% /details %}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
In your project folder root (where `package.json` is):
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
$ bun bun ./entry-point-1.js ./entry-point-2.jsx
|
|
5
|
+
$ bun dev
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
By default, `bun dev` will look for any HTML files in the `public` directory and serve that. For browsers navigating to the page, the `.html` file extension is optional in the URL, and `index.html` will automatically rewrite for the directory.
|
|
9
|
+
|
|
10
|
+
Here are examples of routing from `public/` and how they’re matched:
|
|
11
|
+
| Dev Server URL | File Path |
|
|
12
|
+
|----------------|-----------|
|
|
13
|
+
| /dir | public/dir/index.html |
|
|
14
|
+
| / | public/index.html |
|
|
15
|
+
| /index | public/index.html |
|
|
16
|
+
| /hi | public/hi.html |
|
|
17
|
+
| /file | public/file.html |
|
|
18
|
+
| /font/Inter.woff2 | public/font/Inter.woff2 |
|
|
19
|
+
| /hello | public/index.html |
|
|
20
|
+
|
|
21
|
+
If `public/index.html` exists, it becomes the default page instead of a 404 page, unless that pathname has a file extension.
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
### `bun install`
|
|
2
|
+
|
|
3
|
+
bun install is a fast package manager & npm client.
|
|
4
|
+
|
|
5
|
+
bun install can be configured via `bunfig.toml`, environment variables, and CLI flags.
|
|
6
|
+
|
|
7
|
+
#### Configuring `bun install` with `bunfig.toml`
|
|
8
|
+
|
|
9
|
+
`bunfig.toml` is searched for in the following paths on `bun install`, `bun remove`, and `bun add`:
|
|
10
|
+
|
|
11
|
+
1. `$XDG_CONFIG_HOME/.bunfig.toml` or `$HOME/.bunfig.toml`
|
|
12
|
+
2. `./bunfig.toml`
|
|
13
|
+
|
|
14
|
+
If both are found, the results are merged together.
|
|
15
|
+
|
|
16
|
+
Configuring with `bunfig.toml` is optional. Bun tries to be zero configuration in general, but that's not always possible.
|
|
17
|
+
|
|
18
|
+
```toml
|
|
19
|
+
# Using scoped packages with bun install
|
|
20
|
+
[install.scopes]
|
|
21
|
+
|
|
22
|
+
# Scope name The value can be a URL string or an object
|
|
23
|
+
"@mybigcompany" = { token = "123456", url = "https://registry.mybigcompany.com" }
|
|
24
|
+
# URL is optional and falls back to the default registry
|
|
25
|
+
|
|
26
|
+
# The "@" in the scope is optional
|
|
27
|
+
mybigcompany2 = { token = "123456" }
|
|
28
|
+
|
|
29
|
+
# Environment variables can be referenced as a string that starts with $ and it will be replaced
|
|
30
|
+
mybigcompany3 = { token = "$npm_config_token" }
|
|
31
|
+
|
|
32
|
+
# Setting username and password turns it into a Basic Auth header by taking base64("username:password")
|
|
33
|
+
mybigcompany4 = { username = "myusername", password = "$npm_config_password", url = "https://registry.yarnpkg.com/" }
|
|
34
|
+
# You can set username and password in the registry URL. This is the same as above.
|
|
35
|
+
mybigcompany5 = "https://username:password@registry.yarnpkg.com/"
|
|
36
|
+
|
|
37
|
+
# You can set a token for a registry URL:
|
|
38
|
+
mybigcompany6 = "https://:$NPM_CONFIG_TOKEN@registry.yarnpkg.com/"
|
|
39
|
+
|
|
40
|
+
[install]
|
|
41
|
+
# Default registry
|
|
42
|
+
# can be a URL string or an object
|
|
43
|
+
registry = "https://registry.yarnpkg.com/"
|
|
44
|
+
# as an object
|
|
45
|
+
#registry = { url = "https://registry.yarnpkg.com/", token = "123456" }
|
|
46
|
+
|
|
47
|
+
# Install for production? This is the equivalent to the "--production" CLI argument
|
|
48
|
+
production = false
|
|
49
|
+
|
|
50
|
+
# Disallow changes to lockfile? This is the equivalent to the "--frozen-lockfile" CLI argument
|
|
51
|
+
frozenLockfile = false
|
|
52
|
+
|
|
53
|
+
# Don't actually install
|
|
54
|
+
dryRun = true
|
|
55
|
+
|
|
56
|
+
# Install optionalDependencies (default: true)
|
|
57
|
+
optional = true
|
|
58
|
+
|
|
59
|
+
# Install local devDependencies (default: true)
|
|
60
|
+
dev = true
|
|
61
|
+
|
|
62
|
+
# Install peerDependencies (default: true)
|
|
63
|
+
peer = true
|
|
64
|
+
|
|
65
|
+
# Max number of concurrent lifecycle scripts (default: (cpu count or GOMAXPROCS) x2)
|
|
66
|
+
concurrentScripts = 16
|
|
67
|
+
|
|
68
|
+
# When using `bun install -g`, install packages here
|
|
69
|
+
globalDir = "~/.bun/install/global"
|
|
70
|
+
|
|
71
|
+
# When using `bun install -g`, link package bins here
|
|
72
|
+
globalBinDir = "~/.bun/bin"
|
|
73
|
+
|
|
74
|
+
# cache-related configuration
|
|
75
|
+
[install.cache]
|
|
76
|
+
# The directory to use for the cache
|
|
77
|
+
dir = "~/.bun/install/cache"
|
|
78
|
+
|
|
79
|
+
# Don't load from the global cache.
|
|
80
|
+
# Note: Bun may still write to node_modules/.cache
|
|
81
|
+
disable = false
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# Always resolve the latest versions from the registry
|
|
85
|
+
disableManifest = false
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
# Lockfile-related configuration
|
|
89
|
+
[install.lockfile]
|
|
90
|
+
|
|
91
|
+
# Print a yarn v1 lockfile
|
|
92
|
+
# Note: it does not load the lockfile, it just converts bun.lockb into a yarn.lock
|
|
93
|
+
print = "yarn"
|
|
94
|
+
|
|
95
|
+
# Save the lockfile to disk
|
|
96
|
+
save = true
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If it's easier to read as TypeScript types:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
export interface Root {
|
|
104
|
+
install: Install;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface Install {
|
|
108
|
+
scopes: Scopes;
|
|
109
|
+
registry: Registry;
|
|
110
|
+
production: boolean;
|
|
111
|
+
frozenLockfile: boolean;
|
|
112
|
+
dryRun: boolean;
|
|
113
|
+
optional: boolean;
|
|
114
|
+
dev: boolean;
|
|
115
|
+
peer: boolean;
|
|
116
|
+
globalDir: string;
|
|
117
|
+
globalBinDir: string;
|
|
118
|
+
cache: Cache;
|
|
119
|
+
lockfile: Lockfile;
|
|
120
|
+
logLevel: "debug" | "error" | "warn";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type Registry =
|
|
124
|
+
| string
|
|
125
|
+
| {
|
|
126
|
+
url?: string;
|
|
127
|
+
token?: string;
|
|
128
|
+
username?: string;
|
|
129
|
+
password?: string;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
type Scopes = Record<string, Registry>;
|
|
133
|
+
|
|
134
|
+
export interface Cache {
|
|
135
|
+
dir: string;
|
|
136
|
+
disable: boolean;
|
|
137
|
+
disableManifest: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface Lockfile {
|
|
141
|
+
print?: "yarn";
|
|
142
|
+
save: boolean;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Configuring with environment variables
|
|
147
|
+
|
|
148
|
+
Environment variables have a higher priority than `bunfig.toml`.
|
|
149
|
+
|
|
150
|
+
| Name | Description |
|
|
151
|
+
| -------------------------------- | ------------------------------------------------------------- |
|
|
152
|
+
| BUN_CONFIG_REGISTRY | Set an npm registry (default: <https://registry.npmjs.org>) |
|
|
153
|
+
| BUN_CONFIG_TOKEN | Set an auth token (currently does nothing) |
|
|
154
|
+
| BUN_CONFIG_YARN_LOCKFILE | Save a Yarn v1-style yarn.lock |
|
|
155
|
+
| BUN_CONFIG_LINK_NATIVE_BINS | Point `bin` in package.json to a platform-specific dependency |
|
|
156
|
+
| BUN_CONFIG_SKIP_SAVE_LOCKFILE | Don’t save a lockfile |
|
|
157
|
+
| BUN_CONFIG_SKIP_LOAD_LOCKFILE | Don’t load a lockfile |
|
|
158
|
+
| BUN_CONFIG_SKIP_INSTALL_PACKAGES | Don’t install any packages |
|
|
159
|
+
|
|
160
|
+
Bun always tries to use the fastest available installation method for the target platform. On macOS, that’s `clonefile` and on Linux, that’s `hardlink`. You can change which installation method is used with the `--backend` flag. When unavailable or on error, `clonefile` and `hardlink` fallsback to a platform-specific implementation of copying files.
|
|
161
|
+
|
|
162
|
+
Bun stores installed packages from npm in `~/.bun/install/cache/${name}@${version}`. Note that if the semver version has a `build` or a `pre` tag, it is replaced with a hash of that value instead. This is to reduce the chances of errors from long file paths, but unfortunately complicates figuring out where a package was installed on disk.
|
|
163
|
+
|
|
164
|
+
When the `node_modules` folder exists, before installing, Bun checks if the `"name"` and `"version"` in `package/package.json` in the expected node_modules folder matches the expected `name` and `version`. This is how it determines whether it should install. It uses a custom JSON parser which stops parsing as soon as it finds `"name"` and `"version"`.
|
|
165
|
+
|
|
166
|
+
When a `bun.lockb` doesn’t exist or `package.json` has changed dependencies, tarballs are downloaded & extracted eagerly while resolving.
|
|
167
|
+
|
|
168
|
+
When a `bun.lockb` exists and `package.json` hasn’t changed, Bun downloads missing dependencies lazily. If the package with a matching `name` & `version` already exists in the expected location within `node_modules`, Bun won’t attempt to download the tarball.
|
|
169
|
+
|
|
170
|
+
## Platform-specific dependencies?
|
|
171
|
+
|
|
172
|
+
bun stores normalized `cpu` and `os` values from npm in the lockfile, along with the resolved packages. It skips downloading, extracting, and installing packages disabled for the current target at runtime. This means the lockfile won’t change between platforms/architectures even if the packages ultimately installed do change.
|
|
173
|
+
|
|
174
|
+
## Peer dependencies?
|
|
175
|
+
|
|
176
|
+
Peer dependencies are handled similarly to yarn. `bun install` will automatically install peer dependencies. If the dependency is marked optional in `peerDependenciesMeta`, an existing dependency will be chosen if possible.
|
|
177
|
+
|
|
178
|
+
## Lockfile
|
|
179
|
+
|
|
180
|
+
`bun.lockb` is Bun’s binary lockfile format.
|
|
181
|
+
|
|
182
|
+
## Why is it binary?
|
|
183
|
+
|
|
184
|
+
In a word: Performance. Bun’s lockfile saves & loads incredibly quickly, and saves a lot more data than what is typically inside lockfiles.
|
|
185
|
+
|
|
186
|
+
## How do I inspect it?
|
|
187
|
+
|
|
188
|
+
For now, the easiest thing is to run `bun install -y`. That prints a Yarn v1-style yarn.lock file.
|
|
189
|
+
|
|
190
|
+
## What does the lockfile store?
|
|
191
|
+
|
|
192
|
+
Packages, metadata for those packages, the hoisted install order, dependencies for each package, what packages those dependencies resolved to, an integrity hash (if available), what each package was resolved to and which version (or equivalent).
|
|
193
|
+
|
|
194
|
+
## Why is it fast?
|
|
195
|
+
|
|
196
|
+
It uses linear arrays for all data. [Packages](https://github.com/oven-sh/bun/blob/be03fc273a487ac402f19ad897778d74b6d72963/src/install/install.zig#L1825) are referenced by an auto-incrementing integer ID or a hash of the package name. Strings longer than 8 characters are de-duplicated. Prior to saving on disk, the lockfile is garbage-collected & made deterministic by walking the package tree and cloning the packages in dependency order.
|
|
197
|
+
|
|
198
|
+
## Cache
|
|
199
|
+
|
|
200
|
+
To delete the cache:
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
$ rm -rf ~/.bun/install/cache
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Platform-specific backends
|
|
207
|
+
|
|
208
|
+
`bun install` uses different system calls to install dependencies depending on the platform. This is a performance optimization. You can force a specific backend with the `--backend` flag.
|
|
209
|
+
|
|
210
|
+
**`hardlink`** is the default backend on Linux. Benchmarking showed it to be the fastest on Linux.
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
$ rm -rf node_modules
|
|
214
|
+
$ bun install --backend hardlink
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**`clonefile`** is the default backend on macOS. Benchmarking showed it to be the fastest on macOS. It is only available on macOS.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
$ rm -rf node_modules
|
|
221
|
+
$ bun install --backend clonefile
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**`clonefile_each_dir`** is similar to `clonefile`, except it clones each file individually per directory. It is only available on macOS and tends to perform slower than `clonefile`. Unlike `clonefile`, this does not recursively clone subdirectories in one system call.
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
$ rm -rf node_modules
|
|
228
|
+
$ bun install --backend clonefile_each_dir
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**`copyfile`** is the fallback used when any of the above fail, and is the slowest. on macOS, it uses `fcopyfile()` and on linux it uses `copy_file_range()`.
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
$ rm -rf node_modules
|
|
235
|
+
$ bun install --backend copyfile
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**`symlink`** is typically only used for `file:` dependencies (and eventually `link:`) internally. To prevent infinite loops, it skips symlinking the `node_modules` folder.
|
|
239
|
+
|
|
240
|
+
If you install with `--backend=symlink`, Node.js won't resolve node_modules of dependencies unless each dependency has its own node_modules folder or you pass `--preserve-symlinks` to `node`. See [Node.js documentation on `--preserve-symlinks`](https://nodejs.org/api/cli.html#--preserve-symlinks).
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
$ rm -rf node_modules
|
|
244
|
+
$ bun install --backend symlink
|
|
245
|
+
$ node --preserve-symlinks ./my-file.js # https://nodejs.org/api/cli.html#--preserve-symlinks
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Bun's runtime does not currently expose an equivalent of `--preserve-symlinks`, though the code for it does exist.
|
|
249
|
+
|
|
250
|
+
## npm registry metadata
|
|
251
|
+
|
|
252
|
+
bun uses a binary format for caching NPM registry responses. This loads much faster than JSON and tends to be smaller on disk.
|
|
253
|
+
You will see these files in `~/.bun/install/cache/*.npm`. The filename pattern is `${hash(packageName)}.npm`. It’s a hash so that extra directories don’t need to be created for scoped packages.
|
|
254
|
+
|
|
255
|
+
Bun's usage of `Cache-Control` ignores `Age`. This improves performance, but means bun may be about 5 minutes out of date to receive the latest package version metadata from npm.
|