bun-types 1.3.2-canary.20251105T140650 → 1.3.2-canary.20251106T140813

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 (308) hide show
  1. package/docs/README.md +28 -0
  2. package/package.json +1 -1
  3. package/docs/api/binary-data.md +0 -1038
  4. package/docs/api/cc.md +0 -197
  5. package/docs/api/color.md +0 -262
  6. package/docs/api/console.md +0 -57
  7. package/docs/api/cookie.md +0 -449
  8. package/docs/api/dns.md +0 -110
  9. package/docs/api/fetch.md +0 -463
  10. package/docs/api/ffi.md +0 -557
  11. package/docs/api/file-io.md +0 -366
  12. package/docs/api/file-system-router.md +0 -112
  13. package/docs/api/file.md +0 -19
  14. package/docs/api/glob.md +0 -178
  15. package/docs/api/globals.md +0 -387
  16. package/docs/api/hashing.md +0 -319
  17. package/docs/api/html-rewriter.md +0 -334
  18. package/docs/api/http.md +0 -1408
  19. package/docs/api/import-meta.md +0 -69
  20. package/docs/api/node-api.md +0 -14
  21. package/docs/api/redis.md +0 -597
  22. package/docs/api/s3.md +0 -850
  23. package/docs/api/secrets.md +0 -319
  24. package/docs/api/semver.md +0 -52
  25. package/docs/api/spawn.md +0 -582
  26. package/docs/api/sql.md +0 -1374
  27. package/docs/api/sqlite.md +0 -694
  28. package/docs/api/streams.md +0 -230
  29. package/docs/api/tcp.md +0 -221
  30. package/docs/api/transpiler.md +0 -276
  31. package/docs/api/udp.md +0 -123
  32. package/docs/api/utils.md +0 -891
  33. package/docs/api/websockets.md +0 -573
  34. package/docs/api/workers.md +0 -322
  35. package/docs/api/yaml.md +0 -668
  36. package/docs/benchmarks.md +0 -120
  37. package/docs/bun-flavored-toml.md +0 -42
  38. package/docs/bundler/css.md +0 -1028
  39. package/docs/bundler/css_modules.md +0 -145
  40. package/docs/bundler/executables.md +0 -626
  41. package/docs/bundler/fullstack.md +0 -418
  42. package/docs/bundler/hmr.md +0 -234
  43. package/docs/bundler/html.md +0 -349
  44. package/docs/bundler/index.md +0 -1735
  45. package/docs/bundler/intro.md +0 -75
  46. package/docs/bundler/loaders.md +0 -410
  47. package/docs/bundler/macros.md +0 -329
  48. package/docs/bundler/plugins.md +0 -449
  49. package/docs/bundler/vs-esbuild.md +0 -1127
  50. package/docs/cli/add.md +0 -173
  51. package/docs/cli/bun-completions.md +0 -3
  52. package/docs/cli/bun-create.md +0 -338
  53. package/docs/cli/bun-install.md +0 -349
  54. package/docs/cli/bun-upgrade.md +0 -39
  55. package/docs/cli/bunx.md +0 -89
  56. package/docs/cli/filter.md +0 -90
  57. package/docs/cli/info.md +0 -65
  58. package/docs/cli/init.md +0 -85
  59. package/docs/cli/install.md +0 -344
  60. package/docs/cli/link.md +0 -40
  61. package/docs/cli/outdated.md +0 -90
  62. package/docs/cli/patch-commit.md +0 -11
  63. package/docs/cli/pm.md +0 -285
  64. package/docs/cli/publish.md +0 -120
  65. package/docs/cli/remove.md +0 -7
  66. package/docs/cli/run.md +0 -261
  67. package/docs/cli/test.md +0 -397
  68. package/docs/cli/unlink.md +0 -9
  69. package/docs/cli/update.md +0 -129
  70. package/docs/cli/why.md +0 -67
  71. package/docs/contributing/upgrading-webkit.md +0 -57
  72. package/docs/ecosystem/elysia.md +0 -24
  73. package/docs/ecosystem/express.md +0 -37
  74. package/docs/ecosystem/hono.md +0 -18
  75. package/docs/ecosystem/react.md +0 -65
  76. package/docs/ecosystem/stric.md +0 -38
  77. package/docs/guides/binary/arraybuffer-to-array.md +0 -27
  78. package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
  79. package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
  80. package/docs/guides/binary/arraybuffer-to-string.md +0 -15
  81. package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
  82. package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
  83. package/docs/guides/binary/blob-to-dataview.md +0 -14
  84. package/docs/guides/binary/blob-to-stream.md +0 -14
  85. package/docs/guides/binary/blob-to-string.md +0 -15
  86. package/docs/guides/binary/blob-to-typedarray.md +0 -14
  87. package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
  88. package/docs/guides/binary/buffer-to-blob.md +0 -14
  89. package/docs/guides/binary/buffer-to-readablestream.md +0 -41
  90. package/docs/guides/binary/buffer-to-string.md +0 -25
  91. package/docs/guides/binary/buffer-to-typedarray.md +0 -14
  92. package/docs/guides/binary/dataview-to-string.md +0 -15
  93. package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
  94. package/docs/guides/binary/typedarray-to-blob.md +0 -16
  95. package/docs/guides/binary/typedarray-to-buffer.md +0 -14
  96. package/docs/guides/binary/typedarray-to-dataview.md +0 -14
  97. package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
  98. package/docs/guides/binary/typedarray-to-string.md +0 -16
  99. package/docs/guides/deployment/railway.md +0 -157
  100. package/docs/guides/ecosystem/astro.md +0 -72
  101. package/docs/guides/ecosystem/discordjs.md +0 -77
  102. package/docs/guides/ecosystem/docker.md +0 -140
  103. package/docs/guides/ecosystem/drizzle.md +0 -185
  104. package/docs/guides/ecosystem/edgedb.md +0 -228
  105. package/docs/guides/ecosystem/elysia.md +0 -31
  106. package/docs/guides/ecosystem/express.md +0 -40
  107. package/docs/guides/ecosystem/hono.md +0 -39
  108. package/docs/guides/ecosystem/mongoose.md +0 -87
  109. package/docs/guides/ecosystem/neon-drizzle.md +0 -220
  110. package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
  111. package/docs/guides/ecosystem/nextjs.md +0 -49
  112. package/docs/guides/ecosystem/nuxt.md +0 -56
  113. package/docs/guides/ecosystem/pm2.md +0 -57
  114. package/docs/guides/ecosystem/prisma.md +0 -141
  115. package/docs/guides/ecosystem/qwik.md +0 -107
  116. package/docs/guides/ecosystem/react.md +0 -50
  117. package/docs/guides/ecosystem/remix.md +0 -78
  118. package/docs/guides/ecosystem/render.md +0 -79
  119. package/docs/guides/ecosystem/sentry.md +0 -52
  120. package/docs/guides/ecosystem/solidstart.md +0 -58
  121. package/docs/guides/ecosystem/ssr-react.md +0 -51
  122. package/docs/guides/ecosystem/stric.md +0 -55
  123. package/docs/guides/ecosystem/sveltekit.md +0 -125
  124. package/docs/guides/ecosystem/systemd.md +0 -113
  125. package/docs/guides/ecosystem/vite.md +0 -71
  126. package/docs/guides/html-rewriter/extract-links.md +0 -68
  127. package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
  128. package/docs/guides/http/cluster.md +0 -66
  129. package/docs/guides/http/fetch-unix.md +0 -33
  130. package/docs/guides/http/fetch.md +0 -24
  131. package/docs/guides/http/file-uploads.md +0 -94
  132. package/docs/guides/http/hot.md +0 -26
  133. package/docs/guides/http/proxy.md +0 -24
  134. package/docs/guides/http/server.md +0 -46
  135. package/docs/guides/http/simple.md +0 -18
  136. package/docs/guides/http/stream-file.md +0 -48
  137. package/docs/guides/http/stream-iterator.md +0 -47
  138. package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
  139. package/docs/guides/http/tls.md +0 -30
  140. package/docs/guides/install/add-dev.md +0 -26
  141. package/docs/guides/install/add-git.md +0 -36
  142. package/docs/guides/install/add-optional.md +0 -25
  143. package/docs/guides/install/add-peer.md +0 -43
  144. package/docs/guides/install/add-tarball.md +0 -33
  145. package/docs/guides/install/add.md +0 -42
  146. package/docs/guides/install/azure-artifacts.md +0 -73
  147. package/docs/guides/install/cicd.md +0 -41
  148. package/docs/guides/install/custom-registry.md +0 -30
  149. package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
  150. package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
  151. package/docs/guides/install/jfrog-artifactory.md +0 -28
  152. package/docs/guides/install/npm-alias.md +0 -23
  153. package/docs/guides/install/registry-scope.md +0 -38
  154. package/docs/guides/install/trusted.md +0 -46
  155. package/docs/guides/install/workspaces.md +0 -70
  156. package/docs/guides/install/yarnlock.md +0 -44
  157. package/docs/guides/process/argv.md +0 -58
  158. package/docs/guides/process/ctrl-c.md +0 -16
  159. package/docs/guides/process/ipc.md +0 -66
  160. package/docs/guides/process/nanoseconds.md +0 -13
  161. package/docs/guides/process/os-signals.md +0 -39
  162. package/docs/guides/process/spawn-stderr.md +0 -31
  163. package/docs/guides/process/spawn-stdout.md +0 -26
  164. package/docs/guides/process/spawn.md +0 -41
  165. package/docs/guides/process/stdin.md +0 -54
  166. package/docs/guides/read-file/arraybuffer.md +0 -28
  167. package/docs/guides/read-file/buffer.md +0 -19
  168. package/docs/guides/read-file/exists.md +0 -16
  169. package/docs/guides/read-file/json.md +0 -17
  170. package/docs/guides/read-file/mime.md +0 -20
  171. package/docs/guides/read-file/stream.md +0 -26
  172. package/docs/guides/read-file/string.md +0 -22
  173. package/docs/guides/read-file/uint8array.md +0 -21
  174. package/docs/guides/read-file/watch.md +0 -68
  175. package/docs/guides/runtime/build-time-constants.md +0 -293
  176. package/docs/guides/runtime/cicd.md +0 -43
  177. package/docs/guides/runtime/codesign-macos-executable.md +0 -56
  178. package/docs/guides/runtime/define-constant.md +0 -145
  179. package/docs/guides/runtime/delete-directory.md +0 -37
  180. package/docs/guides/runtime/delete-file.md +0 -19
  181. package/docs/guides/runtime/heap-snapshot.md +0 -26
  182. package/docs/guides/runtime/import-html.md +0 -15
  183. package/docs/guides/runtime/import-json.md +0 -44
  184. package/docs/guides/runtime/import-toml.md +0 -30
  185. package/docs/guides/runtime/import-yaml.md +0 -102
  186. package/docs/guides/runtime/read-env.md +0 -32
  187. package/docs/guides/runtime/set-env.md +0 -47
  188. package/docs/guides/runtime/shell.md +0 -40
  189. package/docs/guides/runtime/timezone.md +0 -35
  190. package/docs/guides/runtime/tsconfig-paths.md +0 -29
  191. package/docs/guides/runtime/typescript.md +0 -49
  192. package/docs/guides/runtime/vscode-debugger.md +0 -47
  193. package/docs/guides/runtime/web-debugger.md +0 -82
  194. package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
  195. package/docs/guides/streams/node-readable-to-blob.md +0 -11
  196. package/docs/guides/streams/node-readable-to-json.md +0 -12
  197. package/docs/guides/streams/node-readable-to-string.md +0 -12
  198. package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
  199. package/docs/guides/streams/to-array.md +0 -14
  200. package/docs/guides/streams/to-arraybuffer.md +0 -14
  201. package/docs/guides/streams/to-blob.md +0 -14
  202. package/docs/guides/streams/to-buffer.md +0 -15
  203. package/docs/guides/streams/to-json.md +0 -14
  204. package/docs/guides/streams/to-string.md +0 -14
  205. package/docs/guides/streams/to-typedarray.md +0 -22
  206. package/docs/guides/test/bail.md +0 -22
  207. package/docs/guides/test/coverage-threshold.md +0 -60
  208. package/docs/guides/test/coverage.md +0 -44
  209. package/docs/guides/test/happy-dom.md +0 -68
  210. package/docs/guides/test/migrate-from-jest.md +0 -143
  211. package/docs/guides/test/mock-clock.md +0 -48
  212. package/docs/guides/test/mock-functions.md +0 -68
  213. package/docs/guides/test/rerun-each.md +0 -14
  214. package/docs/guides/test/run-tests.md +0 -111
  215. package/docs/guides/test/skip-tests.md +0 -39
  216. package/docs/guides/test/snapshot.md +0 -95
  217. package/docs/guides/test/spy-on.md +0 -46
  218. package/docs/guides/test/svelte-test.md +0 -120
  219. package/docs/guides/test/testing-library.md +0 -92
  220. package/docs/guides/test/timeout.md +0 -15
  221. package/docs/guides/test/todo-tests.md +0 -67
  222. package/docs/guides/test/update-snapshots.md +0 -46
  223. package/docs/guides/test/watch-mode.md +0 -19
  224. package/docs/guides/util/base64.md +0 -15
  225. package/docs/guides/util/deep-equals.md +0 -39
  226. package/docs/guides/util/deflate.md +0 -18
  227. package/docs/guides/util/detect-bun.md +0 -23
  228. package/docs/guides/util/entrypoint.md +0 -17
  229. package/docs/guides/util/escape-html.md +0 -22
  230. package/docs/guides/util/file-url-to-path.md +0 -14
  231. package/docs/guides/util/gzip.md +0 -18
  232. package/docs/guides/util/hash-a-password.md +0 -54
  233. package/docs/guides/util/import-meta-dir.md +0 -13
  234. package/docs/guides/util/import-meta-file.md +0 -13
  235. package/docs/guides/util/import-meta-path.md +0 -13
  236. package/docs/guides/util/javascript-uuid.md +0 -23
  237. package/docs/guides/util/main.md +0 -32
  238. package/docs/guides/util/path-to-file-url.md +0 -14
  239. package/docs/guides/util/sleep.md +0 -22
  240. package/docs/guides/util/version.md +0 -21
  241. package/docs/guides/util/which-path-to-executable-bin.md +0 -15
  242. package/docs/guides/websocket/compression.md +0 -31
  243. package/docs/guides/websocket/context.md +0 -77
  244. package/docs/guides/websocket/pubsub.md +0 -41
  245. package/docs/guides/websocket/simple.md +0 -33
  246. package/docs/guides/write-file/append.md +0 -52
  247. package/docs/guides/write-file/basic.md +0 -44
  248. package/docs/guides/write-file/blob.md +0 -28
  249. package/docs/guides/write-file/cat.md +0 -17
  250. package/docs/guides/write-file/file-cp.md +0 -16
  251. package/docs/guides/write-file/filesink.md +0 -52
  252. package/docs/guides/write-file/response.md +0 -17
  253. package/docs/guides/write-file/stdout.md +0 -21
  254. package/docs/guides/write-file/stream.md +0 -17
  255. package/docs/guides/write-file/unlink.md +0 -16
  256. package/docs/index.md +0 -77
  257. package/docs/install/audit.md +0 -57
  258. package/docs/install/cache.md +0 -59
  259. package/docs/install/catalogs.md +0 -298
  260. package/docs/install/index.md +0 -248
  261. package/docs/install/isolated.md +0 -197
  262. package/docs/install/lifecycle.md +0 -46
  263. package/docs/install/lockfile.md +0 -58
  264. package/docs/install/npmrc.md +0 -105
  265. package/docs/install/overrides.md +0 -73
  266. package/docs/install/patch.md +0 -59
  267. package/docs/install/registries.md +0 -30
  268. package/docs/install/security-scanner-api.md +0 -81
  269. package/docs/install/workspaces.md +0 -114
  270. package/docs/installation.md +0 -327
  271. package/docs/project/asan.md +0 -124
  272. package/docs/project/benchmarking.md +0 -203
  273. package/docs/project/bindgen.md +0 -225
  274. package/docs/project/building-windows.md +0 -162
  275. package/docs/project/contributing.md +0 -347
  276. package/docs/project/internals/build-process-for-ci.md +0 -75
  277. package/docs/project/licensing.md +0 -73
  278. package/docs/project/roadmap.md +0 -87
  279. package/docs/quickstart.md +0 -157
  280. package/docs/runtime/autoimport.md +0 -94
  281. package/docs/runtime/bun-apis.md +0 -207
  282. package/docs/runtime/bunfig.md +0 -772
  283. package/docs/runtime/debugger.md +0 -325
  284. package/docs/runtime/env.md +0 -253
  285. package/docs/runtime/hot.md +0 -145
  286. package/docs/runtime/index.md +0 -312
  287. package/docs/runtime/jsx.md +0 -385
  288. package/docs/runtime/loaders.md +0 -130
  289. package/docs/runtime/modules.md +0 -320
  290. package/docs/runtime/nodejs-apis.md +0 -463
  291. package/docs/runtime/plugins.md +0 -561
  292. package/docs/runtime/shell.md +0 -605
  293. package/docs/runtime/typescript.md +0 -139
  294. package/docs/runtime/web-apis.md +0 -128
  295. package/docs/test/configuration.md +0 -154
  296. package/docs/test/coverage.md +0 -142
  297. package/docs/test/discovery.md +0 -85
  298. package/docs/test/dom.md +0 -75
  299. package/docs/test/examples/concurrent-test-glob.md +0 -132
  300. package/docs/test/hot.md +0 -15
  301. package/docs/test/lifecycle.md +0 -81
  302. package/docs/test/mocks.md +0 -313
  303. package/docs/test/reporters.md +0 -117
  304. package/docs/test/runtime-behavior.md +0 -95
  305. package/docs/test/snapshots.md +0 -68
  306. package/docs/test/time.md +0 -126
  307. package/docs/test/writing.md +0 -825
  308. package/docs/typescript.md +0 -53
@@ -1,58 +0,0 @@
1
- ---
2
- name: Build an app with SolidStart and Bun
3
- ---
4
-
5
- {% callout %}
6
- SolidStart currently relies on Node.js APIs that Bun does not yet implement. The guide below uses Bun to initialize a project and install dependencies, but it uses Node.js to run the dev server.
7
- {% /callout %}
8
-
9
- ---
10
-
11
- Initialize a SolidStart app with `create-solid`.
12
-
13
- ```sh
14
- $ bun create solid my-app
15
- create-solid version 0.2.31
16
-
17
- Welcome to the SolidStart setup wizard!
18
-
19
- There are definitely bugs and some feature might not work yet.
20
- If you encounter an issue, have a look at
21
- https://github.com/solidjs/solid-start/issues and open a new one,
22
- if it is not already tracked.
23
-
24
- ✔ Which template do you want to use? › todomvc
25
- ✔ Server Side Rendering? … yes
26
- ✔ Use TypeScript? … yes
27
- cloned solidjs/solid-start#main to /path/to/my-app/.solid-start
28
- ✔ Copied project files
29
- ```
30
-
31
- ---
32
-
33
- As instructed by the `create-solid` CLI, let's install our dependencies.
34
-
35
- ```sh
36
- $ cd my-app
37
- $ bun install
38
- ```
39
-
40
- ---
41
-
42
- Then run the development server.
43
-
44
- ```sh
45
- $ bun run dev
46
- # or, equivalently
47
- $ bunx solid-start dev
48
- ```
49
-
50
- ---
51
-
52
- Open [localhost:3000](http://localhost:3000). Any changes you make to `src/routes/index.tsx` will be hot-reloaded automatically.
53
-
54
- {% image src="https://github.com/oven-sh/bun/assets/3084745/1e8043c4-49d1-498c-9add-c1eaab6c7167" alt="SolidStart demo app" /%}
55
-
56
- ---
57
-
58
- Refer to the [SolidStart website](https://start.solidjs.com/getting-started/what-is-solidstart) for complete framework documentation.
@@ -1,51 +0,0 @@
1
- ---
2
- name: Server-side render (SSR) a React component
3
- ---
4
-
5
- To get started, install `react` & `react-dom`:
6
-
7
- ```sh
8
- # Any package manager can be used
9
- $ bun add react react-dom
10
- ```
11
-
12
- ---
13
-
14
- To render a React component to an HTML stream server-side (SSR):
15
-
16
- ```tsx
17
- import { renderToReadableStream } from "react-dom/server";
18
-
19
- function Component(props: { message: string }) {
20
- return (
21
- <body>
22
- <h1>{props.message}</h1>
23
- </body>
24
- );
25
- }
26
-
27
- const stream = await renderToReadableStream(
28
- <Component message="Hello from server!" />,
29
- );
30
- ```
31
-
32
- ---
33
-
34
- Combining this with `Bun.serve()`, we get a simple SSR HTTP server:
35
-
36
- ```tsx
37
- Bun.serve({
38
- async fetch() {
39
- const stream = await renderToReadableStream(
40
- <Component message="Hello from server!" />,
41
- );
42
- return new Response(stream, {
43
- headers: { "Content-Type": "text/html" },
44
- });
45
- },
46
- });
47
- ```
48
-
49
- ---
50
-
51
- React `19` and later includes an [SSR optimization](https://github.com/facebook/react/pull/25597) that takes advantage of Bun's "direct" `ReadableStream` implementation. If you run into an error like `export named 'renderToReadableStream' not found`, please make sure to install version `19` of `react` & `react-dom`, or import from `react-dom/server.browser` instead of `react-dom/server`. See [facebook/react#28941](https://github.com/facebook/react/issues/28941) for more information.
@@ -1,55 +0,0 @@
1
- ---
2
- name: Build an HTTP server using StricJS and Bun
3
- ---
4
-
5
- [StricJS](https://github.com/bunsvr) is a Bun framework for building high-performance web applications and APIs.
6
-
7
- - **Fast** — Stric is one of the fastest Bun frameworks. See [benchmark](https://github.com/bunsvr/benchmark) for more details.
8
- - **Minimal** — The basic components like `@stricjs/router` and `@stricjs/utils` are under 50kB and require no external dependencies.
9
- - **Extensible** — Stric includes with a plugin system, dependency injection, and optional optimizations for handling requests.
10
-
11
- ---
12
-
13
- Use `bun init` to create an empty project.
14
-
15
- ```bash
16
- $ mkdir myapp
17
- $ cd myapp
18
- $ bun init
19
- $ bun add @stricjs/router @stricjs/utils
20
- ```
21
-
22
- ---
23
-
24
- To implement a simple HTTP server with StricJS:
25
-
26
- ```ts#index.ts
27
- import { Router } from '@stricjs/router';
28
-
29
- export default new Router()
30
- .get('/', () => new Response('Hi'));
31
- ```
32
-
33
- ---
34
-
35
- To serve static files from `/public`:
36
-
37
- ```ts#index.ts
38
- import { dir } from '@stricjs/utils';
39
-
40
- export default new Router()
41
- .get('/', () => new Response('Hi'))
42
- .get('/*', dir('./public'));
43
- ```
44
-
45
- ---
46
-
47
- Run the file in watch mode to start the development server.
48
-
49
- ```bash
50
- $ bun --watch run index.ts
51
- ```
52
-
53
- ---
54
-
55
- For more info, see Stric's [documentation](https://stricjs.netlify.app).
@@ -1,125 +0,0 @@
1
- ---
2
- name: Build an app with SvelteKit and Bun
3
- ---
4
-
5
- Use `sv create my-app` to create a SvelteKit project with SvelteKit CLI. Answer the prompts to select a template and set up your development environment.
6
-
7
- ```sh
8
- $ bunx sv create my-app
9
- ┌ Welcome to the Svelte CLI! (v0.5.7)
10
-
11
- ◇ Which template would you like?
12
- │ SvelteKit demo
13
-
14
- ◇ Add type checking with Typescript?
15
- │ Yes, using Typescript syntax
16
-
17
- ◆ Project created
18
-
19
- ◇ What would you like to add to your project?
20
- │ none
21
-
22
- ◇ Which package manager do you want to install dependencies with?
23
- │ bun
24
-
25
- ◇ Successfully installed dependencies
26
-
27
- ◇ Project next steps ─────────────────────────────────────────────────────╮
28
- │ │
29
- │ 1: cd my-app │
30
- │ 2: git init && git add -A && git commit -m "Initial commit" (optional) │
31
- │ 3: bun run dev -- --open │
32
- │ │
33
- │ To close the dev server, hit Ctrl-C │
34
- │ │
35
- │ Stuck? Visit us at https://svelte.dev/chat │
36
- │ │
37
- ├──────────────────────────────────────────────────────────────────────────╯
38
-
39
- └ You're all set!
40
- ```
41
-
42
- ---
43
-
44
- Once the project is initialized, `cd` into the new project. You don't need to run 'bun install' since the dependencies are already installed.
45
-
46
- Then start the development server with `bun --bun run dev`.
47
-
48
- To run the dev server with Node.js instead of Bun, you can omit the `--bun` flag.
49
-
50
- ```sh
51
- $ cd my-app
52
- $ bun --bun run dev
53
- $ vite dev
54
- Forced re-optimization of dependencies
55
-
56
- VITE v5.4.10 ready in 424 ms
57
-
58
- ➜ Local: http://localhost:5173/
59
- ➜ Network: use --host to expose
60
- ➜ press h + enter to show help
61
- ```
62
-
63
- ---
64
-
65
- Visit [http://localhost:5173](http://localhost:5173/) in a browser to see the template app.
66
-
67
- {% image src="https://github.com/oven-sh/bun/assets/3084745/7c76eae8-78f9-44fa-9f15-1bd3ca1a47c0" /%}
68
-
69
- ---
70
-
71
- If you edit and save `src/routes/+page.svelte`, you should see your changes hot-reloaded in the browser.
72
-
73
- ---
74
-
75
- To build for production, you'll need to add the right SvelteKit adapter. Currently we recommend the
76
-
77
- `bun add -D svelte-adapter-bun`.
78
-
79
- Now, make the following changes to your `svelte.config.js`.
80
-
81
- ```ts-diff
82
- - import adapter from "@sveltejs/adapter-auto";
83
- + import adapter from "svelte-adapter-bun";
84
- import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
85
-
86
- /** @type {import('@sveltejs/kit').Config} */
87
- const config = {
88
- // Consult https://svelte.dev/docs/kit/integrations#preprocessors
89
- // for more information about preprocessors
90
- preprocess: vitePreprocess(),
91
-
92
- kit: {
93
- // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
94
- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
95
- // See https://svelte.dev/docs/kit/adapters for more information about adapters.
96
- adapter: adapter()
97
- }
98
- };
99
-
100
- export default config;
101
- ```
102
-
103
- ---
104
-
105
- To build a production bundle:
106
-
107
- ```sh
108
- $ bun --bun run build
109
- $ vite build
110
- vite v5.4.10 building SSR bundle for production...
111
- "confetti" is imported from external module "@neoconfetti/svelte" but never used in "src/routes/sverdle/+page.svelte".
112
- ✓ 130 modules transformed.
113
- vite v5.4.10 building for production...
114
- ✓ 148 modules transformed.
115
- ...
116
- ✓ built in 231ms
117
- ...
118
- ✓ built in 899ms
119
-
120
- Run npm run preview to preview your production build locally.
121
-
122
- > Using svelte-adapter-bun
123
- ✔ Start server with: bun ./build/index.js
124
- ✔ done
125
- ```
@@ -1,113 +0,0 @@
1
- ---
2
- name: Run Bun as a daemon with systemd
3
- ---
4
-
5
- [systemd](https://systemd.io) is an init system and service manager for Linux operating systems that manages the startup and control of system processes and services.
6
-
7
- <!-- systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, maintains mount and auto mount points, and implements an elaborate transactional dependency-based service control logic. systemd supports SysV and LSB init scripts and works as a replacement for sysvinit. -->
8
-
9
- <!-- Other parts include a logging daemon, utilities to control basic system configuration like the hostname, date, locale, maintain a list of logged-in users and running containers and virtual machines, system accounts, runtime directories and settings, and daemons to manage simple network configuration, network time synchronization, log forwarding, and name resolution. -->
10
-
11
- ---
12
-
13
- To run a Bun application as a daemon using **systemd** you'll need to create a _service file_ in `/lib/systemd/system/`.
14
-
15
- ```sh
16
- $ cd /lib/systemd/system
17
- $ touch my-app.service
18
- ```
19
-
20
- ---
21
-
22
- Here is a typical service file that runs an application on system start. You can use this as a template for your own service. Replace `YOUR_USER` with the name of the user you want to run the application as. To run as `root`, replace `YOUR_USER` with `root`, though this is generally not recommended for security reasons.
23
-
24
- Refer to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd.service.html) for more information on each setting.
25
-
26
- ```ini#my-app.service
27
- [Unit]
28
- # describe the app
29
- Description=My App
30
- # start the app after the network is available
31
- After=network.target
32
-
33
- [Service]
34
- # usually you'll use 'simple'
35
- # one of https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=
36
- Type=simple
37
- # which user to use when starting the app
38
- User=YOUR_USER
39
- # path to your application's root directory
40
- WorkingDirectory=/home/YOUR_USER/path/to/my-app
41
- # the command to start the app
42
- # requires absolute paths
43
- ExecStart=/home/YOUR_USER/.bun/bin/bun run index.ts
44
- # restart policy
45
- # one of {no|on-success|on-failure|on-abnormal|on-watchdog|on-abort|always}
46
- Restart=always
47
-
48
- [Install]
49
- # start the app automatically
50
- WantedBy=multi-user.target
51
- ```
52
-
53
- ---
54
-
55
- If your application starts a webserver, note that non-`root` users are not able to listen on ports 80 or 443 by default. To permanently allow Bun to listen on these ports when executed by a non-`root` user, use the following command. This step isn't necessary when running as `root`.
56
-
57
- ```bash
58
- $ sudo setcap CAP_NET_BIND_SERVICE=+eip ~/.bun/bin/bun
59
- ```
60
-
61
- ---
62
-
63
- With the service file configured, you can now _enable_ the service. Once enabled, it will start automatically on reboot. This requires `sudo` permissions.
64
-
65
- ```bash
66
- $ sudo systemctl enable my-app
67
- ```
68
-
69
- ---
70
-
71
- To start the service without rebooting, you can manually _start_ it.
72
-
73
- ```bash
74
- $ sudo systemctl start my-app
75
- ```
76
-
77
- ---
78
-
79
- Check the status of your application with `systemctl status`. If you've started your app successfully, you should see something like this:
80
-
81
- ```bash
82
- $ sudo systemctl status my-app
83
- ● my-app.service - My App
84
- Loaded: loaded (/lib/systemd/system/my-app.service; enabled; preset: enabled)
85
- Active: active (running) since Thu 2023-10-12 11:34:08 UTC; 1h 8min ago
86
- Main PID: 309641 (bun)
87
- Tasks: 3 (limit: 503)
88
- Memory: 40.9M
89
- CPU: 1.093s
90
- CGroup: /system.slice/my-app.service
91
- └─309641 /home/YOUR_USER/.bun/bin/bun run /home/YOUR_USER/application/index.ts
92
- ```
93
-
94
- ---
95
-
96
- To update the service, edit the contents of the service file, then reload the daemon.
97
-
98
- ```bash
99
- $ sudo systemctl daemon-reload
100
- ```
101
-
102
- ---
103
-
104
- For a complete guide on the service unit configuration, you can check [this page](https://www.freedesktop.org/software/systemd/man/systemd.service.html). Or refer to this cheatsheet of common commands:
105
-
106
- ```bash
107
- $ sudo systemctl daemon-reload # tell systemd that some files got changed
108
- $ sudo systemctl enable my-app # enable the app (to allow auto-start)
109
- $ sudo systemctl disable my-app # disable the app (turns off auto-start)
110
- $ sudo systemctl start my-app # start the app if is stopped
111
- $ sudo systemctl stop my-app # stop the app
112
- $ sudo systemctl restart my-app # restart the app
113
- ```
@@ -1,71 +0,0 @@
1
- ---
2
- name: Build a frontend using Vite and Bun
3
- ---
4
-
5
- {% callout %}
6
- You can use Vite with Bun, but many projects get faster builds & drop hundreds of dependencies by switching to [HTML imports](/docs/bundler/html).
7
- {% /callout %}
8
-
9
- ---
10
-
11
- Vite works out of the box with Bun. Get started with one of Vite's templates.
12
-
13
- ```bash
14
- $ bun create vite my-app
15
- ✔ Select a framework: › React
16
- ✔ Select a variant: › TypeScript + SWC
17
- Scaffolding project in /path/to/my-app...
18
- ```
19
-
20
- ---
21
-
22
- Then `cd` into the project directory and install dependencies.
23
-
24
- ```bash
25
- cd my-app
26
- bun install
27
- ```
28
-
29
- ---
30
-
31
- Start the development server with the `vite` CLI using `bunx`.
32
-
33
- The `--bun` flag tells Bun to run Vite's CLI using `bun` instead of `node`; by default Bun respects Vite's `#!/usr/bin/env node` [shebang line](<https://en.wikipedia.org/wiki/Shebang_(Unix)>).
34
-
35
- ```bash
36
- bunx --bun vite
37
- ```
38
-
39
- ---
40
-
41
- To simplify this command, update the `"dev"` script in `package.json` to the following.
42
-
43
- ```json-diff#package.json
44
- "scripts": {
45
- - "dev": "vite",
46
- + "dev": "bunx --bun vite",
47
- "build": "vite build",
48
- "serve": "vite preview"
49
- },
50
- // ...
51
- ```
52
-
53
- ---
54
-
55
- Now you can start the development server with `bun run dev`.
56
-
57
- ```bash
58
- bun run dev
59
- ```
60
-
61
- ---
62
-
63
- The following command will build your app for production.
64
-
65
- ```sh
66
- $ bunx --bun vite build
67
- ```
68
-
69
- ---
70
-
71
- This is a stripped down guide to get you started with Vite + Bun. For more information, see the [Vite documentation](https://vitejs.dev/guide/).
@@ -1,68 +0,0 @@
1
- ---
2
- name: Extract links from a webpage using HTMLRewriter
3
- ---
4
-
5
- ## Extract links from a webpage
6
-
7
- Bun's [HTMLRewriter](https://bun.com/docs/api/html-rewriter) API can be used to efficiently extract links from HTML content. It works by chaining together CSS selectors to match the elements, text, and attributes you want to process. This is a simple example of how to extract links from a webpage. You can pass `.transform` a `Response`, `Blob`, or `string`.
8
-
9
- ```ts
10
- async function extractLinks(url: string) {
11
- const links = new Set<string>();
12
- const response = await fetch(url);
13
-
14
- const rewriter = new HTMLRewriter().on("a[href]", {
15
- element(el) {
16
- const href = el.getAttribute("href");
17
- if (href) {
18
- links.add(href);
19
- }
20
- },
21
- });
22
-
23
- // Wait for the response to be processed
24
- await rewriter.transform(response).blob();
25
- console.log([...links]); // ["https://bun.com", "/docs", ...]
26
- }
27
-
28
- // Extract all links from the Bun website
29
- await extractLinks("https://bun.com");
30
- ```
31
-
32
- ---
33
-
34
- ## Convert relative URLs to absolute
35
-
36
- When scraping websites, you often want to convert relative URLs (like `/docs`) to absolute URLs. Here's how to handle URL resolution:
37
-
38
- ```ts
39
- async function extractLinksFromURL(url: string) {
40
- const response = await fetch(url);
41
- const links = new Set<string>();
42
-
43
- const rewriter = new HTMLRewriter().on("a[href]", {
44
- element(el) {
45
- const href = el.getAttribute("href");
46
- if (href) {
47
- // Convert relative URLs to absolute
48
- try {
49
- const absoluteURL = new URL(href, url).href;
50
- links.add(absoluteURL);
51
- } catch {
52
- links.add(href);
53
- }
54
- }
55
- },
56
- });
57
-
58
- // Wait for the response to be processed
59
- await rewriter.transform(response).blob();
60
- return [...links];
61
- }
62
-
63
- const websiteLinks = await extractLinksFromURL("https://example.com");
64
- ```
65
-
66
- ---
67
-
68
- See [Docs > API > HTMLRewriter](https://bun.com/docs/api/html-rewriter) for complete documentation on HTML transformation with Bun.
@@ -1,93 +0,0 @@
1
- ---
2
- name: Extract social share images and Open Graph tags
3
- ---
4
-
5
- ## Extract social share images and Open Graph tags
6
-
7
- Bun's [HTMLRewriter](https://bun.com/docs/api/html-rewriter) API can be used to efficiently extract social share images and Open Graph metadata from HTML content. This is particularly useful for building link preview features, social media cards, or web scrapers. We can use HTMLRewriter to match CSS selectors to HTML elements, text, and attributes we want to process.
8
-
9
- ```ts
10
- interface SocialMetadata {
11
- title?: string;
12
- description?: string;
13
- image?: string;
14
- url?: string;
15
- siteName?: string;
16
- type?: string;
17
- }
18
-
19
- async function extractSocialMetadata(url: string): Promise<SocialMetadata> {
20
- const metadata: SocialMetadata = {};
21
- const response = await fetch(url);
22
-
23
- const rewriter = new HTMLRewriter()
24
- // Extract Open Graph meta tags
25
- .on('meta[property^="og:"]', {
26
- element(el) {
27
- const property = el.getAttribute("property");
28
- const content = el.getAttribute("content");
29
- if (property && content) {
30
- // Convert "og:image" to "image" etc.
31
- const key = property.replace("og:", "") as keyof SocialMetadata;
32
- metadata[key] = content;
33
- }
34
- },
35
- })
36
- // Extract Twitter Card meta tags as fallback
37
- .on('meta[name^="twitter:"]', {
38
- element(el) {
39
- const name = el.getAttribute("name");
40
- const content = el.getAttribute("content");
41
- if (name && content) {
42
- const key = name.replace("twitter:", "") as keyof SocialMetadata;
43
- // Only use Twitter Card data if we don't have OG data
44
- if (!metadata[key]) {
45
- metadata[key] = content;
46
- }
47
- }
48
- },
49
- })
50
- // Fallback to regular meta tags
51
- .on('meta[name="description"]', {
52
- element(el) {
53
- const content = el.getAttribute("content");
54
- if (content && !metadata.description) {
55
- metadata.description = content;
56
- }
57
- },
58
- })
59
- // Fallback to title tag
60
- .on("title", {
61
- text(text) {
62
- if (!metadata.title) {
63
- metadata.title = text.text;
64
- }
65
- },
66
- });
67
-
68
- // Process the response
69
- await rewriter.transform(response).blob();
70
-
71
- // Convert relative image URLs to absolute
72
- if (metadata.image && !metadata.image.startsWith("http")) {
73
- try {
74
- metadata.image = new URL(metadata.image, url).href;
75
- } catch {
76
- // Keep the original URL if parsing fails
77
- }
78
- }
79
-
80
- return metadata;
81
- }
82
-
83
- // Example usage
84
- const metadata = await extractSocialMetadata("https://bun.com");
85
- console.log(metadata);
86
- // {
87
- // title: "Bun — A fast all-in-one JavaScript runtime",
88
- // description: "Bundle, transpile, install and run JavaScript & TypeScript projects — all in Bun. Bun is a fast all-in-one JavaScript runtime & toolkit designed for speed, complete with a bundler, test runner, and Node.js-compatible package manager.",
89
- // image: "https://bun.com/share.jpg",
90
- // type: "website",
91
- // ...
92
- // }
93
- ```