Commit 640bf4b
authored
fix: only run husky in a git checkout so npm consumers don't break (#3211)
### π― 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](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.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Chores**
* Improved post-install script configuration to make Git hook
initialization more reliable and conditional based on repository
presence.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent e2c53c2 commit 640bf4b
2 files changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments