Skip to content

Commit fb7463b

Browse files
committed
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.
1 parent 0d36144 commit fb7463b

3 files changed

Lines changed: 51 additions & 37 deletions

File tree

lefthook.yml

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,7 @@ pre-commit:
1313
commands:
1414
check-binaries:
1515
tags: binaries
16-
run: |
17-
VIOLATIONS=0
18-
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
19-
[ -z "$STAGED" ] && exit 0
20-
21-
BINARIES=$(echo "$STAGED" | grep -iE '\.(exe|dll|so|dylib|o|obj|a|lib|wasm)$' || true)
22-
if [ -n "$BINARIES" ]; then
23-
echo "Binary files detected:" && echo "$BINARIES"
24-
VIOLATIONS=1
25-
fi
26-
27-
BUILD=$(echo "$STAGED" | grep -E '/build/' || true)
28-
if [ -n "$BUILD" ]; then
29-
echo "Files in build directories:" && echo "$BUILD"
30-
VIOLATIONS=1
31-
fi
32-
33-
DSYM=$(echo "$STAGED" | grep -E '\.dSYM/' || true)
34-
if [ -n "$DSYM" ]; then
35-
echo "dSYM directories:" && echo "$DSYM"
36-
VIOLATIONS=1
37-
fi
38-
39-
for f in $STAGED; do
40-
[ ! -f "$f" ] && continue
41-
case "$f" in pnpm-lock.yaml|*/package-lock.json) continue ;; esac
42-
SIZE=$(wc -c < "$f" | tr -d ' ')
43-
if [ "$SIZE" -gt 1048576 ]; then
44-
echo "Oversized file: $f ($((SIZE / 1024)) KB)"
45-
VIOLATIONS=1
46-
fi
47-
done
48-
49-
[ "$VIOLATIONS" -eq 1 ] && exit 1
50-
exit 0
16+
run: bash scripts/hooks/check-binaries.sh
5117
sync-lockfile:
5218
tags: lockfile
5319
glob: "**/package.json"

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"lint": "oxlint .",
1111
"format": "oxfmt --write .",
1212
"check-format": "oxfmt --check .",
13-
"test": "nx run-many -t test",
13+
"test": "nx run-many -t test --projects=packages/**",
1414
"test:watch": "pnpm run test && nx watch --all -- pnpm run test",
15-
"test:coverage": "nx run-many -t test:coverage",
15+
"test:coverage": "nx run-many -t test:coverage --projects=packages/**",
1616
"dev": "pnpm run build && nx watch --projects=packages/** -- pnpm run build",
1717
"dev:examples": "pnpm run build:examples && nx watch --projects=examples/** -- pnpm run build:examples",
1818
"storybook:angular": "pnpm -C examples/v2/angular/storybook dev",

scripts/hooks/check-binaries.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
# Rejects staged binary artifacts, build output, dSYM dirs, and files > 1 MB.
3+
# Invoked by lefthook pre-commit. Lives in a standalone file so Windows Git Bash
4+
# doesn't mangle the quoting when lefthook passes it through `sh.exe -c`.
5+
6+
set -u
7+
8+
VIOLATIONS=0
9+
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
10+
[ -z "$STAGED" ] && exit 0
11+
12+
BINARIES=$(echo "$STAGED" | grep -iE '\.(exe|dll|so|dylib|o|obj|a|lib|wasm)$' || true)
13+
if [ -n "$BINARIES" ]; then
14+
echo "Binary files detected:"
15+
echo "$BINARIES"
16+
VIOLATIONS=1
17+
fi
18+
19+
BUILD=$(echo "$STAGED" | grep -E '/build/' || true)
20+
if [ -n "$BUILD" ]; then
21+
echo "Files in build directories:"
22+
echo "$BUILD"
23+
VIOLATIONS=1
24+
fi
25+
26+
DSYM=$(echo "$STAGED" | grep -E '\.dSYM/' || true)
27+
if [ -n "$DSYM" ]; then
28+
echo "dSYM directories:"
29+
echo "$DSYM"
30+
VIOLATIONS=1
31+
fi
32+
33+
while IFS= read -r f; do
34+
[ -z "$f" ] && continue
35+
[ ! -f "$f" ] && continue
36+
case "$f" in
37+
pnpm-lock.yaml|*/package-lock.json) continue ;;
38+
esac
39+
SIZE=$(wc -c < "$f" | tr -d ' ')
40+
[ -z "$SIZE" ] && continue
41+
if [ "$SIZE" -gt 1048576 ]; then
42+
echo "Oversized file: $f ($((SIZE / 1024)) KB)"
43+
VIOLATIONS=1
44+
fi
45+
done <<< "$STAGED"
46+
47+
[ "$VIOLATIONS" -eq 1 ] && exit 1
48+
exit 0

0 commit comments

Comments
 (0)