Skip to content

Commit aa5c1e7

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 1882f50 commit aa5c1e7

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
@@ -99,6 +99,7 @@ plugins/available/history.plugin.bash
9999
plugins/available/hub.plugin.bash
100100
plugins/available/jump.plugin.bash
101101
plugins/available/less-pretty-cat.plugin.bash
102+
plugins/available/nenv.plugin.bash
102103
plugins/available/node.plugin.bash
103104
plugins/available/nodenv.plugin.bash
104105
plugins/available/percol.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
@@ -159,35 +159,35 @@ function local_setup {
159159

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

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

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

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

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

193193
@test "helpers: enable an unknown plugin" {
@@ -222,24 +222,24 @@ function local_setup {
222222

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

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

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

239239
run _disable-plugin "nvm"
240240
assert_line -n 0 'nvm disabled.'
241-
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
242-
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
241+
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]
242+
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
243243
}
244244

245245
@test "helpers: disable the nvm plugin if it was enabled without a priority" {
@@ -258,29 +258,29 @@ function local_setup {
258258
run _enable-plugin "nvm"
259259
assert_line -n 0 'nvm is already enabled.'
260260
assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash"
261-
assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ]
262-
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
261+
assert [ ! -L "$BASH_IT/plugins/enabled/260---nvm.plugin.bash" ]
262+
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
263263
}
264264

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

269269
run _enable-plugin "nvm"
270270
assert_line -n 0 'nvm is already enabled.'
271271
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
272-
assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash"
273-
assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ]
272+
assert_link_exist "$BASH_IT/plugins/enabled/260---nvm.plugin.bash"
273+
assert [ ! -L "$BASH_IT/enabled/260---nvm.plugin.bash" ]
274274
}
275275

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

281281
run _enable-plugin "nvm"
282282
assert_line -n 0 'nvm is already enabled.'
283-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
283+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
284284
}
285285

286286
@test "helpers: migrate plugins and completions that share the same name" {
@@ -323,8 +323,8 @@ function local_setup {
323323
assert_line -n 1 'todo.txt-cli disabled.'
324324
assert_line -n 2 'todo.txt-cli enabled with priority 150.'
325325

326-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
327-
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
326+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
327+
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
328328
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
329329
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
330330
assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ]
@@ -333,11 +333,11 @@ function local_setup {
333333
}
334334

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

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

342342
ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash
343343
assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash"
@@ -346,12 +346,12 @@ function local_setup {
346346
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
347347

348348
run _bash-it-migrate
349-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
350-
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
349+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
350+
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
351351
assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash"
352352
assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash"
353-
assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ]
354-
assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ]
353+
assert [ ! -L "$BASH_IT/plugins/enabled/270----node.plugin.bash" ]
354+
assert [ ! -L "$BASH_IT/plugins/enabled/260----nvm.plugin.bash" ]
355355
assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ]
356356
}
357357

@@ -447,33 +447,33 @@ function __migrate_all_components() {
447447
run bash-it enable plugin "node"
448448
assert_line -n 0 'Migrating plugin nvm.'
449449
assert_line -n 1 'nvm disabled.'
450-
assert_line -n 2 'nvm enabled with priority 225.'
450+
assert_line -n 2 'nvm enabled with priority 260.'
451451
assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate'
452-
assert_line -n 4 'node enabled with priority 250.'
452+
assert_line -n 4 'node enabled with priority 270.'
453453
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
454-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
455-
assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash"
454+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
455+
assert_link_exist "$BASH_IT/enabled/270---node.plugin.bash"
456456
}
457457

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

464464
run bash-it disable plugin "node"
465465
assert_line -n 0 'Migrating plugin node.'
466466
assert_line -n 1 'node disabled.'
467-
assert_line -n 2 'node enabled with priority 250.'
467+
assert_line -n 2 'node enabled with priority 270.'
468468
assert_line -n 3 'Migrating plugin nvm.'
469469
assert_line -n 4 'nvm disabled.'
470-
assert_line -n 5 'nvm enabled with priority 225.'
470+
assert_line -n 5 'nvm enabled with priority 260.'
471471
assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate'
472472
assert_line -n 7 'node disabled.'
473473
assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ]
474-
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
475-
assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ]
476-
assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ]
474+
assert_link_exist "$BASH_IT/enabled/260---nvm.plugin.bash"
475+
assert [ ! -L "$BASH_IT/plugins/enabled/270---node.plugin.bash" ]
476+
assert [ ! -L "$BASH_IT/enabled/270---node.plugin.bash" ]
477477
}
478478

479479
@test "helpers: enable all plugins" {
@@ -521,8 +521,8 @@ function __migrate_all_components() {
521521
ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash
522522
assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash"
523523

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

527527
local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs)
528528
assert_equal "2" "$enabled"
@@ -561,8 +561,8 @@ function __migrate_all_components() {
561561

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

567567
_bash-it-plugins | grep "nvm" | grep "\[x\]"
568568
}
@@ -575,8 +575,8 @@ function __migrate_all_components() {
575575
}
576576

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

581581
_bash-it-plugins | grep "nvm" | grep "\[x\]"
582582
}

0 commit comments

Comments
 (0)