From 1d5a68e6aa03df2139681c2fd0e700510502fe6c Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Sun, 6 Sep 2026 21:00:07 +0800 Subject: [PATCH] chore: replace native pre-commit hook with husky running pnpm test --- .husky/pre-commit | 1 + package.json | 5 +++-- pnpm-lock.yaml | 10 ++++++++++ scripts/install-hooks.sh | 17 ----------------- 4 files changed, 14 insertions(+), 19 deletions(-) create mode 100644 .husky/pre-commit delete mode 100644 scripts/install-hooks.sh diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..98475b5 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm test diff --git a/package.json b/package.json index e311d90..25d0c5e 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "test": "pnpm run typecheck && vitest run --coverage", "coverage": "vitest run --coverage", "release": "bash scripts/publish.sh", - "hooks": "bash scripts/install-hooks.sh", - "social-preview": "node docs/social-preview/generate.ts" + "social-preview": "node docs/social-preview/generate.ts", + "prepare": "husky" }, "dsh": { "bundle": { @@ -110,6 +110,7 @@ "@types/react-dom": "^19.2.4", "@vitest/coverage-v8": "^4.1.11", "eslint-plugin-sonarjs": "^4.2.0", + "husky": "^9.1.7", "jsdom": "^30.0.1", "lightningcss": "^1.33.0", "oxlint": "1.76.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8d0f6c..69500e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -54,6 +54,9 @@ importers: eslint-plugin-sonarjs: specifier: ^4.2.0 version: 4.2.0(eslint@10.8.1) + husky: + specifier: ^9.1.7 + version: 9.1.7 jsdom: specifier: ^30.0.1 version: 30.0.1 @@ -1247,6 +1250,11 @@ packages: html-void-elements@3.0.0: resolution: {integrity: sha512-bEqo66MRXsUGxWHV5IP0PUiAWwoEjba4VCzg0LjFJBpchPaTfyfCKTG6bc5F8ucKec3q5y6qOdGyYTSBEvhCrg==} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + ignore@5.3.2: resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==} engines: {node: '>= 4'} @@ -2967,6 +2975,8 @@ snapshots: html-void-elements@3.0.0: {} + husky@9.1.7: {} + ignore@5.3.2: {} import-without-cache@0.4.0: {} diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh deleted file mode 100644 index 48d467d..0000000 --- a/scripts/install-hooks.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# Installs a native pre-commit hook that runs `pnpm run typecheck`. Git only -# executes .git/hooks when `core.hooksPath` is unset (husky sets it to .husky/_). -set -euo pipefail - -ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -HOOKS_DIR="$ROOT/.git/hooks" - -mkdir -p "$HOOKS_DIR" - -cat > "$HOOKS_DIR/pre-commit" <<'EOF' -#!/usr/bin/env sh -pnpm run typecheck -EOF - -chmod +x "$HOOKS_DIR/pre-commit" -echo "pre-commit hook installed at .git/hooks/pre-commit"