aboutsummaryrefslogtreecommitdiff
path: root/docs/guides
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /docs/guides
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'docs/guides')
-rw-r--r--docs/guides/binary/blob-to-stream.md2
-rw-r--r--docs/guides/binary/blob-to-string.md2
-rw-r--r--docs/guides/ecosystem/astro.md18
-rw-r--r--docs/guides/ecosystem/discordjs.md2
-rw-r--r--docs/guides/ecosystem/docker.md140
-rw-r--r--docs/guides/ecosystem/elysia.md2
-rw-r--r--docs/guides/ecosystem/hono.md2
-rw-r--r--docs/guides/ecosystem/nextjs.md17
-rw-r--r--docs/guides/ecosystem/nuxt.md2
-rw-r--r--docs/guides/ecosystem/pm2.md54
-rw-r--r--docs/guides/ecosystem/prisma.md47
-rw-r--r--docs/guides/ecosystem/qwik.md107
-rw-r--r--docs/guides/ecosystem/react.md47
-rw-r--r--docs/guides/ecosystem/remix.md24
-rw-r--r--docs/guides/ecosystem/solidstart.md2
-rw-r--r--docs/guides/ecosystem/sveltekit.md4
-rw-r--r--docs/guides/ecosystem/systemd.md113
-rw-r--r--docs/guides/ecosystem/vite.md5
-rw-r--r--docs/guides/http/file-uploads.md2
-rw-r--r--docs/guides/install/azure-artifacts.md73
-rw-r--r--docs/guides/install/custom-registry.md2
-rw-r--r--docs/guides/install/jfrog-artifactory.md28
-rw-r--r--docs/guides/install/registry-scope.md8
-rw-r--r--docs/guides/install/trusted.md50
-rw-r--r--docs/guides/install/workspaces.md8
-rw-r--r--docs/guides/process/ipc.md66
-rw-r--r--docs/guides/read-file/exists.md2
-rw-r--r--docs/guides/read-file/stream.md2
-rw-r--r--docs/guides/runtime/read-env.md2
-rw-r--r--docs/guides/runtime/set-env.md2
-rw-r--r--docs/guides/runtime/tsconfig-paths.md4
-rw-r--r--docs/guides/runtime/typescript.md69
-rw-r--r--docs/guides/runtime/vscode-debugger.md6
-rw-r--r--docs/guides/test/happy-dom.md2
-rw-r--r--docs/guides/test/migrate-from-jest.md112
-rw-r--r--docs/guides/test/mock-functions.md2
-rw-r--r--docs/guides/test/spy-on.md2
-rw-r--r--docs/guides/util/entrypoint.md4
-rw-r--r--docs/guides/websocket/context.md2
-rw-r--r--docs/guides/websocket/simple.md2
40 files changed, 967 insertions, 73 deletions
diff --git a/docs/guides/binary/blob-to-stream.md b/docs/guides/binary/blob-to-stream.md
index 37a916ab3..ff2b3fbe0 100644
--- a/docs/guides/binary/blob-to-stream.md
+++ b/docs/guides/binary/blob-to-stream.md
@@ -2,7 +2,7 @@
name: Convert a Blob to a ReadableStream
---
-The [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) class provides a number of methods for consuming its contents in different formats, inluding `.stream()`. This returns `Promise<ReadableStream>`.
+The [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) class provides a number of methods for consuming its contents in different formats, including `.stream()`. This returns `Promise<ReadableStream>`.
```ts
const blob = new Blob(["hello world"]);
diff --git a/docs/guides/binary/blob-to-string.md b/docs/guides/binary/blob-to-string.md
index 05692c32e..0b334af66 100644
--- a/docs/guides/binary/blob-to-string.md
+++ b/docs/guides/binary/blob-to-string.md
@@ -2,7 +2,7 @@
name: Convert a Blob to a string
---
-The [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) class provides a number of methods for consuming its contents in different formats, inluding `.text()`.
+The [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) class provides a number of methods for consuming its contents in different formats, including `.text()`.
```ts
const blob = new Blob(["hello world"]);
diff --git a/docs/guides/ecosystem/astro.md b/docs/guides/ecosystem/astro.md
index 6a8a9fa5f..04be12012 100644
--- a/docs/guides/ecosystem/astro.md
+++ b/docs/guides/ecosystem/astro.md
@@ -2,15 +2,15 @@
name: Build an app with Astro and Bun
---
-Initialize a fresh Astro app with `bunx create-astro`. The `create-astro` package detects when you are using `bunx` and will automatically install dependencies using `bun`.
+Initialize a fresh Astro app with `bun create astro`. The `create-astro` package detects when you are using `bunx` and will automatically install dependencies using `bun`.
```sh
-$ bunx create-astro
+$ bun create astro
╭─────╮ Houston:
│ ◠ ◡ ◠ We're glad to have you on board.
╰─────╯
- astro v2.10.5 Launch sequence initiated.
+ astro v3.1.4 Launch sequence initiated.
dir Where should we create your new project?
./fumbling-field
@@ -55,21 +55,17 @@ By default, Bun will run the dev server with Node.js. To use the Bun runtime ins
```sh
$ bunx --bun astro dev
- 🚀 astro v2.10.5 started in 200ms
+ 🚀 astro v3.1.4 started in 200ms
- ┃ Local http://localhost:3000/
+ ┃ Local http://localhost:4321/
┃ Network use --host to expose
-
-01:48:34 PM [content] Watching src/content/ for changes
-01:48:34 PM [content] Types generated
-01:48:34 PM [astro] update /.astro/types.d.ts
```
---
-Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. Astro will hot-reload your app as you edit your source files.
+Open [http://localhost:4321](http://localhost:4321) with your browser to see the result. Astro will hot-reload your app as you edit your source files.
-{% image src="https://github.com/vitejs/vite/assets/3084745/bb1d5063-32f4-4598-b33e-50b44a1c4e8a" caption="An Astro starter app running on Bun" %}
+{% image src="https://i.imgur.com/Dswiu6w.png" caption="An Astro v3 starter app running on Bun" %}
---
diff --git a/docs/guides/ecosystem/discordjs.md b/docs/guides/ecosystem/discordjs.md
index 0a70f6f05..ec12a247d 100644
--- a/docs/guides/ecosystem/discordjs.md
+++ b/docs/guides/ecosystem/discordjs.md
@@ -74,4 +74,4 @@ Ready! Logged in as my-bot#1234
---
-You're up and running with a bare-bones Discord.js bot! This is a basic guide to setting up your bot with Bun; we recommend the [official Discord docs](https://discordjs.guide/) for complete information on the `discord.js` API.
+You're up and running with a bare-bones Discord.js bot! This is a basic guide to setting up your bot with Bun; we recommend the [official discord.js docs](https://discordjs.guide/) for complete information on the `discord.js` API.
diff --git a/docs/guides/ecosystem/docker.md b/docs/guides/ecosystem/docker.md
new file mode 100644
index 000000000..26a1eaccd
--- /dev/null
+++ b/docs/guides/ecosystem/docker.md
@@ -0,0 +1,140 @@
+---
+name: Containerize a Bun application with Docker
+---
+
+{% callout %}
+This guide assumes you already have [Docker Desktop](https://www.docker.com/products/docker-desktop/) installed.
+{% /callout %}
+
+[Docker](https://www.docker.com) is a platform for packaging and running an application as a lightweight, portable _container_ that encapsulates all the necessary dependencies.
+
+---
+
+To _containerize_ our application, we define a `Dockerfile`. This file contains a list of instructions to initialize the container, copy our local project files into it, install dependencies, and starts the application.
+
+```docker#Dockerfile
+# use the official Bun image
+# see all versions at https://hub.docker.com/r/oven/bun/tags
+FROM oven/bun:1 as base
+WORKDIR /usr/src/app
+
+# install dependencies into temp directory
+# this will cache them and speed up future builds
+FROM base AS install
+RUN mkdir -p /temp/dev
+COPY package.json bun.lockb /temp/dev/
+RUN cd /temp/dev && bun install --frozen-lockfile
+
+# install with --production (exclude devDependencies)
+RUN mkdir -p /temp/prod
+COPY package.json bun.lockb /temp/prod/
+RUN cd /temp/prod && bun install --frozen-lockfile --production
+
+# copy node_modules from temp directory
+# then copy all (non-ignored) project files into the image
+FROM install AS prerelease
+COPY --from=install /temp/dev/node_modules node_modules
+COPY . .
+
+# [optional] tests & build
+ENV NODE_ENV=production
+RUN bun test
+RUN bun run build
+
+# copy production dependencies and source code into final image
+FROM base AS release
+COPY --from=install /temp/prod/node_modules node_modules
+COPY --from=prerelease /usr/src/app/index.ts .
+COPY --from=prerelease /usr/src/app/package.json .
+
+# run the app
+USER bun
+EXPOSE 3000/tcp
+ENTRYPOINT [ "bun", "run", "index.ts" ]
+```
+
+---
+
+Now that you have your docker image, let's look at `.dockerignore` which has the same syntax as `.gitignore`, here you need to specify the files/directories that must not go in any stage of the docker build. An example for a ignore file is
+
+```txt#.dockerignore
+node_modules
+Dockerfile*
+docker-compose*
+.dockerignore
+.git
+.gitignore
+README.md
+LICENSE
+.vscode
+Makefile
+helm-charts
+.env
+.editorconfig
+.idea
+coverage*
+```
+
+---
+
+We'll now use `docker build` to convert this `Dockerfile` into a _Docker image_, is a self-contained template containing all the dependencies and configuration required to run the application.
+
+The `-t` flag lets us specify a name for the image, and `--pull` tells Docker to automatically download the latest version of the base image (`oven/bun`). The initial build will take longer, as Docker will download all the base images and dependencies.
+
+```bash
+$ docker build --pull -t bun-hello-world .
+[+] Building 0.9s (21/21) FINISHED
+ => [internal] load build definition from Dockerfile 0.0s
+ => => transferring dockerfile: 37B 0.0s
+ => [internal] load .dockerignore 0.0s
+ => => transferring context: 35B 0.0s
+ => [internal] load metadata for docker.io/oven/bun:1 0.8s
+ => [auth] oven/bun:pull token for registry-1.docker.io 0.0s
+ => [base 1/2] FROM docker.io/oven/bun:1@sha256:373265748d3cd3624cb3f3ee6004f45b1fc3edbd07a622aeeec17566d2756997 0.0s
+ => [internal] load build context 0.0s
+ => => transferring context: 155B 0.0s
+ # ...lots of commands...
+ => exporting to image 0.0s
+ => => exporting layers 0.0s
+ => => writing image sha256:360663f7fdcd6f11e8e94761d5592e2e4dfc8d167f034f15cd5a863d5dc093c4 0.0s
+ => => naming to docker.io/library/bun-hello-world 0.0s
+```
+
+---
+
+We've built a new _Docker image_. Now let's use that image to spin up an actual, running _container_.
+
+We'll use `docker run` to start a new container using the `bun-hello-world` image. It will be run in _detached_ mode (`-d`) and we'll map the container's port 3000 to our local machine's port 3000 (`-p 3000:3000`).
+
+The `run` command prints a string representing the _container ID_.
+
+```sh
+$ docker run -d -p 3000:3000 bun-hello-world
+7f03e212a15ede8644379bce11a13589f563d3909a9640446c5bbefce993678d
+```
+
+---
+
+The container is now running in the background. Visit [localhost:3000](http://localhost:3000). You should see a `Hello, World!` message.
+
+---
+
+To stop the container, we'll use `docker stop <container-id>`.
+
+```sh
+$ docker stop 7f03e212a15ede8644379bce11a13589f563d3909a9640446c5bbefce993678d
+```
+
+---
+
+If you can't find the container ID, you can use `docker ps` to list all running containers.
+
+```sh
+$ docker ps
+CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
+7f03e212a15e bun-hello-world "bun run index.ts" 2 minutes ago Up 2 minutes 0.0.0.0:3000->3000/tcp flamboyant_cerf
+```
+
+---
+
+That's it! Refer to the [Docker documentation](https://docs.docker.com/) for more advanced usage.
diff --git a/docs/guides/ecosystem/elysia.md b/docs/guides/ecosystem/elysia.md
index ae1a8e37b..019686a63 100644
--- a/docs/guides/ecosystem/elysia.md
+++ b/docs/guides/ecosystem/elysia.md
@@ -21,7 +21,7 @@ const app = new Elysia()
.get('/', () => 'Hello Elysia')
.listen(8080)
-console.log(`🦊 Elysia is running at on port ${app.server.port}...`)
+console.log(`🦊 Elysia is running at on port ${app.server?.port}...`)
```
---
diff --git a/docs/guides/ecosystem/hono.md b/docs/guides/ecosystem/hono.md
index 6d928a655..df662973d 100644
--- a/docs/guides/ecosystem/hono.md
+++ b/docs/guides/ecosystem/hono.md
@@ -18,7 +18,7 @@ export default app;
Use `create-hono` to get started with one of Hono's project templates. Select `bun` when prompted for a template.
```bash
-$ bunx create-hono myapp
+$ bun create hono myapp
✔ Which template do you want to use? › bun
cloned honojs/starter#main to /path/to/myapp
✔ Copied project files
diff --git a/docs/guides/ecosystem/nextjs.md b/docs/guides/ecosystem/nextjs.md
index a455eb23e..d8bf337c2 100644
--- a/docs/guides/ecosystem/nextjs.md
+++ b/docs/guides/ecosystem/nextjs.md
@@ -3,7 +3,7 @@ name: Build an app with Next.js and Bun
---
{% callout %}
-Next.js 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.
+The Next.js [App Router](https://nextjs.org/docs/app) 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.
{% /callout %}
---
@@ -11,7 +11,7 @@ Next.js currently relies on Node.js APIs that Bun does not yet implement. The gu
Initialize a Next.js app with `create-next-app`. This automatically installs dependencies using `npm`.
```sh
-$ bunx create-next-app
+$ bun create next-app
✔ What is your project named? … my-app
✔ Would you like to use TypeScript with this project? … No / Yes
✔ Would you like to use ESLint with this project? … No / Yes
@@ -23,7 +23,16 @@ Creating a new Next.js app in /path/to/my-app.
---
-To start the dev server, run `bun run dev` from the project root.
+To start the dev server with Bun, run `bun --bun run dev` from the project root.
+
+```sh
+$ cd my-app
+$ bun --bun run dev
+```
+
+---
+
+To run the dev server with Node.js instead, omit `--bun`.
```sh
$ cd my-app
@@ -32,4 +41,4 @@ $ bun run dev
---
-Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. Any changes you make to `pages/index.tsx` will be hot-reloaded in the browser.
+Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. Any changes you make to `(pages/app)/index.tsx` will be hot-reloaded in the browser.
diff --git a/docs/guides/ecosystem/nuxt.md b/docs/guides/ecosystem/nuxt.md
index c86029dc2..ca42c765b 100644
--- a/docs/guides/ecosystem/nuxt.md
+++ b/docs/guides/ecosystem/nuxt.md
@@ -22,7 +22,7 @@ bun install v1.x (16b4bf34)
---
-To start the dev server, run `bun run dev` from the project root. This will execute the `nuxt dev` command (as defined in the `"dev"` script in `package.json`).
+To start the dev server, run `bun --bun run dev` from the project root. This will execute the `nuxt dev` command (as defined in the `"dev"` script in `package.json`).
{% callout %}
The `nuxt` CLI uses Node.js by default; passing the `--bun` flag forces the dev server to use the Bun runtime instead.
diff --git a/docs/guides/ecosystem/pm2.md b/docs/guides/ecosystem/pm2.md
new file mode 100644
index 000000000..c775c8ca3
--- /dev/null
+++ b/docs/guides/ecosystem/pm2.md
@@ -0,0 +1,54 @@
+---
+name: Run Bun as a daemon with PM2
+---
+
+[PM2](https://pm2.keymetrics.io/) is a popular process manager that manages and runs your applications as daemons (background processes).
+
+It offers features like process monitoring, automatic restarts, and easy scaling. Using a process manager is common when deploying a Bun application on a cloud-hosted virtual private server (VPS), as it:
+
+- Keeps your Node.js application running continuously.
+- Ensure high availability and reliability of your application.
+- Monitor and manage multiple processes with ease.
+- Simplify the deployment process.
+
+---
+
+You can use PM2 with Bun in two ways: as a CLI option or in a configuration file.
+
+### With `--interpreter`
+
+---
+
+To start your application with PM2 and Bun as the interpreter, open your terminal and run the following command:
+
+```bash
+pm2 start --interpreter ~/.bun/bin/bun index.ts
+```
+
+---
+
+### With a configuration file
+
+---
+
+Alternatively, you can create a PM2 configuration file. Create a file named `pm2.config.js` in your project directory and add the following content.
+
+```javascript
+module.exports = {
+ name: "app", // Name of your application
+ script: "index.ts", // Entry point of your application
+ interpreter: "~/.bun/bin/bun", // Path to the Bun interpreter
+};
+```
+
+---
+
+After saving the file, you can start your application with PM2
+
+```bash
+pm2 start pm2.config.js
+```
+
+---
+
+That’s it! Your JavaScript/TypeScript web server is now running as a daemon with PM2 using Bun as the interpreter.
diff --git a/docs/guides/ecosystem/prisma.md b/docs/guides/ecosystem/prisma.md
index e697e2133..af83a47e4 100644
--- a/docs/guides/ecosystem/prisma.md
+++ b/docs/guides/ecosystem/prisma.md
@@ -2,20 +2,26 @@
name: Get started using Prisma
---
+{% callout %}
+**Note** — At the moment Prisma needs Node.js to be installed to run certain generation code. Make sure Node.js is installed in the environment where you're running `bunx prisma` commands.
+{% /callout %}
+
+---
+
Prisma works out of the box with Bun. First, create a directory and initialize it with `bun init`.
```bash
-mkdir prisma-app
-cd prisma-app
-bun init
+$ mkdir prisma-app
+$ cd prisma-app
+$ bun init
```
---
-Then add Prisma as a dependency.
+Then install the Prisma CLI (`prisma`) and Prisma Client (`@prisma/client`) as dependencies.
```bash
-bun add prisma
+$ bun add prisma @prisma/client
```
---
@@ -23,7 +29,7 @@ bun add prisma
We'll use the Prisma CLI with `bunx` to initialize our schema and migration directory. For simplicity we'll be using an in-memory SQLite database.
```bash
-bunx prisma init --datasource-provider sqlite
+$ bunx prisma init --datasource-provider sqlite
```
---
@@ -54,14 +60,37 @@ Then generate and run initial migration.
This will generate a `.sql` migration file in `prisma/migrations`, create a new SQLite instance, and execute the migration against the new instance.
```bash
-bunx prisma migrate dev --name init
+$ bunx prisma migrate dev --name init
+Environment variables loaded from .env
+Prisma schema loaded from prisma/schema.prisma
+Datasource "db": SQLite database "dev.db" at "file:./dev.db"
+
+SQLite database dev.db created at file:./dev.db
+
+Applying migration `20230928182242_init`
+
+The following migration(s) have been created and applied from new schema changes:
+
+migrations/
+ └─ 20230928182242_init/
+ └─ migration.sql
+
+Your database is now in sync with your schema.
+
+✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 41ms
```
---
-Prisma automatically generates our _Prisma client_ whenever we execute a new migration. The client provides a fully typed API for reading and writing from our database.
+As indicated in the output, Prisma re-generates our _Prisma client_ whenever we execute a new migration. The client provides a fully typed API for reading and writing from our database. You can manually re-generate the client with the Prisma CLI.
+
+```sh
+$ bunx prisma generate
+```
+
+---
-It can be imported from `@prisma/client`.
+We can import the generated client from `@prisma/client`.
```ts#src/index.ts
import {PrismaClient} from "@prisma/client";
diff --git a/docs/guides/ecosystem/qwik.md b/docs/guides/ecosystem/qwik.md
new file mode 100644
index 000000000..45d3f9c1a
--- /dev/null
+++ b/docs/guides/ecosystem/qwik.md
@@ -0,0 +1,107 @@
+---
+name: Build an app with Qwik and Bun
+---
+
+Initialize a new Qwik app with `bunx create-qwik`.
+
+The `create-qwik` package detects when you are using `bunx` and will automatically install dependencies using `bun`.
+
+```sh
+$ bun create qwik
+
+ ............
+ .::: :--------:.
+ .:::: .:-------:.
+ .:::::. .:-------.
+ ::::::. .:------.
+ ::::::. :-----:
+ ::::::. .:-----.
+ :::::::. .-----.
+ ::::::::.. ---:.
+ .:::::::::. :-:.
+ ..::::::::::::
+ ...::::
+
+
+┌ Let's create a Qwik App ✨ (v1.2.10)
+│
+◇ Where would you like to create your new project? (Use '.' or './' for current directory)
+│ ./my-app
+│
+● Creating new project in /path/to/my-app ... 🐇
+│
+◇ Select a starter
+│ Basic App
+│
+◇ Would you like to install bun dependencies?
+│ Yes
+│
+◇ Initialize a new git repository?
+│ No
+│
+◇ Finishing the install. Wanna hear a joke?
+│ Yes
+│
+○ ────────────────────────────────────────────────────────╮
+│ │
+│ How do you know if there’s an elephant under your bed? │
+│ Your head hits the ceiling! │
+│ │
+├──────────────────────────────────────────────────────────╯
+│
+◇ App Created 🐰
+│
+◇ Installed bun dependencies 📋
+│
+○ Result ─────────────────────────────────────────────╮
+│ │
+│ Success! Project created in my-app directory │
+│ │
+│ Integrations? Add Netlify, Cloudflare, Tailwind... │
+│ bun qwik add │
+│ │
+│ Relevant docs: │
+│ https://qwik.builder.io/docs/getting-started/ │
+│ │
+│ Questions? Start the conversation at: │
+│ https://qwik.builder.io/chat │
+│ https://twitter.com/QwikDev │
+│ │
+│ Presentations, Podcasts and Videos: │
+│ https://qwik.builder.io/media/ │
+│ │
+│ Next steps: │
+│ cd my-app │
+│ bun start │
+│ │
+│ │
+├──────────────────────────────────────────────────────╯
+│
+└ Happy coding! 🎉
+
+```
+
+---
+
+Run `bun run dev` to start the development server.
+
+```sh
+$ bun run dev
+ $ vite--mode ssr
+
+ VITE v4.4.7 ready in 1190 ms
+
+ ➜ Local: http://localhost:5173/
+ ➜ Network: use --host to expose
+ ➜ press h to show help
+```
+
+---
+
+Open [http://localhost:5173](http://localhost:5173) with your browser to see the result. Qwik will hot-reload your app as you edit your source files.
+
+{% image src="https://github.com/oven-sh/bun/assets/3084745/ec35f2f7-03dd-4c90-851e-fb4ad150bb28" alt="Qwik screenshot" /%}
+
+---
+
+Refer to the [Qwik docs](https://qwik.builder.io/docs/getting-started/) for complete documentation.
diff --git a/docs/guides/ecosystem/react.md b/docs/guides/ecosystem/react.md
index b712e210e..f3c16c153 100644
--- a/docs/guides/ecosystem/react.md
+++ b/docs/guides/ecosystem/react.md
@@ -2,29 +2,48 @@
name: Use React and JSX
---
-React just works with Bun. Bun supports `.jsx` and `.tsx` files out of the box. Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
-
-```tsx#react.tsx
-function Component(props: {message: string}) {
- return (
- <body>
- <h1 style={{color: 'red'}}>{props.message}</h1>
- </body>
- );
-}
-
-console.log(<Component message="Hello world!" />);
+React just works with Bun. Bun supports `.jsx` and `.tsx` files out of the box.
+
+Remember that JSX is just a special syntax for including HTML-like syntax in JavaScript files. It's commonReact uses JSX syntax, as do other React alternatives like [Preact](https://preactjs.com/) and [Solid](https://www.solidjs.com/). Bun's internal transpiler converts JSX syntax into vanilla JavaScript before execution.
+
+---
+
+Bun _assumes_ you're using React (unless you [configure it otherwise](/docs/runtime/bunfig#jsx)) so a line like this:
+
+```
+const element = <h1>Hello, world!</h1>;
```
---
-Bun implements special logging for JSX to make debugging easier.
+is internally converted into something like this:
+
+```ts
+// jsxDEV
+import { jsx } from "react/jsx-dev-runtime";
+
+const element = jsx("h1", { children: "Hello, world!" });
+```
+
+---
+
+This code requires `react` to run, so make sure you you've installed React.
```bash
-$ bun run react.tsx
+$ bun install react
+```
+
+---
+
+Bun implements special logging for JSX components to make debugging easier.
+
+```bash
+$ bun run log-my-component.tsx
<Component message="Hello world!" />
```
---
+As far as "official support" for React goes, that's it. React is a library like any other, and Bun can run that library. Bun is not a framework, so you should use a framework like [Vite](https://vitejs.dev/) to build an app with server-side rendering and hot reloading in the browser.
+
Refer to [Runtime > JSX](/docs/runtime/jsx) for complete documentation on configuring JSX.
diff --git a/docs/guides/ecosystem/remix.md b/docs/guides/ecosystem/remix.md
index ee6185294..5adf648ec 100644
--- a/docs/guides/ecosystem/remix.md
+++ b/docs/guides/ecosystem/remix.md
@@ -3,7 +3,7 @@ name: Build an app with Remix and Bun
---
{% callout %}
-Remix 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.
+Currently the Remix development server (`remix dev`) 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.
{% /callout %}
---
@@ -11,14 +11,14 @@ Remix currently relies on Node.js APIs that Bun does not yet implement. The guid
Initialize a Remix app with `create-remix`.
```sh
-$ bunx create-remix
+$ bun create remix
remix v1.19.3 💿 Let's build a better website...
dir Where should we create your new project?
./my-app
- ◼ Using basic template See https://remix.run/docs/pages/templates for more
+ ◼ Using basic template See https://remix.run/docs/en/main/guides/templates#templates for more
✔ Template copied
git Initialize a new git repository?
@@ -58,3 +58,21 @@ $ bun run dev
Open [http://localhost:3000](http://localhost:3000) to see the app. Any changes you make to `app/routes/_index.tsx` will be hot-reloaded in the browser.
{% image src="https://github.com/oven-sh/bun/assets/3084745/c26f1059-a5d4-4c0b-9a88-d9902472fd77" caption="Remix app running on localhost" /%}
+
+---
+
+To build and start your app, run `bun run build` then `bun run start` from the project root.
+
+```sh
+$ bun run build
+ $ remix build
+ info building... (NODE_ENV=production)
+ info built (158ms)
+$ bun start
+ $ remix-serve ./build/index.js
+ [remix-serve] http://localhost:3000 (http://192.168.86.237:3000)
+```
+
+---
+
+Read the [Remix docs](https://remix.run/) for more information on how to build apps with Remix.
diff --git a/docs/guides/ecosystem/solidstart.md b/docs/guides/ecosystem/solidstart.md
index ca2ef471e..fb8d54d91 100644
--- a/docs/guides/ecosystem/solidstart.md
+++ b/docs/guides/ecosystem/solidstart.md
@@ -11,7 +11,7 @@ SolidStart currently relies on Node.js APIs that Bun does not yet implement. The
Initialize a SolidStart app with `create-solid`.
```sh
-$ bunx create-solid my-app
+$ bun create solid my-app
create-solid version 0.2.31
Welcome to the SolidStart setup wizard!
diff --git a/docs/guides/ecosystem/sveltekit.md b/docs/guides/ecosystem/sveltekit.md
index 172b77299..6386673bc 100644
--- a/docs/guides/ecosystem/sveltekit.md
+++ b/docs/guides/ecosystem/sveltekit.md
@@ -2,10 +2,10 @@
name: Build an app with SvelteKit and Bun
---
-Use `bunx` to scaffold your app with the `create-svelte` CLI. Answer the prompts to select a template and set up your development environment.
+Use `bun create` to scaffold your app with the `svelte` package. Answer the prompts to select a template and set up your development environment.
```sh
-$ bunx create-svelte my-app
+$ bun create svelte@latest my-app
┌ Welcome to SvelteKit!
◇ Which Svelte app template?
diff --git a/docs/guides/ecosystem/systemd.md b/docs/guides/ecosystem/systemd.md
new file mode 100644
index 000000000..c22fc9ae2
--- /dev/null
+++ b/docs/guides/ecosystem/systemd.md
@@ -0,0 +1,113 @@
+---
+name: Run Bun as a daemon with systemd
+---
+
+[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.
+
+<!-- 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. -->
+
+<!-- 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. -->
+
+---
+
+To run a Bun application as a daemon using **systemd** you'll need to create a _service file_ in `/lib/systemd/system/`.
+
+```sh
+$ cd /lib/systemd/system
+$ touch my-app.service
+```
+
+---
+
+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.
+
+Refer to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd.service.html) for more information on each setting.
+
+```ini#my-app.service
+[Unit]
+# describe the app
+Description=My App
+# start the app after the network is available
+After=network.target
+
+[Service]
+# usually you'll use 'simple'
+# one of https://www.freedesktop.org/software/systemd/man/systemd.service.html#Type=
+Type=simple
+# which user to use when starting the app
+User=YOUR_USER
+# path to your application's root directory
+WorkingDirectory=/home/YOUR_USER/path/to/my-app
+# the command to start the app
+# requires absolute paths
+ExecStart=/home/YOUR_USER/.bun/bin/bun run index.ts
+# restart policy
+# one of {no|on-success|on-failure|on-abnormal|on-watchdog|on-abort|always}
+Restart=always
+
+[Install]
+# start the app automatically
+WantedBy=multi-user.target
+```
+
+---
+
+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`.
+
+```bash
+$ sudo setcap CAP_NET_BIND_SERVICE=+eip ~/.bun/bin/bun
+```
+
+---
+
+With the service file configured, you can now _enable_ the service. Once enabled, it will start automatically on reboot. This requires `sudo` permissions.
+
+```bash
+$ sudo systemctl enable my-app
+```
+
+---
+
+To start the service without rebooting, you can manually _start_ it.
+
+```bash
+$ sudo systemctl start my-app
+```
+
+---
+
+Check the status of your application with `systemctl status`. If you've started your app successfully, you should see something like this:
+
+```bash
+$ sudo systemctl status my-app
+● my-app.service - My App
+ Loaded: loaded (/lib/systemd/system/my-app.service; enabled; preset: enabled)
+ Active: active (running) since Thu 2023-10-12 11:34:08 UTC; 1h 8min ago
+ Main PID: 309641 (bun)
+ Tasks: 3 (limit: 503)
+ Memory: 40.9M
+ CPU: 1.093s
+ CGroup: /system.slice/my-app.service
+ └─309641 /home/YOUR_USER/.bun/bin/bun run /home/YOUR_USER/application/index.ts
+```
+
+---
+
+To update the service, edit the contents of the service file, then reload the daemon.
+
+```bash
+$ sudo systemctl daemon-reload
+```
+
+---
+
+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:
+
+```bash
+$ sudo systemctl daemon-reload # tell systemd that some files got changed
+$ sudo systemctl enable my-app # enable the app (to allow auto-start)
+$ sudo systemctl disable my-app # disable the app (turns off auto-start)
+$ sudo systemctl start my-app # start the app if is stopped
+$ sudo systemctl stop my-app # stop the app
+$ sudo systemctl restart my-app # restart the app
+```
diff --git a/docs/guides/ecosystem/vite.md b/docs/guides/ecosystem/vite.md
index 3cad145f9..cf77e7249 100644
--- a/docs/guides/ecosystem/vite.md
+++ b/docs/guides/ecosystem/vite.md
@@ -11,7 +11,7 @@ While Vite currently works with Bun, it has not been heavily optimized, nor has
Vite works out of the box with Bun. Get started with one of Vite's templates.
```bash
-$ bunx create-vite my-app
+$ bun create vite my-app
✔ Select a framework: › React
✔ Select a variant: › TypeScript + SWC
Scaffolding project in /path/to/my-app...
@@ -30,8 +30,7 @@ bun install
Start the development server with the `vite` CLI using `bunx`.
-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)>). After Bun 1.0 this flag will no longer be necessary.
-
+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)>).
```bash
bunx --bun vite
```
diff --git a/docs/guides/http/file-uploads.md b/docs/guides/http/file-uploads.md
index 7cc0e742a..ce23b5d0c 100644
--- a/docs/guides/http/file-uploads.md
+++ b/docs/guides/http/file-uploads.md
@@ -59,7 +59,7 @@ Listening on http://localhost:4000
Our form will send a `POST` request to the `/action` endpoint with the form data. Let's handle that request in our server.
-First we use the [`.formData()`](https://developer.mozilla.org/en-US/docs/Web/API/Request/formData) method on the incoming `Request` to asynchonously parse its contents to a `FormData` instance. Then we can use the [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/get) method to extract the value of the `name` and `profilePicture` fields. Here `name` corresponds to a `string` and `profilePicture` is a `Blob`.
+First we use the [`.formData()`](https://developer.mozilla.org/en-US/docs/Web/API/Request/formData) method on the incoming `Request` to asynchronously parse its contents to a `FormData` instance. Then we can use the [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/get) method to extract the value of the `name` and `profilePicture` fields. Here `name` corresponds to a `string` and `profilePicture` is a `Blob`.
Finally, we write the `Blob` to disk using [`Bun.write()`](/docs/api/file-io#writing-files-bun-write).
diff --git a/docs/guides/install/azure-artifacts.md b/docs/guides/install/azure-artifacts.md
new file mode 100644
index 000000000..659e75fd6
--- /dev/null
+++ b/docs/guides/install/azure-artifacts.md
@@ -0,0 +1,73 @@
+---
+name: Using bun install with an Azure Artifacts npm registry
+---
+
+{% callout %}
+In [Azure Artifact's](https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops&tabs=windows%2Cclassic) instructions for `.npmrc`, they say to base64 encode the password. Do not do this for `bun install`. Bun will automatically base64 encode the password for you if needed.
+{% /callout %}
+
+[Azure Artifacts](https://azure.microsoft.com/en-us/products/devops/artifacts) is a package management system for Azure DevOps. It allows you to host your own private npm registry, npm packages, and other types of packages as well.
+
+---
+
+### Configure with bunfig.toml
+
+---
+
+To use it with `bun install`, add a `bunfig.toml` file to your project with the following contents. Make sure to replace `my-azure-artifacts-user` with your Azure Artifacts username, such as `jarred1234`.
+
+```toml#bunfig.toml
+[install.registry]
+url = "https://pkgs.dev.azure.com/my-azure-artifacts-user/_packaging/my-azure-artifacts-user/npm/registry"
+username = "my-azure-artifacts-user"
+# Bun v1.0.3+ supports using an environment variable here
+password = "$NPM_PASSWORD"
+```
+
+---
+
+Then assign your Azure Personal Access Token to the the `NPM_PASSWORD` environment variable. Bun [automatically reads](/docs/runtime/env) `.env` files, so create a file called `.env` in your project root. There is no need to base-64 encode this token! Bun will do this for you.
+
+```txt#.env
+NPM_PASSWORD=<paste token here>
+```
+
+---
+
+### Configure with environment variables
+
+---
+
+To configure Azure Artifacts without `bunfig.toml`, you can set the `NPM_CONFIG_REGISTRY` environment variable. The URL should include `:username` and `:_password` as query parameters. Replace `<USERNAME>` and `<PASSWORD>` with the apprropriate values.
+
+```bash#shell
+NPM_CONFIG_REGISTRY=https://pkgs.dev.azure.com/my-azure-artifacts-user/_packaging/my-azure-artifacts-user/npm/registry/:username=<USERNAME>:_password=<PASSWORD>
+```
+
+---
+
+### Don't base64 encode the password
+
+---
+
+In [Azure Artifact's](https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops&tabs=windows%2Cclassic) instructions for `.npmrc`, they say to base64 encode the password. Do not do this for `bun install`. Bun will automatically base64 encode the password for you if needed.
+
+{% callout %}
+**Tip** — If it ends with `==`, it probably is base64 encoded.
+{% /callout %}
+
+---
+
+To decode a base64-encoded password, open your browser console and run:
+
+```js
+atob("<base64-encoded password>");
+```
+
+---
+
+Alternatively, use the `base64` command line tool, but doing so means it may be saved in your terminal history which is not recommended:
+
+```bash
+echo "base64-encoded-password" | base64 --decode
+```
diff --git a/docs/guides/install/custom-registry.md b/docs/guides/install/custom-registry.md
index 64b3cf76b..12bb3b77f 100644
--- a/docs/guides/install/custom-registry.md
+++ b/docs/guides/install/custom-registry.md
@@ -18,7 +18,7 @@ registry = "https://username:password@registry.npmjs.org"
---
-Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/docs/cli/run#environment-variables) for more information.
+Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/docs/runtime/env) for more information.
```toml#bunfig.toml
[install]
diff --git a/docs/guides/install/jfrog-artifactory.md b/docs/guides/install/jfrog-artifactory.md
new file mode 100644
index 000000000..e4872982b
--- /dev/null
+++ b/docs/guides/install/jfrog-artifactory.md
@@ -0,0 +1,28 @@
+---
+name: Using bun install with Artifactory
+---
+
+[JFrog Artifactory](https://jfrog.com/artifactory/) is a package management system for npm, Docker, Maven, NuGet, Ruby, Helm, and more. It allows you to host your own private npm registry, npm packages, and other types of packages as well.
+
+To use it with `bun install`, add a `bunfig.toml` file to your project with the following contents:
+
+---
+
+### Configure with bunfig.toml
+
+Make sure to replace `MY_SUBDOMAIN` with your JFrog Artifactory subdomain, such as `jarred1234` and MY_TOKEN with your JFrog Artifactory token.
+
+```toml#bunfig.toml
+[install.registry]
+url = "https://MY_SUBDOMAIN.jfrog.io/artifactory/api/npm/npm/_auth=MY_TOKEN"
+# Bun v1.0.3+ supports using an environment variable here
+# url = "$NPM_CONFIG_REGISTRY"
+```
+
+---
+
+### Configure with `$NPM_CONFIG_REGISTRY`
+
+Like with npm, you can use the `NPM_CONFIG_REGISTRY` environment variable to configure JFrog Artifactory with bun install.
+
+---
diff --git a/docs/guides/install/registry-scope.md b/docs/guides/install/registry-scope.md
index 48f7dee79..aade23116 100644
--- a/docs/guides/install/registry-scope.md
+++ b/docs/guides/install/registry-scope.md
@@ -11,7 +11,11 @@ Bun does not read `.npmrc` files; instead private registries are configured via
# as an object with username/password
# you can reference environment variables
-"@myorg2" = { username = "myusername", password = "$npm_pass", url = "https://registry.myorg.com/" }
+"@myorg2" = {
+ username = "myusername",
+ password = "$npm_pass",
+ url = "https://registry.myorg.com/"
+}
# as an object with token
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }
@@ -20,7 +24,7 @@ Bun does not read `.npmrc` files; instead private registries are configured via
---
-Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/docs/cli/run#environment-variables) for more information.
+Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/docs/runtime/env) for more information.
```toml#bunfig.toml
[install.scopes]
diff --git a/docs/guides/install/trusted.md b/docs/guides/install/trusted.md
new file mode 100644
index 000000000..0c1ac6362
--- /dev/null
+++ b/docs/guides/install/trusted.md
@@ -0,0 +1,50 @@
+---
+name: Add a trusted dependency
+---
+
+Unlike other npm clients, Bun does not execute arbitrary lifecycle scripts for installed dependencies, such as `postinstall` and `node-gyp` builds. These scripts represent a potential security risk, as they can execute arbitrary code on your machine.
+
+{% callout %}
+Soon, Bun will include a built-in allow-list that automatically allows lifecycle scripts to be run by popular packages that are known to be safe. This is still under development.
+{% /callout %}
+
+---
+
+If you are seeing one of the following errors, you are probably trying to use a package that uses `postinstall` to work properly:
+
+- `error: could not determine executable to run for package`
+- `InvalidExe`
+
+---
+
+To tell Bun to allow lifecycle scripts for a particular package, add the package to `trustedDependencies` in your package.json.
+
+Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!
+
+<!-- Bun maintains an allow-list of popular packages containing `postinstall` scripts that are known to be safe. To run lifecycle scripts for packages that aren't on this list, add the package to `trustedDependencies` in your package.json. -->
+
+```json-diff
+ {
+ "name": "my-app",
+ "version": "1.0.0",
++ "trustedDependencies": ["my-trusted-package"]
+ }
+```
+
+---
+
+Once this is added, run a fresh install. Bun will re-install your dependencies and properly install
+
+```sh
+$ rm -rf node_modules
+$ rm bun.lockb
+$ bun install
+```
+
+---
+
+Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!
+
+---
+
+See [Docs > Package manager > Trusted dependencies](/docs/install/lifecycle) for complete documentation of trusted dependencies.
diff --git a/docs/guides/install/workspaces.md b/docs/guides/install/workspaces.md
index f87c1e337..b271a33b0 100644
--- a/docs/guides/install/workspaces.md
+++ b/docs/guides/install/workspaces.md
@@ -4,6 +4,8 @@ name: Configuring a monorepo using workspaces
Bun's package manager supports npm `"workspaces"`. This allows you to split a codebase into multiple distinct "packages" that live in the same repository, can depend on each other, and (when possible) share a `node_modules` directory.
+Clone [this sample project](https://github.com/colinhacks/bun-workspaces) to experiment with workspaces.
+
---
The root `package.json` should not contain any `"dependencies"`, `"devDependencies"`, etc. Each individual package should be self-contained and declare its own dependencies. Similarly, it's conventional to declare `"private": true` to avoid accidentally publishing the root package to `npm`.
@@ -35,13 +37,13 @@ It's common to place all packages in a `packages` directory. The `"workspaces"`
---
-To add one workspace as a dependency of another, modify its `package.json`. Here we're adding `stuff-a` as a dependency of `stuff-b`.
+To add dependencies between workspaces, use the `"workspace:*"` syntax. Here we're adding `stuff-a` as a dependency of `stuff-b`.
-```json#packages/stuff-b/package.json
+```json-diff#packages/stuff-b/package.json
{
"name": "stuff-b",
"dependencies": {
-+ "stuff-a": "*"
++ "stuff-a": "workspace:*"
}
}
```
diff --git a/docs/guides/process/ipc.md b/docs/guides/process/ipc.md
new file mode 100644
index 000000000..af029a524
--- /dev/null
+++ b/docs/guides/process/ipc.md
@@ -0,0 +1,66 @@
+---
+name: Spawn a child process and communicate using IPC
+---
+
+Use [`Bun.spawn()`](/docs/api/spawn) to spawn a child process. When spawning a second `bun` process, you can open a direct inter-process communication (IPC) channel between the two processes.
+
+{%callout%}
+**Note** — This API is only compatible with other `bun` processes. Use `process.execPath` to get a path to the currently running `bun` executable.
+{%/callout%}
+
+```ts#parent.ts
+const child = Bun.spawn(["bun", "child.ts"], {
+ ipc(message) {
+ /**
+ * The message received from the sub process
+ **/
+ },
+});
+```
+
+---
+
+The parent process can send messages to the subprocess using the `.send()` method on the returned `Subprocess` instance. A reference to the sending subprocess is also available as the second argument in the `ipc` handler.
+
+```ts#parent.ts
+const childProc = Bun.spawn(["bun", "child.ts"], {
+ ipc(message, childProc) {
+ /**
+ * The message received from the sub process
+ **/
+ childProc.send("Respond to child")
+ },
+});
+
+childProc.send("I am your father"); // The parent can send messages to the child as well
+```
+
+---
+
+Meanwhile the child process can send messages to its parent using with `process.send()` and receive messages with `process.on("message")`. This is the same API used for `child_process.fork()` in Node.js.
+
+```ts#child.ts
+process.send("Hello from child as string");
+process.send({ message: "Hello from child as object" });
+
+process.on("message", (message) => {
+ // print message from parent
+ console.log(message);
+});
+```
+
+---
+
+All messages are serialized using the JSC `serialize` API, which allows for the same set of [transferrable types](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects) supported by `postMessage` and `structuredClone`, including strings, typed arrays, streams, and objects.
+
+```ts#child.ts
+// send a string
+process.send("Hello from child as string");
+
+// send an object
+process.send({ message: "Hello from child as object" });
+```
+
+---
+
+See [Docs > API > Child processes](/docs/api/spawn) for complete documentation.
diff --git a/docs/guides/read-file/exists.md b/docs/guides/read-file/exists.md
index fd6cbbf9a..0359f5728 100644
--- a/docs/guides/read-file/exists.md
+++ b/docs/guides/read-file/exists.md
@@ -8,7 +8,7 @@ The `Bun.file()` function accepts a path and returns a `BunFile` instance. Use t
const path = "/path/to/package.json";
const file = Bun.file(path);
-file.exists(); // boolean;
+await file.exists(); // boolean;
```
---
diff --git a/docs/guides/read-file/stream.md b/docs/guides/read-file/stream.md
index ac4bd9e2f..bc54af2ce 100644
--- a/docs/guides/read-file/stream.md
+++ b/docs/guides/read-file/stream.md
@@ -8,7 +8,7 @@ The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `
const path = "/path/to/package.json";
const file = Bun.file(path);
-const stream = await file.stream();
+const stream = file.stream();
```
---
diff --git a/docs/guides/runtime/read-env.md b/docs/guides/runtime/read-env.md
index 512f731dd..7295a6726 100644
--- a/docs/guides/runtime/read-env.md
+++ b/docs/guides/runtime/read-env.md
@@ -29,4 +29,4 @@ FOOBAR=aaaaaa
---
-See [Docs > Runtime > Environment variables](/docs/cli/run#environment-variables) for more information on using environment variables with Bun.
+See [Docs > Runtime > Environment variables](/docs/runtime/env) for more information on using environment variables with Bun.
diff --git a/docs/guides/runtime/set-env.md b/docs/guides/runtime/set-env.md
index 97cac3488..684da940a 100644
--- a/docs/guides/runtime/set-env.md
+++ b/docs/guides/runtime/set-env.md
@@ -34,4 +34,4 @@ $ FOO=helloworld bun run dev
---
-See [Docs > Runtime > Environment variables](/docs/cli/run#environment-variables) for more information on using environment variables with Bun.
+See [Docs > Runtime > Environment variables](/docs/runtime/env) for more information on using environment variables with Bun.
diff --git a/docs/guides/runtime/tsconfig-paths.md b/docs/guides/runtime/tsconfig-paths.md
index 5c3f591f5..176051d5a 100644
--- a/docs/guides/runtime/tsconfig-paths.md
+++ b/docs/guides/runtime/tsconfig-paths.md
@@ -8,8 +8,8 @@ Bun reads the `paths` field in your `tsconfig.json` to re-write import paths. Th
{
"compilerOptions": {
"paths": {
- "my-custom-name": "zod",
- "@components/*": "./src/components/*"
+ "my-custom-name": ["zod"],
+ "@components/*": ["./src/components/*"]
}
}
}
diff --git a/docs/guides/runtime/typescript.md b/docs/guides/runtime/typescript.md
new file mode 100644
index 000000000..f6afe02c1
--- /dev/null
+++ b/docs/guides/runtime/typescript.md
@@ -0,0 +1,69 @@
+---
+name: Install TypeScript declarations for Bun
+---
+
+To install TypeScript definitions for Bun's built-in APIs in your project, install `bun-types`.
+
+```sh
+$ bun add -d bun-types # dev dependency
+```
+
+---
+
+Then include `"bun-types"` in the `compilerOptions.types` in your `tsconfig.json`:
+
+```json-diff
+ {
+ "compilerOptions": {
++ "types": ["bun-types"]
+ }
+ }
+```
+
+---
+
+Unfortunately, setting a value for `"types"` means that TypeScript will ignore other global type definitions, including `lib: ["dom"]`. If you need to add DOM types into your project, add the following [triple-slash directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) at the top of any TypeScript file in your project.
+
+```ts
+/// <reference lib="dom" />
+/// <reference lib="dom.iterable" />
+```
+
+---
+
+Below is the full set of recommended `compilerOptions` for a Bun project. With this `tsconfig.json`, you can use top-level await, extensioned or extensionless imports, and JSX.
+
+```jsonc
+{
+ "compilerOptions": {
+ // add Bun type definitions
+ "types": ["bun-types"],
+
+ // enable latest features
+ "lib": ["esnext"],
+ "module": "esnext",
+ "target": "esnext",
+
+ // if TS 5.x+
+ "moduleResolution": "bundler",
+ "noEmit": true,
+ "allowImportingTsExtensions": true,
+ "moduleDetection": "force",
+ // if TS 4.x or earlier
+ // "moduleResolution": "nodenext",
+
+ "jsx": "react-jsx", // support JSX
+ "allowJs": true, // allow importing `.js` from `.ts`
+ "esModuleInterop": true, // allow default imports for CommonJS modules
+
+ // best practices
+ "strict": true,
+ "forceConsistentCasingInFileNames": true,
+ "skipLibCheck": true
+ }
+}
+```
+
+---
+
+Refer to [Ecosystem > TypeScript](/docs/runtime/typescript) for a complete guide to TypeScript support in Bun.
diff --git a/docs/guides/runtime/vscode-debugger.md b/docs/guides/runtime/vscode-debugger.md
index 616524c17..fdfdb2f2e 100644
--- a/docs/guides/runtime/vscode-debugger.md
+++ b/docs/guides/runtime/vscode-debugger.md
@@ -2,6 +2,12 @@
name: Debugging Bun with the VS Code extension
---
+{% note %}
+
+VSCode extension support is currently buggy. We recommend the [Web Debugger](https://bun.sh/guides/runtime/web-debugger) for now.
+
+{% /note %}
+
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-vscode/types/jsc.d.ts) so you can debug your code with an interactive debugger.
---
diff --git a/docs/guides/test/happy-dom.md b/docs/guides/test/happy-dom.md
index 9c6728f88..072790929 100644
--- a/docs/guides/test/happy-dom.md
+++ b/docs/guides/test/happy-dom.md
@@ -49,7 +49,7 @@ test("set button text", () => {
---
-With Happy DOM propertly configured, this test runs as expected.
+With Happy DOM properly configured, this test runs as expected.
```sh
$ bun test
diff --git a/docs/guides/test/migrate-from-jest.md b/docs/guides/test/migrate-from-jest.md
new file mode 100644
index 000000000..4adbddc34
--- /dev/null
+++ b/docs/guides/test/migrate-from-jest.md
@@ -0,0 +1,112 @@
+---
+name: Migrate from Jest to Bun's test runner
+---
+
+In many cases, Bun's test runner can run Jest test suites with no code changes. Just run `bun test` instead of `npx jest`, `yarn test`, etc.
+
+```sh-diff
+- $ npx jest
+- $ yarn test
++ $ bun test
+```
+
+---
+
+There's often no need for code changes.
+
+- Bun internally re-writes imports from `@jest/globals` to use the `bun:test` equivalents.
+- If you're relying on Jest to inject `test`, `expect`, etc. as globals, Bun does that too.
+
+But if you'd rather switch to the `bun:test` imports, you can do that too.
+
+```ts-diff
+- import {test, expect} from "@jest/globals";
++ import {test, expect} from "bun:test";
+```
+
+---
+
+Bun implements the vast majority of Jest's matchers, but compatibility isn't 100% yet. Refer to the full compatibility table at [Docs > Test runner > Writing tests](/docs/test/writing#matchers).
+
+Some notable missing features:
+
+- `expect.extend()`
+- `expect().toMatchInlineSnapshot()`
+- `expect().toHaveBeenCalledWith()`
+- `expect().toHaveReturned()`
+
+---
+
+If you're using `testEnvironment: "jsdom"` to run your tests in a browser-like environment, you should follow the [DOM testing with Bun and happy-dom](/guides/test/happy-dom) guide to inject browser APIs into the global scope. This guide relies on [`happy-dom`](https://github.com/capricorn86/happy-dom), which is a leaner and faster alternative to [`jsdom`](https://github.com/jsdom/jsdom).
+
+At the moment jsdom does not work in Bun due to its internal use of V8 APIs. Track support for it [here](https://github.com/oven-sh/bun/issues/3554).
+
+```toml#bunfig.toml
+[test]
+preload = ["./happy-dom.ts"]
+```
+
+---
+
+Replace `bail` in your Jest config with the `--bail` CLI flag.
+
+<!-- ```ts-diff
+- import type {Config} from 'jest';
+-
+- const config: Config = {
+- bail: 3
+- };
+``` -->
+
+```sh-diff
+$ bun test --bail 3
+```
+
+---
+
+Replace `collectCoverage` with the `--coverage` CLI flag.
+
+<!-- ```ts-diff
+- import type {Config} from 'jest';
+-
+- const config: Config = {
+- collectCoverageFrom: [
+- '**/*.{js,jsx}',
+- '!**/node_modules/**',
+- '!**/vendor/**',
+- ],
+- };
+``` -->
+
+```sh
+$ bun test --coverage
+```
+
+---
+
+Replace `testTimeout` with the `--test-timeout` CLI flag.
+
+```sh
+$ bun test --timeout 10000
+```
+
+---
+
+Many other flags become irrelevant or obsolete when using `bun test`.
+
+- `transform` — Buns supports TypeScript & JSX. Other file types can be configured with [Plugins](/docs/runtime/plugins).
+- `extensionsToTreatAsEsm`
+- `haste` — Bun uses it's own internal source maps
+- `watchman`, `watchPlugins`, `watchPathIgnorePatterns` — use `--watch` to run tests in watch mode
+- `verbose` — set `logLevel: "debug"` in [`bunfig.toml`](/docs/runtime/bunfig#loglevel)
+
+---
+
+Settings that aren't mentioned here are not supported or have no equivalent. Please [file a feature request](https://github.com/oven-sh/bun) if something important is missing.
+
+---
+
+See also:
+
+- [Mark a test as a todo](/guides/test/todo-tests)
+- [Docs > Test runner > Writing tests](/docs/test/writing)
diff --git a/docs/guides/test/mock-functions.md b/docs/guides/test/mock-functions.md
index c7e8af411..fbcf03e86 100644
--- a/docs/guides/test/mock-functions.md
+++ b/docs/guides/test/mock-functions.md
@@ -47,7 +47,7 @@ random.mock.results;
These extra properties make it possible to write `expect` assertions about usage of the mock function, including how many times it was called, the arguments, and the return values.
```ts
-import { test, mock } from "bun:test";
+import { test, expect, mock } from "bun:test";
const random = mock((multiplier: number) => multiplier * Math.random());
diff --git a/docs/guides/test/spy-on.md b/docs/guides/test/spy-on.md
index 003c05d96..4d4902f9d 100644
--- a/docs/guides/test/spy-on.md
+++ b/docs/guides/test/spy-on.md
@@ -36,7 +36,7 @@ Once the spy is created, it can be used to write `expect` assertions relating to
+ test("turtles", ()=>{
+ expect(spy).toHaveBeenCalledTimes(0);
+ leo.sayHi("pizza");
-+ expect(spy).toHaveBeenCalledTimes(0);
++ expect(spy).toHaveBeenCalledTimes(1);
+ expect(spy.mock.calls).toEqual([[ "pizza" ]]);
+ })
```
diff --git a/docs/guides/util/entrypoint.md b/docs/guides/util/entrypoint.md
index e53d4c9a1..63d71b630 100644
--- a/docs/guides/util/entrypoint.md
+++ b/docs/guides/util/entrypoint.md
@@ -5,9 +5,9 @@ name: Check if the current file is the entrypoint
Bun provides a handful of module-specific utilities on the [`import.meta`](/docs/api/import-meta) object. Use `import.meta.main` to check if the current file is the entrypoint of the current process.
```ts#index.ts
-if(import.meta.main){
+if (import.meta.main) {
// this file is directly executed with `bun run`
-}else{
+} else {
// this file is being imported by another file
}
```
diff --git a/docs/guides/websocket/context.md b/docs/guides/websocket/context.md
index 9e387d685..8658c5d4b 100644
--- a/docs/guides/websocket/context.md
+++ b/docs/guides/websocket/context.md
@@ -47,7 +47,7 @@ Bun.serve<WebSocketData>({
// use a library to parse cookies
const cookies = parseCookies(req.headers.get("Cookie"));
const token = cookies["X-Token"];
- const user = await getUserFromToken(ws.data.authToken);
+ const user = await getUserFromToken(token);
const upgraded = server.upgrade(req, {
data: {
diff --git a/docs/guides/websocket/simple.md b/docs/guides/websocket/simple.md
index 5aabf2fdf..e1d95ce36 100644
--- a/docs/guides/websocket/simple.md
+++ b/docs/guides/websocket/simple.md
@@ -29,5 +29,5 @@ const server = Bun.serve<{ authToken: string }>({
},
});
-console.log(`Listening on localhost:\${server.port}`);
+console.log(`Listening on ${server.hostname}:${server.port}`);
```