plugins/node: use _command_exists

Addresses bash-it/bash-it#1632

alsö, quote variable, use `[[`, &c.
This commit is contained in:
John D Pell
2021-09-19 21:54:21 -07:00
parent 9378a8318f
commit e701660ff1
2 changed files with 7 additions and 5 deletions

View File

@@ -1,13 +1,14 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Node.js helper functions'
# Check that we have npm
_command_exists npm || return
# Ensure local modules are preferred in PATH
pathmunge "./node_modules/.bin" "after"
# Check that we have npm
out=$(command -v npm 2>&1) || return
# If not using nodenv, ensure global modules are in PATH
if [[ ! $out == *"nodenv/shims"* ]] ; then
pathmunge "$(npm config get prefix)/bin" "after"
if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
pathmunge "$(npm config get prefix)/bin" "after"
fi