toplenboren / simple-git-hooks

A simple git hooks manager for small projects
MIT License
1.32k stars 43 forks source link

[Question] run npx simple-git-hooks every time you change a command #34

Open pustovalov opened 3 years ago

pustovalov commented 3 years ago

Is this a good idea to do something like this?

"simple-git-hooks": {
  "pre-commit": "npx simple-git-hooks && npx lint-staged"
}

so that people don't need to run npx simple-git-hooks command when the config change

toplenboren commented 3 years ago

This shouldn't break things :) Gonna try it tomorrow, if this solution doesnt affect performance and works well, then gonna add it to the docs

Thanks for the idea!

glen-84 commented 3 years ago

Couldn't this be done internally, before each command is run?

Check the hash and/or file modification time of the package.json or configuration file, and if it has changed, re-run setup?

Another idea: Install a post-merge hook that checks for updates to configuration, and if necessary, re-runs setup.

JonKrone commented 3 years ago

Definitely a fan of automatically keeping this synced as well! If a package updates a hooks' command, consumers' hooks should be updated without manual work of their own.

Thanks for the library, toplenboren!

Djaler commented 3 years ago

Also, what about initial hooks install? For example, if I'll replace husky with simple-git-hooks in my project, I need to say all project members to run npx simple-git-hooks. Doesn't seem nice to me.

glen-84 commented 3 years ago

@Djaler Is that not handled by the postinstall script?

Djaler commented 3 years ago

Hmm, looks like yes. I just didn't see this in readme

JaneJeon commented 3 years ago

Can someone confirm that the post-merge "auto-updating" of hooks work? It's the only thing holding me back from migrating/fleeing from husky@4

glen-84 commented 3 years ago

@JaneJeon It hasn't been implemented, as far as I know.

JaneJeon commented 3 years ago

@glen-84 sorry, I didn’t mean if that feature was “built-in” to this library, but rather whether it was possible to get the husky-like functionality by just prepending a npx simple-git-hooks to the post-merge hook.

glen-84 commented 3 years ago

@JaneJeon Oh I see. I haven't tried it yet, TBH. 🙂

DanielRuf commented 3 years ago

You may not need npx, you can also do simple-git-hooks as script after npm i simple-git-hooks --save-dev, that you can add to the prepare script in your package.json.

peschee commented 2 years ago

I am using this:

"prepare": "is-ci || npx simple-git-hooks"

https://www.npmjs.com/package/is-ci