Skip to content

Build: Upgrade husky from v4 to v9#34027

Merged
kasperpeulen merged 1 commit into
nextfrom
kasper/upgrade-husky-v9
Mar 5, 2026
Merged

Build: Upgrade husky from v4 to v9#34027
kasperpeulen merged 1 commit into
nextfrom
kasper/upgrade-husky-v9

Conversation

@kasperpeulen
Copy link
Copy Markdown
Member

@kasperpeulen kasperpeulen commented Mar 5, 2026

What I did

Upgraded husky from v4 to v9 to fix git hooks breaking in worktrees.

Husky v4 configured hooks via package.json and used husky.local.sh for path resolution, which got overwritten on every yarn install in a worktree (the monorepo cd path was wrong).

Husky v9 uses plain shell scripts in .husky/ and core.hooksPath, which works correctly across worktrees.

  • Replace package.json husky config with .husky/pre-commit shell script
  • Add prepare script and husky dependency to root package.json
  • Run lint-staged in both code/ and scripts/ directories
  • Preserve SKIP_STORYBOOK_GIT_HOOKS escape hatch
  • Remove husky v4 from code/ and scripts/ package.json

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

  1. Run yarn install at the repo root — verify git config core.hooksPath is .husky/_
  2. Make a lint error, stage it, try to commit — verify lint-staged catches it
  3. Set SKIP_STORYBOOK_GIT_HOOKS=1 — verify hooks are skipped
  4. Create a new worktree — verify hooks work there too

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3a72e579-21b4-4572-aaed-e2ba94868889

📥 Commits

Reviewing files that changed from the base of the PR and between bd11a6b and 2621d24.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (4)
  • .husky/pre-commit
  • code/package.json
  • package.json
  • scripts/package.json
💤 Files with no reviewable changes (2)
  • scripts/package.json
  • code/package.json

📝 Walkthrough

Walkthrough

This PR consolidates Husky Git hooks configuration from subdirectory package.json files to the root level. It removes husky from code/ and scripts/ package.json files, adds husky as a devDependency to the root package.json with a prepare script, and introduces a new .husky/pre-commit hook that conditionally runs lint-staged.

Changes

Cohort / File(s) Summary
Husky removal from subdirectories
code/package.json, scripts/package.json
Removes husky configuration block and dependency from both subdirectory package.json files.
Root-level Husky setup
package.json
Adds husky ^9.1.7 as devDependency and defines prepare script to initialize Husky.
Git hooks configuration
.husky/pre-commit
New pre-commit hook script that conditionally runs lint-staged in both code/ and scripts/ directories when SKIP_STORYBOOK_GIT_HOOKS is not set.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Comment @coderabbitai help to get the list of available commands and usage tips.

@kasperpeulen kasperpeulen force-pushed the kasper/upgrade-husky-v9 branch from bd11a6b to 78601a6 Compare March 5, 2026 13:37
Husky v4 configured hooks via package.json and used husky.local.sh for
path resolution, which broke in git worktrees (the monorepo cd path got
overwritten on every yarn install).

Husky v9 uses plain shell scripts in .husky/ and sets core.hooksPath,
which works correctly across worktrees without any postinstall hacks.

- Replace package.json husky config with .husky/pre-commit script
- Add prepare script and husky dependency to root package.json
- Run lint-staged in both code/ and scripts/ directories
- Preserve SKIP_STORYBOOK_GIT_HOOKS escape hatch
- Remove husky v4 from code/ and scripts/ package.json
@kasperpeulen kasperpeulen force-pushed the kasper/upgrade-husky-v9 branch from 78601a6 to 2621d24 Compare March 5, 2026 13:40
@kasperpeulen kasperpeulen added the build Internal-facing build tooling & test updates label Mar 5, 2026
@kasperpeulen kasperpeulen changed the title Upgrade husky from v4 to v9 Build: Upgrade husky from v4 to v9 Mar 5, 2026
@kasperpeulen kasperpeulen added the ci:normal Run our default set of CI jobs (choose this for most PRs). label Mar 5, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit 2621d24

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ❌ Failed 13m 45s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-05 14:00:13 UTC

@kasperpeulen kasperpeulen merged commit b8033d6 into next Mar 5, 2026
19 of 27 checks passed
@kasperpeulen kasperpeulen deleted the kasper/upgrade-husky-v9 branch March 5, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:normal Run our default set of CI jobs (choose this for most PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant