Skip to content

Commit ed34355

Browse files
Merge pull request #278 from augustobmoura/fix/add-link-cmds-npm-shim
Add auto reshim for npm link
2 parents b842e07 + 05a7fc6 commit ed34355

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

shims/npm

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ should_reshim() {
2222
fi
2323

2424
local is_global= cmd= cmd_needs_reshim=
25+
local additional_bare_cmds=()
2526

2627
for arg; do
2728
case "$arg" in
@@ -32,7 +33,11 @@ should_reshim() {
3233
-*) ;; # Skip other options
3334

3435
*)
35-
cmd="${cmd:-$arg}"
36+
if ! [ "$cmd" ]; then
37+
cmd="$arg"
38+
else
39+
additional_bare_cmds+=("$arg")
40+
fi
3641
;;
3742
esac
3843
done
@@ -47,6 +52,20 @@ should_reshim() {
4752
uninstall|un|unlink|remove|rm|r)
4853
cmd_needs_reshim=true
4954
;;
55+
56+
link|ln)
57+
# Bare link installs a global package
58+
if ! [ "${additional_bare_cmds[0]-}" ]; then
59+
is_global=1
60+
cmd_needs_reshim=true
61+
fi
62+
63+
# Links to directories also install a global package
64+
if [[ "${additional_bare_cmds[0]-}" =~ [./].* && -d "${additional_bare_cmds[0]-}" ]]; then
65+
is_global=1
66+
cmd_needs_reshim=true
67+
fi
68+
;;
5069
esac
5170

5271
# Implicit return

0 commit comments

Comments
 (0)