This repository uses Husky to manage git hooks and enforce code quality standards before commits.
All package.json files must use strict versioning for npm dependencies. This means:
- ❌ Not allowed:
^1.2.3,~1.2.3(caret and tilde prefixes) - ✅ Allowed:
1.2.3(exact version)
Special version formats that are allowed:
workspace:*,workspace:^,workspace:~(pnpm workspace protocol)file:../path/to/package(local file dependencies)link:../path/to/package(symlinked packages)npm:package@version(npm alias)git+https://...(git URLs)http://...,https://...(tarball URLs)*,latest(special version keywords)
When you attempt to commit changes that include modifications to any package.json file, the pre-commit hook will:
- Identify all staged
package.jsonfiles - Validate that all dependency versions use strict versioning
- Block the commit if non-strict versions are found
- Display which files and dependencies need to be fixed
{
"dependencies": {
"express": "^4.18.0",
"lodash": "~4.17.21"
}
}{
"dependencies": {
"express": "4.18.0",
"lodash": "4.17.21"
}
}You can manually run the validation script at any time:
node common/scripts/validate-package-versions.js path/to/package.jsonOr validate multiple files:
node common/scripts/validate-package-versions.js workspaces/*/package.jsonIn exceptional circumstances, you can bypass the pre-commit hook:
git commit --no-verify -m "your message"Warning: Bypassing hooks should only be done when absolutely necessary and with good reason.
The hooks are automatically installed when you run:
pnpm installThis triggers the prepare script which initializes Husky.
If the pre-commit hook isn't running:
- Ensure you're in a git repository:
git status - Check that Husky is installed:
ls .husky - Reinstall hooks:
pnpm run prepare - Verify git hooks are enabled:
git config core.hooksPath
If you get permission errors:
chmod +x .husky/pre-commit
chmod +x common/scripts/validate-package-versions.jsTo add additional pre-commit checks:
- Edit
.husky/pre-commit - Add your validation logic
- Ensure the script exits with code 1 on failure, 0 on success
Example:
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Existing validation...
# Add new validation
echo "🔍 Running lint checks..."
pnpm run lint
if [ $? -ne 0 ]; then
echo "❌ Lint failed"
exit 1
fi