Zero-dependency git hooks for Deno projects. Run your tasks automatically before commits and pushes.
- Pure Deno - No Python (pre-commit) or Node.js (Husky) required
- Fast - Runs in milliseconds, no complex runtime
- Simple - Just shell commands, no magic
- Transparent - Generated hooks are readable bash scripts
Run this command in your Deno project:
deno run -A jsr:@theswanfactory/deno-hooksThat's it! If you don't have a configuration file, it will offer to create one for you with sensible defaults.
Hooks run automatically on every commit:
git commit -m "fix: typo"
# Running pre-commit hooks...
# deno task fmt
# deno task lint
# ✓ All hooks passedAdd to your deno.json so you can run deno task hooks:
{
"imports": {
"deno-hooks": "jsr:@theswanfactory/deno-hooks@^0.3.0"
},
"tasks": {
"hooks": "deno run -A deno-hooks"
}
}hooks:
pre-commit:
- deno task fmt
- deno task lint
pre-push:
- deno task testThat's it! Each hook is just a list of commands to run.
{
"tasks": {
"fmt": "deno fmt --check",
"lint": "deno lint",
"test": "deno test -A"
}
}You can also configure hooks directly in deno.json:
{
"tasks": {
"fmt": "deno fmt --check",
"lint": "deno lint",
"test": "deno test -A"
},
"deno-hooks": {
"pre-commit": [
"deno task fmt",
"deno task lint"
],
"pre-push": [
"deno task test"
]
}
}# Skip interactive prompts (use defaults)
deno run -A jsr:@theswanfactory/deno-hooks --yes
# Show detailed output during installation
deno run -A jsr:@theswanfactory/deno-hooks --verbose
# Show help
deno run -A jsr:@theswanfactory/deno-hooks --help| Option | Short | Description |
|---|---|---|
--yes |
-y |
Skip interactive prompts and use defaults |
--verbose |
-v |
Show detailed output |
--help |
-h |
Show help message |
When you install, deno-hooks generates self-contained shell scripts in
.git/hooks/:
#!/bin/sh
# Generated by deno-hooks - DO NOT EDIT
# To update, run: deno task hooks
set -e
deno task fmt
deno task lint
echo "✓ All hooks passed"Key features:
- Self-contained: No reference to deno-hooks
- Simple: Just runs commands in order
- Fail-fast:
set -estops on first error - Transparent: Easy to read and debug
hooks:
pre-commit:
- deno task fmt
- deno task linthooks:
pre-push:
- deno task testhooks:
pre-commit:
- deno task fmt
- deno task lint
- deno run -A scripts/check-todos.ts
- ./scripts/validate.shhooks:
pre-commit:
- deno task fmt
- deno task lint
- deno task typecheck
pre-push:
- deno task test
- deno task test:integration
- deno run -A scripts/build.tsYou can configure any standard git hook:
- pre-commit - Before commits (most common)
- pre-push - Before pushing to remote
- commit-msg - Validate commit messages
- pre-rebase - Before rebasing
- And more - see git hooks documentation
Hooks not running?
# Reinstall hooks
deno task hooks
# Or with verbose output to see what's happening
deno task hooks --verbosePermission errors?
# Hooks need -A flag for full permissions
deno run -A jsr:@theswanfactory/deno-hooksWant to skip hooks temporarily?
# Use --no-verify flag
git commit --no-verify -m "emergency fix"Need to debug?
# Check what hooks are installed
cat .git/hooks/pre-commit
# Run hooks manually to see output
./.git/hooks/pre-commitYou can run the same tasks in CI/CD:
# GitHub Actions example
- name: Format check
run: deno task fmt
- name: Lint
run: deno task lint
- name: Tests
run: deno task testSince hooks just run deno task commands, your CI and git hooks stay in sync.
Version 1.0.0 is a major simplification. The old format:
# OLD (v0.2.x)
hooks:
pre-commit:
- id: deno-fmt
run: deno-fmt
glob: "*.{ts,js}"
pass_filenames: trueBecomes:
# NEW (v1.0.0+)
hooks:
pre-commit:
- deno task fmtKey changes:
- No more built-in hooks (
deno-fmt,deno-lint,deno-test) - No more file glob patterns
- No more
pass_filenameslogic - Just simple shell commands
Why simpler?
- File filtering is git's job (staged files)
- Deno tasks handle their own file discovery
- Less magic = easier to understand and debug
- Generated hooks work without deno-hooks installed
- Contributing Guide - Developer documentation
- Changelog - Version history
- JSR Package - Published package
MIT