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,203 @@
1
+ Bun is designed for speed. Hot paths are extensively profiled and benchmarked. The source code for all of Bun's public benchmarks can be found in the [`/bench`](https://github.com/oven-sh/bun/tree/main/bench) directory of the Bun repo.
2
+
3
+ ## Measuring time
4
+
5
+ To precisely measure time, Bun offers two runtime APIs functions:
6
+
7
+ 1. The Web-standard [`performance.now()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) function
8
+ 2. `Bun.nanoseconds()` which is similar to `performance.now()` except it returns the current time since the application started in nanoseconds. You can use `performance.timeOrigin` to convert this to a Unix timestamp.
9
+
10
+ ## Benchmarking tools
11
+
12
+ When writing your own benchmarks, it's important to choose the right tool.
13
+
14
+ - For microbenchmarks, a great general-purpose tool is [`mitata`](https://github.com/evanwashere/mitata).
15
+ - For load testing, you _must use_ an HTTP benchmarking tool that is at least as fast as `Bun.serve()`, or your results will be skewed. Some popular Node.js-based benchmarking tools like [`autocannon`](https://github.com/mcollina/autocannon) are not fast enough. We recommend one of the following:
16
+ - [`bombardier`](https://github.com/codesenberg/bombardier)
17
+ - [`oha`](https://github.com/hatoo/oha)
18
+ - [`http_load_test`](https://github.com/uNetworking/uSockets/blob/master/examples/http_load_test.c)
19
+ - For benchmarking scripts or CLI commands, we recommend [`hyperfine`](https://github.com/sharkdp/hyperfine).
20
+
21
+ ## Measuring memory usage
22
+
23
+ Bun has two heaps. One heap is for the JavaScript runtime and the other heap is for everything else.
24
+
25
+ {% anchor id="bunjsc" /%}
26
+
27
+ ### JavaScript heap stats
28
+
29
+ The `bun:jsc` module exposes a few functions for measuring memory usage:
30
+
31
+ ```ts
32
+ import { heapStats } from "bun:jsc";
33
+ console.log(heapStats());
34
+ ```
35
+
36
+ {% details summary="View example statistics" %}
37
+
38
+ ```ts
39
+ {
40
+ heapSize: 1657575,
41
+ heapCapacity: 2872775,
42
+ extraMemorySize: 598199,
43
+ objectCount: 13790,
44
+ protectedObjectCount: 62,
45
+ globalObjectCount: 1,
46
+ protectedGlobalObjectCount: 1,
47
+ // A count of every object type in the heap
48
+ objectTypeCounts: {
49
+ CallbackObject: 25,
50
+ FunctionExecutable: 2078,
51
+ AsyncGeneratorFunction: 2,
52
+ 'RegExp String Iterator': 1,
53
+ FunctionCodeBlock: 188,
54
+ ModuleProgramExecutable: 13,
55
+ String: 1,
56
+ UnlinkedModuleProgramCodeBlock: 13,
57
+ JSON: 1,
58
+ AsyncGenerator: 1,
59
+ Symbol: 1,
60
+ GetterSetter: 68,
61
+ ImportMeta: 10,
62
+ DOMAttributeGetterSetter: 1,
63
+ UnlinkedFunctionCodeBlock: 174,
64
+ RegExp: 52,
65
+ ModuleLoader: 1,
66
+ Intl: 1,
67
+ WeakMap: 4,
68
+ Generator: 2,
69
+ PropertyTable: 95,
70
+ 'Array Iterator': 1,
71
+ JSLexicalEnvironment: 75,
72
+ UnlinkedFunctionExecutable: 2067,
73
+ WeakSet: 1,
74
+ console: 1,
75
+ Map: 23,
76
+ SparseArrayValueMap: 14,
77
+ StructureChain: 19,
78
+ Set: 18,
79
+ 'String Iterator': 1,
80
+ FunctionRareData: 3,
81
+ JSGlobalLexicalEnvironment: 1,
82
+ Object: 481,
83
+ BigInt: 2,
84
+ StructureRareData: 55,
85
+ Array: 179,
86
+ AbortController: 2,
87
+ ModuleNamespaceObject: 11,
88
+ ShadowRealm: 1,
89
+ 'Immutable Butterfly': 103,
90
+ Primordials: 1,
91
+ 'Set Iterator': 1,
92
+ JSGlobalProxy: 1,
93
+ AsyncFromSyncIterator: 1,
94
+ ModuleRecord: 13,
95
+ FinalizationRegistry: 1,
96
+ AsyncIterator: 1,
97
+ InternalPromise: 22,
98
+ Iterator: 1,
99
+ CustomGetterSetter: 65,
100
+ Promise: 19,
101
+ WeakRef: 1,
102
+ InternalPromisePrototype: 1,
103
+ Function: 2381,
104
+ AsyncFunction: 2,
105
+ GlobalObject: 1,
106
+ ArrayBuffer: 2,
107
+ Boolean: 1,
108
+ Math: 1,
109
+ CallbackConstructor: 1,
110
+ Error: 2,
111
+ JSModuleEnvironment: 13,
112
+ WebAssembly: 1,
113
+ HashMapBucket: 300,
114
+ Callee: 3,
115
+ symbol: 37,
116
+ string: 2484,
117
+ Performance: 1,
118
+ ModuleProgramCodeBlock: 12,
119
+ JSSourceCode: 13,
120
+ JSPropertyNameEnumerator: 3,
121
+ NativeExecutable: 290,
122
+ Number: 1,
123
+ Structure: 1550,
124
+ SymbolTable: 108,
125
+ GeneratorFunction: 2,
126
+ 'Map Iterator': 1
127
+ },
128
+ protectedObjectTypeCounts: {
129
+ CallbackConstructor: 1,
130
+ BigInt: 1,
131
+ RegExp: 2,
132
+ GlobalObject: 1,
133
+ UnlinkedModuleProgramCodeBlock: 13,
134
+ HashMapBucket: 2,
135
+ Structure: 41,
136
+ JSPropertyNameEnumerator: 1
137
+ }
138
+ }
139
+ ```
140
+
141
+ {% /details %}
142
+
143
+ JavaScript is a garbage-collected language, not reference counted. It's normal and correct for objects to not be freed immediately in all cases, though it's not normal for objects to never be freed.
144
+
145
+ To force garbage collection to run manually:
146
+
147
+ ```js
148
+ Bun.gc(true); // synchronous
149
+ Bun.gc(false); // asynchronous
150
+ ```
151
+
152
+ Heap snapshots let you inspect what objects are not being freed. You can use the `bun:jsc` module to take a heap snapshot and then view it with Safari or WebKit GTK developer tools. To generate a heap snapshot:
153
+
154
+ ```ts
155
+ import { generateHeapSnapshot } from "bun";
156
+
157
+ const snapshot = generateHeapSnapshot();
158
+ await Bun.write("heap.json", JSON.stringify(snapshot, null, 2));
159
+ ```
160
+
161
+ To view the snapshot, open the `heap.json` file in Safari's Developer Tools (or WebKit GTK)
162
+
163
+ 1. Open the Developer Tools
164
+ 2. Click "Timeline"
165
+ 3. Click "JavaScript Allocations" in the menu on the left. It might not be visible until you click the pencil icon to show all the timelines
166
+ 4. Click "Import" and select your heap snapshot JSON
167
+
168
+ {% image alt="Import heap json" src="https://user-images.githubusercontent.com/709451/204428943-ba999e8f-8984-4f23-97cb-b4e3e280363e.png" caption="Importing a heap snapshot" /%}
169
+
170
+ Once imported, you should see something like this:
171
+
172
+ {% image alt="Viewing heap snapshot in Safari" src="https://user-images.githubusercontent.com/709451/204429337-b0d8935f-3509-4071-b991-217794d1fb27.png" caption="Viewing heap snapshot in Safari Dev Tools" /%}
173
+
174
+ > The [web debugger](https://bun.sh/docs/runtime/debugger#inspect) also offers the timeline feature which allows you to track and examine the memory usage of the running debug session.
175
+
176
+ ### Native heap stats
177
+
178
+ Bun uses mimalloc for the other heap. To report a summary of non-JavaScript memory usage, set the `MIMALLOC_SHOW_STATS=1` environment variable. and stats will print on exit.
179
+
180
+ ```js
181
+ MIMALLOC_SHOW_STATS=1 bun script.js
182
+
183
+ # will show something like this:
184
+ heap stats: peak total freed current unit count
185
+ reserved: 64.0 MiB 64.0 MiB 0 64.0 MiB not all freed!
186
+ committed: 64.0 MiB 64.0 MiB 0 64.0 MiB not all freed!
187
+ reset: 0 0 0 0 ok
188
+ touched: 128.5 KiB 128.5 KiB 5.4 MiB -5.3 MiB ok
189
+ segments: 1 1 0 1 not all freed!
190
+ -abandoned: 0 0 0 0 ok
191
+ -cached: 0 0 0 0 ok
192
+ pages: 0 0 53 -53 ok
193
+ -abandoned: 0 0 0 0 ok
194
+ -extended: 0
195
+ -noretire: 0
196
+ mmaps: 0
197
+ commits: 0
198
+ threads: 0 0 0 0 ok
199
+ searches: 0.0 avg
200
+ numa nodes: 1
201
+ elapsed: 0.068 s
202
+ process: user: 0.061 s, system: 0.014 s, faults: 0, rss: 57.4 MiB, commit: 64.0 MiB
203
+ ```
@@ -0,0 +1,162 @@
1
+ This document describes the build process for Windows. If you run into problems, please join the [#contributing channel on our Discord](http://bun.sh/discord) for help.
2
+
3
+ It is strongly recommended to use [PowerShell 7 (`pwsh.exe`)](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4) instead of the default `powershell.exe`.
4
+
5
+ ## Prerequisites
6
+
7
+ <!--
8
+ {% details summary="Extra notes for Bun Core Team Members" %}
9
+
10
+ Here are the extra steps I ran on my fresh windows machine (some of these are a little opiniated)
11
+
12
+ - Change user to a local account (set username to `window` and 'bun!')
13
+ - Set Windows Terminal as default terminal
14
+ - Install latest version of Powershell
15
+ - Display scale to 100%
16
+ - Remove McAfee and enable Windows Defender (default antivirus, does not nag you)
17
+ - Install Software
18
+ - OpenSSH server (run these in an elevated terminal)
19
+ - `Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0`
20
+ - `Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0`
21
+ - `Start-Service sshd`
22
+ - `Set-Service -Name sshd -StartupType 'Automatic'`
23
+ - `New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force`
24
+ - Configure in `C:\ProgramData\ssh`
25
+ - Add ssh keys (in ProgramData because it is an admin account)
26
+ - Tailscale (login with GitHub so it joins the team tailnet)
27
+ - Visual Studio Code
28
+ - Configure `git`
29
+ - `git config user.name "your name"`
30
+ - `git config user.email "your@email"`
31
+ - Disable sleep mode and the lid switch by going to "Power Options" and configuring everything there.
32
+
33
+ I recommend using VSCode through SSH instead of Tunnels or the Tailscale extension, it seems to be more reliable.
34
+
35
+ {% /details %} -->
36
+
37
+ ### Enable Scripts
38
+
39
+ By default, running unverified scripts are blocked.
40
+
41
+ ```ps1
42
+ > Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
43
+ ```
44
+
45
+ ### System Dependencies
46
+
47
+ Bun v1.1 or later. We use Bun to run it's own code generators.
48
+
49
+ ```ps1
50
+ > irm bun.sh/install.ps1 | iex
51
+ ```
52
+
53
+ [Visual Studio](https://visualstudio.microsoft.com) with the "Desktop Development with C++" workload. While installing, make sure to install Git as well, if Git for Windows is not already installed.
54
+
55
+ Visual Studio can be installed graphically using the wizard or through WinGet:
56
+
57
+ ```ps1
58
+ > winget install "Visual Studio Community 2022" --override "--add Microsoft.VisualStudio.Workload.NativeDesktop Microsoft.VisualStudio.Component.Git " -s msstore
59
+ ```
60
+
61
+ After Visual Studio, you need the following:
62
+
63
+ - LLVM 18.1.8
64
+ - Go
65
+ - Rust
66
+ - NASM
67
+ - Perl
68
+ - Ruby
69
+ - Node.js
70
+ - Ccache
71
+
72
+ {% callout %}
73
+ **Note** – The Zig compiler is automatically downloaded, installed, and updated by the building process.
74
+ {% /callout %}
75
+
76
+ [Scoop](https://scoop.sh) can be used to install these remaining tools easily.
77
+
78
+ {% codetabs group="a" %}
79
+
80
+ ```ps1#Scoop
81
+ > irm https://get.scoop.sh | iex
82
+ > scoop install nodejs-lts go rust nasm ruby perl ccache
83
+ # scoop seems to be buggy if you install llvm and the rest at the same time
84
+ > scoop install llvm@18.1.8
85
+ ```
86
+
87
+ {% /codetabs %}
88
+
89
+ {% callout %}
90
+ Please do not use WinGet/other package manager for these, as you will likely install Strawberry Perl instead of a more minimal installation of Perl. Strawberry Perl includes many other utilities that get installed into `$Env:PATH` that will conflict with MSVC and break the build.
91
+ {% /callout %}
92
+
93
+ If you intend on building WebKit locally (optional), you should install these packages:
94
+
95
+ ```ps1#Scoop
96
+ > scoop install make cygwin python
97
+ ```
98
+
99
+ From here on out, it is **expected you use a PowerShell Terminal with `.\scripts\vs-shell.ps1` sourced**. This script is available in the Bun repository and can be loaded by executing it:
100
+
101
+ ```ps1
102
+ > .\scripts\vs-shell.ps1
103
+ ```
104
+
105
+ To verify, you can check for an MSVC-only command line such as `mt.exe`
106
+
107
+ ```ps1
108
+ > Get-Command mt
109
+ ```
110
+
111
+ {% callout %}
112
+ It is not recommended to install `ninja` / `cmake` into your global path, because you may run into a situation where you try to build bun without .\scripts\vs-shell.ps1 sourced.
113
+ {% /callout %}
114
+
115
+ ## Building
116
+
117
+ ```ps1
118
+ > bun run build
119
+
120
+ # after the initial `bun run build` you can use the following to build
121
+ > ninja -Cbuild/debug
122
+ ```
123
+
124
+ If this was successful, you should have a `bun-debug.exe` in the `build/debug` folder.
125
+
126
+ ```ps1
127
+ > .\build\debug\bun-debug.exe --revision
128
+ ```
129
+
130
+ You should add this to `$Env:PATH`. The simplest way to do so is to open the start menu, type "Path", and then navigate the environment variables menu to add `C:\.....\bun\build\debug` to the user environment variable `PATH`. You should then restart your editor (if it does not update still, log out and log back in).
131
+
132
+ ## Extra paths
133
+
134
+ - WebKit is extracted to `build/debug/cache/webkit/`
135
+ - Zig is extracted to `build/debug/cache/zig/bin/zig.exe`
136
+
137
+ ## Tests
138
+
139
+ You can run the test suite either using `bun test <path>`, or by using the wrapper script `packages\bun-internal-test`. The internal test package is a wrapper cli to run every test file in a separate instance of bun.exe, to prevent a crash in the test runner from stopping the entire suite.
140
+
141
+ ```ps1
142
+ # Setup
143
+ > bun i --cwd packages\bun-internal-test
144
+
145
+ # Run the entire test suite with reporter
146
+ # the package.json script "test" uses "build/debug/bun-debug.exe" by default
147
+ > bun run test
148
+
149
+ # Run an individual test file:
150
+ > bun-debug test node\fs
151
+ > bun-debug test "C:\bun\test\js\bun\resolve\import-meta.test.js"
152
+ ```
153
+
154
+ ## Troubleshooting
155
+
156
+ ### .rc file fails to build
157
+
158
+ `llvm-rc.exe` is odd. don't use it. use `rc.exe`, to do this make sure you are in a visual studio dev terminal, check `rc /?` to ensure it is `Microsoft Resource Compiler`
159
+
160
+ ### failed to write output 'bun-debug.exe': permission denied
161
+
162
+ you cannot overwrite `bun-debug.exe` if it is already open. you likely have a running instance, maybe in the vscode debugger?
@@ -0,0 +1,75 @@
1
+ There are four parts to the CI build:
2
+
3
+ - Dependencies: should be cached across builds as much as possible, it depends on git submodule hashes
4
+ - Zig Object: depends on \*.zig and src/js
5
+ - C++ Object: depends on \*.cpp and src/js
6
+ - Linking: depends on the above three
7
+
8
+ Utilizing multiple GitHub Action runners allows us to do a lot of work in parallel.
9
+
10
+ ## Dependencies
11
+
12
+ ```sh
13
+ BUN_DEPS_OUT_DIR="/optional/out/dir" bash ./scripts/all-dependencies.sh
14
+ ```
15
+
16
+ ## Zig Object
17
+
18
+ This does not have a dependency on WebKit or any of the dependencies at all. It can be compiled without checking out submodules, but you will need to have bun install run. It can be very easily cross compiled. Note that the zig object is always `bun-zig.o`.
19
+
20
+ ```sh
21
+ BUN_REPO=/path/to/oven-sh/bun
22
+
23
+ cd tmp1
24
+
25
+ cmake $BUN_REPO \
26
+ -G Ninja \
27
+ -DCMAKE_BUILD_TYPE=Release \
28
+ -DCPU_TARGET="native" \
29
+ -DZIG_TARGET="native" \
30
+ -DBUN_ZIG_OBJ_DIR="./build"
31
+
32
+ ninja ./build/bun-zig.o
33
+ # -> bun-zig.o
34
+ ```
35
+
36
+ ## C++ Object
37
+
38
+ Note: if WEBKIT_DIR is not passed, it is automatically downloaded from GitHub releases. This depends on the headers from submodules but not necessarily the build copies of them, .a files, etc.
39
+
40
+ ```sh
41
+ cd tmp2
42
+
43
+ cmake $BUN_REPO \
44
+ -G Ninja \
45
+ -DCMAKE_BUILD_TYPE=Release \
46
+ -DBUN_CPP_ONLY=1 \
47
+
48
+ bash compile-cpp-only.sh
49
+ # -> bun-cpp-objects.a
50
+ ```
51
+
52
+ ## Linking
53
+
54
+ The goal is you run both stages from above on different machines, so that they can build in parallel. Zig build is slow, and MacOS build runners are slower on average than the linux ones. With both artifacts from above, you can link them together:
55
+
56
+ ```sh
57
+ cd tmp3
58
+
59
+ cmake $BUN_REPO \
60
+ -G Ninja \
61
+ -DCMAKE_BUILD_TYPE=Release \
62
+ -DBUN_LINK_ONLY=1 \
63
+ -DBUN_ZIG_OBJ_DIR="/path/to/bun-zig-dir" \
64
+ -DBUN_CPP_ARCHIVE="/path/to/bun-cpp-objects.a"
65
+
66
+ ninja
67
+
68
+ # optional:
69
+ # -DBUN_DEPS_OUT_DIR=... custom deps dir, use this to cache the built deps between rebuilds
70
+ # -DWEBKIT_DIR=... same thing, but it's probably fast enough to pull from github releases
71
+
72
+ # -> bun
73
+ # -> bun-profile
74
+ # -> bun.dSYM/
75
+ ```
@@ -0,0 +1,87 @@
1
+ Bun is a project with an incredibly large scope and is still in its early days. Long-term, Bun aims to provide an all-in-one toolkit to replace the complex, fragmented toolchains common today: Node.js, Jest, Webpack, esbuild, Babel, yarn, PostCSS, etc.
2
+
3
+ Refer to [Bun's Roadmap](https://github.com/oven-sh/bun/issues/159) on GitHub to learn more about the project's long-term plans and priorities.
4
+
5
+ <!--
6
+ {% table %}
7
+
8
+ - Feature
9
+ - Implemented in
10
+
11
+ ---
12
+
13
+ - Web Streams with HTMLRewriter
14
+ - Bun.js
15
+
16
+ ---
17
+
18
+ - Source Maps (unbundled is supported)
19
+ - JS Bundler
20
+
21
+ ---
22
+
23
+ - Source Maps
24
+ - CSS
25
+
26
+ ---
27
+
28
+ - JavaScript Minifier
29
+ - JS Transpiler
30
+
31
+ ---
32
+
33
+ - CSS Minifier
34
+ - CSS
35
+
36
+ ---
37
+
38
+ - CSS Parser (it only bundles)
39
+ - CSS
40
+
41
+ ---
42
+
43
+ - Tree-shaking
44
+ - JavaScript
45
+
46
+ ---
47
+
48
+ - Tree-shaking
49
+ - CSS
50
+
51
+ ---
52
+
53
+ - [TypeScript Decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
54
+ - TS Transpiler
55
+
56
+ ---
57
+
58
+ - `@jsxPragma` comments
59
+ - JS Transpiler
60
+
61
+ ---
62
+
63
+ - Sharing `.bun` files
64
+ - Bun
65
+
66
+ ---
67
+
68
+ - Dates & timestamps
69
+ - TOML parser
70
+
71
+ ---
72
+
73
+ - [Hash components for Fast Refresh](https://github.com/oven-sh/bun/issues/18)
74
+ - JSX Transpiler
75
+
76
+ {% /table %} -->
77
+
78
+ <!-- ## Limitations & intended usage
79
+
80
+ Today, Bun is mostly focused on Bun.js: the JavaScript runtime.
81
+
82
+ While you could use Bun's bundler & transpiler separately to build for browsers or node, Bun doesn't have a minifier or support tree-shaking yet. For production browser builds, you probably should use a tool like esbuild or swc.
83
+
84
+ ## Upcoming breaking changes
85
+
86
+ - Bun's CLI flags will change to better support Bun as a JavaScript runtime. They were chosen when Bun was just a frontend development tool.
87
+ - Bun's bundling format will change to accommodate production browser bundles and on-demand production bundling -->
@@ -0,0 +1,144 @@
1
+ Let's write a simple HTTP server using the built-in `Bun.serve` API. First, create a fresh directory.
2
+
3
+ ```bash
4
+ $ mkdir quickstart
5
+ $ cd quickstart
6
+ ```
7
+
8
+ Run `bun init` to scaffold a new project. It's an interactive tool; for this tutorial, just press `enter` to accept the default answer for each prompt.
9
+
10
+ ```bash
11
+ $ bun init
12
+ bun init helps you get started with a minimal project and tries to
13
+ guess sensible defaults. Press ^C anytime to quit.
14
+
15
+ package name (quickstart):
16
+ entry point (index.ts):
17
+
18
+ Done! A package.json file was saved in the current directory.
19
+ + index.ts
20
+ + .gitignore
21
+ + tsconfig.json (for editor auto-complete)
22
+ + README.md
23
+
24
+ To get started, run:
25
+ bun run index.ts
26
+ ```
27
+
28
+ Since our entry point is a `*.ts` file, Bun generates a `tsconfig.json` for you. If you're using plain JavaScript, it will generate a [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) instead.
29
+
30
+ ## Run a file
31
+
32
+ Open `index.ts` and paste the following code snippet, which implements a simple HTTP server with [`Bun.serve`](https://bun.sh/docs/api/http).
33
+
34
+ ```ts
35
+ const server = Bun.serve({
36
+ port: 3000,
37
+ fetch(req) {
38
+ return new Response("Bun!");
39
+ },
40
+ });
41
+
42
+ console.log(`Listening on http://localhost:${server.port} ...`);
43
+ ```
44
+
45
+ {% details summary="Seeing TypeScript errors on `Bun`?" %}
46
+ If you used `bun init`, Bun will have automatically installed Bun's TypeScript declarations and configured your `tsconfig.json`. If you're trying out Bun in an existing project, you may see a type error on the `Bun` global.
47
+
48
+ To fix this, first install `@types/bun` as a dev dependency.
49
+
50
+ ```sh
51
+ $ bun add -d @types/bun
52
+ ```
53
+
54
+ Then add the following to your `compilerOptions` in `tsconfig.json`:
55
+
56
+ ```json#tsconfig.json
57
+ {
58
+ "compilerOptions": {
59
+ "lib": ["ESNext"],
60
+ "target": "ESNext",
61
+ "module": "ESNext",
62
+ "moduleDetection": "force",
63
+ "moduleResolution": "bundler",
64
+ "allowImportingTsExtensions": true,
65
+ "verbatimModuleSyntax": true,
66
+ "noEmit": true,
67
+ }
68
+ }
69
+ ```
70
+
71
+ {% /details %}
72
+
73
+ Run the file from your shell.
74
+
75
+ ```bash
76
+ $ bun index.ts
77
+ Listening on http://localhost:3000 ...
78
+ ```
79
+
80
+ Visit [http://localhost:3000](http://localhost:3000) to test the server. You should see a simple page that says "Bun!".
81
+
82
+ ## Run a script
83
+
84
+ Bun can also execute `"scripts"` from your `package.json`. Add the following script:
85
+
86
+ ```json-diff
87
+ {
88
+ "name": "quickstart",
89
+ "module": "index.ts",
90
+ "type": "module",
91
+ + "scripts": {
92
+ + "start": "bun run index.ts"
93
+ + },
94
+ "devDependencies": {
95
+ "@types/bun": "^1.0.0"
96
+ }
97
+ }
98
+ ```
99
+
100
+ Then run it with `bun run start`.
101
+
102
+ ```bash
103
+ $ bun run start
104
+ $ bun run index.ts
105
+ Listening on http://localhost:3000 ...
106
+ ```
107
+
108
+ {% callout %}
109
+ ⚡️ **Performance** — `bun run` is roughly 28x faster than `npm run` (6ms vs 170ms of overhead).
110
+ {% /callout %}
111
+
112
+ ## Install a package
113
+
114
+ Let's make our server a little more interesting by installing a package. First install the `figlet` package and its type declarations. Figlet is a utility for converting strings into ASCII art.
115
+
116
+ ```bash
117
+ $ bun add figlet
118
+ $ bun add -d @types/figlet # TypeScript users only
119
+ ```
120
+
121
+ Update `index.ts` to use `figlet` in the `fetch` handler.
122
+
123
+ ```ts-diff
124
+ + import figlet from "figlet";
125
+
126
+ const server = Bun.serve({
127
+ port: 3000,
128
+ fetch(req) {
129
+ + const body = figlet.textSync("Bun!");
130
+ + return new Response(body);
131
+ - return new Response("Bun!");
132
+ },
133
+ });
134
+ ```
135
+
136
+ Restart the server and refresh the page. You should see a new ASCII art banner.
137
+
138
+ ```txt
139
+ ____ _
140
+ | __ ) _ _ _ __ | |
141
+ | _ \| | | | '_ \| |
142
+ | |_) | |_| | | | |_|
143
+ |____/ \__,_|_| |_(_)
144
+ ```