bun-git-hooks โ
A modern, zero-dependency tool for managing git hooks in Bun projects with a robust set of configuration options.
Introduction โ
bun-git-hooks
is a powerful tool designed to simplify git hooks management in your Bun projects. It provides a type-safe, flexible way to configure and manage your git hooks with minimal setup.
Key Features โ
- ๐ฏ Simple Configuration: Easy setup through multiple config file formats
- ๐ Automatic Installation: Hooks are installed automatically during 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 variables to skip hook installation or execution
- ๐งน Cleanup: Optional cleanup of unused hooks
- ๐ฆ Zero Dependencies: Minimal footprint
- โก Fast: Built for Bun with performance in mind
- ๐ Verbose Mode: Detailed logging for troubleshooting
Why bun-git-hooks? โ
Git hooks are powerful tools for automating tasks in your development workflow, but they can be challenging to manage and distribute across a team. bun-git-hooks
solves this by:
- Simplifying Configuration: Use TypeScript/JavaScript/JSON to define your hooks
- Ensuring Consistency: Automatically install hooks for all team members
- Providing Flexibility: Skip hooks when needed with environment variables
- Type Safety: Get IDE autocompletion and type checking for your configurations
Quick Start โ
- Install the package:
bun add -D bun-git-hooks
- Create a configuration file (e.g.,
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 config
- The hooks will be automatically installed when you run
bun install
Configuration Options โ
Supported Config Files โ
git-hooks.config.ts
(TypeScript)git-hooks.config.js
(JavaScript)git-hooks.config.cjs
(CommonJS)git-hooks.config.json
(JSON)package.json
(withgitHooks
field)
Environment Variables โ
SKIP_BUN_GIT_HOOKS
: Set to "1" to skip hook executionBUN_GIT_HOOKS_RC
: Path to initialization scriptSKIP_INSTALL_GIT_HOOKS
: Set to "1" to skip hook installation
Advanced Features โ
Custom Initialization Scripts โ
Create a .git-hooks.rc
file to set up environment variables or perform custom initialization:
#!/bin/bash
export NODE_ENV=development
export CUSTOM_VAR=value
Skip Hooks Temporarily โ
# Skip hooks for a single command
SKIP_BUN_GIT_HOOKS=1 git commit -m "message"
# Skip hook installation
SKIP_INSTALL_GIT_HOOKS=1 bun install
Troubleshooting โ
Common Issues โ
Hooks not installing
- Ensure
bun-git-hooks
is in yourdevDependencies
- Check if
SKIP_INSTALL_GIT_HOOKS
is not set to "1" - Verify your configuration file is valid
- Ensure
Hooks not executing
- Check if
SKIP_BUN_GIT_HOOKS
is not set to "1" - Verify hook scripts have execute permissions
- Enable verbose mode in config for detailed logs
- Check if
TypeScript configuration issues
- Ensure you're using the correct type imports
- Check your
tsconfig.json
includes the package types
Stargazers โ
Community โ
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Postcardware โ
Two things are true: Stacks OSS will always stay open-source, and we do love to receive postcards from wherever Stacks is used! ๐
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094
Sponsors โ
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
License โ
The MIT License (MIT). Please see LICENSE for more information.
Made with ๐