You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Install `husky` and [pinst](https://github.com/typicode/pinst) (optional)
52
+
1. Install `husky`
53
53
54
54
```shell
55
55
# npm
56
56
npm install husky --save-dev
57
-
npm install pinst --save-dev # if your package is not private
58
57
59
58
# yarn
60
59
yarn add husky --dev
61
-
yarn add pinst --dev # if your package is not private
62
60
```
63
61
64
62
2. Enable Git hooks
@@ -76,23 +74,8 @@ yarn husky install
76
74
```js
77
75
// package.json
78
76
{
79
-
"private":true,
80
77
"scripts": {
81
-
"postinstall":"husky install"
82
-
}
83
-
}
84
-
```
85
-
86
-
!> **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.
87
-
88
-
```js
89
-
// package.json
90
-
{
91
-
"private":false,
92
-
"scripts": {
93
-
"postinstall":"husky install",
94
-
"prepublishOnly":"pinst --disable",
95
-
"postpublish":"pinst --enable"
78
+
"prepare":"husky install"
96
79
}
97
80
}
98
81
```
@@ -105,8 +88,6 @@ To add a hook, use `husky add <file> [cmd]` (don't forget to run `husky install`
105
88
npx husky add .husky/pre-commit "npm test"
106
89
```
107
90
108
-
_Requires npm v7.4+ on Windows_
109
-
110
91
Try to make a commit
111
92
112
93
```shell
@@ -143,20 +124,20 @@ If you want to install husky in another directory, for example `.config`, you ca
143
124
// package.json
144
125
{
145
126
"scripts": {
146
-
"postinstall":"husky install .config/husky"
127
+
"prepare":"husky install .config/husky"
147
128
}
148
129
}
149
130
```
150
131
151
132
Another case you may be in is if your `package.json` file and `.git` directory are not at the same level. For example, `project/.git` and `project/front/package.json`.
152
133
153
-
By design, `husky install` must be run in the same directory as `.git`, but you can change directory during `postinstall` script and pass a subdirectory:
134
+
By design, `husky install` must be run in the same directory as `.git`, but you can change directory during `prepare` script and pass a subdirectory:
0 commit comments