typicode / husky

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

Husky replaces my "prepare" script #1387

Open ezeamin opened 3 months ago

ezeamin commented 3 months ago

Context

Hi! Husky is working great so far, thanks for your time! But, when I run pnpm exec husky init, following the docs, it installs the hooks but also replaces my prepare script with prepare: husky. I understand the purpose of this behaviour, but if I have a prepare script already, it should't replace it with its own script.

It also replaces my repo pre-commit file inside of /husky with a default one that does pnpm test. This is undesired behavior, because I already had a configuration written for the pre-commit hook.

typicode commented 3 months ago

Hi!

For existing hooks, it's better to follow the 'How to migrate' section from https://github.com/typicode/husky/releases/tag/v9.0.1

I'll update docs to make that clearer.

deleonio commented 2 months ago

Hello @typicode and @ezeamin,

we use the script prepare for more than just husky. I think it is more comfortable to leave it as it is.

zayne-wang commented 2 months ago

@typicode I created a pull request #1407 to fix this issue, please test and check.

SH4LIN commented 1 month ago

At least there should be a condition to check if prepare script has any commands in it or not If there is a command then this husky command should be appended.

Like this

- 14 ;(o.scripts ||= {}).prepare = 'husky'
+ 14 ;(o.scripts ||= {}).prepare = '' === (o.scripts ||= {}).prepare ? 'husky' : (o.scripts ||= {}).prepare + ' && husky'

Raised the PR for the mentioned solution please check it out.

zayne-wang commented 1 month ago

At least there should be a condition to check if prepare script has any commands in it or not If there is a command then this husky command should be appended.

Like this

- 14 ;(o.scripts ||= {}).prepare = 'husky'
+ 14 ;(o.scripts ||= {}).prepare = '' === (o.scripts ||= {}).prepare ? 'husky' : (o.scripts ||= {}).prepare + ' && husky'

Raised the PR for the mentioned solution please check it out.

Hi @SH4LIN,

Maybe we experienced the same mistake. According to typicode's reply in PR #1407, the custom scripts should be placed in .husky/, but not in .husky/_/. The .husky/_/ directory is managed by husky itself.

Hope this could make sense for you.