Skip to content

Commit 3f5bf93

Browse files
fix: add husky install fallback
1 parent faa7ed2 commit 3f5bf93

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

.husky/install.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Skip Husky installation in environments where dev dependencies may be omitted
2+
if (
3+
process.env.NODE_ENV === 'production' ||
4+
process.env.CI === 'true' ||
5+
process.env.HUSKY === '0'
6+
) {
7+
process.exit(0);
8+
}
9+
10+
try {
11+
const { install } = await import('husky');
12+
13+
// Only call install if it exists (safe check)
14+
if (typeof install === 'function') {
15+
install();
16+
}
17+
} catch (error) {
18+
// Ignore error if husky is not installed (e.g., production/CI environments)
19+
if (
20+
error?.code === 'ERR_MODULE_NOT_FOUND' ||
21+
error?.message?.includes("Cannot find package 'husky'")
22+
) {
23+
process.exit(0);
24+
}
25+
26+
// Re-throw other unexpected errors
27+
throw error;
28+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
"docker:cover:integration": "pnpm run docker:integration:run pnpm exec nyc --report-dir .coverage/integration pnpm run test:integration -- -p cover",
9494
"postdocker:integration:run": "docker compose -f ./test/integration/docker-compose.yml down",
9595
"prepack": "pnpm run build",
96-
"prepare": "husky install || exit 0",
96+
"prepare": "node .husky/install.mjs",
9797
"changeset:version": "changeset version && pnpm install --lockfile-only",
9898
"changeset:publish": "changeset publish"
9999
},

0 commit comments

Comments
 (0)