typicode / husky

Git hooks made easy 🐢 woof!
https://typicode.github.io/husky
MIT License
31.75k stars 999 forks source link

git hook install triggered via npm but not yarn #227

Closed mavogel closed 3 years ago

mavogel commented 6 years ago

Do you want to request a feature or report a bug? => Bug

Installing the git hook is only triggered when husky is installed via npm but not yarn whereas uninstalling the hooks works for both tools. Similar to #81

Current Behaviour

Install

$ yarn add husky@0.15.0-rc.3 -D
arn add v1.4.0
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 5 new dependencies.
β”œβ”€ ci-info@1.1.2
β”œβ”€ husky@0.14.3
β”œβ”€ is-ci@1.1.0
β”œβ”€ normalize-path@1.0.0
└─ strip-indent@2.0.0
✨  Done in 3.13s.

and npm

$ npm i husky@0.15.0-rc.3 --save-dev
...
> husky@0.15.0-rc.3 postinstall /Users/abc/Development/project/node_modules/husky
> node lib/installer/bin install

husky > setting up git hooks
husky > done
+ husky@0.15.0-rc.3
added 8 packages, removed 575 packages and updated 47 packages in 8.268s

Uninstall

$ yarn remove husky
yarn remove v1.4.0
[1/2] Removing module husky...
$ node ./bin/uninstall.js
husky
uninstalling Git hooks
done

$ node ./bin/uninstall.js
husky
uninstalling Git hooks
done

[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
✨  Done in 2.83s.

and npm

$ npm un husky --save-dev
> husky@0.15.0-rc.3 preuninstall /Users/abc/Development/project/node_modules/husky
> node lib/installer/bin uninstall

husky > uninstalling git hooks
husky > done
added 483 packages, removed 14 packages and updated 22 packages in 18.134s

Expected Behaviour

yarn add husky@0.15.0-rc.3 -D should also trigger the install of the git hooks.

Please mention your node.js, yarn and operating system version.

OS: macOS High Sierra 10.13.3 yarn: v1.4.0 node: v9.4.0 npm: 5.6.0

fernandopasik commented 6 years ago

@typicode would merging #126 be fixing this?

typicode commented 6 years ago

@mavogel thanks for the detailed issue πŸ‘ that's super helpful :) I'm not getting this issue with yarn v1.3.2, so not sure if it's related to husky install script. I'll have to try with yarn v1.4.0.

@fernandopasik https://github.com/typicode/husky/pull/126 could have but not really :) The PR is only for picking between npm or yarn when running a package.json script (for example, it would run precommit with yarn precommit or npm run precommit depending on which one is installed) and wouldn't have any effect during husky installation.

Meanwhile, as a temporary workaround, you can manually run node node_modules/husky/lib/installer/bin install or add it to your package.json:

{
  "scripts": {
    "postinstall": "node node_modules/husky/lib/installer/bin install"
  }
}

One word of caution, use the postinstall hook only if you're not publishing your project on npm, else your users will get errors when trying to install your module.

jasonkuhrt commented 6 years ago

@typicode FWIW I'm using v1.3.2:

❯ yarn add husky
yarn add v1.3.2
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 2 new dependencies.
β”œβ”€ husky@0.14.3
└─ strip-indent@2.0.0
✨  Done in 3.00s.

❯ yarn -v
1.3.2
typicode commented 6 years ago

@jasonkuhrt and it's installing nothing with v1.3.2?

Can you try with

yarn add husky@next --dev # it should install the latest rc release
cat .git/hooks/pre-commit
typicode commented 6 years ago

I've published a new version if you want to give another try (just run yarn add husky@next --dev). I've moved v0.15 install script from postinstall to install (as it is in v0.14).

mavogel commented 6 years ago

@typicode yep now the githooks are installed, although yarn does not log it on installing, while npm does. Nevertheless it works now with rc7 πŸ‘

$ yarn add husky@0.15.0-rc.7 -D
yarn add v1.4.0
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
success Saved lockfile.
success Saved 9 new dependencies.
β”œβ”€ ci-info@1.1.2
β”œβ”€ cosmiconfig@4.0.0
β”œβ”€ husky@0.15.0-rc.7
β”œβ”€ is-ci@1.1.0
β”œβ”€ json-parse-better-errors@1.0.1
β”œβ”€ pkg-dir@2.0.0
β”œβ”€ pupa@1.0.0
β”œβ”€ run-node@0.2.0
└─ slash@1.0.0
✨  Done in 3.10s.
...
$ cat .git/hooks/pre-commit
#!/bin/sh -e
# husky
# v0.15.0-rc.7 darwin

export GIT_PARAMS="$*"
node_modules/run-node/run-node ./node_modules/husky/lib/runner/bin `basename "$0"`

how about you @jasonkuhrt ?

Nxt3 commented 6 years ago

Fixed for me as well.

jasonkuhrt commented 6 years ago

@typicode @mavogel seems good now!

mavogel commented 6 years ago

Fixed with 2b16499 and rc7

chrislim commented 4 years ago

I'm experiencing this with husky v3.0.1 Had to use https://github.com/typicode/husky/issues/227#issuecomment-361779926

joebartels commented 4 years ago

experiencing this with husky: 3.0.9 node: 12.2.0 (via nvm) yarn: 1.19.1 yarn workspaces

yarn install husky --dev -W

☝️ does not create the git hooks, confirmed via ls -l .git/hooks

Manually running husky's bin install script does work though https://github.com/typicode/husky/issues/227#issuecomment-361779926

drewlustro commented 4 years ago

Could we reopen this issue?

benouat commented 4 years ago

Same here ! Could we please re-open this issue ?

husky: 3.1.0 node: 12.10.0 (via nvm) yarn: 1.19.2 npm: 6.13.0

It does not install hooks on yarn add but npm install does

ConradLang commented 4 years ago

The behaviour I have is yarn install does install the git hooks but make install (which just runs yarn install) does not install the git hooks.

We're not using workspaces.

husky: 3.1.0 nvm: 0.35.2 node: 12.14.1 yarn: 1.21.1 npm: 6.13.4 GNU Make: 3.81

lmuntaner commented 4 years ago

I had the same problem and I fixed it upgrading git.

Installing Husky didn't create the hooks.

I tried running the script directly:

node node_modules/husky/lib/installer/bin install

And got this:

husky > Setting up git hooks
Husky requires Git >=2.13.0. Got v2.10.2.
husky > Failed to install

I guessed that during the installation this error was hidden among all the logs and I didn't see it.

After updating git, I removed node_modules and run yarn install again. Everything worked.

I hope this helps πŸ˜„

devinrhode2 commented 3 years ago

Just in case, make sure you don't have a .yarnrc (https://github.com/typicode/husky/issues/664)

typicode commented 3 years ago

Closing as workarounds/fixes seem to have been found (thanks @lmuntaner @devinrhode2) and also husky 5 should be exempt from this issue. You may try to run npm rebuild or yarn rebuild to force a re-install with husky 4.

aprilmintacpineda commented 3 years ago

I'm currently going through this, I just updated my husky from version 4 to version 5, and then it stopped working, I deleted .git/hooks and then did git init then yarn add husky, nothing worked.

jannomeister commented 3 years ago

me too. I'm experiencing this with husky version 5

kkoomen commented 2 years ago

I still experience this with v7.0.4 with yarn and npm via nvm.