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

git-pre-commit-2

v3.0.0

Published

You can run the pre-commit with any build tool (Gulp, Grunt etc..) and it will ignore all the **unstaged changes** that wasn't added to the git index (using the command ```git add```).

Downloads

3

Readme

Build Status Dependency Status devDependency Status

NPM

You can run any pre-commit command (Shell, Gulp, Grunt etc..) and it will ignore all the unstaged changes that wasn't added to the git index (using the command git add).

Installation

First install the package in your devDependencies:

npm install git-pre-commit --save-dev

Or by using yarn:

yarn add git-pre-commit --dev

Using the package

Now, add to your package.json the entry:

"scripts": {
    "precommit": "<task to run>"
}

That is it! No more that you need to do (except for writing what to run :) )

Note: If your root directory has a yarn.lock file, all the scripts will be run using yarn.

Examples

So for example you can do something like that to run Gulp task named pre-commit:

"scripts": {
    "precommit": "gulp lint"
}

Or just a shell command:

"scripts": {
    "precommit": "echo Hello_World"
}

Have fun!

What this package is actually solving?

Most of the git pre-commit hooks are WRONG! Why? Because most of the pre-commit hooks also take into account the unstaged changes when performing the task.

Lets take for example the most common pre-commit hook: lint. So what usually people do? You try to perform a commit and then your pre-commit hook runs and lints all of your files.

There are 2 issues with that common approach:

#1 - When you have some unstaged changes and you would like to commit only the staged changes (the ones you performed git add on) your lint task checks the file itself and doesn't know if the code there will be part of the commit or not. This resolves into 2 possible situations:

  • The code in the unstaged changes break the lint task - why should I care?!? I'm not trying to commit this code!!
  • The code in the unstaged changes is actualy fixing the lint task, but it is not part of the commit - so for example you got an eslint error on your commit, you fixed it but forgot to git add the changes, now the lint task passes BUT you ended up with the fixing changes outside of your commit.

#2 - It lints all the files and not just the changed files. This is not addressed in this package as it is not the point of it. (For example on how to lint only the changed files you can checkout my eslint example that also uses the git-pre-commit package).

Like I said, this package fixes issue #1 by stashing your unstaged changes and returning the changes to the unstaged state once the pre-commit task has finished (with or without errors).

P.S

Even in this package repository I'm using the package pre-commit hook to lint all of the js files. For example on how to address the #2 issue:

It lints all the files and not just the changed files

Take a look at my eslint example that does just that. It will save you and your team A LOT of time!