diff --git a/package.json b/package.json index 44b0b2d9c..e5d1c58f0 100644 --- a/package.json +++ b/package.json @@ -196,7 +196,7 @@ "start:css": "node scripts/watch-styling.mjs", "start:tutorial": "yarn workspace @stream-io/stream-chat-react-tutorial dev", "start:vite": "yarn workspace @stream-io/stream-chat-react-vite dev", - "postinstall": "husky", + "postinstall": "node -e \"require('fs').existsSync('scripts/install-husky.mjs') && import('./scripts/install-husky.mjs')\"", "test": "vitest run", "test:watch": "vitest", "types": "tsc --emitDeclarationOnly false --noEmit", diff --git a/scripts/install-husky.mjs b/scripts/install-husky.mjs new file mode 100644 index 000000000..a00e4212b --- /dev/null +++ b/scripts/install-husky.mjs @@ -0,0 +1,11 @@ +import { existsSync } from 'node:fs'; + +// husky installs this repo's local git hooks and is a dev-only dependency. It is +// invoked from a presence-guarded postinstall (see package.json) so it never runs +// for consumers — this file is intentionally not published. The .git check is a +// secondary guard for non-checkout environments; husky's own default() already +// no-ops gracefully on a missing .git or HUSKY=0, and any genuine setup error is +// left to surface rather than be swallowed. See GetStream/stream-chat-js#1763. +if (existsSync('.git')) { + (await import('husky')).default(); +}