Skip to content

Commit 043ad03

Browse files
committed
fix-dev: handle npm unavailable circumstance
\### Rationale For vscode switching of branches where it doesn't always have a login shell that commands are being run in
1 parent c03e429 commit 043ad03

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

.husky/post-checkout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ update_npm_dependencies() {
2424
log "Dependency requirements changed! This will take a few seconds..."
2525

2626
local cmd="npm install --prefer-offline"
27+
if ! command -v npm &>/dev/null; then
28+
log "NPM not found on \$PATH, however '$cmd' is desired. Please accomplish manually."
29+
return
30+
fi
2731
log "$> $cmd"
2832
eval "$cmd"
2933
fi

.husky/post-merge

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ update_npm_dependencies() {
3030

3131
if [ "$NEEDS_INSTALL" == true ]; then
3232
cmd="npm install"
33+
if ! command -v npm &>/dev/null; then
34+
log "NPM not found on \$PATH, however '$cmd' is desired. Please accomplish manually."
35+
return
36+
fi
3337
log "$> $cmd"
3438
eval "$cmd"
3539

.husky/pre-commit

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ LOG_PREFIX="[.husky/pre-commit]"
77

88
. "$(dirname "$0")/hook-utils.sh"
99

10-
log "$> npm run lint"
11-
if ! npm run lint; then
12-
error "ERROR: Dirty code detected!"
13-
error "Fix the lint errors before committing to the repository."
10+
if command -v npm &>/dev/null; then
11+
log "$> npm run lint"
12+
if ! npm run lint; then
13+
error "ERROR: Dirty code detected!"
14+
error "Fix the lint errors before committing to the repository."
15+
exit -1
16+
fi
17+
else
18+
error "NPM not found on \$PATH, unable to run pre-commit lint hook."
1419
exit -1
1520
fi

0 commit comments

Comments
 (0)