talira

pre-commit (npm)

Installs a git pre-commit hook that runs your npm scripts before each commit

open sourceMITfree

pre-commit is an npm package that installs a git pre-commit hook, so your npm test, or other scripts you list in package.json, must pass before a commit goes through. Installed as a dev dependency, it replaces the repository's existing pre-commit hook (keeping a backup as pre-commit.old) and reads which scripts to run, in order, from a pre-commit field in package.json. A commit can still skip it with git's --no-verify. It's a separate project from the Python-based pre-commit framework.

Problems it solves

  • stop teammates committing code when the npm tests fail
  • run my lint and test npm scripts automatically before every git commit
  • set up a git pre-commit hook from package.json without writing shell scripts

Features

  • installs a git pre-commit hook when added as a dev dependency
  • runs npm test, or the scripts listed in package.json, before each commit
  • backs up an existing pre-commit hook as pre-commit.old

Alternatives

The same job

These do what pre-commit (npm) does.

  1. Husky Native Git hooks for npm projects, in 2 kB with no dependencies
  2. pre-commit A framework for managing and maintaining multi-language pre-commit hooks.
  3. Lefthook Fast and powerful Git hooks manager for any type of projects.
  4. simple-git-hooks A zero-dependency tool to manage git hooks from package.json
  5. commitlint Lint commit messages against your team's commit convention
  6. lint-staged Run tasks like formatters and linters against files staged in Git

Compare pre-commit (npm) with the top 3