@@ -11,6 +11,16 @@ case `uname` in
1111 * CYGWIN* ) basedir=` cygpath -w " $basedir " ` ;;
1212esac
1313
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+
1424NODE_EXE=" $basedir /node.exe"
1525if ! [ -x " $NODE_EXE " ]; then
1626 NODE_EXE=" $basedir /node"
2131
2232# this path is passed to node.exe, so it needs to match whatever
2333# 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
2544NPM_CLI_JS=" $CLI_BASEDIR /node_modules/npm/bin/npm-cli.js"
2645NPX_CLI_JS=" $CLI_BASEDIR /node_modules/npm/bin/npx-cli.js"
2746NPM_PREFIX=` " $NODE_EXE " " $NPM_CLI_JS " prefix -g`
2847if [ $? -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
3249fi
3350NPM_PREFIX_NPX_CLI_JS=" $NPM_PREFIX /node_modules/npm/bin/npx-cli.js"
3451
@@ -38,7 +55,7 @@ NPX_WSL_PATH="/.."
3855# WSL can run Windows binaries, so we have to give it the win32 path
3956# however, WSL bash tests against posix paths, so we need to construct that
4057# to know if npm is installed globally.
41- if [ ` uname ` = ' Linux ' ] && type wslpath & > /dev/null ; then
58+ if [ " $IS_WSL " == " true " ] ; then
4259 NPX_WSL_PATH=` wslpath " $NPM_PREFIX_NPX_CLI_JS " `
4360fi
4461if [ -f " $NPM_PREFIX_NPX_CLI_JS " ] || [ -f " $NPX_WSL_PATH " ]; then
0 commit comments