fix(hooks): move check-binaries to standalone script + scope test runner to packages/**

The inline check-binaries hook broke on Windows Git Bash because lefthook invoked
it via sh.exe -c with the multi-line YAML script as a single argument, and the
nested quotes inside (`echo "$STAGED" | grep -iE '...'`) got mangled during
Windows command-line argument escaping. Move it to scripts/hooks/check-binaries.sh
so lefthook just invokes bash against a file, avoiding the escaping issue.

Also scope the root test script (and test:coverage) to --projects=packages/**,
mirroring check:packages. The previous unscoped nx run-many -t test triggered
showcase starter generation tests that fail on leftover state from prior runs;
these aren't relevant to the pre-commit gate, which is about verifying shipped
packages.
This commit is contained in:
Alem Tuzlak
2026-04-17 12:55:00 +02:00
parent 0d361448a2
commit fb7463becd
3 changed files with 51 additions and 37 deletions
+1 -35
View File
@@ -13,41 +13,7 @@ pre-commit:
commands:
check-binaries:
tags: binaries
run: |
VIOLATIONS=0
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
[ -z "$STAGED" ] && exit 0
BINARIES=$(echo "$STAGED" | grep -iE '\.(exe|dll|so|dylib|o|obj|a|lib|wasm)$' || true)
if [ -n "$BINARIES" ]; then
echo "Binary files detected:" && echo "$BINARIES"
VIOLATIONS=1
fi
BUILD=$(echo "$STAGED" | grep -E '/build/' || true)
if [ -n "$BUILD" ]; then
echo "Files in build directories:" && echo "$BUILD"
VIOLATIONS=1
fi
DSYM=$(echo "$STAGED" | grep -E '\.dSYM/' || true)
if [ -n "$DSYM" ]; then
echo "dSYM directories:" && echo "$DSYM"
VIOLATIONS=1
fi
for f in $STAGED; do
[ ! -f "$f" ] && continue
case "$f" in pnpm-lock.yaml|*/package-lock.json) continue ;; esac
SIZE=$(wc -c < "$f" | tr -d ' ')
if [ "$SIZE" -gt 1048576 ]; then
echo "Oversized file: $f ($((SIZE / 1024)) KB)"
VIOLATIONS=1
fi
done
[ "$VIOLATIONS" -eq 1 ] && exit 1
exit 0
run: bash scripts/hooks/check-binaries.sh
sync-lockfile:
tags: lockfile
glob: "**/package.json"
+2 -2
View File
@@ -10,9 +10,9 @@
"lint": "oxlint .",
"format": "oxfmt --write .",
"check-format": "oxfmt --check .",
"test": "nx run-many -t test",
"test": "nx run-many -t test --projects=packages/**",
"test:watch": "pnpm run test && nx watch --all -- pnpm run test",
"test:coverage": "nx run-many -t test:coverage",
"test:coverage": "nx run-many -t test:coverage --projects=packages/**",
"dev": "pnpm run build && nx watch --projects=packages/** -- pnpm run build",
"dev:examples": "pnpm run build:examples && nx watch --projects=examples/** -- pnpm run build:examples",
"storybook:angular": "pnpm -C examples/v2/angular/storybook dev",
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# Rejects staged binary artifacts, build output, dSYM dirs, and files > 1 MB.
# Invoked by lefthook pre-commit. Lives in a standalone file so Windows Git Bash
# doesn't mangle the quoting when lefthook passes it through `sh.exe -c`.
set -u
VIOLATIONS=0
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
[ -z "$STAGED" ] && exit 0
BINARIES=$(echo "$STAGED" | grep -iE '\.(exe|dll|so|dylib|o|obj|a|lib|wasm)$' || true)
if [ -n "$BINARIES" ]; then
echo "Binary files detected:"
echo "$BINARIES"
VIOLATIONS=1
fi
BUILD=$(echo "$STAGED" | grep -E '/build/' || true)
if [ -n "$BUILD" ]; then
echo "Files in build directories:"
echo "$BUILD"
VIOLATIONS=1
fi
DSYM=$(echo "$STAGED" | grep -E '\.dSYM/' || true)
if [ -n "$DSYM" ]; then
echo "dSYM directories:"
echo "$DSYM"
VIOLATIONS=1
fi
while IFS= read -r f; do
[ -z "$f" ] && continue
[ ! -f "$f" ] && continue
case "$f" in
pnpm-lock.yaml|*/package-lock.json) continue ;;
esac
SIZE=$(wc -c < "$f" | tr -d ' ')
[ -z "$SIZE" ] && continue
if [ "$SIZE" -gt 1048576 ]; then
echo "Oversized file: $f ($((SIZE / 1024)) KB)"
VIOLATIONS=1
fi
done <<< "$STAGED"
[ "$VIOLATIONS" -eq 1 ] && exit 1
exit 0