@proplan-utvikling/husky
v1.0.1
Published
Shared Husky git hook scripts for Proplan applications.
Readme
husky/
Git hook scripts for Node.js projects (Angular and Azure Functions).
Copy the hooks you need into your project's .husky/ directory.
Contents
| File | Git hook | Runs |
| ------------------ | -------------------------------------- | ---------------------------------------------------- |
| pre-commit | Before every commit | lint-staged — lint and format staged files only |
| commit-msg | After writing the commit message | commitlint — validates Conventional Commits format |
| pre-push | Before every push | npm test — full unit test run |
| pre-merge-commit | Before a non-fast-forward merge commit | lint-staged — quality check on merged files |
Prerequisites
Install the required packages in your application repo:
# Husky and lint-staged (for pre-commit and pre-merge-commit hooks)
npm install --save-dev husky lint-staged
# commitlint (for commit-msg hook)
npm install --save-dev @commitlint/cli @commitlint/config-conventionalSetup
1. Initialise Husky
# Husky v9
npx husky init
# Husky v8
npx husky install2. Add the prepare script to package.json
{
"scripts": {
"prepare": "husky"
}
}This ensures hooks are installed automatically after npm install.
3. Copy hook files
cp husky/pre-commit .husky/pre-commit
cp husky/commit-msg .husky/commit-msg
cp husky/pre-push .husky/pre-push
cp husky/pre-merge-commit .husky/pre-merge-commitMake them executable (Linux/macOS and WSL):
chmod +x .husky/pre-commit .husky/commit-msg .husky/pre-push .husky/pre-merge-commit4. Configure lint-staged in package.json
{
"lint-staged": {
"*.{ts,html}": ["eslint --fix"],
"*.{ts,js,json,html,scss,css,md}": ["prettier --write"]
}
}5. Configure commitlint
Create commitlint.config.cjs in your project root:
module.exports = { extends: ["@commitlint/config-conventional"] };Accepted commit types: feat | fix | docs | style | refactor | perf | test | build | ci | chore | revert
Example valid commit messages:
feat(auth): add JWT refresh token support
fix: handle null response from API
chore(deps): bump eslint from 8.0.0 to 9.0.0Husky v8 vs v9
The hook files default to Husky v9 (plain shell, no boilerplate). If your project uses Husky v8, uncomment the two lines at the top of each hook and remove the bare command:
# v8 form — uncomment these two lines
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged
# and remove this line
npx lint-stagedCI pipelines
In CI, Husky's prepare script must not attempt to install git hooks (there is no .git directory with write access on the build agent). Use the shared pipeline template to disable this automatically:
# In your azure-pipelines.yml job steps — place BEFORE npm ci
steps:
- template: pipelines/templates/shared/husky.yml@infrastructure
parameters:
skipInCI: true # sets HUSKY=0 for all subsequent steps (default: true)
runHooks: # optional: re-run specific hooks as CI quality gates
- pre-commit # runs sh .husky/pre-commit on the build agentSee pipelines/templates/shared/husky.yml for full parameter reference.
