diff --git a/.husky/pre-commit b/.husky/pre-commit index 72c4429..88744bf 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1,2 @@ -npm test +npx lint-staged +bash scripts/pre-commit-tests.sh diff --git a/scripts/pre-commit-tests.sh b/scripts/pre-commit-tests.sh new file mode 100755 index 0000000..4c74316 --- /dev/null +++ b/scripts/pre-commit-tests.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Detect which workspace packages have staged .ts/.tsx files and run tests +# only for those packages via turbo --filter. + +STAGED_TS_FILES=$(git diff --cached --name-only --diff-filter=ACMR -- '*.ts' '*.tsx') + +if [ -z "$STAGED_TS_FILES" ]; then + exit 0 +fi + +FILTERS="" +SEEN="" + +while IFS= read -r file; do + case "$file" in + apps/api/*) pkg="@goodgo/api" ;; + apps/web/*) pkg="@goodgo/web" ;; + libs/mcp-servers/*) pkg="@goodgo/mcp-servers" ;; + *) continue ;; + esac + + if [[ ! " $SEEN " =~ " $pkg " ]]; then + SEEN="$SEEN $pkg" + FILTERS="$FILTERS --filter=$pkg" + fi +done <<< "$STAGED_TS_FILES" + +if [ -z "$FILTERS" ]; then + exit 0 +fi + +echo "Running tests for affected packages:$SEEN" +exec npx turbo run test $FILTERS