Skip to content

fix: only run husky in a git checkout so npm consumers don't break#3211

Merged
oliverlaz merged 1 commit into
masterfrom
fix/husky-postinstall-npm-consumers
Jun 5, 2026
Merged

fix: only run husky in a git checkout so npm consumers don't break#3211
oliverlaz merged 1 commit into
masterfrom
fix/husky-postinstall-npm-consumers

Conversation

@oliverlaz
Copy link
Copy Markdown
Member

@oliverlaz oliverlaz commented Jun 5, 2026

🎯 Goal

postinstall ran husky unconditionally. npm executes a dependency's postinstall for every consumer, but husky is a devDependency and isn't installed in a consumer's tree, so npm install stream-chat-react failed:

npm error code 127
npm error sh: husky: command not found

This ports the same fix already merged for the JS SDK in GetStream/stream-chat-js#1764 β€” stream-chat-react had the identical "postinstall": "husky".

πŸ›  Implementation details

Why husky has to stay in postinstall: Yarn Berry (this repo's package manager) runs the root workspace's postinstall on yarn install but not its prepare. Moving husky to prepare would silently stop installing contributors' git hooks. husky must stay in postinstall; the fix is to stop running it for consumers.

  • postinstall now invokes a dev-only scripts/install-husky.mjs only when it is present β€” and that file is intentionally not in package.json#files (which publishes only dist, package.json, README.md, AI.md), so consumers never receive it and the guard short-circuits to a no-op.
  • The invocation runs via node (not a shell || true) so it's cross-platform β€” npm runs consumer postinstalls through cmd.exe on Windows, where ||/true aren't valid.
  • scripts/install-husky.mjs runs husky only inside a git checkout, and lets genuine husky setup errors surface (not swallowed) so contributors learn if hook installation actually fails.

Note: unlike the JS SDK PR (which left prepare: yarn run build untouched), this repo uses prepack: yarn build and has no prepare script, so nothing there needed changing β€” the husky fix is independent of it.

Verified locally:

Scenario Result
Consumer (no scripts/install-husky.mjs) exit 0 Β· husky never executed
Contributor (.git + script present) core.hooksPath=.husky/_ Β· hooks installed Β· exit 0

yarn prettier and yarn eslint clean on both changed files.

🎨 UI Changes

None β€” build/install tooling only.

Summary by CodeRabbit

  • Chores
    • Improved post-install script configuration to make Git hook initialization more reliable and conditional based on repository presence.

postinstall ran husky unconditionally. npm executes a dependency's
postinstall for every consumer, but husky is a devDependency and isn't
installed in a consumer's tree, so `npm install stream-chat-react` failed
with `code 127 Β· husky: command not found`.

Yarn Berry runs the root workspace's postinstall on `yarn install` but not
its prepare, so husky must stay in postinstall; the fix is to stop running
it for consumers. postinstall now invokes a dev-only scripts/install-husky.mjs
only when present, and that file is intentionally not in package.json#files,
so consumers never receive it and the guard short-circuits to a no-op. The
invocation runs via node (not a shell `|| true`) for Windows compatibility,
and genuine husky setup errors surface instead of being swallowed.

Ports GetStream/stream-chat-js#1764.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 96b0af7c-6687-4854-9829-079c68b2a147

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between e2c53c2 and 3f8af1f.

πŸ“’ Files selected for processing (2)
  • package.json
  • scripts/install-husky.mjs

πŸ“ Walkthrough

Walkthrough

The PR updates the post-install setup to conditionally initialize Husky Git hooks. The postinstall script in package.json now calls a new Node ESM helper (scripts/install-husky.mjs) that checks for a .git directory before importing and running Husky, avoiding failures in non-checkout environments.

Changes

Conditional Husky Installation

Layer / File(s) Summary
Conditional Husky installation helper
package.json, scripts/install-husky.mjs
The postinstall script invokes a new ESM helper that conditionally imports Husky only when a .git directory is present, preventing initialization errors in non-repository contexts.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A hook installer, wrapped in guard,
Checks for .git when times are hardβ€”
No errors when the repo's not there,
Just peaceful installs, safe and fair! 🌿

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately and concisely summarizes the main change: preventing Husky from running for npm consumers by guarding execution to git checkouts only.
Description check βœ… Passed The description follows the template with comprehensive Goal, Implementation details, and UI Changes sections, clearly explaining the problem, solution, technical reasoning, and verification.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/husky-postinstall-npm-consumers

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.

❀️ Share

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Size Change: 0 B

Total Size: 656 kB

ℹ️ View Unchanged
Filename Size
dist/cjs/audioProcessing.js 1.74 kB
dist/cjs/emojis.js 2.54 kB
dist/cjs/index.js 255 kB
dist/cjs/mp3-encoder.js 814 B
dist/cjs/ReactPlayerWrapper.js 545 B
dist/cjs/useNotificationApi.js 49.8 kB
dist/css/emoji-picker.css 178 B
dist/css/emoji-replacement.css 456 B
dist/css/index.css 39.7 kB
dist/es/audioProcessing.mjs 1.65 kB
dist/es/emojis.mjs 2.47 kB
dist/es/index.mjs 252 kB
dist/es/mp3-encoder.mjs 768 B
dist/es/ReactPlayerWrapper.mjs 485 B
dist/es/useNotificationApi.mjs 48.6 kB

compressed-size-action

@oliverlaz oliverlaz merged commit 640bf4b into master Jun 5, 2026
11 of 12 checks passed
@oliverlaz oliverlaz deleted the fix/husky-postinstall-npm-consumers branch June 5, 2026 15:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 83.92%. Comparing base (2faa620) to head (3f8af1f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3211   +/-   ##
=======================================
  Coverage   83.92%   83.92%           
=======================================
  Files         439      439           
  Lines       13222    13222           
  Branches     4293     4293           
=======================================
  Hits        11097    11097           
  Misses       2125     2125           

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

github-actions Bot pushed a commit that referenced this pull request Jun 5, 2026
## [14.4.1](v14.4.0...v14.4.1) (2026-06-05)

### Bug Fixes

* only run husky in a git checkout so npm consumers don't break ([#3211](#3211)) ([640bf4b](640bf4b))
@stream-ci-bot
Copy link
Copy Markdown

πŸŽ‰ This PR is included in version 14.4.1 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants