Skip to content

Commit 8326430

Browse files
committed
fix: enforce-pnpm hook now catches npm/npx in compound commands
1 parent 5a46d58 commit 8326430

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

.claude/hooks/enforce-pnpm.sh

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,10 @@ input=$(cat)
77
# Extract command field from JSON
88
command=$(echo "$input" | grep -o '"command":"[^"]*' | cut -d'"' -f4 | head -1)
99

10-
# Check if command starts with npm or npx
11-
if [[ "$command" =~ ^npm[[:space:]] ]] || [[ "$command" =~ ^npx[[:space:]] ]]; then
12-
# Extract the npm command for suggestion
13-
npm_cmd=$(echo "$command" | cut -d' ' -f1)
14-
rest=$(echo "$command" | cut -d' ' -f2-)
15-
16-
# Suggest pnpm equivalent
17-
if [ "$npm_cmd" = "npm" ]; then
18-
suggested="pnpm $rest"
19-
elif [ "$npm_cmd" = "npx" ]; then
20-
suggested="pnpx $rest"
21-
fi
22-
23-
echo "❌ npm is not allowed in this workspace. Use pnpm instead." >&2
24-
echo "💡 Suggested: $suggested" >&2
10+
# Check if command contains npm or npx as a standalone word (catches compound commands like "cd /x && npx foo")
11+
if [[ "$command" =~ (^|[;&|[:space:]])npm[[:space:]] ]] || [[ "$command" =~ (^|[;&|[:space:]])npx[[:space:]] ]]; then
12+
echo "❌ npm/npx is not allowed in this workspace. Use pnpm/pnpx instead." >&2
13+
echo "💡 Command: $command" >&2
2514
exit 2
2615
fi
2716

0 commit comments

Comments
 (0)