File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
set -eu
4
4
5
- if ! [ -x " $( command -v npm) " ]; then
6
- echo ' Error: npm not found. Make it available to the host shell (e.g., with "nvm use --lts").'
7
- exit 2
5
+ NPM_CMD=" npm"
6
+
7
+ if ! (type $NPM_CMD >> /dev/null); then
8
+ echo " npm not found, trying to make it available using nvm..."
9
+ if type nvm >> /dev/null; then
10
+ echo " nvm found, using it to install the latest lts node"
11
+ nvm use --lts
12
+ else
13
+ echo " nvm not found, trying to make it available using the nvm.sh"
14
+ # try to make it available based on https://github.com/typicode/husky/issues/912#issuecomment-817522060
15
+ export NVM_DIR=" $HOME /.nvm/nvm.sh"
16
+ . " $( dirname $NVM_DIR ) /nvm.sh"
17
+
18
+ export NVM_DIR=" $HOME /.nvm"
19
+ a=$( nvm ls --no-colors | grep ' node' )
20
+ v=$( echo " $a " | sed -E ' s/.*\(-> ([^ ]+).*/\1/' )
21
+
22
+ export PATH=" $NVM_DIR /versions/node/$v /bin:$PATH "
23
+
24
+ if ! (type $NPM_CMD >> /dev/null); then
25
+ echo " no variant of npm or nvm found, trying to use the npm.cmd"
26
+ NPM_CMD=" npm.cmd"
27
+ fi
28
+ fi
8
29
fi
9
30
10
31
@@ -37,7 +58,7 @@ if [ -n "$(git status --porcelain)" ]; then
37
58
fi
38
59
39
60
echo " Linting project (local mode)..."
40
- npm run lint-local
61
+ $NPM_CMD run lint-local
41
62
42
63
43
64
# shellcheck disable=SC2124 # we want the argument splitting
You can’t perform that action at this time.
0 commit comments