A tool, that let you set any command from package.json as a pre-commit hook.
-
Zero dependency
-
Easy to configure (one line in
package.json) -
Lightweight*:
Package name Unpacked size husky v4 4.3.853.5 kBhusky v5 5.0.924.5 kBpre-commit 1.2.2~80 kBsimple-pre-commit 1.1.39.02 kB
Pre-commit hook is a command that is going to be run every time you commit a file to git.
If pre-commit hook fails, then commit aborts.
Usually you would like to run linters and code-formatters on every staged file to ensure code quality in your project
Check out lint-staged. It works really well with simple-pre-commit
You can look up about git hooks on git book
simple-pre-commit works well for small-sized projects when you need quickly setup pre-commit hook with one or a few commands and forget about it.
However, this package only allows you to set the pre-commit hook. If you need, for example pre-push hook or something else — this package wouln't be able to help you
Also, this package requires you to manually update the pre-commit hook. If you want update pre-commit hook often - this is probably not the best choice
If you need multiple hooks, flexible configuration or git hook automatic update feature — please check out other packages:
-
Install the simple-pre-commit as dev dependency
npm install simple-pre-commit --save-dev
-
Add the
simple-pre-committo yourpackage.json. Feed it with any command you would like to run as apre-commithook."simple-pre-commit": "npx lint-staged"`
There are more ways to configure the package. Check out [additional configuration](#Additional configuration options)
-
Run the CLI script to update the git hook with command from
package.jsonnpx simple-pre-commit
Now the command from package.json is set up as executable git pre-commit hook.
Run npx simple-pre-commit from root of your project
Note that you should manually run npx simple-pre-commit every time you change the command
You can also add the .simple-pre-commit.json or simple-pre-commit.json to the project and write the command inside it, if you do not want to put command inside package.json
That way, .simple-pre-commit.json or simple-pre-commit.json should look like this and package.json may not have simple-pre-commit configuration inside it
{
"simple-pre-commit":"npx lint-staged"
}npm uninstall --save-dev simple-pre-commit