Skip to content

Commit

Permalink
docs: Add documentation for Bun.sh (prettier#16153)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
Pietrucci-Blacher and fisker committed Apr 10, 2024
1 parent a9ccba6 commit 09316aa
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"bottlenecked",
"Breakell",
"Brevik",
"bunx",
"Burgener",
"callees",
"camelcase",
Expand Down
22 changes: 22 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ yarn add --dev --exact prettier
pnpm add --save-dev --save-exact prettier
```

<!--bun-->

```bash
bun add --dev --exact prettier
```

<!--END_DOCUSAURUS_CODE_TABS-->

Then, create an empty config file to let editors and other tools know you are using Prettier:
Expand Down Expand Up @@ -80,6 +86,14 @@ pnpm exec prettier . --write

> What is `pnpm` doing at the start? `pnpm prettier` runs the locally installed version of Prettier. We’ll leave off the `pnpm` part for brevity throughout the rest of this file!
<!--bun-->

```bash
bun prettier . --write
```

> What is `bun` doing at the start? `bun prettier` runs the locally installed version of Prettier. We’ll leave off the `bun` part for brevity throughout the rest of this file!
<!--END_DOCUSAURUS_CODE_TABS-->

`prettier --write .` is great for formatting everything, but for a big project it might take a little while. You may run `prettier --write app/` to format a certain directory, or `prettier --write app/components/Button.js` to format a certain file. Or use a _glob_ like `prettier --write "app/**/*.test.js"` to format all tests in a directory (see [fast-glob](https://github.com/mrmlnc/fast-glob#pattern-syntax) for supported glob syntax).
Expand Down Expand Up @@ -143,6 +157,14 @@ For example, you can do the following to have Prettier run before each commit:
node --eval "fs.writeFileSync('.husky/pre-commit','pnpm exec lint-staged\n')"
```

<!--bun-->

```bash
bun add --dev husky lint-staged
bunx husky init
bun --eval "fs.writeFileSync('.husky/pre-commit','bunx lint-staged\n')"
```

<!--END_DOCUSAURUS_CODE_TABS-->

2. Add the following to your `package.json`:
Expand Down
8 changes: 8 additions & 0 deletions docs/precommit.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ pnpm add --save-dev git-format-staged
pnpm husky set .husky/pre-commit "git-format-staged -f 'prettier --ignore-unknown --stdin --stdin-filepath \"{}\"' ."
```

<!--bun-->

```bash
bunx husky-init
bun add --dev git-format-staged
echo "git-format-staged -f 'prettier --ignore-unknown --stdin --stdin-filepath \"{}\"' ." > .husky/pre-commit
```

<!--END_DOCUSAURUS_CODE_TABS-->

Add or remove file extensions to suit your project. Note that regardless of which extensions you list formatting will respect any `.prettierignore` files in your project.
Expand Down
22 changes: 22 additions & 0 deletions website/versioned_docs/version-stable/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ yarn add --dev --exact prettier
pnpm add --save-dev --save-exact prettier
```

<!--bun-->

```bash
bun add --dev --exact prettier
```

<!--END_DOCUSAURUS_CODE_TABS-->

Then, create an empty config file to let editors and other tools know you are using Prettier:
Expand Down Expand Up @@ -81,6 +87,14 @@ pnpm exec prettier . --write

> What is `pnpm` doing at the start? `pnpm prettier` runs the locally installed version of Prettier. We’ll leave off the `pnpm` part for brevity throughout the rest of this file!
<!--bun-->

```bash
bun prettier . --write
```

> What is `bun` doing at the start? `bun prettier` runs the locally installed version of Prettier. We’ll leave off the `bun` part for brevity throughout the rest of this file!
<!--END_DOCUSAURUS_CODE_TABS-->

`prettier --write .` is great for formatting everything, but for a big project it might take a little while. You may run `prettier --write app/` to format a certain directory, or `prettier --write app/components/Button.js` to format a certain file. Or use a _glob_ like `prettier --write "app/**/*.test.js"` to format all tests in a directory (see [fast-glob](https://github.com/mrmlnc/fast-glob#pattern-syntax) for supported glob syntax).
Expand Down Expand Up @@ -144,6 +158,14 @@ For example, you can do the following to have Prettier run before each commit:
node --eval "fs.writeFileSync('.husky/pre-commit','pnpm exec lint-staged\n')"
```

<!--bun-->

```bash
bun add --dev husky lint-staged
bunx husky init
bun --eval "fs.writeFileSync('.husky/pre-commit','pnpm exec lint-staged\n')"
```

<!--END_DOCUSAURUS_CODE_TABS-->

2. Add the following to your `package.json`:
Expand Down
8 changes: 8 additions & 0 deletions website/versioned_docs/version-stable/precommit.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ pnpm add --save-dev git-format-staged
pnpm husky set .husky/pre-commit "git-format-staged -f 'prettier --ignore-unknown --stdin --stdin-filepath \"{}\"' ."
```

<!--bun-->

```bash
bunx husky init
bun add --dev git-format-staged
echo "git-format-staged -f 'prettier --ignore-unknown --stdin --stdin-filepath \"{}\"' ." > .husky/pre-commit
```

<!--END_DOCUSAURUS_CODE_TABS-->

Add or remove file extensions to suit your project. Note that regardless of which extensions you list formatting will respect any `.prettierignore` files in your project.
Expand Down

0 comments on commit 09316aa

Please sign in to comment.