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

skooh

v0.3.2

Published

skooh is a git hooks manager

Downloads

10

Readme

skooh

skooh is a git hooks management tool. It has no dependencies and aims to have the simplest developer experience possible.

npm install -D skooh
npm set-script prepare skooh
// package.json
{
  "hooks": {
    "pre-commit": "npm run test"
  }
}

All valid git hooks are supported.

How-To Guides

How to run tests in a pre-commit hook

After installing (npm i -D skooh) and setting up the prepare script (npm set-script prepare skooh), then, assuming you have already setup a npm run test script, then add the following as a top-level key to your package.json file:

// package.json
{
  "hooks": {
    "pre-commit": "npm run test"
  }
}

Then run npx skooh, which updates your .git/hooks/pre-commit file.

Now, in the future, when you checkout this branch or clone this repo, skooh's builtin post-checkout hook will run which will looks for hooks and write them to .git/hooks/.

How to edit your hooks block

Run npx skooh after manually editing the package.json hooks block. (This is normally ran automatically via the prepare life-cycle hook, but, manual edits cannot be detected.)

Reference

skooh

skooh sets up your git hooks. Call it by runnings npx skooh on the CLI.

Explanation

The goal of skooh is to version control your git hooks so you have a consistent way of triggering them across teams and development environments. .git/hooks/ is not version controlled itself, but it is a straightforward, user-friendly, and git-approved way of managing git hooks. This means we should use it for managing hooks. Skooh reads your package.json in order to prepare your git hooks.

How the "prepare: skooh" script works

prepare is a npm life-cycle script that runs automatically on npm install (and at a few other times as well). prepare calls skooh, which works as follows:

  1. It removes previously defined git hooks in preparation for updates.

  2. It scans your package.json for a top-level "hooks" block.

  3. It writes all valid hooks to .git/hooks/. For example, a "pre-commit": "npm run test" hook would result in the file .git/hooks/pre-commit with the following contents:

    #!bin/sh
    
    npm run test
    
  4. It writes a post-checkout hook to manage automatic updates (or appends to the one you define). This ensures that differently defined hooks from branches, changesets, etc., are automatically applied.

Migrating from Husky

Husky changes the hook path in git via the core.hookspath setting. You can see your current settings by running git config -l. You will need to unset this config by running git config --unset core.hookspath in order reset the git hooks path back to the default .git/hooks/.

Skooh vs Husky

  1. To begin with, husky is reliable. It has been battle-tested throughout the years. It's a safe bet with good documentation, and the author seems friendly. So, use husky, (unless you are persuaded by what follows).

  2. husky edits your core.hookspath

    1. This forces you to use husky for all your git hooks, because git isn't looking in the default location anymore (.git/hooks).
    2. If you move on from husky and forget to unset the core.hookspath overwrite, you will get unfamiliar errors and have an unpleasant debugging experience (you don't often get "missing git hook" errors, and so it will feel foreign to you).
  3. Husky also makes you write a top-level .husky/ folder that contains all your hooks.

    1. This is overkill for many use-cases, such as when you want to "just" run your linter on pre-commit. Do you really want yet another top-level folder which contains "just" a single file with a single line of code in it? I don't. I'd rather have that one-liner in my package.json.
  4. Husky has a CLI.

    1. It is simple, but that's because it's almost unnecessary.
    2. You will use it so rarely that you will forget the keywords and help commands.
    3. It's purpose is to help you add simple one-liner code to your .husky files. If you didn't have .husky files, you wouldn't need the CLI.

In conclusions, it is my opinion that skooh is simpler to use than husky. No top-level directory, no shell script management, no git config overrides, and no CLI needed.

What does a good git hook look like

I'd argue that the "ideal git hook" is a combination of other package.json scripts. Personally, the goal I aim for in most of my projects is something like the following:

// package.json
{
  "scripts": {
    "format": "...",
    "lint": "...",
    "test": "..."
  },
  "hooks": {
    "pre-commit": "npm run format && npm run lint && npm run test"
  }
}