Skip to content

chore: upgrade husky from 4.x to 9.x #430

@hb2708

Description

@hb2708

Summary

Upgrade husky from 4.2.5 to 9.x. This is a complete configuration format change — v4 uses package.json hooks, while v9 uses a .husky/ directory with shell scripts.

Current → Target

Package Current Latest
husky 4.2.5 9.1.7

Why Upgrade

  • v4 is unmaintained and uses a deprecated installation approach
  • v9 is faster, simpler, and uses native Git hooks
  • Smaller install footprint

Migration Steps

  1. Remove old husky config from package.json:
    // DELETE this block from package.json:
    "husky": {
      "hooks": {
        "pre-commit": "yarn ci"
      }
    }
  2. Install and initialize:
    yarn add --dev husky@latest
    npx husky init
  3. Create the pre-commit hook:
    echo 'yarn ci' > .husky/pre-commit
  4. Add prepare script to package.json:
    "scripts": {
      "prepare": "husky"
    }
  5. Test — make a commit and verify the pre-commit hook runs yarn ci
  6. Add .husky/ directory to git

Files Affected

  • package.json — remove husky.hooks, add prepare script, upgrade dependency
  • .husky/pre-commit — new file with hook script

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions