33export NVM_DIR=" $HOME /.nvm"
44[ -s " $NVM_DIR /nvm.sh" ] && \. " $NVM_DIR /nvm.sh"
55# Use Node 20 if available (or install if needed)
6- if [ -f .nvmrc ]; then
6+ if command -v nvm > /dev/null 2>&1 && [ -f .nvmrc ]; then
77 nvm use 20 2> /dev/null || nvm install 20 && nvm use 20
88fi
99
1010. " $( dirname " $0 " ) /_/husky.sh"
1111
12- echo " 🧪 Running tests before push..."
13- npm run test -- --bail=1
14- test_status=$?
12+ changed_files=$( git diff --name-only @{upstream}...HEAD 2> /dev/null)
1513
16- echo " 🧹 Running lint before push..."
17- npm run lint
18- lint_status=$?
14+ if [ -z " $changed_files " ]; then
15+ echo " ℹ️ No outgoing changes to validate. Skipping pre-push checks."
16+ exit 0
17+ fi
18+
19+ if ! printf ' %s\n' " $changed_files " | grep -qvE ' ^\.husky/' ; then
20+ echo " ℹ️ Only Husky hook changes detected. Skipping full test and lint checks."
21+ exit 0
22+ fi
23+
24+ js_files=$( printf ' %s\n' " $changed_files " | grep -E ' \.(js|jsx|ts|tsx)$' || true)
25+ style_files=$( printf ' %s\n' " $changed_files " | grep -E ' \.(css|scss|sass)$' || true)
26+
27+ test_status=0
28+ lint_status=0
29+ style_status=0
30+
31+ if [ -n " $js_files " ]; then
32+ echo " 🧪 Running related tests before push..."
33+ npx vitest related --run $js_files
34+ test_status=$?
35+
36+ echo " 🧹 Running ESLint on changed files before push..."
37+ npx eslint $js_files
38+ lint_status=$?
39+ fi
40+
41+ if [ -n " $style_files " ]; then
42+ echo " 🎨 Running Stylelint on changed files before push..."
43+ npx stylelint $style_files
44+ style_status=$?
45+ fi
1946
2047# Block push if either fails
21- if [ $test_status -ne 0 ] || [ $lint_status -ne 0 ]; then
22- echo " ❌ Push blocked: Lint or test failed."
48+ if [ $test_status -ne 0 ] || [ $lint_status -ne 0 ] || [ $style_status -ne 0 ] ; then
49+ echo " ❌ Push blocked: changed-file validation failed."
2350 exit 1
2451fi
2552
26- echo " ✅ All checks passed. Proceeding with push..."
53+ echo " ✅ All checks passed. Proceeding with push..."
0 commit comments