From 3471d5200217bfa612b1a262e36c9c043a52eb09 Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 13:44:42 +0800 Subject: [PATCH] windows: Add preliminary WSL support for npm and npx This commit would make it possible to run `npm` installed on Windows within Windows Subsystem for Linux. It is required, however, that the end of line characters of `npm` and `npx` be `\n` for the fix to take effect. PR-URL: https://github.com/npm/cli/pull/253 Credit: @infinnie Close: #253 Reviewed-by: @claudiahdz --- bin/npm | 4 ++++ bin/npx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/bin/npm b/bin/npm index 4183703a7857e..737d1f1706489 100755 --- a/bin/npm +++ b/bin/npm @@ -8,6 +8,10 @@ case `uname` in esac NODE_EXE="$basedir/node.exe" +if [ -x "$NODE_EXE" ] && [ -f "/bin/wslpath" ]; then # run the corresponding command prompt when Node for Windows is executed within WSL + cmd.exe /c `wslpath -w "$basedir/npm.cmd"` "$@" + exit $? +fi if ! [ -x "$NODE_EXE" ]; then NODE_EXE="$basedir/node" fi diff --git a/bin/npx b/bin/npx index 261e339850da5..3516c8c415dba 100644 --- a/bin/npx +++ b/bin/npx @@ -8,6 +8,10 @@ case `uname` in esac NODE_EXE="$basedir/node.exe" +if [ -x "$NODE_EXE" ] && [ -f "/bin/wslpath" ]; then # run the corresponding command prompt when Node for Windows is executed within WSL + cmd.exe /c `wslpath -w "$basedir/npx.cmd"` "$@" + exit $? +fi if ! [ -x "$NODE_EXE" ]; then NODE_EXE=node fi