Skip to content

fix: improve Husky installation strategy for CI and Docker builds#7

Merged
stephschofield merged 2 commits into
shyamsridhar123:mainfrom
stephschofield:main
Jan 9, 2026
Merged

fix: improve Husky installation strategy for CI and Docker builds#7
stephschofield merged 2 commits into
shyamsridhar123:mainfrom
stephschofield:main

Conversation

@stephschofield
Copy link
Copy Markdown
Collaborator

Problem

Previous builds were failing with husky: not found errors in CI and Docker environments because the prepare script tried to run Husky when devDependencies weren't installed.

Solution

Replaced the prepare script with a smart postinstall script that:

  • Checks for the existence of a .git directory
  • Only installs git hooks in actual development environments
  • Gracefully skips installation in CI, Docker builds, and npm package installs
  • Requires no environment variable configuration

Changes

  • package.json: Changed preparepostinstall with .git directory check
  • Dockerfile: Removed HUSKY=0 workaround (no longer needed)
  • .github/workflows/ci.yml: Removed HUSKY=0 workaround (no longer needed)

This is a cleaner, more robust solution that automatically handles all deployment scenarios without manual configuration.

Testing

✅ Works in development (git hooks install)
✅ Works in CI (gracefully skips)
✅ Works in Docker builds (gracefully skips)

Setting HUSKY=0 environment variable prevents Husky from running
during CI and Docker builds where git hooks are not needed. This
fixes the 'husky: not found' error when npm ci --omit=dev skips
installing devDependencies.
Instead of using HUSKY=0 environment variable, use postinstall script
that checks for .git directory existence. This automatically installs
git hooks only in development environments where a git repository exists,
and skips installation in CI, Docker builds, and npm package installs.

This is a cleaner solution that doesn't require environment variable
configuration and handles all edge cases gracefully.
@stephschofield stephschofield merged commit d01625f into shyamsridhar123:main Jan 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant