@@ -11,6 +11,16 @@ case `uname` in
11
11
* CYGWIN* ) basedir=` cygpath -w " $basedir " ` ;;
12
12
esac
13
13
14
+ if [ ` uname` = ' Linux' ] && type wslpath & > /dev/null ; then
15
+ IS_WSL=" true"
16
+ fi
17
+
18
+ function no_node_dir {
19
+ # if this didn't work, then everything else below will fail
20
+ echo " Could not determine Node.js install directory" >&2
21
+ exit 1
22
+ }
23
+
14
24
NODE_EXE=" $basedir /node.exe"
15
25
if ! [ -x " $NODE_EXE " ]; then
16
26
NODE_EXE=" $basedir /node"
21
31
22
32
# this path is passed to node.exe, so it needs to match whatever
23
33
# kind of paths Node.js thinks it's using, typically win32 paths.
24
- CLI_BASEDIR=" $( " $NODE_EXE " -p ' require("path").dirname(process.execPath)' ) "
34
+ CLI_BASEDIR=" $( " $NODE_EXE " -p ' require("path").dirname(process.execPath)' 2> /dev/null) "
35
+ if [ $? -ne 0 ]; then
36
+ # this fails under WSL 1 so add an additional message. we also suppress stderr above
37
+ # because the actual error raised is not helpful. in WSL 1 node.exe cannot handle
38
+ # output redirection properly. See https://github.com/microsoft/WSL/issues/2370
39
+ if [ " $IS_WSL " == " true" ]; then
40
+ echo " WSL 1 is not supported. Please upgrade to WSL 2 or above." >&2
41
+ fi
42
+ no_node_dir
43
+ fi
25
44
NPM_CLI_JS=" $CLI_BASEDIR /node_modules/npm/bin/npm-cli.js"
26
45
NPX_CLI_JS=" $CLI_BASEDIR /node_modules/npm/bin/npx-cli.js"
27
46
NPM_PREFIX=` " $NODE_EXE " " $NPM_CLI_JS " prefix -g`
28
47
if [ $? -ne 0 ]; then
29
- # if this didn't work, then everything else below will fail
30
- echo " Could not determine Node.js install directory" >&2
31
- exit 1
48
+ no_node_dir
32
49
fi
33
50
NPM_PREFIX_NPX_CLI_JS=" $NPM_PREFIX /node_modules/npm/bin/npx-cli.js"
34
51
@@ -38,7 +55,7 @@ NPX_WSL_PATH="/.."
38
55
# WSL can run Windows binaries, so we have to give it the win32 path
39
56
# however, WSL bash tests against posix paths, so we need to construct that
40
57
# to know if npm is installed globally.
41
- if [ ` uname ` = ' Linux ' ] && type wslpath & > /dev/null ; then
58
+ if [ " $IS_WSL " == " true " ] ; then
42
59
NPX_WSL_PATH=` wslpath " $NPM_PREFIX_NPX_CLI_JS " `
43
60
fi
44
61
if [ -f " $NPM_PREFIX_NPX_CLI_JS " ] || [ -f " $NPX_WSL_PATH " ]; then
0 commit comments