Skip to content

Commit

Permalink
docs: add yarn v2 install
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Mar 2, 2021
1 parent 77a7f03 commit 4ff36dc
Showing 1 changed file with 48 additions and 23 deletions.
71 changes: 48 additions & 23 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ Already using husky? See [Migrate from 4 to 5](https://typicode.github.io/husky/
## Automatic (recommended)

```shell
# npm
npm install husky --save-dev && npx husky init

# yarn
yarn add husky --dev && yarn husky init
```

The command above will setup husky and create a sample `pre-commit` hook that you can edit. By default, it will run `npm test` when you commit.
The command above will setup husky, modify `package.json` and create a sample `pre-commit` hook that you can edit. By default, it will run `npm test` when you commit.

To add another hook use `husky add`.

To add another hook use `husky add`. For example:
For example:

```shell
# npm
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'

# yarn
yarn husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
```

## Manual
Expand All @@ -52,21 +46,13 @@ yarn husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
1. Install `husky`

```shell
# npm
npm install husky --save-dev

# yarn
yarn add husky --dev
```

2. Enable Git hooks

```shell
# npm
npx husky install

# yarn
yarn husky install
```

3. To automatically have Git hooks enabled after install, edit `package.json`
Expand All @@ -80,6 +66,8 @@ yarn husky install
}
```

!> **Yarn v2 doesn't support `prepare` lifecycle script, so husky needs to be installed differently (this doesn't apply to yarn v1 though). See [Yarn v2 install](/?id=yarn-v2).**

### Add a hook

To add a hook, use `husky add <file> [cmd]` (don't forget to run `husky install` before).
Expand All @@ -98,17 +86,54 @@ If `npm test` command fails, your commit will be automatically aborted.

!> **Using Yarn to run commands? There's an issue on Windows with Git Bash, see [Yarn on Windows](#/?id=yarn-on-windows).**

## Uninstall
### Uninstall

```shell
# npm
npm uninstall husky
```

## Yarn v2

### Install

1. Install `husky`

```shell
yarn install husky --save-dev
yarn add pinst --dev # if your package is not private
```

2. Enable Git hooks

```shell
yarn husky install
```

3. To automatically have Git hooks enabled after install, edit `package.json`

# yarn
yarn remove husky && git config --unset core.hooksPath
```js
// package.json
{
"private": true,
"scripts": {
"postinstall": "husky install"
}
}
```

**Note:** When uninstalling with npm, `git config --unset core.hooksPath` will be automatically run for you.
!> **if your package is not private and you're publishing it on a registry like [npmjs.com](https://npmjs.com), you need to disable `postinstall` script using [pinst](https://github.com/typicode/pinst)**. Otherwise, `postinstall` will run when someone installs your package and result in an error.

```js
// package.json
{
"private": false,
"scripts": {
"postinstall": "husky install",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable"
}
}
```

# Recipes

Expand Down

0 comments on commit 4ff36dc

Please sign in to comment.