Skip to content

Commit

Permalink
fix-dev: handle npm unavailable circumstance
Browse files Browse the repository at this point in the history
\### Rationale
For vscode switching of branches where it doesn't always have a login
shell that commands are being run in
  • Loading branch information
codejedi365 committed Oct 6, 2021
1 parent c03e429 commit 043ad03
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ update_npm_dependencies() {
log "Dependency requirements changed! This will take a few seconds..."

local cmd="npm install --prefer-offline"
if ! command -v npm &>/dev/null; then
log "NPM not found on \$PATH, however '$cmd' is desired. Please accomplish manually."
return
fi
log "$> $cmd"
eval "$cmd"
fi
Expand Down
4 changes: 4 additions & 0 deletions .husky/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ update_npm_dependencies() {

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

Expand Down
13 changes: 9 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ LOG_PREFIX="[.husky/pre-commit]"

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

log "$> npm run lint"
if ! npm run lint; then
error "ERROR: Dirty code detected!"
error "Fix the lint errors before committing to the repository."
if command -v npm &>/dev/null; then
log "$> npm run lint"
if ! npm run lint; then
error "ERROR: Dirty code detected!"
error "Fix the lint errors before committing to the repository."
exit -1
fi
else
error "NPM not found on \$PATH, unable to run pre-commit lint hook."
exit -1
fi

0 comments on commit 043ad03

Please sign in to comment.