Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wholesale cleanup of nodejs related components #1990

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ plugins/available/jump.plugin.bash
plugins/available/latex.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/man.plugin.bash
plugins/available/nenv.plugin.bash
plugins/available/nginx.plugin.bash
plugins/available/node.plugin.bash
plugins/available/nodenv.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 'Node.js environment management using https://github.com/ryuone/nenv'

# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt we still check this?

# 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
13 changes: 9 additions & 4 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'
about-plugin 'Node.js environment management using https://github.com/nodenv/nodenv'

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
34 changes: 8 additions & 26 deletions plugins/available/nvm.plugin.bash
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
# shellcheck shell=bash
#
# BASH_IT_LOAD_PRIORITY: 225
#
# Bash-it no longer bundles nvm, as this was quickly becoming outdated.
# Please install nvm from https://github.com/creationix/nvm.git if you want to use it.
about-plugin 'Node.js version manager, https://github.com/nvm-sh/nvm'

cite about-plugin
about-plugin 'node version manager configuration'
# Load after basher
# BASH_IT_LOAD_PRIORITY: 260

export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
# This loads nvm
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]]
then
source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh"
else
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
fi
export NVM_DIR="${NVM_DIR:-${HOME?}/.nvm}"

if ! _command_exists nvm
then
function nvm() {
echo "Bash-it no longer bundles the nvm script. Please install the latest version from"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about logging a warning in the case we dont find nvm.sh?

echo ""
echo "https://github.com/creationix/nvm.git"
echo ""
echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm."
}

nvm
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh" ]]; then
source "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh"
else
[[ -s "${NVM_DIR?}/nvm.sh" ]] && source "${NVM_DIR?}/nvm.sh"
fi
114 changes: 57 additions & 57 deletions test/lib/helpers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -166,35 +166,35 @@ function local_setup {

@test "helpers: enable the node plugin" {
run _enable-plugin "node"
assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash"
assert_line -n 0 'node enabled with priority 270.'
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash" "../plugins/available/node.plugin.bash"
}

@test "helpers: enable the node plugin through the bash-it function" {
run bash-it enable plugin "node"
assert_line -n 0 'node enabled with priority 250.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_line -n 0 'node enabled with priority 270.'
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
}

@test "helpers: enable the node and nvm plugins through the bash-it function" {
run bash-it enable plugin "node" "nvm"
assert_line -n 0 'node enabled with priority 250.'
assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_line -n 0 'node enabled with priority 270.'
assert_line -n 1 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
}

@test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" {
run bash-it enable plugin "foo-unknown" "nvm"
assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.'
assert_line -n 1 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_line -n 1 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
}

@test "helpers: enable the nvm plugin" {
run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_line -n 0 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
}

@test "helpers: enable an unknown plugin" {
Expand Down Expand Up @@ -229,24 +229,24 @@ function local_setup {

@test "helpers: enable and disable the nvm plugin" {
run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert_line -n 0 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]

run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
}

@test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/260---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]

run _disable-plugin "nvm"
assert_line -n 0 'nvm disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
}

@test "helpers: disable the nvm plugin if it was enabled without a priority" {
Expand All @@ -265,29 +265,29 @@ function local_setup {
run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
}

@test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/260---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"

run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
}

@test "helpers: enable the nvm plugin twice" {
run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_line -n 0 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"

run _enable-plugin "nvm"
assert_line -n 0 'nvm is already enabled.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
}

@test "helpers: profile load command sanity" {
Expand Down Expand Up @@ -474,8 +474,8 @@ function local_setup {
assert_line -n 1 'todo.txt-cli disabled.'
assert_line -n 2 'todo.txt-cli enabled with priority 150.'

assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
Expand All @@ -484,11 +484,11 @@ function local_setup {
}

@test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/260---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"

ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/270---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/270---node.plugin.bash"

ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash
assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash"
Expand All @@ -497,12 +497,12 @@ function local_setup {
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"

run _bash-it-migrate
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/270----node.plugin.bash" ]
assert [ ! -L "$BASH_IT/plugins/enabled/260----nvm.plugin.bash" ]
assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ]
}

Expand Down Expand Up @@ -598,33 +598,33 @@ function __migrate_all_components() {
run bash-it enable plugin "node"
assert_line -n 0 'Migrating plugin nvm.'
assert_line -n 1 'nvm disabled.'
assert_line -n 2 'nvm enabled with priority 225.'
assert_line -n 2 'nvm enabled with priority 260.'
assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 4 'node enabled with priority 250.'
assert_line -n 4 'node enabled with priority 270.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
}

@test "helpers: verify that existing components are automatically migrated when something is disabled" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/270---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/270---node.plugin.bash"

run bash-it disable plugin "node"
assert_line -n 0 'Migrating plugin node.'
assert_line -n 1 'node disabled.'
assert_line -n 2 'node enabled with priority 250.'
assert_line -n 2 'node enabled with priority 270.'
assert_line -n 3 'Migrating plugin nvm.'
assert_line -n 4 'nvm disabled.'
assert_line -n 5 'nvm enabled with priority 225.'
assert_line -n 5 'nvm enabled with priority 260.'
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
assert_line -n 7 'node disabled.'
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ]
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
assert [ ! -L "$BASH_IT/plugins/enabled/270---node.plugin.bash" ]
assert [ ! -L "$BASH_IT/enabled/270---node.plugin.bash" ]
}

@test "helpers: enable all plugins" {
Expand Down Expand Up @@ -672,8 +672,8 @@ function __migrate_all_components() {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash"

ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash"
ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/270---node.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/270---node.plugin.bash"

local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
assert_equal "2" "$enabled"
Expand Down Expand Up @@ -712,8 +712,8 @@ function __migrate_all_components() {

@test "helpers: describe the nvm plugin after enabling it" {
run _enable-plugin "nvm"
assert_line -n 0 'nvm enabled with priority 225.'
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
assert_line -n 0 'nvm enabled with priority 260.'
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"

_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
Expand All @@ -726,8 +726,8 @@ function __migrate_all_components() {
}

@test "helpers: describe the nvm plugin after enabling it in the old directory with priority" {
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/260---nvm.plugin.bash
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"

_bash-it-plugins | grep "nvm" | grep "\[x\]"
}
Expand Down
4 changes: 2 additions & 2 deletions test/lib/search.bats
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ function local_teardown {
run _bash-it-search rails ruby gem bundler rake --no-color

assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: chruby chruby-auto rails ruby '
assert_line -n 1 ' plugins: chruby chruby-auto nenv nodenv rails ruby '
assert_line -n 2 ' completions: bundler gem rake '
}

@test "search: rails ruby gem bundler rake -chruby" {
run _bash-it-search rails ruby gem bundler rake -chruby --no-color

assert_line -n 0 ' aliases: bundler rails '
assert_line -n 1 ' plugins: rails ruby '
assert_line -n 1 ' plugins: nenv nodenv rails ruby '
assert_line -n 2 ' completions: bundler gem rake '
}

Expand Down