<p align="center"<img src=".github/art/cover.jpg" alt="Social Card of this repo"</p
bun-git-hooks
A Bun-optimized TypeScript library for managing Git hooks with a robust set of configuration options.
Features
- 🎯 Simple Configuration Easy setup through multiple config file formats
- 🔄 Automatic Installation Hooks are installed on package installation
- 🛡️ Type Safe Written in TypeScript with comprehensive type definitions
- 🔧 Flexible Config Supports .ts, .js, .mjs, .json configurations
- 💪 Robust Handles complex Git workspace configurations
- 🚫 Skip Option Environment variable to skip hook installation
- 🧹 Cleanup Optional cleanup of unused hooks
- 📦 Zero Dependencies Minimal footprint
- ⚡ Fast Built for Bun with performance in mind
- 🔍 Verbose Mode Detailed logging for troubleshooting
- 🔀 Staged Lint Run commands only on staged files that match specific patterns
Installation
bun add -D bun-git-hooksUsage
Basic Configuration
Create a git-hooks.config.{ts,js,mjs,cjs,mts,cts,json} (git-hooks.ts works too) file in your project root:
// git-hooks.config.ts
import type { GitHooksConfig } from 'bun-git-hooks'
const config: GitHooksConfig = {
'pre-commit': 'bun run lint && bun run test',
'commit-msg': 'bun commitlint --edit $1',
'pre-push': 'bun run build',
'verbose': true,
}
export default configJSON Configuration
{
"git-hooks": {
"pre-commit": "bun run lint && bun run test",
"commit-msg": "bun commitlint --edit $1",
"pre-push": "bun run build"
}
}CLI Usage
# Install hooks from config
git-hooks
# alternatively, trigger the CLI with bunx
bunx git-hooks
bunx bun-git-hooks
# Use specific config file
git-hooks ./custom-config.ts
# Remove all hooks
git-hooks uninstallEnable verbose logging
git-hooks --verbose