Skip to content

Commit

Permalink
Wholesale cleanup of nodejs related components
Browse files Browse the repository at this point in the history
- remove redundant cite
- support Basher
- add nenv plugin
- uplift nodenv to follow newer pattern and standard
- ensure node components play well with *env tools
  • Loading branch information
cornfeedhobo committed Dec 2, 2021
1 parent 1882f50 commit 47d5c77
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash
plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/nenv.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash
plugins/available/percol.plugin.bash
Expand Down
5 changes: 3 additions & 2 deletions completion/available/npm.completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "npm (Node Package Manager) completion"

if _command_exists npm; then
# Test `npm version` because *env tools create shim scripts that will be found in PATH
# but do not always resolve to a working install.
if _command_exists npm && npm --version &> /dev/null; then
eval "$(npm completion)"
fi
15 changes: 15 additions & 0 deletions plugins/available/nenv.plugin.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# shellcheck shell=bash
about-plugin 'load nenv, if you are using it'

# Load after basher
# BASH_IT_LOAD_PRIORITY: 260

export NENV_ROOT="${NENV_ROOT:-${HOME?}/.nenv}"

if [[ -d "${NENV_ROOT?}/bin" ]]; then
pathmunge "${NENV_ROOT?}/bin"
fi

if _command_exists nenv; then
eval "$(nenv init - bash)"
fi
13 changes: 6 additions & 7 deletions plugins/available/node.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'Node.js helper functions'

# Check that we have npm
_command_exists npm || return
# Load after *env plugins
# BASH_IT_LOAD_PRIORITY: 270

# Ensure local modules are preferred in PATH
pathmunge "./node_modules/.bin" "after"
pathmunge './node_modules/.bin' 'after'

# If not using nodenv, ensure global modules are in PATH
if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
pathmunge "$(npm config get prefix)/bin" "after"
# If not using an *env tool, ensure global modules are in PATH
if [[ ! "$(type -p npm)" == *'/shims/npm' ]]; then
pathmunge "$(npm config get prefix)/bin" 'after'
fi
11 changes: 8 additions & 3 deletions plugins/available/nodenv.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# shellcheck shell=bash
cite about-plugin
about-plugin 'load nodenv, if you are using it'

export NODENV_ROOT="$HOME/.nodenv"
pathmunge "$NODENV_ROOT/bin"
# Load after basher
# BASH_IT_LOAD_PRIORITY: 260

export NODENV_ROOT="${NODENV_ROOT:-${HOME?}/.nodenv}"

if [[ -d "${NODENV_ROOT?}/bin" ]]; then
pathmunge "${NODENV_ROOT?}/bin"
fi

if _command_exists nodenv; then
eval "$(nodenv init - bash)"
Expand Down

0 comments on commit 47d5c77

Please sign in to comment.