Run Husky pre-commit hooks with PNPM rather than NPM - #2548
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe changes add pnpm-first command execution for Husky setup and lint-staged pre-commit checks. Each command falls back to an equivalent npx command when the pnpm command fails. ChangesPackage manager fallback commands
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.husky/pre-commit:
- Line 1: Update the pre-commit command so the directory change is handled
separately and failure does not trigger the fallback. After entering
frontend/viewer, select pnpm exec lint-staged when pnpm is available, and use
npx lint-staged only when pnpm is unavailable; preserve the lint-staged exit
status.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4837cdc8-e140-4946-930b-2d928bc8b05d
📒 Files selected for processing (2)
.husky/pre-commitTaskfile.yml
Keep the extension glob in the husky hook and only invoke lint-staged when a matching file is actually staged, so backend-only commits work without node_modules. Co-authored-by: Cursor <cursoragent@cursor.com>
|
ok it turns out |
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
The hook needed frontend/viewer/node_modules to already exist, so a fresh worktree had to run pnpm install before any commit touching a prettier-managed file. Install it from the hook instead (gated on the same staged-file check, so backend-only commits still skip Node). --frozen-lockfile keeps a commit from rewriting pnpm-lock.yaml. Also drop the npx fallback for husky: npm can't install this repo at all (pnpm-workspace.yaml catalogs, pinned packageManager), so the fallback only fires where nothing else works, and it hides real pnpm failures. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The check probes for the lint-staged binary, so an interrupted install (dir present, binary absent) reported a missing directory that was right there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
myieye
left a comment
There was a problem hiding this comment.
Looks good!
I took it a slightly gutsy step further: the hook runs pnpm install if lint-staged is not yet available.
I feel like that'll mostly only ever happen when we want it to, so it seemed like an improvement.
The `set --` syntax pushes items into `$1`, `$2`, and so on, then the `for` loop without an `in` clause loops over the script parameters. But since these parameters aren't used elsewhere, it's simpler to just loop over the list explicitly, and this avoids overwriting script parameters if the pre-commit hook is ever changed to be called with params.
rmunn
left a comment
There was a problem hiding this comment.
LGTM. Can't approve since GitHub considers me the author.
Use PNPM first if it's there, fall back to NPM if PNPM not available.
Would make it slightly easier for me to create a minimal VM to run Claude Code: we use PNPM almost everywhere, but pre-commit hooks still require NPM. I'd rather not have NPM installed in my VM at all, and this would make that possible.