diff --git a/.husky/pre-push b/.husky/pre-push index dd0fdf09e2d..8d6d1f415fe 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,44 @@ #!/bin/sh +# Checks only what this push changes against its merge base with origin/staging (the PR base): +# biome format + lint on the changed files, then type-check for the affected workspaces. +# CI runs the full lint, type-check and audit gate on every PR, so it stays the backstop. set -e -bun run lint:check -bun run type-check +# git passes one " " line per pushed ref. +zero=0000000000000000000000000000000000000000 +head=$(git rev-parse HEAD) +pushes_head=false +while read -r _local_ref local_sha _remote_ref _remote_sha; do + [ "$local_sha" = "$zero" ] && continue + if [ "$local_sha" != "$head" ]; then + # These checks read the working tree, which holds HEAD, not this commit. + echo "pre-push: $local_sha is not the checked-out commit; leaving it to CI" + continue + fi + pushes_head=true +done +[ "$pushes_head" = true ] || exit 0 + +base=$(git merge-base HEAD origin/staging 2>/dev/null || true) +if [ -z "$base" ]; then + echo "pre-push: origin/staging not found, running the full lint and type-check" + bun run lint:check + bun run type-check + exit 0 +fi + +# Deletions still decide the type-check (an import of a deleted module breaks); biome only +# reads files that exist. +changed=$(git diff --name-only "$base" HEAD) +[ -z "$changed" ] && exit 0 +existing=$(git diff --name-only --diff-filter=ACMR "$base" HEAD) + +if [ -n "$existing" ]; then + # Word-splitting the list is deliberate; no path biome checks contains a space. + bunx biome check --no-errors-on-unmatched --files-ignore-unknown=true $existing +fi + +if printf '%s\n' "$changed" | grep -qE '^scripts/'; then + bun run type-check:scripts:esm +fi +TURBO_SCM_BASE="$base" bunx turbo run type-check --affected --output-logs=errors-only