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.
Files changed (272) hide show
  1. package/docs/api/binary-data.md +1028 -0
  2. package/docs/api/cc.md +197 -0
  3. package/docs/api/color.md +262 -0
  4. package/docs/api/console.md +38 -0
  5. package/docs/api/dns.md +113 -0
  6. package/docs/api/fetch.md +308 -0
  7. package/docs/api/ffi.md +536 -0
  8. package/docs/api/file-io.md +358 -0
  9. package/docs/api/file-system-router.md +112 -0
  10. package/docs/api/file.md +19 -0
  11. package/docs/api/glob.md +157 -0
  12. package/docs/api/globals.md +387 -0
  13. package/docs/api/hashing.md +314 -0
  14. package/docs/api/html-rewriter.md +31 -0
  15. package/docs/api/http.md +661 -0
  16. package/docs/api/import-meta.md +69 -0
  17. package/docs/api/node-api.md +16 -0
  18. package/docs/api/semver.md +52 -0
  19. package/docs/api/spawn.md +441 -0
  20. package/docs/api/sqlite.md +692 -0
  21. package/docs/api/streams.md +214 -0
  22. package/docs/api/tcp.md +221 -0
  23. package/docs/api/test.md +1 -0
  24. package/docs/api/transpiler.md +274 -0
  25. package/docs/api/udp.md +125 -0
  26. package/docs/api/utils.md +773 -0
  27. package/docs/api/websockets.md +547 -0
  28. package/docs/api/workers.md +230 -0
  29. package/docs/benchmarks.md +120 -0
  30. package/docs/bun-flavored-toml.md +42 -0
  31. package/docs/bundler/executables.md +291 -0
  32. package/docs/bundler/index.md +1543 -0
  33. package/docs/bundler/intro.md +75 -0
  34. package/docs/bundler/loaders.md +288 -0
  35. package/docs/bundler/macros.md +327 -0
  36. package/docs/bundler/plugins.md +30 -0
  37. package/docs/bundler/vs-esbuild.md +1127 -0
  38. package/docs/cli/add.md +163 -0
  39. package/docs/cli/bun-completions.md +3 -0
  40. package/docs/cli/bun-create.md +254 -0
  41. package/docs/cli/bun-dev.md +21 -0
  42. package/docs/cli/bun-install.md +255 -0
  43. package/docs/cli/bun-upgrade.md +39 -0
  44. package/docs/cli/bunx.md +80 -0
  45. package/docs/cli/filter.md +57 -0
  46. package/docs/cli/init.md +40 -0
  47. package/docs/cli/install.md +205 -0
  48. package/docs/cli/link.md +38 -0
  49. package/docs/cli/outdated.md +61 -0
  50. package/docs/cli/patch-commit.md +9 -0
  51. package/docs/cli/pm.md +150 -0
  52. package/docs/cli/publish.md +107 -0
  53. package/docs/cli/remove.md +5 -0
  54. package/docs/cli/run.md +196 -0
  55. package/docs/cli/test.md +247 -0
  56. package/docs/cli/unlink.md +7 -0
  57. package/docs/cli/update.md +34 -0
  58. package/docs/contributing/upgrading-webkit.md +57 -0
  59. package/docs/ecosystem/elysia.md +24 -0
  60. package/docs/ecosystem/express.md +37 -0
  61. package/docs/ecosystem/hono.md +18 -0
  62. package/docs/ecosystem/react.md +65 -0
  63. package/docs/ecosystem/stric.md +37 -0
  64. package/docs/guides/binary/arraybuffer-to-array.md +27 -0
  65. package/docs/guides/binary/arraybuffer-to-blob.md +24 -0
  66. package/docs/guides/binary/arraybuffer-to-buffer.md +25 -0
  67. package/docs/guides/binary/arraybuffer-to-string.md +15 -0
  68. package/docs/guides/binary/arraybuffer-to-typedarray.md +39 -0
  69. package/docs/guides/binary/blob-to-arraybuffer.md +14 -0
  70. package/docs/guides/binary/blob-to-dataview.md +14 -0
  71. package/docs/guides/binary/blob-to-stream.md +14 -0
  72. package/docs/guides/binary/blob-to-string.md +15 -0
  73. package/docs/guides/binary/blob-to-typedarray.md +14 -0
  74. package/docs/guides/binary/buffer-to-arraybuffer.md +14 -0
  75. package/docs/guides/binary/buffer-to-blob.md +14 -0
  76. package/docs/guides/binary/buffer-to-readablestream.md +41 -0
  77. package/docs/guides/binary/buffer-to-string.md +25 -0
  78. package/docs/guides/binary/buffer-to-typedarray.md +14 -0
  79. package/docs/guides/binary/dataview-to-string.md +15 -0
  80. package/docs/guides/binary/typedarray-to-arraybuffer.md +25 -0
  81. package/docs/guides/binary/typedarray-to-blob.md +16 -0
  82. package/docs/guides/binary/typedarray-to-buffer.md +14 -0
  83. package/docs/guides/binary/typedarray-to-dataview.md +14 -0
  84. package/docs/guides/binary/typedarray-to-readablestream.md +41 -0
  85. package/docs/guides/binary/typedarray-to-string.md +16 -0
  86. package/docs/guides/ecosystem/astro.md +72 -0
  87. package/docs/guides/ecosystem/discordjs.md +77 -0
  88. package/docs/guides/ecosystem/docker.md +140 -0
  89. package/docs/guides/ecosystem/drizzle.md +185 -0
  90. package/docs/guides/ecosystem/edgedb.md +228 -0
  91. package/docs/guides/ecosystem/elysia.md +31 -0
  92. package/docs/guides/ecosystem/express.md +40 -0
  93. package/docs/guides/ecosystem/hono.md +39 -0
  94. package/docs/guides/ecosystem/mongoose.md +87 -0
  95. package/docs/guides/ecosystem/neon-drizzle.md +220 -0
  96. package/docs/guides/ecosystem/neon-serverless-postgres.md +55 -0
  97. package/docs/guides/ecosystem/nextjs.md +38 -0
  98. package/docs/guides/ecosystem/nuxt.md +56 -0
  99. package/docs/guides/ecosystem/pm2.md +57 -0
  100. package/docs/guides/ecosystem/prisma.md +140 -0
  101. package/docs/guides/ecosystem/qwik.md +107 -0
  102. package/docs/guides/ecosystem/react.md +49 -0
  103. package/docs/guides/ecosystem/remix.md +78 -0
  104. package/docs/guides/ecosystem/render.md +79 -0
  105. package/docs/guides/ecosystem/sentry.md +52 -0
  106. package/docs/guides/ecosystem/solidstart.md +58 -0
  107. package/docs/guides/ecosystem/ssr-react.md +51 -0
  108. package/docs/guides/ecosystem/stric.md +55 -0
  109. package/docs/guides/ecosystem/sveltekit.md +125 -0
  110. package/docs/guides/ecosystem/systemd.md +113 -0
  111. package/docs/guides/ecosystem/vite.md +70 -0
  112. package/docs/guides/http/cluster.md +66 -0
  113. package/docs/guides/http/fetch-unix.md +33 -0
  114. package/docs/guides/http/fetch.md +24 -0
  115. package/docs/guides/http/file-uploads.md +94 -0
  116. package/docs/guides/http/hot.md +22 -0
  117. package/docs/guides/http/proxy.md +24 -0
  118. package/docs/guides/http/server.md +46 -0
  119. package/docs/guides/http/simple.md +18 -0
  120. package/docs/guides/http/stream-file.md +48 -0
  121. package/docs/guides/http/stream-iterator.md +47 -0
  122. package/docs/guides/http/stream-node-streams-in-bun.md +20 -0
  123. package/docs/guides/http/tls.md +30 -0
  124. package/docs/guides/install/add-dev.md +26 -0
  125. package/docs/guides/install/add-git.md +36 -0
  126. package/docs/guides/install/add-optional.md +25 -0
  127. package/docs/guides/install/add-peer.md +17 -0
  128. package/docs/guides/install/add-tarball.md +33 -0
  129. package/docs/guides/install/add.md +42 -0
  130. package/docs/guides/install/azure-artifacts.md +73 -0
  131. package/docs/guides/install/cicd.md +41 -0
  132. package/docs/guides/install/custom-registry.md +30 -0
  133. package/docs/guides/install/from-npm-install-to-bun-install.md +214 -0
  134. package/docs/guides/install/git-diff-bun-lockfile.md +38 -0
  135. package/docs/guides/install/jfrog-artifactory.md +28 -0
  136. package/docs/guides/install/npm-alias.md +23 -0
  137. package/docs/guides/install/registry-scope.md +36 -0
  138. package/docs/guides/install/trusted.md +48 -0
  139. package/docs/guides/install/workspaces.md +70 -0
  140. package/docs/guides/install/yarnlock.md +42 -0
  141. package/docs/guides/process/argv.md +57 -0
  142. package/docs/guides/process/ctrl-c.md +16 -0
  143. package/docs/guides/process/ipc.md +66 -0
  144. package/docs/guides/process/nanoseconds.md +13 -0
  145. package/docs/guides/process/os-signals.md +39 -0
  146. package/docs/guides/process/spawn-stderr.md +31 -0
  147. package/docs/guides/process/spawn-stdout.md +26 -0
  148. package/docs/guides/process/spawn.md +41 -0
  149. package/docs/guides/process/stdin.md +54 -0
  150. package/docs/guides/read-file/arraybuffer.md +28 -0
  151. package/docs/guides/read-file/buffer.md +19 -0
  152. package/docs/guides/read-file/exists.md +16 -0
  153. package/docs/guides/read-file/json.md +17 -0
  154. package/docs/guides/read-file/mime.md +20 -0
  155. package/docs/guides/read-file/stream.md +26 -0
  156. package/docs/guides/read-file/string.md +22 -0
  157. package/docs/guides/read-file/uint8array.md +21 -0
  158. package/docs/guides/read-file/watch.md +68 -0
  159. package/docs/guides/runtime/cicd.md +43 -0
  160. package/docs/guides/runtime/define-constant.md +145 -0
  161. package/docs/guides/runtime/import-html.md +15 -0
  162. package/docs/guides/runtime/import-json.md +44 -0
  163. package/docs/guides/runtime/import-toml.md +30 -0
  164. package/docs/guides/runtime/read-env.md +32 -0
  165. package/docs/guides/runtime/set-env.md +37 -0
  166. package/docs/guides/runtime/shell.md +40 -0
  167. package/docs/guides/runtime/timezone.md +35 -0
  168. package/docs/guides/runtime/tsconfig-paths.md +29 -0
  169. package/docs/guides/runtime/typescript.md +47 -0
  170. package/docs/guides/runtime/vscode-debugger.md +47 -0
  171. package/docs/guides/runtime/web-debugger.md +82 -0
  172. package/docs/guides/streams/node-readable-to-arraybuffer.md +11 -0
  173. package/docs/guides/streams/node-readable-to-blob.md +11 -0
  174. package/docs/guides/streams/node-readable-to-json.md +12 -0
  175. package/docs/guides/streams/node-readable-to-string.md +12 -0
  176. package/docs/guides/streams/node-readable-to-uint8array.md +11 -0
  177. package/docs/guides/streams/to-array.md +14 -0
  178. package/docs/guides/streams/to-arraybuffer.md +14 -0
  179. package/docs/guides/streams/to-blob.md +14 -0
  180. package/docs/guides/streams/to-buffer.md +15 -0
  181. package/docs/guides/streams/to-json.md +14 -0
  182. package/docs/guides/streams/to-string.md +14 -0
  183. package/docs/guides/streams/to-typedarray.md +22 -0
  184. package/docs/guides/test/bail.md +22 -0
  185. package/docs/guides/test/coverage-threshold.md +60 -0
  186. package/docs/guides/test/coverage.md +44 -0
  187. package/docs/guides/test/happy-dom.md +68 -0
  188. package/docs/guides/test/migrate-from-jest.md +110 -0
  189. package/docs/guides/test/mock-clock.md +48 -0
  190. package/docs/guides/test/mock-functions.md +68 -0
  191. package/docs/guides/test/rerun-each.md +14 -0
  192. package/docs/guides/test/run-tests.md +111 -0
  193. package/docs/guides/test/skip-tests.md +39 -0
  194. package/docs/guides/test/snapshot.md +99 -0
  195. package/docs/guides/test/spy-on.md +46 -0
  196. package/docs/guides/test/testing-library.md +87 -0
  197. package/docs/guides/test/timeout.md +15 -0
  198. package/docs/guides/test/todo-tests.md +67 -0
  199. package/docs/guides/test/update-snapshots.md +50 -0
  200. package/docs/guides/test/watch-mode.md +19 -0
  201. package/docs/guides/util/base64.md +15 -0
  202. package/docs/guides/util/deep-equals.md +39 -0
  203. package/docs/guides/util/deflate.md +18 -0
  204. package/docs/guides/util/detect-bun.md +23 -0
  205. package/docs/guides/util/entrypoint.md +17 -0
  206. package/docs/guides/util/escape-html.md +22 -0
  207. package/docs/guides/util/file-url-to-path.md +14 -0
  208. package/docs/guides/util/gzip.md +18 -0
  209. package/docs/guides/util/hash-a-password.md +54 -0
  210. package/docs/guides/util/import-meta-dir.md +13 -0
  211. package/docs/guides/util/import-meta-file.md +13 -0
  212. package/docs/guides/util/import-meta-path.md +13 -0
  213. package/docs/guides/util/main.md +32 -0
  214. package/docs/guides/util/path-to-file-url.md +14 -0
  215. package/docs/guides/util/sleep.md +22 -0
  216. package/docs/guides/util/version.md +21 -0
  217. package/docs/guides/util/which-path-to-executable-bin.md +15 -0
  218. package/docs/guides/websocket/compression.md +31 -0
  219. package/docs/guides/websocket/context.md +72 -0
  220. package/docs/guides/websocket/pubsub.md +38 -0
  221. package/docs/guides/websocket/simple.md +33 -0
  222. package/docs/guides/write-file/append.md +52 -0
  223. package/docs/guides/write-file/basic.md +44 -0
  224. package/docs/guides/write-file/blob.md +28 -0
  225. package/docs/guides/write-file/cat.md +17 -0
  226. package/docs/guides/write-file/file-cp.md +16 -0
  227. package/docs/guides/write-file/filesink.md +52 -0
  228. package/docs/guides/write-file/response.md +17 -0
  229. package/docs/guides/write-file/stdout.md +21 -0
  230. package/docs/guides/write-file/stream.md +17 -0
  231. package/docs/guides/write-file/unlink.md +23 -0
  232. package/docs/index.md +77 -0
  233. package/docs/install/cache.md +57 -0
  234. package/docs/install/index.md +202 -0
  235. package/docs/install/lifecycle.md +46 -0
  236. package/docs/install/lockfile.md +90 -0
  237. package/docs/install/npmrc.md +75 -0
  238. package/docs/install/overrides.md +73 -0
  239. package/docs/install/patch.md +57 -0
  240. package/docs/install/registries.md +30 -0
  241. package/docs/install/workspaces.md +70 -0
  242. package/docs/installation.md +289 -0
  243. package/docs/project/benchmarking.md +203 -0
  244. package/docs/project/building-windows.md +162 -0
  245. package/docs/project/internals/build-process-for-ci.md +75 -0
  246. package/docs/project/roadmap.md +87 -0
  247. package/docs/quickstart.md +144 -0
  248. package/docs/runtime/autoimport.md +94 -0
  249. package/docs/runtime/bun-apis.md +129 -0
  250. package/docs/runtime/bunfig.md +532 -0
  251. package/docs/runtime/debugger.md +325 -0
  252. package/docs/runtime/env.md +214 -0
  253. package/docs/runtime/hot.md +139 -0
  254. package/docs/runtime/index.md +309 -0
  255. package/docs/runtime/jsx.md +326 -0
  256. package/docs/runtime/loaders.md +127 -0
  257. package/docs/runtime/modules.md +298 -0
  258. package/docs/runtime/nodejs-apis.md +456 -0
  259. package/docs/runtime/plugins.md +605 -0
  260. package/docs/runtime/shell.md +537 -0
  261. package/docs/runtime/typescript.md +60 -0
  262. package/docs/runtime/web-apis.md +128 -0
  263. package/docs/test/coverage.md +91 -0
  264. package/docs/test/dom.md +75 -0
  265. package/docs/test/hot.md +15 -0
  266. package/docs/test/lifecycle.md +81 -0
  267. package/docs/test/mocks.md +236 -0
  268. package/docs/test/snapshots.md +15 -0
  269. package/docs/test/time.md +106 -0
  270. package/docs/test/writing.md +547 -0
  271. package/docs/typescript.md +51 -0
  272. package/package.json +5 -4
@@ -0,0 +1,107 @@
1
+ Use `bun publish` to publish a package to the npm registry.
2
+
3
+ `bun publish` will automatically pack your package into a tarball, strip workspace protocols from the `package.json` (resolving versions if necessary), and publish to the registry specified in your configuration files. Both `bunfig.toml` and `.npmrc` files are supported.
4
+
5
+ ```sh
6
+ ## Publishing the package from the current working directory
7
+ $ bun publish
8
+
9
+ ## Output
10
+ bun publish v1.1.30 (ca7428e9)
11
+
12
+ packed 203B package.json
13
+ packed 224B README.md
14
+ packed 30B index.ts
15
+ packed 0.64KB tsconfig.json
16
+
17
+ Total files: 4
18
+ Shasum: 79e2b4377b63f4de38dc7ea6e5e9dbee08311a69
19
+ Integrity: sha512-6QSNlDdSwyG/+[...]X6wXHriDWr6fA==
20
+ Unpacked size: 1.1KB
21
+ Packed size: 0.76KB
22
+ Tag: latest
23
+ Access: default
24
+ Registry: http://localhost:4873/
25
+
26
+ + publish-1@1.0.0
27
+ ```
28
+
29
+ Alternatively, you can pack and publish your package separately by using `bun pm pack` followed by `bun publish` with the path to the output tarball.
30
+
31
+ ```sh
32
+ $ bun pm pack
33
+ ...
34
+ $ bun publish ./package.tgz
35
+ ```
36
+
37
+ {% callout %}
38
+ **Note** - `bun publish` will not run lifecycle scripts (`prepublishOnly/prepack/prepare/postpack/publish/postpublish`) if a tarball path is provided. Scripts will only be run if the package is packed by `bun publish`.
39
+ {% /callout %}
40
+
41
+ ### `--access`
42
+
43
+ The `--access` flag can be used to set the access level of the package being published. The access level can be one of `public` or `restricted`. Unscoped packages are always public, and attempting to publish an unscoped package with `--access restricted` will result in an error.
44
+
45
+ ```sh
46
+ $ bun publish --access public
47
+ ```
48
+
49
+ `--access` can also be set in the `publishConfig` field of your `package.json`.
50
+
51
+ ```json
52
+ {
53
+ "publishConfig": {
54
+ "access": "restricted"
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### `--tag`
60
+
61
+ Set the tag of the package version being published. By default, the tag is `latest`. The initial version of a package is always given the `latest` tag in addition to the specified tag.
62
+
63
+ ```sh
64
+ $ bun publish --tag alpha
65
+ ```
66
+
67
+ `--tag` can also be set in the `publishConfig` field of your `package.json`.
68
+
69
+ ```json
70
+ {
71
+ "publishConfig": {
72
+ "tag": "next"
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### `--dry-run`
78
+
79
+ The `--dry-run` flag can be used to simulate the publish process without actually publishing the package. This is useful for verifying the contents of the published package without actually publishing the package.
80
+
81
+ ```sh
82
+ $ bun publish --dry-run
83
+ ```
84
+
85
+ ### `--auth-type`
86
+
87
+ If you have 2FA enabled for your npm account, `bun publish` will prompt you for a one-time password. This can be done through a browser or the CLI. The `--auth-type` flag can be used to tell the npm registry which method you prefer. The possible values are `web` and `legacy`, with `web` being the default.
88
+
89
+ ```sh
90
+ $ bun publish --auth-type legacy
91
+ ...
92
+ This operation requires a one-time password.
93
+ Enter OTP: 123456
94
+ ...
95
+ ```
96
+
97
+ ### `--otp`
98
+
99
+ Provide a one-time password directly to the CLI. If the password is valid, this will skip the extra prompt for a one-time password before publishing. Example usage:
100
+
101
+ ```sh
102
+ $ bun publish --otp 123456
103
+ ```
104
+
105
+ ### `--gzip-level`
106
+
107
+ Specify the level of gzip compression to use when packing the package. Only applies to `bun publish` without a tarball path argument. Values range from `0` to `9` (default is `9`).
@@ -0,0 +1,5 @@
1
+ To remove a dependency:
2
+
3
+ ```bash
4
+ $ bun remove ts-node
5
+ ```
@@ -0,0 +1,196 @@
1
+ The `bun` CLI can be used to execute JavaScript/TypeScript files, `package.json` scripts, and [executable packages](https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin).
2
+
3
+ ## Performance
4
+
5
+ Bun is designed to start fast and run fast.
6
+
7
+ Under the hood Bun uses the [JavaScriptCore engine](https://developer.apple.com/documentation/javascriptcore), which is developed by Apple for Safari. In most cases, the startup and running performance is faster than V8, the engine used by Node.js and Chromium-based browsers. Its transpiler and runtime are written in Zig, a modern, high-performance language. On Linux, this translates into startup times [4x faster](https://twitter.com/jarredsumner/status/1499225725492076544) than Node.js.
8
+
9
+ {% table %}
10
+
11
+ ---
12
+
13
+ - `bun hello.js`
14
+ - `5.2ms`
15
+
16
+ ---
17
+
18
+ - `node hello.js`
19
+ - `25.1ms`
20
+
21
+ {% /table %}
22
+ {% caption content="Running a simple Hello World script on Linux" /%}
23
+
24
+ <!-- {% image src="/images/bun-run-speed.jpeg" caption="Bun vs Node.js vs Deno running Hello World" /%} -->
25
+
26
+ <!-- ## Speed -->
27
+
28
+ <!--
29
+ Performance sensitive APIs like `Buffer`, `fetch`, and `Response` are heavily profiled and optimized. Under the hood Bun uses the [JavaScriptCore engine](https://developer.apple.com/documentation/javascriptcore), which is developed by Apple for Safari. It starts and runs faster than V8, the engine used by Node.js and Chromium-based browsers. -->
30
+
31
+ ## Run a file
32
+
33
+ {% callout %}
34
+ Compare to `node <file>`
35
+ {% /callout %}
36
+
37
+ Use `bun run` to execute a source file.
38
+
39
+ ```bash
40
+ $ bun run index.js
41
+ ```
42
+
43
+ Bun supports TypeScript and JSX out of the box. Every file is transpiled on the fly by Bun's fast native transpiler before being executed.
44
+
45
+ ```bash
46
+ $ bun run index.js
47
+ $ bun run index.jsx
48
+ $ bun run index.ts
49
+ $ bun run index.tsx
50
+ ```
51
+
52
+ Alternatively, you can omit the `run` keyword and use the "naked" command; it behaves identically.
53
+
54
+ ```bash
55
+ $ bun index.tsx
56
+ $ bun index.js
57
+ ```
58
+
59
+ ### `--watch`
60
+
61
+ To run a file in watch mode, use the `--watch` flag.
62
+
63
+ ```bash
64
+ $ bun --watch run index.tsx
65
+ ```
66
+
67
+ {% callout %}
68
+ **Note** — When using `bun run`, put Bun flags like `--watch` immediately after `bun`.
69
+
70
+ ```bash
71
+ $ bun --watch run dev # ✔️ do this
72
+ $ bun run dev --watch # ❌ don't do this
73
+ ```
74
+
75
+ Flags that occur at the end of the command will be ignored and passed through to the `"dev"` script itself.
76
+ {% /callout %}
77
+
78
+ ## Run a `package.json` script
79
+
80
+ {% note %}
81
+ Compare to `npm run <script>` or `yarn <script>`
82
+ {% /note %}
83
+
84
+ ```sh
85
+ $ bun [bun flags] run <script> [script flags]
86
+ ```
87
+
88
+ Your `package.json` can define a number of named `"scripts"` that correspond to shell commands.
89
+
90
+ ```json
91
+ {
92
+ // ... other fields
93
+ "scripts": {
94
+ "clean": "rm -rf dist && echo 'Done.'",
95
+ "dev": "bun server.ts"
96
+ }
97
+ }
98
+ ```
99
+
100
+ Use `bun run <script>` to execute these scripts.
101
+
102
+ ```bash
103
+ $ bun run clean
104
+ $ rm -rf dist && echo 'Done.'
105
+ Cleaning...
106
+ Done.
107
+ ```
108
+
109
+ Bun executes the script command in a subshell. It checks for the following shells in order, using the first one it finds: `bash`, `sh`, `zsh`.
110
+
111
+ {% callout %}
112
+ ⚡️ The startup time for `npm run` on Linux is roughly 170ms; with Bun it is `6ms`.
113
+ {% /callout %}
114
+
115
+ If there is a name conflict between a `package.json` script and a built-in `bun` command (`install`, `dev`, `upgrade`, etc.) Bun's built-in command takes precedence. In this case, use the more explicit `bun run` command to execute your package script.
116
+
117
+ ```bash
118
+ $ bun run dev
119
+ ```
120
+
121
+ To see a list of available scripts, run `bun run` without any arguments.
122
+
123
+ ```bash
124
+ $ bun run
125
+ quickstart scripts:
126
+
127
+ bun run clean
128
+ rm -rf dist && echo 'Done.'
129
+
130
+ bun run dev
131
+ bun server.ts
132
+
133
+ 2 scripts
134
+ ```
135
+
136
+ Bun respects lifecycle hooks. For instance, `bun run clean` will execute `preclean` and `postclean`, if defined. If the `pre<script>` fails, Bun will not execute the script itself.
137
+
138
+ ### `--bun`
139
+
140
+ It's common for `package.json` scripts to reference locally-installed CLIs like `vite` or `next`. These CLIs are often JavaScript files marked with a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) to indicate that they should be executed with `node`.
141
+
142
+ ```js
143
+ #!/usr/bin/env node
144
+
145
+ // do stuff
146
+ ```
147
+
148
+ By default, Bun respects this shebang and executes the script with `node`. However, you can override this behavior with the `--bun` flag. For Node.js-based CLIs, this will run the CLI with Bun instead of Node.js.
149
+
150
+ ```bash
151
+ $ bun run --bun vite
152
+ ```
153
+
154
+ ### Filtering
155
+
156
+ in monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.
157
+
158
+ Use `bun run --filter <name_pattern> <script>` to execute `<script>` in all packages whose name matches `<name_pattern>`.
159
+ For example, if you have subdirectories containing packages named `foo`, `bar` and `baz`, running
160
+
161
+ ```bash
162
+ bun run --filter 'ba*' <script>
163
+ ```
164
+
165
+ will execute `<script>` in both `bar` and `baz`, but not in `foo`.
166
+
167
+ Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter).
168
+
169
+ ## `bun run -` to pipe code from stdin
170
+
171
+ `bun run -` lets you read JavaScript, TypeScript, TSX, or JSX from stdin and execute it without writing to a temporary file first.
172
+
173
+ ```bash
174
+ $ echo "console.log('Hello')" | bun run -
175
+ Hello
176
+ ```
177
+
178
+ You can also use `bun run -` to redirect files into Bun. For example, to run a `.js` file as if it were a `.ts` file:
179
+
180
+ ```bash
181
+ $ echo "console.log!('This is TypeScript!' as any)" > secretly-typescript.js
182
+ $ bun run - < secretly-typescript.js
183
+ This is TypeScript!
184
+ ```
185
+
186
+ For convenience, all code is treated as TypeScript with JSX support when using `bun run -`.
187
+
188
+ ## `bun run --smol`
189
+
190
+ In memory-constrained environments, use the `--smol` flag to reduce memory usage at a cost to performance.
191
+
192
+ ```bash
193
+ $ bun --smol run index.tsx
194
+ ```
195
+
196
+ This causes the garbage collector to run more frequently, which can slow down execution. However, it can be useful in environments with limited memory. Bun automatically adjusts the garbage collector's heap size based on the available memory (accounting for cgroups and other memory limits) with and without the `--smol` flag, so this is mostly useful for cases where you want to make the heap size grow more slowly.
@@ -0,0 +1,247 @@
1
+ Bun ships with a fast, built-in, Jest-compatible test runner. Tests are executed with the Bun runtime, and support the following features.
2
+
3
+ - TypeScript and JSX
4
+ - Lifecycle hooks
5
+ - Snapshot testing
6
+ - UI & DOM testing
7
+ - Watch mode with `--watch`
8
+ - Script pre-loading with `--preload`
9
+
10
+ {% callout %}
11
+ Bun aims for compatibility with Jest, but not everything is implemented. To track compatibility, see [this tracking issue](https://github.com/oven-sh/bun/issues/1825).
12
+ {% /callout %}
13
+
14
+ ## Run tests
15
+
16
+ ```bash
17
+ $ bun test
18
+ ```
19
+
20
+ Tests are written in JavaScript or TypeScript with a Jest-like API. Refer to [Writing tests](https://bun.sh/docs/test/writing) for full documentation.
21
+
22
+ ```ts#math.test.ts
23
+ import { expect, test } from "bun:test";
24
+
25
+ test("2 + 2", () => {
26
+ expect(2 + 2).toBe(4);
27
+ });
28
+ ```
29
+
30
+ The runner recursively searches the working directory for files that match the following patterns:
31
+
32
+ - `*.test.{js|jsx|ts|tsx}`
33
+ - `*_test.{js|jsx|ts|tsx}`
34
+ - `*.spec.{js|jsx|ts|tsx}`
35
+ - `*_spec.{js|jsx|ts|tsx}`
36
+
37
+ You can filter the set of _test files_ to run by passing additional positional arguments to `bun test`. Any test file with a path that matches one of the filters will run. Commonly, these filters will be file or directory names; glob patterns are not yet supported.
38
+
39
+ ```bash
40
+ $ bun test <filter> <filter> ...
41
+ ```
42
+
43
+ To filter by _test name_, use the `-t`/`--test-name-pattern` flag.
44
+
45
+ ```sh
46
+ # run all tests or test suites with "addition" in the name
47
+ $ bun test --test-name-pattern addition
48
+ ```
49
+
50
+ To run a specific file in the test runner, make sure the path starts with `./` or `/` to distinguish it from a filter name.
51
+
52
+ ```bash
53
+ $ bun test ./test/specific-file.test.ts
54
+ ```
55
+
56
+ The test runner runs all tests in a single process. It loads all `--preload` scripts (see [Lifecycle](https://bun.sh/docs/test/lifecycle) for details), then runs all tests. If a test fails, the test runner will exit with a non-zero exit code.
57
+
58
+ ## CI/CD integration
59
+
60
+ `bun test` supports a variety of CI/CD integrations.
61
+
62
+ ### GitHub Actions
63
+
64
+ `bun test` automatically detects if it's running inside GitHub Actions and will emit GitHub Actions annotations to the console directly.
65
+
66
+ No configuration is needed, other than installing `bun` in the workflow and running `bun test`.
67
+
68
+ #### How to install `bun` in a GitHub Actions workflow
69
+
70
+ To use `bun test` in a GitHub Actions workflow, add the following step:
71
+
72
+ ```yaml
73
+ jobs:
74
+ build:
75
+ name: build-app
76
+ runs-on: ubuntu-latest
77
+ steps:
78
+ - name: Install bun
79
+ uses: oven-sh/setup-bun
80
+ - name: Install dependencies # (assuming your project has dependencies)
81
+ run: bun install # You can use npm/yarn/pnpm instead if you prefer
82
+ - name: Run tests
83
+ run: bun test
84
+ ```
85
+
86
+ From there, you'll get GitHub Actions annotations.
87
+
88
+ ### JUnit XML reports (GitLab, etc.)
89
+
90
+ To use `bun test` with a JUnit XML reporter, you can use the `--reporter=junit` in combination with `--reporter-outfile`.
91
+
92
+ ```sh
93
+ $ bun test --reporter=junit --reporter-outfile=./bun.xml
94
+ ```
95
+
96
+ This will continue to output to stdout/stderr as usual, and also write a JUnit
97
+ XML report to the given path at the very end of the test run.
98
+
99
+ JUnit XML is a popular format for reporting test results in CI/CD pipelines.
100
+
101
+ ## Timeouts
102
+
103
+ Use the `--timeout` flag to specify a _per-test_ timeout in milliseconds. If a test times out, it will be marked as failed. The default value is `5000`.
104
+
105
+ ```bash
106
+ # default value is 5000
107
+ $ bun test --timeout 20
108
+ ```
109
+
110
+ ## Rerun tests
111
+
112
+ Use the `--rerun-each` flag to run each test multiple times. This is useful for detecting flaky or non-deterministic test failures.
113
+
114
+ ```sh
115
+ $ bun test --rerun-each 100
116
+ ```
117
+
118
+ ## Bail out with `--bail`
119
+
120
+ Use the `--bail` flag to abort the test run early after a pre-determined number of test failures. By default Bun will run all tests and report all failures, but sometimes in CI environments it's preferable to terminate earlier to reduce CPU usage.
121
+
122
+ ```sh
123
+ # bail after 1 failure
124
+ $ bun test --bail
125
+
126
+ # bail after 10 failure
127
+ $ bun test --bail=10
128
+ ```
129
+
130
+ ## Watch mode
131
+
132
+ Similar to `bun run`, you can pass the `--watch` flag to `bun test` to watch for changes and re-run tests.
133
+
134
+ ```bash
135
+ $ bun test --watch
136
+ ```
137
+
138
+ ## Lifecycle hooks
139
+
140
+ Bun supports the following lifecycle hooks:
141
+
142
+ | Hook | Description |
143
+ | ------------ | --------------------------- |
144
+ | `beforeAll` | Runs once before all tests. |
145
+ | `beforeEach` | Runs before each test. |
146
+ | `afterEach` | Runs after each test. |
147
+ | `afterAll` | Runs once after all tests. |
148
+
149
+ These hooks can be defined inside test files, or in a separate file that is preloaded with the `--preload` flag.
150
+
151
+ ```ts
152
+ $ bun test --preload ./setup.ts
153
+ ```
154
+
155
+ See [Test > Lifecycle](https://bun.sh/docs/test/lifecycle) for complete documentation.
156
+
157
+ ## Mocks
158
+
159
+ Create mock functions with the `mock` function. Mocks are automatically reset between tests.
160
+
161
+ ```ts
162
+ import { test, expect, mock } from "bun:test";
163
+ const random = mock(() => Math.random());
164
+
165
+ test("random", () => {
166
+ const val = random();
167
+ expect(val).toBeGreaterThan(0);
168
+ expect(random).toHaveBeenCalled();
169
+ expect(random).toHaveBeenCalledTimes(1);
170
+ });
171
+ ```
172
+
173
+ Alternatively, you can use `jest.fn()`, it behaves identically.
174
+
175
+ ```ts-diff
176
+ - import { test, expect, mock } from "bun:test";
177
+ + import { test, expect, jest } from "bun:test";
178
+
179
+ - const random = mock(() => Math.random());
180
+ + const random = jest.fn(() => Math.random());
181
+ ```
182
+
183
+ See [Test > Mocks](https://bun.sh/docs/test/mocks) for complete documentation.
184
+
185
+ ## Snapshot testing
186
+
187
+ Snapshots are supported by `bun test`.
188
+
189
+ ```ts
190
+ // example usage of toMatchSnapshot
191
+ import { test, expect } from "bun:test";
192
+
193
+ test("snapshot", () => {
194
+ expect({ a: 1 }).toMatchSnapshot();
195
+ });
196
+ ```
197
+
198
+ To update snapshots, use the `--update-snapshots` flag.
199
+
200
+ ```sh
201
+ $ bun test --update-snapshots
202
+ ```
203
+
204
+ See [Test > Snapshots](https://bun.sh/docs/test/snapshots) for complete documentation.
205
+
206
+ ## UI & DOM testing
207
+
208
+ Bun is compatible with popular UI testing libraries:
209
+
210
+ - [HappyDOM](https://github.com/capricorn86/happy-dom)
211
+ - [DOM Testing Library](https://testing-library.com/docs/dom-testing-library/intro/)
212
+ - [React Testing Library](https://testing-library.com/docs/react-testing-library/intro)
213
+
214
+ See [Test > DOM Testing](https://bun.sh/docs/test/dom) for complete documentation.
215
+
216
+ ## Performance
217
+
218
+ Bun's test runner is fast.
219
+
220
+ {% image src="/images/buntest.jpeg" caption="Running 266 React SSR tests faster than Jest can print its version number." /%}
221
+
222
+ <!--
223
+ Consider the following directory structure:
224
+
225
+ ```
226
+ .
227
+ ├── a.test.ts
228
+ ├── b.test.ts
229
+ ├── c.test.ts
230
+ └── foo
231
+ ├── a.test.ts
232
+ └── b.test.ts
233
+ ```
234
+
235
+ To run both `a.test.ts` files:
236
+
237
+ ```
238
+ $ bun test a
239
+ ```
240
+
241
+ To run all tests in the `foo` directory:
242
+
243
+ ```
244
+ $ bun test foo
245
+ ```
246
+
247
+ Any test file in the directory with an _absolute path_ that contains one of the targets will run. Glob patterns are not yet supported. -->
@@ -0,0 +1,7 @@
1
+ Use `bun unlink` in the root directory to unregister a local package.
2
+
3
+ ```bash
4
+ $ cd /path/to/cool-pkg
5
+ $ bun unlink
6
+ bun unlink v1.x (7416672e)
7
+ ```
@@ -0,0 +1,34 @@
1
+ To update all dependencies to the latest version:
2
+
3
+ ```sh
4
+ $ bun update
5
+ ```
6
+
7
+ To update a specific dependency to the latest version:
8
+
9
+ ```sh
10
+ $ bun update [package]
11
+ ```
12
+
13
+ ## `--latest`
14
+
15
+ By default, `bun update` will update to the latest version of a dependency that satisfies the version range specified in your `package.json`.
16
+
17
+ To update to the latest version, regardless of if it's compatible with the current version range, use the `--latest` flag:
18
+
19
+ ```sh
20
+ $ bun update --latest
21
+ ```
22
+
23
+ For example, with the following `package.json`:
24
+
25
+ ```json
26
+ {
27
+ "dependencies": {
28
+ "react": "^17.0.2"
29
+ }
30
+ }
31
+ ```
32
+
33
+ - `bun update` would update to a version that matches `17.x`.
34
+ - `bun update --latest` would update to a version that matches `18.x` or later.
@@ -0,0 +1,57 @@
1
+ Bun uses [a fork](https://github.com/oven-sh/WebKit) of WebKit with a small number of changes.
2
+
3
+ It's important to periodically update WebKit for many reasons:
4
+
5
+ - Security
6
+ - Performance
7
+ - Compatibility
8
+ - …and many more.
9
+
10
+ To upgrade, first find the commit in **Bun's WebKit fork** (not Bun!) between when we last upgraded and now.
11
+
12
+ ```bash
13
+ $ cd src/bun.js/WebKit # In the WebKit directory! not bun
14
+ $ git checkout $COMMIT
15
+ ```
16
+
17
+ This is the main command to run:
18
+
19
+ ```bash
20
+ $ git merge upstream main
21
+ # If you get an error saying histories are unrelated, run this and try again:
22
+ $ git fetch --unshallow
23
+ ```
24
+
25
+ Then, you will likely see some silly merge conflicts. Fix them and then run:
26
+
27
+ ```bash
28
+ # You might have to run this multiple times.
29
+ $ rm -rf WebKitBuild
30
+
31
+ # Go to Bun's directory! Not WebKit.
32
+ cd ../../../../
33
+ make jsc-build-mac-compile
34
+ ```
35
+
36
+ Make sure that JSC's CLI is able to load successfully. This verifies that the build is working.
37
+
38
+ You know this worked when it printed help options. If it complains about symbols, crashes, or anything else that looks wrong, something is wrong.
39
+
40
+ ```bash
41
+ src/bun.js/WebKit/WebKitBuild/Release/bin/jsc --help
42
+ ```
43
+
44
+ Then, clear out our bindings and regenerate the C++<>Zig headers:
45
+
46
+ ```bash
47
+ make clean-bindings headers builtins
48
+ ```
49
+
50
+ Now update Bun's bindings wherever there are compiler errors:
51
+
52
+ ```bash
53
+ # It will take awhile if you don't pass -j here
54
+ make bindings -j10
55
+ ```
56
+
57
+ This is the hard part. It might involve digging through WebKit's commit history to figure out what changed and why. Fortunately, WebKit contributors write great commit messages.
@@ -0,0 +1,24 @@
1
+ [Elysia](https://elysiajs.com) is a Bun-first performance focused web framework that takes full advantage of Bun's HTTP, file system, and hot reloading APIs.
2
+ Designed with TypeScript in mind, you don't need to understand TypeScript to gain the benefit of TypeScript with Elysia. The library understands what you want and automatically infers the type from your code.
3
+
4
+ ⚡️ Elysia is [one of the fastest Bun web frameworks](https://github.com/SaltyAom/bun-http-framework-benchmark)
5
+
6
+ ```ts#server.ts
7
+ import { Elysia } from 'elysia'
8
+
9
+ const app = new Elysia()
10
+ .get('/', () => 'Hello Elysia')
11
+ .listen(8080)
12
+
13
+ console.log(`🦊 Elysia is running at on port ${app.server.port}...`)
14
+ ```
15
+
16
+ Get started with `bun create`.
17
+
18
+ ```bash
19
+ $ bun create elysia ./myapp
20
+ $ cd myapp
21
+ $ bun run dev
22
+ ```
23
+
24
+ Refer to the Elysia [documentation](https://elysiajs.com/quick-start.html) for more information.