Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor guide fixes for consistency #16273

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/file-io.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ Bun.stdout;
Bun.stderr;
```

### Deleting files (`file.delete()`)

You can delete a file by calling the `.delete()` function.

```ts
await Bun.file("logs.json").delete()
```

## Writing files (`Bun.write()`)

`Bun.write(destination, data): Promise<number>`
Expand Down
6 changes: 3 additions & 3 deletions docs/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ If you're using Ubuntu 20.04, here's how to install a [newer kernel](https://wik

```bash
# If this returns a version >= 5.6, you don't need to do anything
uname -r
$ uname -r

# Install the official Ubuntu hardware enablement kernel
sudo apt install --install-recommends linux-generic-hwe-20.04
$ sudo apt install --install-recommends linux-generic-hwe-20.04
```

{% /details %}
Expand Down Expand Up @@ -229,7 +229,7 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install bun
uses: oven-sh/setup-bun@v1
uses: oven-sh/setup-bun@v2
- name: Install dependencies
run: bun install
- name: Build app
Expand Down
14 changes: 7 additions & 7 deletions docs/guides/ecosystem/discordjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ name: Create a Discord bot

Discord.js works out of the box with Bun. Let's write a simple bot. First create a directory and initialize it with `bun init`.

```bash
mkdir my-bot
cd my-bot
bun init
```sh
$ mkdir my-bot
$ cd my-bot
$ bun init
```

---

Now install Discord.js.

```bash
bun add discord.js
```sh
$ bun add discord.js
```

---
Expand Down Expand Up @@ -67,7 +67,7 @@ client.login(process.env.DISCORD_TOKEN);

Now we can run our bot with `bun run`. It may take a several seconds for the client to initialize the first time you run the file.

```bash
```sh
$ bun run bot.ts
Ready! Logged in as my-bot#1234
```
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/ecosystem/hono.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
```sh
$ bun create hono myapp
✔ Which template do you want to use? › bun
cloned honojs/starter#main to /path/to/myapp
Expand All @@ -30,7 +30,7 @@ $ bun install

Then start the dev server and visit [localhost:3000](http://localhost:3000).

```bash
```sh
$ bun run dev
```

Expand Down
12 changes: 6 additions & 6 deletions docs/guides/ecosystem/mongoose.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ MongoDB and Mongoose work out of the box with Bun. This guide assumes you've alr

Once MongoDB is running, create a directory and initialize it with `bun init`.

```bash
mkdir mongoose-app
cd mongoose-app
bun init
```sh
$ mkdir mongoose-app
$ cd mongoose-app
$ bun init
```

---

Then add Mongoose as a dependency.

```bash
bun add mongoose
```sh
$ bun add mongoose
```

---
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/ecosystem/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ $ bun create next-app
Creating a new Next.js app in /path/to/my-app.
```

---

You can specify a starter template using the `--example` flag.

```sh
Expand Down
18 changes: 9 additions & 9 deletions docs/guides/ecosystem/render.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ As an example, let's deploy a simple Express HTTP server to Render.

Create a new GitHub repo named `myapp`. Git clone it locally.

```bash
git clone [email protected]:my-github-username/myapp.git
cd myapp
```sh
$ git clone [email protected]:my-github-username/myapp.git
$ cd myapp
```

---

Add the Express library.

```bash
bun add express
```sh
$ bun add express
```

---
Expand All @@ -52,10 +52,10 @@ app.listen(port, () => {

Commit your changes and push to GitHub.

```bash
git add app.ts bun.lockb package.json
git commit -m "Create simple Express app"
git push origin main
```sh
$ git add app.ts bun.lockb package.json
$ git commit -m "Create simple Express app"
$ git push origin main
```

---
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/ecosystem/sentry.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Don't already have an account and Sentry project established? Head over to [sent

To start using Sentry with Bun, first install the Sentry Bun SDK.

```bash
bun add @sentry/bun
```sh
$ bun add @sentry/bun
```

---
Expand Down
8 changes: 6 additions & 2 deletions docs/guides/http/hot.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ name: Hot reload an HTTP server
Bun supports the [`--hot`](https://bun.sh/docs/runtime/hot#hot-mode) flag to run a file with hot reloading enabled. When any module or file changes, Bun re-runs the file.

```sh
bun --hot run index.ts
$ bun --hot run index.ts
```

---

Bun detects when you are running an HTTP server with `Bun.serve()`. It reloads your fetch handler when source files change, _without_ restarting the `bun` process. This makes hot reloads nearly instantaneous.

{% callout %}
Note that this doesn't reload the page on your browser.
{% /callout %}

```ts
Bun.serve({
port: 3000,
fetch(req) {
return new Response(`Hello world`);
return new Response("Hello world");
},
});
```
31 changes: 29 additions & 2 deletions docs/guides/install/add-peer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,43 @@
name: Add a peer dependency
---

To add an npm package as a peer dependency, directly modify the `peerDependencies` object in your package.json. Running `bun install` will install peer dependencies by default, unless marked optional in `peerDependenciesMeta`.

To add an npm package as a peer dependency, use the `--peer` flag.

```sh
$ bun add @types/bun --peer
```

---

This will add the package to `peerDependencies` in `package.json`.

```json-diff
{
"peerDependencies": {
+ "zod": "^3.0.0"
+ "@types/bun": "^1.0.0"
}
}
```

---

Running `bun install` will install peer dependencies by default, unless marked optional in `peerDependenciesMeta`.

```json-diff
{
"peerDependencies": {
"@types/bun": "^1.0.0"
},
"peerDependenciesMeta": {
+ "@types/bun": {
+ "optional": true
+ }
}

}
```

---

See [Docs > Package manager](https://bun.sh/docs/cli/install) for complete documentation of Bun's package manager.
2 changes: 1 addition & 1 deletion docs/guides/install/add.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This will add the package to `dependencies` in `package.json`. By default, the `

---

To "pin" to the `latest` version of the package, use `--exact`. This will add the package to `dependencies` without the `^`, pinning your project to the exact version you installed.
To "pin" to an exact version of the package, use `--exact`. This will add the package to `dependencies` without the `^`, pinning your project to the exact version you installed.

```sh
$ bun add zod --exact
Expand Down
6 changes: 3 additions & 3 deletions docs/guides/install/cicd.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
# ...
- uses: actions/checkout@v4
+ - uses: oven-sh/setup-bun@v1
+ - uses: oven-sh/setup-bun@v2

# run any `bun` or `bunx` command
+ - run: bun install
Expand All @@ -31,9 +31,9 @@ jobs:
runs-on: ubuntu-latest
steps:
# ...
- uses: oven-sh/setup-bun@v1
- uses: oven-sh/setup-bun@v2
+ with:
+ version: 0.7.0 # or "canary"
+ version: 1.1.0 # or "canary"
```

---
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/install/git-diff-bun-lockfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name: Configure git to diff Bun's lockb lockfile
---

{% callout %}
Bun v1.1.39 introduced `bun.lock`, a JSONC formatted lockfile. `bun.lock` is human-readable and git-diffable without configuration, at no cost to performance. [**Learn more.**](https://bun.sh/docs/install/lockfile#text-based-lockfile)
{% /callout %}

---

To teach `git` how to generate a human-readable diff of Bun's binary lockfile format (`.lockb`), add the following to your local or global `.gitattributes` file:

```js
Expand Down
2 changes: 0 additions & 2 deletions docs/guides/install/trusted.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ To allow Bun to execute lifecycle scripts for a specific package, add the packag
Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!
{% /callout %}

<!-- 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",
Expand Down
6 changes: 6 additions & 0 deletions docs/guides/install/yarnlock.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
name: Generate a human-readable lockfile
---

{% callout %}
Bun v1.1.39 introduced `bun.lock`, a JSONC formatted lockfile. `bun.lock` is human-readable and git-diffable without configuration, at no cost to performance. [**Learn more.**](https://bun.sh/docs/install/lockfile#text-based-lockfile)
{% /callout %}

---

By default Bun generates a binary `bun.lockb` file when you run `bun install`. In some cases, it's preferable to generate a human-readable lockfile instead.

---
Expand Down
4 changes: 3 additions & 1 deletion docs/guides/process/argv.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ console.log(values);
console.log(positionals);
```

---

then it outputs

```
```sh
$ bun run cli.ts --flag1 --flag2 value
{
flag1: true,
Expand Down
30 changes: 15 additions & 15 deletions docs/guides/runtime/define-constant.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: Define and replace static globals & constants

The `--define` flag lets you declare statically-analyzable constants and globals. It replace all usages of an identifier or property in a JavaScript or TypeScript file with a constant value. This feature is supported at runtime and also in `bun build`. This is sort of similar to `#define` in C/C++, except for JavaScript.

```ts
bun --define process.env.NODE_ENV="'production'" src/index.ts # Runtime
bun build --define process.env.NODE_ENV="'production'" src/index.ts # Build
```sh
$ bun --define process.env.NODE_ENV="'production'" src/index.ts # Runtime
$ bun build --define process.env.NODE_ENV="'production'" src/index.ts # Build
```

---
Expand All @@ -25,12 +25,12 @@ if (process.env.NODE_ENV === "production") {

Before the code reaches the JavaScript engine, Bun replaces `process.env.NODE_ENV` with `"production"`.

```ts
if ("production" === "production") {
console.log("Production mode");
} else {
console.log("Development mode");
}
```ts-diff
+ if ("production" === "production") {
console.log("Production mode");
} else {
console.log("Development mode");
}
```

---
Expand All @@ -39,12 +39,12 @@ It doesn't stop there. Bun's optimizing transpiler is smart enough to do some ba

Since `"production" === "production"` is always `true`, Bun replaces the entire expression with the `true` value.

```ts
if (true) {
console.log("Production mode");
} else {
console.log("Development mode");
}
```ts-diff
+ if (true) {
console.log("Production mode");
} else {
console.log("Development mode");
}
```

---
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/streams/node-readable-to-blob.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Convert a Node.js Readable to a Blob
---

To convert a Node.js `Readable` stream to a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.blob()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) to read the stream into a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
To convert a Node.js `Readable` stream to a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`Response.blob()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) to read the stream into a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).

```ts
import { Readable } from "stream";
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/streams/node-readable-to-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Convert a Node.js Readable to JSON
---

To convert a Node.js `Readable` stream to a JSON object in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json) to read the stream into a JSON object.
To convert a Node.js `Readable` stream to a JSON object in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`Response.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json) to read the stream into a JSON object.

```ts
import { Readable } from "stream";
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/streams/node-readable-to-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Convert a Node.js Readable to a string
---

To convert a Node.js `Readable` stream to a string in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/text) to read the stream into a string.
To convert a Node.js `Readable` stream to a string in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`Response.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/text) to read the stream into a string.

```ts
import { Readable } from "stream";
Expand Down
Loading
Loading