Skip to content

Commit ea8f906

Browse files
committed
fix: add lefthook pre-commit check for binary artifacts
Mirrors the CI workflow check locally — catches binary extensions, build directories, dSYM directories, and files over 1 MB at commit time instead of waiting for CI.
1 parent f9cfb91 commit ea8f906

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

lefthook.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,43 @@ output:
1111
pre-commit:
1212
parallel: true
1313
commands:
14+
check-binaries:
15+
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
1451
sync-lockfile:
1552
tags: lockfile
1653
glob: "**/package.json"

0 commit comments

Comments
 (0)