npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

check-commit

v1.0.0

Published

Command line tools for commit validation with regular expressions suitable for husky

Downloads

16

Readme

check-commit

Command line tools for commit validation with regular expressions suitable for husky.

Usage

check-commit requires Node 6+. Add check-commit and husky to your project:

npm install check-commit husky --save-dev

Then enable commit branch name validation by adding this your package.json file:

{
  "scripts": {
    "precommit": "check-commit-branch"
  },
  "config": {
    "checkCommit": {
      "branch": "^feature/\\w+$"
    }
  }
}

Now you can only commit on branches that satisfy the pattern feature/<identifier>

API

npm install check-commit --save-dev

will locally install a binary check-commit-branch which is then available to your package.json scripts.

check-commit-branch will evaluate the config.checkCommit.branch key of your package.json file. The following configuration formats are supported:

  • Simple regular expression

    "branch": "<RegExp>"

    Only allow commits if the current branch satisfies <RegExp>.

  • Array of regular expressions

    "branch": ["<RegExp1>", "<RegExp2>", "<RegExp3>"]

    Only allow commits if the current branch satisfies either of the regular expressions <RegExp1>, <RegExp2> or <RegExp3>.

  • Array of validation rules

    "branch": [
      {
        test: "<RegExp1>",
        forbid: "<ForbiddenRegExp1>",
        reason: "Lovely commits need to be cool"
      },
      {
        test: "<RegExp2>",
        require: "<RequiredRegExp2>",
        reason: "Cool commits need to be lovely"
      },
      "<RegExp3>"
    ]

    In the previous case, you can replace regular expressions by validation rules. Validation rule objects can have the following fields:

    • test (mandatory): This rule only applies to branches which satisfy this regular expression. A branch can only be valid if it satisfies at least one rule.
    • require (optional): An additional regular expression that needs to be satisfied by branches satisfying test
    • forbid (optional): An additional regular expression that branches that satisfy test must not satisfy
    • reason (optional): A description why this rule is in place. This is printed to the console as additional information when this rule is violated.

    If a branch satisfies the test expressions of several rules, all require and forbid conditions of these rules need to be met in order for the commit to pass.

    If you only have a single validation rule, you do not need to wrap it in an array.

    Simple strings are equivalent to rules that only have a test field.

Troubleshooting

You may safely check your configured hook against the current branch without committing by running

npm run precommit

Git hooks triggering

If the git hooks do not trigger on commit, there might have already been custom git hooks defined in your git repository before you installed husky. To solve this, you can run

rm .git/hooks/*
npm install husky

which will replace all git hooks by husky's hooks.

Using yarn

If you install husky using yarn, it is possible that husky's post-install scripts do not run. In that case, you can try running

npm install husky

after the installation, which will not change your package.json or yarn.lock file but make sure husky's scripts run.