Skip to content

Commit 43c5f28

Browse files
committed
if pnpm is unavailable in husky hook - fallback to dockerized lint
1 parent 635addf commit 43c5f28

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

.husky/pre-commit

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
pnpm lint-staged
1+
if command -v pnpm >/dev/null 2>&1; then
2+
pnpm lint-staged
3+
else
4+
echo "pnpm unavailable, trying via docker..."
5+
sh ./compose/lint.sh
6+
fi

compose/lint.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Always run from repo root
5+
PROJECT_ROOT="$(git rev-parse --show-toplevel)"
6+
cd "$PROJECT_ROOT"
7+
8+
# Name of the pnpm store volume used as cache between runs
9+
PNPM_STORE_VOLUME="pnpm-store"
10+
PNPM_COREPACK_CACHE_VOLUME="pnpm-corepack-cache"
11+
12+
docker run --rm \
13+
-e CI=1 \
14+
-v "$PROJECT_ROOT":/src:ro \
15+
-v "${PNPM_STORE_VOLUME}":/pnpm/store \
16+
-v "${PNPM_COREPACK_CACHE_VOLUME}":/root/.cache \
17+
node:24-alpine \
18+
sh -lc '
19+
set -euo pipefail
20+
21+
# 1) Create a throwaway working dir inside container
22+
APP_DIR="$(mktemp -d)"
23+
24+
tar \
25+
--exclude="node_modules" \
26+
--exclude="*/node_modules" \
27+
--exclude=".git" \
28+
--exclude=".turbo" \
29+
--exclude=".pnpm-store" \
30+
--exclude="dist" \
31+
--exclude="*/dist" \
32+
--exclude="coverage" \
33+
-C /src \
34+
-cf - . \
35+
| tar -C "$APP_DIR" -xf -
36+
37+
cd "$APP_DIR"
38+
39+
export PNPM_HOME=/pnpm
40+
export PNPM_STORE_DIR=/pnpm/store
41+
export PATH="$PNPM_HOME:$PATH"
42+
43+
corepack enable pnpm
44+
45+
pnpm install \
46+
--frozen-lockfile \
47+
--prefer-offline \
48+
--ignore-scripts \
49+
--filter .
50+
51+
pnpm lint
52+
'

0 commit comments

Comments
 (0)