typicode / husky

Git hooks made easy 🐶 woof!
https://typicode.github.io/husky
MIT License
32.51k stars 1.03k forks source link

"prepare": "husky" 每次下载依赖的时候会覆盖钩子文件 #1462

Open orochitian opened 3 months ago

orochitian commented 3 months ago

目前使用的版本是:9.0.11 由于package.json中配置了"prepare": "husky", 团队其他成员从仓库中拉取代码后,执行npm install后会自动重新创建.husky目录,包括里面的文件都会被覆盖。 这就意味着,如果我在.husky/pre-commit 中定义了自己的东西,那么别人在安装依赖的时候,就被把这些自定义的内容覆盖掉。

squidjam commented 3 months ago

I noticed this too, I wonder if there should be something that makes the behavior conditional. If the file exists, don't overwrite it would be the best solution imo.

hasan-aa commented 3 months ago

Actually this is the behavior I want to have. So that I can enforce linting rules to the team automatically. But it doesn't happen using yarn v4.1.1.

The prepare script doesn't run at all unless called manually like yarn prepare.

typicode commented 3 months ago

Yarn is a special case, check docs

squidjam commented 2 months ago

This does not sort out the situation with npm, though. Right? For future readers of this issue, "check docs" === a link to his blog at the bottom of the docs, so here's the link to save you all the trouble: https://blog.typicode.com/posts/husky-git-hooks-autoinstall/