2.5 KiB
2.5 KiB
Research: Pre-Commit Gate
R1: Hook Management Tool
Decision: Use Lefthook (npm package) as the Git hooks manager.
Rationale:
- User explicitly requested Lefthook.
- Lightweight, standalone Go binary distributed via npm -- no runtime dependencies.
- Simple YAML configuration (
lefthook.yml). - Auto-installs hooks via npm
postinstalllifecycle script -- satisfies FR-005 (no manual setup). - Well-maintained, widely adopted (used by n8n, Shopify, and others).
- Respects
--no-verifyby default (standard Git behavior) -- satisfies FR-006.
Alternatives considered:
- Husky: Popular but heavier configuration, requires
.husky/directory with shell scripts. core.hooksPath: Native Git, but requires manual setup or custom scripts for auto-install.- Simple
preparescript copying a shell script: Works but no parallel jobs, no structured config.
R2: Auto-Install Mechanism
Decision: Use a prepare script in root package.json that runs lefthook install.
Rationale:
- The
preparelifecycle hook runs automatically afterpnpm install. - This ensures every developer gets hooks installed without extra steps after cloning.
- Lefthook's npm package includes a
postinstallscript that can auto-install, but an explicitpreparescript is more transparent and reliable across package managers. - In CI environments,
CI=trueprevents thepreparescript from running (standard npm/pnpm behavior), avoiding unnecessary hook installation in CI.
Alternatives considered:
- Relying solely on lefthook's built-in
postinstall: Less transparent; behavior varies withCIenv var. - Manual
lefthook installstep in README: Violates FR-005.
R3: Hook Command Strategy
Decision: The pre-commit hook runs pnpm check as a single command.
Rationale:
pnpm checkalready orchestrates format, lint, typecheck, and test in sequence.- Running it as one command keeps the hook configuration minimal and consistent with the existing merge-gate workflow.
- Output from
pnpm checkalready identifies which specific check failed (FR-004, SC-004).
Alternatives considered:
- Running each check as a separate Lefthook job with
parallel: true: Could be faster but adds configuration complexity and the existingpnpm checkscript already handles sequencing. MVP baseline does not include parallel hook jobs. - Using
{staged_files}for file-scoped checks: MVP baseline does not include staged-only checking per spec assumptions.