bun-types 1.1.37-canary.20241123T140655 → 1.1.37-canary.20241125T140601

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,309 @@
1
+ Bun is a new JavaScript & TypeScript runtime designed to be a faster, leaner, and more modern drop-in replacement for Node.js.
2
+
3
+ ## Speed
4
+
5
+ Bun is designed to start fast and run fast. 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.
6
+
7
+ {% image src="/images/bun-run-speed.jpeg" caption="Bun vs Node.js vs Deno running Hello World" /%}
8
+
9
+ <!-- If no `node_modules` directory is found in the working directory or above, Bun will abandon Node.js-style module resolution in favor of the `Bun module resolution algorithm`. Under Bun-style module resolution, all packages are _auto-installed_ on the fly into a [global module cache](https://bun.sh/docs/install/cache). For full details on this algorithm, refer to [Runtime > Modules](https://bun.sh/docs/runtime/modules). -->
10
+
11
+ 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.
12
+
13
+ ## TypeScript
14
+
15
+ Bun natively supports TypeScript out of the box. All files are transpiled on the fly by Bun's fast native transpiler before being executed. Similar to other build tools, Bun does not perform typechecking; it simply removes type annotations from the file.
16
+
17
+ ```bash
18
+ $ bun index.js
19
+ $ bun index.jsx
20
+ $ bun index.ts
21
+ $ bun index.tsx
22
+ ```
23
+
24
+ Some aspects of Bun's runtime behavior are affected by the contents of your `tsconfig.json` file. Refer to [Runtime > TypeScript](https://bun.sh/docs/runtime/typescript) page for details.
25
+
26
+ <!-- Before execution, Bun internally transforms all source files to vanilla JavaScript using its fast native transpiler. The transpiler looks at the files extension to determine how to handle it. -->
27
+
28
+ <!--
29
+
30
+ every file before execution. Its transpiler can directly run TypeScript and JSX `{.js|.jsx|.ts|.tsx}` files directly. During execution, Bun internally transpiles all files (including `.js` files) to vanilla JavaScript with its fast native transpiler. -->
31
+
32
+ <!-- A loader determines how to map imports &amp; file extensions to transforms and output. -->
33
+
34
+ <!-- Currently, Bun implements the following loaders: -->
35
+
36
+ <!-- {% table %}
37
+
38
+ - Extension
39
+ - Transforms
40
+ - Output (internal)
41
+
42
+ ---
43
+
44
+ - `.js`
45
+ - JSX + JavaScript
46
+ - `.js`
47
+
48
+ ---
49
+
50
+ - `.jsx`
51
+ - JSX + JavaScript
52
+ - `.js`
53
+
54
+ ---
55
+
56
+ - `.ts`
57
+ - TypeScript + JavaScript
58
+ - `.js`
59
+
60
+ ---
61
+
62
+ - `.tsx`
63
+ - TypeScript + JSX + JavaScript
64
+ - `.js`
65
+
66
+ ---
67
+
68
+ - `.mjs`
69
+ - JavaScript
70
+ - `.js`
71
+
72
+ ---
73
+
74
+ - `.cjs`
75
+ - JavaScript
76
+ - `.js`
77
+
78
+ ---
79
+
80
+ - `.mts`
81
+ - TypeScript
82
+ - `.js`
83
+
84
+ ---
85
+
86
+ - `.cts`
87
+ - TypeScript
88
+ - `.js`
89
+
90
+
91
+ {% /table %} -->
92
+
93
+ ## JSX
94
+
95
+ ## JSON and TOML
96
+
97
+ Source files can import a `*.json` or `*.toml` file to load its contents as a plain old JavaScript object.
98
+
99
+ ```ts
100
+ import pkg from "./package.json";
101
+ import bunfig from "./bunfig.toml";
102
+ ```
103
+
104
+ ## WASI
105
+
106
+ {% callout %}
107
+ 🚧 **Experimental**
108
+ {% /callout %}
109
+
110
+ Bun has experimental support for WASI, the [WebAssembly System Interface](https://github.com/WebAssembly/WASI). To run a `.wasm` binary with Bun:
111
+
112
+ ```bash
113
+ $ bun ./my-wasm-app.wasm
114
+ # if the filename doesn't end with ".wasm"
115
+ $ bun run ./my-wasm-app.whatever
116
+ ```
117
+
118
+ {% callout %}
119
+
120
+ **Note** — WASI support is based on [wasi-js](https://github.com/sagemathinc/cowasm/tree/main/core/wasi-js). Currently, it only supports WASI binaries that use the `wasi_snapshot_preview1` or `wasi_unstable` APIs. Bun's implementation is not fully optimized for performance; this will become more of a priority as WASM grows in popularity.
121
+ {% /callout %}
122
+
123
+ ## Node.js compatibility
124
+
125
+ Long-term, Bun aims for complete Node.js compatibility. Most Node.js packages already work with Bun out of the box, but certain low-level APIs like `dgram` are still unimplemented. Track the current compatibility status at [Ecosystem > Node.js](https://bun.sh/docs/runtime/nodejs-apis).
126
+
127
+ Bun implements the Node.js module resolution algorithm, so dependencies can still be managed with `package.json`, `node_modules`, and CommonJS-style imports.
128
+
129
+ {% callout %}
130
+ **Note** — We recommend using Bun's [built-in package manager](https://bun.sh/docs/cli/install) for a performance boost over other npm clients.
131
+ {% /callout %}
132
+
133
+ ## Web APIs
134
+
135
+ <!-- When prudent, Bun attempts to implement Web-standard APIs instead of introducing new APIs. Refer to [Runtime > Web APIs](https://bun.sh/docs/web-apis) for a list of Web APIs that are available in Bun. -->
136
+
137
+ Some Web APIs aren't relevant in the context of a server-first runtime like Bun, such as the [DOM API](https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API#html_dom_api_interfaces) or [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API). Many others, though, are broadly useful outside of the browser context; when possible, Bun implements these Web-standard APIs instead of introducing new APIs.
138
+
139
+ The following Web APIs are partially or completely supported.
140
+
141
+ {% table %}
142
+
143
+ ---
144
+
145
+ - HTTP
146
+ - [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers) [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
147
+
148
+ ---
149
+
150
+ - URLs
151
+ - [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
152
+
153
+ ---
154
+
155
+ - Streams
156
+ - [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) [`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream) [`TransformStream`](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream) [`ByteLengthQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/ByteLengthQueuingStrategy) [`CountQueuingStrategy`](https://developer.mozilla.org/en-US/docs/Web/API/CountQueuingStrategy) and associated classes
157
+
158
+ ---
159
+
160
+ - Blob
161
+ - [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
162
+
163
+ ---
164
+
165
+ - WebSockets
166
+ - [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
167
+
168
+ ---
169
+
170
+ - Encoding and decoding
171
+ - [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/btoa) [`TextEncoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder) [`TextDecoder`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder)
172
+
173
+ ---
174
+
175
+ - Timeouts
176
+ - [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout) [`clearTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/clearTimeout)
177
+
178
+ ---
179
+
180
+ - Intervals
181
+ - [`setInterval`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval)[`clearInterval`](https://developer.mozilla.org/en-US/docs/Web/API/clearInterval)
182
+
183
+ ---
184
+
185
+ - Crypto
186
+ - [`crypto`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto) [`SubtleCrypto`](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto)
187
+ [`CryptoKey`](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey)
188
+
189
+ ---
190
+
191
+ - Debugging
192
+
193
+ - [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) [`performance`](https://developer.mozilla.org/en-US/docs/Web/API/Performance)
194
+
195
+ ---
196
+
197
+ - Microtasks
198
+ - [`queueMicrotask`](https://developer.mozilla.org/en-US/docs/Web/API/queueMicrotask)
199
+
200
+ ---
201
+
202
+ - Errors
203
+ - [`reportError`](https://developer.mozilla.org/en-US/docs/Web/API/reportError)
204
+
205
+ ---
206
+
207
+ - User interaction
208
+ - [`alert`](https://developer.mozilla.org/en-US/docs/Web/API/Window/alert) [`confirm`](https://developer.mozilla.org/en-US/docs/Web/API/Window/confirm) [`prompt`](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt) (intended for interactive CLIs)
209
+
210
+ <!-- - Blocking. Prints the alert message to terminal and awaits `[ENTER]` before proceeding. -->
211
+ <!-- - Blocking. Prints confirmation message and awaits `[y/N]` input from user. Returns `true` if user entered `y` or `Y`, `false` otherwise.
212
+ - Blocking. Prints prompt message and awaits user input. Returns the user input as a string. -->
213
+
214
+ ---
215
+
216
+ - Realms
217
+ - [`ShadowRealm`](https://github.com/tc39/proposal-shadowrealm)
218
+
219
+ ---
220
+
221
+ - Events
222
+ - [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
223
+ [`Event`](https://developer.mozilla.org/en-US/docs/Web/API/Event) [`ErrorEvent`](https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent) [`CloseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent) [`MessageEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent)
224
+
225
+ ---
226
+
227
+ {% /table %}
228
+
229
+ ## Bun APIs
230
+
231
+ Bun exposes a set of Bun-specific APIs on the `Bun` global object and through a number of built-in modules. These APIs represent the canonical "Bun-native" way to perform some common development tasks. They are all heavily optimized for performance. Click the link in the left column to view the associated documentation.
232
+
233
+ {% table %}
234
+
235
+ - Topic
236
+ - APIs
237
+
238
+ ---
239
+
240
+ - [HTTP](https://bun.sh/docs/api/http)
241
+ - `Bun.serve`
242
+
243
+ ---
244
+
245
+ - [File I/O](https://bun.sh/docs/api/file-io)
246
+ - `Bun.file` `Bun.write`
247
+
248
+ ---
249
+
250
+ - [Processes](https://bun.sh/docs/api/spawn)
251
+ - `Bun.spawn` `Bun.spawnSync`
252
+
253
+ ---
254
+
255
+ - [TCP](https://bun.sh/docs/api/tcp)
256
+ - `Bun.listen` `Bun.connect`
257
+
258
+ ---
259
+
260
+ - [Transpiler](https://bun.sh/docs/api/transpiler)
261
+ - `Bun.Transpiler`
262
+
263
+ ---
264
+
265
+ - [Routing](https://bun.sh/docs/api/file-system-router)
266
+ - `Bun.FileSystemRouter`
267
+
268
+ ---
269
+
270
+ - [HTMLRewriter](https://bun.sh/docs/api/html-rewriter)
271
+ - `HTMLRewriter`
272
+
273
+ ---
274
+
275
+ - [Utils](https://bun.sh/docs/api/utils)
276
+ - `Bun.peek` `Bun.which`
277
+
278
+ ---
279
+
280
+ - [SQLite](https://bun.sh/docs/api/sqlite)
281
+ - `bun:sqlite`
282
+
283
+ ---
284
+
285
+ - [FFI](https://bun.sh/docs/api/ffi)
286
+ - `bun:ffi`
287
+
288
+ ---
289
+
290
+ - [DNS](https://bun.sh/docs/api/dns)
291
+ - `bun:dns`
292
+
293
+ ---
294
+
295
+ - [Testing](https://bun.sh/docs/api/test)
296
+ - `bun:test`
297
+
298
+ ---
299
+
300
+ - [Node-API](https://bun.sh/docs/api/node-api)
301
+ - `Node-API`
302
+
303
+ ---
304
+
305
+ {% /table %}
306
+
307
+ ## Plugins
308
+
309
+ Support for additional file types can be implemented with plugins. Refer to [Runtime > Plugins](https://bun.sh/docs/bundler/plugins) for full documentation.
@@ -0,0 +1,326 @@
1
+ Bun supports `.jsx` and `.tsx` files out of the box. Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
2
+
3
+ ```tsx#react.tsx
4
+ function Component(props: {message: string}) {
5
+ return (
6
+ <body>
7
+ <h1 style={{color: 'red'}}>{props.message}</h1>
8
+ </body>
9
+ );
10
+ }
11
+
12
+ console.log(<Component message="Hello world!" />);
13
+ ```
14
+
15
+ ## Configuration
16
+
17
+ Bun reads your `tsconfig.json` or `jsconfig.json` configuration files to determines how to perform the JSX transform internally. To avoid using either of these, the following options can also be defined in [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig).
18
+
19
+ The following compiler options are respected.
20
+
21
+ ### [`jsx`](https://www.typescriptlang.org/tsconfig#jsx)
22
+
23
+ How JSX constructs are transformed into vanilla JavaScript internally. The table below lists the possible values of `jsx`, along with their transpilation of the following simple JSX component:
24
+
25
+ ```tsx
26
+ <Box width={5}>Hello</Box>
27
+ ```
28
+
29
+ {% table %}
30
+
31
+ - Compiler options
32
+ - Transpiled output
33
+
34
+ ---
35
+
36
+ - ```json
37
+ {
38
+ "jsx": "react"
39
+ }
40
+ ```
41
+
42
+ - ```tsx
43
+ import { createElement } from "react";
44
+ createElement("Box", { width: 5 }, "Hello");
45
+ ```
46
+
47
+ ---
48
+
49
+ - ```json
50
+ {
51
+ "jsx": "react-jsx"
52
+ }
53
+ ```
54
+
55
+ - ```tsx
56
+ import { jsx } from "react/jsx-runtime";
57
+ jsx("Box", { width: 5 }, "Hello");
58
+ ```
59
+
60
+ ---
61
+
62
+ - ```json
63
+ {
64
+ "jsx": "react-jsxdev"
65
+ }
66
+ ```
67
+
68
+ - ```tsx
69
+ import { jsxDEV } from "react/jsx-dev-runtime";
70
+ jsxDEV(
71
+ "Box",
72
+ { width: 5, children: "Hello" },
73
+ undefined,
74
+ false,
75
+ undefined,
76
+ this,
77
+ );
78
+ ```
79
+
80
+ The `jsxDEV` variable name is a convention used by React. The `DEV` suffix is a visible way to indicate that the code is intended for use in development. The development version of React is slower and includes additional validity checks & debugging tools.
81
+
82
+ ---
83
+
84
+ - ```json
85
+ {
86
+ "jsx": "preserve"
87
+ }
88
+ ```
89
+
90
+ - ```tsx
91
+ // JSX is not transpiled
92
+ // "preserve" is not supported by Bun currently
93
+ <Box width={5}>Hello</Box>
94
+ ```
95
+
96
+ {% /table %}
97
+
98
+ <!-- {% table %}
99
+
100
+ - `react`
101
+ - `React.createElement("Box", {width: 5}, "Hello")`
102
+
103
+ ---
104
+
105
+ - `react-jsx`
106
+ - `jsx("Box", {width: 5}, "Hello")`
107
+
108
+ ---
109
+
110
+ - `react-jsxdev`
111
+ - `jsxDEV("Box", {width: 5}, "Hello", void 0, false)`
112
+
113
+ ---
114
+
115
+ - `preserve`
116
+ - `<Box width={5}>Hello</Box>` Left as-is; not yet supported by Bun.
117
+
118
+ {% /table %} -->
119
+
120
+ ### [`jsxFactory`](https://www.typescriptlang.org/tsconfig#jsxFactory)
121
+
122
+ {% callout %}
123
+ **Note** — Only applicable when `jsx` is `react`.
124
+ {% /callout %}
125
+
126
+ The function name used to represent JSX constructs. Default value is `"createElement"`. This is useful for libraries like [Preact](https://preactjs.com/) that use a different function name (`"h"`).
127
+
128
+ {% table %}
129
+
130
+ - Compiler options
131
+ - Transpiled output
132
+
133
+ ---
134
+
135
+ - ```json
136
+ {
137
+ "jsx": "react",
138
+ "jsxFactory": "h"
139
+ }
140
+ ```
141
+
142
+ - ```tsx
143
+ import { h } from "react";
144
+ h("Box", { width: 5 }, "Hello");
145
+ ```
146
+
147
+ {% /table %}
148
+
149
+ ### [`jsxFragmentFactory`](https://www.typescriptlang.org/tsconfig#jsxFragmentFactory)
150
+
151
+ {% callout %}
152
+ **Note** — Only applicable when `jsx` is `react`.
153
+ {% /callout %}
154
+
155
+ The function name used to represent [JSX fragments](https://react.dev/reference/react/Fragment) such as `<>Hello</>`; only applicable when `jsx` is `react`. Default value is `"Fragment"`.
156
+
157
+ {% table %}
158
+
159
+ - Compiler options
160
+ - Transpiled output
161
+
162
+ ---
163
+
164
+ - ```json
165
+ {
166
+ "jsx": "react",
167
+ "jsxFactory": "myjsx",
168
+ "jsxFragmentFactory": "MyFragment"
169
+ }
170
+ ```
171
+
172
+ - ```tsx
173
+ // input
174
+ <>Hello</>;
175
+
176
+ // output
177
+ import { myjsx, MyFragment } from "react";
178
+ myjsx(MyFragment, null, "Hello");
179
+ ```
180
+
181
+ {% /table %}
182
+
183
+ ### [`jsxImportSource`](https://www.typescriptlang.org/tsconfig#jsxImportSource)
184
+
185
+ {% callout %}
186
+ **Note** — Only applicable when `jsx` is `react-jsx` or `react-jsxdev`.
187
+ {% /callout %}
188
+
189
+ The module from which the component factory function (`createElement`, `jsx`, `jsxDEV`, etc) will be imported. Default value is `"react"`. This will typically be necessary when using a component library like Preact.
190
+
191
+ {% table %}
192
+
193
+ - Compiler options
194
+ - Transpiled output
195
+
196
+ ---
197
+
198
+ - ```jsonc
199
+ {
200
+ "jsx": "react",
201
+ // jsxImportSource is not defined
202
+ // default to "react"
203
+ }
204
+ ```
205
+
206
+ - ```tsx
207
+ import { jsx } from "react/jsx-runtime";
208
+ jsx("Box", { width: 5, children: "Hello" });
209
+ ```
210
+
211
+ ---
212
+
213
+ - ```jsonc
214
+ {
215
+ "jsx": "react-jsx",
216
+ "jsxImportSource": "preact",
217
+ }
218
+ ```
219
+
220
+ - ```tsx
221
+ import { jsx } from "preact/jsx-runtime";
222
+ jsx("Box", { width: 5, children: "Hello" });
223
+ ```
224
+
225
+ ---
226
+
227
+ - ```jsonc
228
+ {
229
+ "jsx": "react-jsxdev",
230
+ "jsxImportSource": "preact",
231
+ }
232
+ ```
233
+
234
+ - ```tsx
235
+ // /jsx-runtime is automatically appended
236
+ import { jsxDEV } from "preact/jsx-dev-runtime";
237
+ jsxDEV(
238
+ "Box",
239
+ { width: 5, children: "Hello" },
240
+ undefined,
241
+ false,
242
+ undefined,
243
+ this,
244
+ );
245
+ ```
246
+
247
+ {% /table %}
248
+
249
+ ### JSX pragma
250
+
251
+ All of these values can be set on a per-file basis using _pragmas_. A pragma is a special comment that sets a compiler option in a particular file.
252
+
253
+ {% table %}
254
+
255
+ - Pragma
256
+ - Equivalent config
257
+
258
+ ---
259
+
260
+ - ```ts
261
+ // @jsx h
262
+ ```
263
+
264
+ - ```jsonc
265
+ {
266
+ "jsxFactory": "h",
267
+ }
268
+ ```
269
+
270
+ ---
271
+
272
+ - ```ts
273
+ // @jsxFrag MyFragment
274
+ ```
275
+ - ```jsonc
276
+ {
277
+ "jsxFragmentFactory": "MyFragment",
278
+ }
279
+ ```
280
+
281
+ ---
282
+
283
+ - ```ts
284
+ // @jsxImportSource preact
285
+ ```
286
+ - ```jsonc
287
+ {
288
+ "jsxImportSource": "preact",
289
+ }
290
+ ```
291
+
292
+ {% /table %}
293
+
294
+ ## Logging
295
+
296
+ Bun implements special logging for JSX to make debugging easier. Given the following file:
297
+
298
+ ```tsx#index.tsx
299
+ import { Stack, UserCard } from "./components";
300
+
301
+ console.log(
302
+ <Stack>
303
+ <UserCard name="Dom" bio="Street racer and Corona lover" />
304
+ <UserCard name="Jakob" bio="Super spy and Dom's secret brother" />
305
+ </Stack>
306
+ );
307
+ ```
308
+
309
+ Bun will pretty-print the component tree when logged:
310
+
311
+ {% image src="https://github.com/oven-sh/bun/assets/3084745/d29db51d-6837-44e2-b8be-84fc1b9e9d97" / %}
312
+
313
+ ## Prop punning
314
+
315
+ The Bun runtime also supports "prop punning" for JSX. This is a shorthand syntax useful for assigning a variable to a prop with the same name.
316
+
317
+ ```tsx
318
+ function Div(props: {className: string;}) {
319
+ const {className} = props;
320
+
321
+ // without punning
322
+ return <div className={className} />;
323
+ // with punning
324
+ return <div {className} />;
325
+ }
326
+ ```