Skip to content
This repository was archived by the owner on Nov 17, 2025. It is now read-only.

Latest commit

 

History

History
186 lines (132 loc) · 3.46 KB

File metadata and controls

186 lines (132 loc) · 3.46 KB

@funish/githooks

npm version npm downloads npm license Contributor Covenant

Modern Git hooks management with configuration support, powered by Funish.

Features

  • 🚀 Simple and intuitive CLI
  • ⚙️ Configuration-driven setup
  • 📦 Automatic package manager detection
  • 🔄 Easy migration from husky
  • 🎯 Supports all Git hooks
  • 💪 TypeScript support
  • 🔒 Secure hook execution
  • 🌟 Zero dependencies

Installation

# npm
$ npm install @funish/githooks

# yarn
$ yarn add @funish/githooks

# pnpm
$ pnpm add @funish/githooks

Usage

CLI

Install Hooks

# Install in default location (.githooks)
$ githooks install

# Install in custom directory
$ githooks install --path .hooks

# Install and save postinstall script
$ githooks install --script

Set Up Hooks

# Set up pre-commit hook
$ githooks setup pre-commit

# Set up with script
$ githooks setup pre-commit --script "npm test"

Uninstall Hooks

$ githooks uninstall

Migrate from Husky

$ githooks migrate

Configuration

Create a githooks.config.ts file:

import { defineGithooksConfig } from "@funish/githooks";

export default defineGithooksConfig({
  // Custom hooks directory
  path: ".hooks",

  // Hook scripts
  hooks: {
    "pre-commit": "npm test",
    "pre-push": "npm run build",
  },

  // Additional Git config
  gitConfig: {
    core: {
      autocrlf: "input",
    },
  },
});

Programmatic Usage

import {
  githooksInstall,
  githooksSetup,
  githooksUninstall,
  githooksMigrateFromHusky,
} from "@funish/githooks";

// Install hooks
await githooksInstall(".hooks", true);

// Set up a hook
await githooksSetup("pre-commit", "npm test");

// Uninstall hooks
await githooksUninstall();

// Migrate from husky
await githooksMigrateFromHusky();

Supported Hooks

All standard Git hooks are supported:

  • applypatch-msg
  • pre-applypatch
  • post-applypatch
  • pre-commit
  • pre-merge-commit
  • prepare-commit-msg
  • commit-msg
  • post-commit
  • pre-rebase
  • post-checkout
  • post-merge
  • pre-push
  • And more

API Reference

githooksInstall(path?, isSaveScript?)

Installs Git hooks in the specified directory.

  • path (string): Directory to install hooks in
  • isSaveScript (boolean | string): Whether to save installation script

githooksSetup(hooks, script?)

Sets up a specific Git hook.

  • hooks (GithooksName): Name of the hook to set up
  • script (string): Script content for the hook

githooksUninstall()

Uninstalls all Git hooks and restores original configuration.

githooksMigrateFromHusky()

Migrates hooks from Husky to @funish/githooks.

Configuration

GithooksConfig

interface GithooksConfig {
  path?: string; // Custom hooks directory
  hooks?: {
    // Hook scripts
    [key in GithooksName]?: string;
  };
  gitConfig?: object; // Additional Git config
  extends?: string | [string]; // Base config to extend
}

Contributing

Please read our Contributing Guide before submitting a Pull Request to the project.

License

MIT © Funish