Skip to content

Commit bce2b41

Browse files
committed
Wholesale cleanup of nodejs related components
- remove redundant cite - support Basher - add nenv plugin - uplift nodenv to follow newer pattern and standard - ensure node components play well with *env tools
1 parent 33bade2 commit bce2b41

File tree

7 files changed

+99
-96
lines changed

7 files changed

+99
-96
lines changed

clean_files.txt

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ plugins/available/jump.plugin.bash
114114
plugins/available/latex.plugin.bash
115115
plugins/available/less-pretty-cat.plugin.bash
116116
plugins/available/man.plugin.bash
117+
plugins/available/nenv.plugin.bash
117118
plugins/available/nginx.plugin.bash
118119
plugins/available/node.plugin.bash
119120
plugins/available/nodenv.plugin.bash
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# shellcheck shell=bash
2-
cite "about-completion"
32
about-completion "npm (Node Package Manager) completion"
43

5-
if _command_exists npm; then
4+
# Test `npm version` because *env tools create shim scripts that will be found in PATH
5+
# but do not always resolve to a working install.
6+
if _command_exists npm && npm --version &> /dev/null; then
67
eval "$(npm completion)"
78
fi

plugins/available/nenv.plugin.bash

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# shellcheck shell=bash
2+
about-plugin 'Node.js environment management using https://github.com/ryuone/nenv'
3+
4+
# Load after basher
5+
# BASH_IT_LOAD_PRIORITY: 260
6+
7+
export NENV_ROOT="${NENV_ROOT:-${HOME?}/.nenv}"
8+
9+
if [[ -d "${NENV_ROOT?}/bin" ]]; then
10+
pathmunge "${NENV_ROOT?}/bin"
11+
fi
12+
13+
if _command_exists nenv; then
14+
eval "$(nenv init - bash)"
15+
fi

plugins/available/node.plugin.bash

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
# shellcheck shell=bash
2-
cite about-plugin
32
about-plugin 'Node.js helper functions'
43

5-
# Check that we have npm
6-
_command_exists npm || return
4+
# Load after *env plugins
5+
# BASH_IT_LOAD_PRIORITY: 270
76

87
# Ensure local modules are preferred in PATH
9-
pathmunge "./node_modules/.bin" "after"
8+
pathmunge './node_modules/.bin' 'after'
109

11-
# If not using nodenv, ensure global modules are in PATH
12-
if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then
13-
pathmunge "$(npm config get prefix)/bin" "after"
10+
# If not using an *env tool, ensure global modules are in PATH
11+
if [[ ! "$(type -p npm)" == *'/shims/npm' ]]; then
12+
pathmunge "$(npm config get prefix)/bin" 'after'
1413
fi

plugins/available/nodenv.plugin.bash

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# shellcheck shell=bash
2-
cite about-plugin
3-
about-plugin 'load nodenv, if you are using it'
2+
about-plugin 'Node.js environment management using https://github.com/nodenv/nodenv'
43

5-
export NODENV_ROOT="$HOME/.nodenv"
6-
pathmunge "$NODENV_ROOT/bin"
4+
# Load after basher
5+
# BASH_IT_LOAD_PRIORITY: 260
6+
7+
export NODENV_ROOT="${NODENV_ROOT:-${HOME?}/.nodenv}"
8+
9+
if [[ -d "${NODENV_ROOT?}/bin" ]]; then
10+
pathmunge "${NODENV_ROOT?}/bin"
11+
fi
712

813
if _command_exists nodenv; then
914
eval "$(nodenv init - bash)"

plugins/available/nvm.plugin.bash

+8-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,13 @@
11
# shellcheck shell=bash
2-
#
3-
# BASH_IT_LOAD_PRIORITY: 225
4-
#
5-
# Bash-it no longer bundles nvm, as this was quickly becoming outdated.
6-
# Please install nvm from https://github.com/creationix/nvm.git if you want to use it.
2+
about-plugin 'Node.js version manager, https://github.com/nvm-sh/nvm'
73

8-
cite about-plugin
9-
about-plugin 'node version manager configuration'
4+
# Load after basher
5+
# BASH_IT_LOAD_PRIORITY: 260
106

11-
export NVM_DIR="${NVM_DIR:-$HOME/.nvm}"
12-
# This loads nvm
13-
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]]
14-
then
15-
source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh"
16-
else
17-
[[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
18-
fi
7+
export NVM_DIR="${NVM_DIR:-${HOME?}/.nvm}"
198

20-
if ! _command_exists nvm
21-
then
22-
function nvm() {
23-
echo "Bash-it no longer bundles the nvm script. Please install the latest version from"
24-
echo ""
25-
echo "https://github.com/creationix/nvm.git"
26-
echo ""
27-
echo "if you want to use nvm. You can keep this plugin enabled once you have installed nvm."
28-
}
29-
30-
nvm
9+
if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh" ]]; then
10+
source "${BASH_IT_HOMEBREW_PREFIX?}/nvm.sh"
11+
else
12+
[[ -s "${NVM_DIR?}/nvm.sh" ]] && source "${NVM_DIR?}/nvm.sh"
3113
fi

test/lib/helpers.bats

+57-57
Original file line numberDiff line numberDiff line change
@@ -166,35 +166,35 @@ function local_setup {
166166

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

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

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

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

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

200200
@test "helpers: enable an unknown plugin" {
@@ -229,24 +229,24 @@ function local_setup {
229229

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

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

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

246246
run _disable-plugin "nvm"
247247
assert_line -n 0 'nvm disabled.'
248-
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
249-
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
248+
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]
249+
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
250250
}
251251

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

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

276276
run _enable-plugin "nvm"
277277
assert_line -n 0 'nvm is already enabled.'
278278
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
279-
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
280-
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
279+
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"
280+
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
281281
}
282282

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

288288
run _enable-plugin "nvm"
289289
assert_line -n 0 'nvm is already enabled.'
290-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
290+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
291291
}
292292

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

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

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

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

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

499499
run _bash-it-migrate
500-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
501-
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
500+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
501+
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
502502
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
503503
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
504-
assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ]
505-
assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ]
504+
assert [ ! -L "$BASH_IT/plugins/enabled/270----node.plugin.bash" ]
505+
assert [ ! -L "$BASH_IT/plugins/enabled/260----nvm.plugin.bash" ]
506506
assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ]
507507
}
508508

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

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

615615
run bash-it disable plugin "node"
616616
assert_line -n 0 'Migrating plugin node.'
617617
assert_line -n 1 'node disabled.'
618-
assert_line -n 2 'node enabled with priority 250.'
618+
assert_line -n 2 'node enabled with priority 270.'
619619
assert_line -n 3 'Migrating plugin nvm.'
620620
assert_line -n 4 'nvm disabled.'
621-
assert_line -n 5 'nvm enabled with priority 225.'
621+
assert_line -n 5 'nvm enabled with priority 260.'
622622
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
623623
assert_line -n 7 'node disabled.'
624624
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
625-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
626-
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
627-
assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ]
625+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
626+
assert [ ! -L "$BASH_IT/plugins/enabled/270---node.plugin.bash" ]
627+
assert [ ! -L "$BASH_IT/enabled/270---node.plugin.bash" ]
628628
}
629629

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

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

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

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

718718
_bash-it-plugins | grep "nvm" | grep "\[x\]"
719719
}
@@ -726,8 +726,8 @@ function __migrate_all_components() {
726726
}
727727

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

732732
_bash-it-plugins | grep "nvm" | grep "\[x\]"
733733
}

0 commit comments

Comments
 (0)