From eb938a5b4d3579cd8d0be38ca70fd106ed421ac3 Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 13:44:42 +0800 Subject: [PATCH 1/7] windows: Add preliminary WSL support for npm 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. --- bin/npm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/npm b/bin/npm index 4183703a7857e..1a60d10aa0566 100755 --- a/bin/npm +++ b/bin/npm @@ -2,12 +2,16 @@ (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix basedir=`dirname "$0"` +isexe=0 case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac NODE_EXE="$basedir/node.exe" +if [ -x "$NODE_EXE" ]; then + isexe=1 +fi if ! [ -x "$NODE_EXE" ]; then NODE_EXE="$basedir/node" fi @@ -34,4 +38,8 @@ case `uname` in ;; esac +if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # normalize path back to Windows path + NPM_CLI_JS=`wslpath -w "$NPM_CLI_JS"` +fi + "$NODE_EXE" "$NPM_CLI_JS" "$@" From 9db8a3a33aa349e251e47413953ee5c6afa06be4 Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 13:48:42 +0800 Subject: [PATCH 2/7] windows: Add preliminary WSL support for npx This commit would make it possible to run `npx` 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. --- bin/npx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/npx b/bin/npx index 261e339850da5..5e5c7ef62e8ee 100644 --- a/bin/npx +++ b/bin/npx @@ -2,12 +2,16 @@ (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix basedir=`dirname "$0"` +isexe=0 case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac NODE_EXE="$basedir/node.exe" +if [ -x "$NODE_EXE" ]; then + isexe=1 +fi if ! [ -x "$NODE_EXE" ]; then NODE_EXE=node fi @@ -32,4 +36,8 @@ case `uname` in ;; esac +if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # normalize path back to Windows path + NPM_CLI_JS=`wslpath -w "$NPM_CLI_JS"` +fi + "$NODE_EXE" "$NPX_CLI_JS" "$@" From 00fe2a0874ba3bab08fa1751f4251acaa8949eaa Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 13:54:42 +0800 Subject: [PATCH 3/7] fix: spelling within npx --- bin/npx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/npx b/bin/npx index 5e5c7ef62e8ee..baaf41f8160e5 100644 --- a/bin/npx +++ b/bin/npx @@ -37,7 +37,7 @@ case `uname` in esac if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # normalize path back to Windows path - NPM_CLI_JS=`wslpath -w "$NPM_CLI_JS"` + NPX_CLI_JS=`wslpath -w "$NPX_CLI_JS"` fi "$NODE_EXE" "$NPX_CLI_JS" "$@" From 179c892d4251a55094780e9e82cd7772ba7727af Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 17:13:52 +0800 Subject: [PATCH 4/7] windows: run the corresponding command prompt Run the corresponding command prompt when Node for Windows is executed within WSL. --- bin/npm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/npm b/bin/npm index 1a60d10aa0566..0a6bace5c4c56 100755 --- a/bin/npm +++ b/bin/npm @@ -38,8 +38,9 @@ case `uname` in ;; esac -if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # normalize path back to Windows path - NPM_CLI_JS=`wslpath -w "$NPM_CLI_JS"` +if [ isexe==1 ] && [ -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"` "$@" + return fi "$NODE_EXE" "$NPM_CLI_JS" "$@" From 2d5bdacc21447bfcee44e2760f0fd68e506f4545 Mon Sep 17 00:00:00 2001 From: joan xie Date: Fri, 20 Sep 2019 17:15:04 +0800 Subject: [PATCH 5/7] windows: ditto for npx --- bin/npx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/npx b/bin/npx index baaf41f8160e5..632931ddc530f 100644 --- a/bin/npx +++ b/bin/npx @@ -36,8 +36,9 @@ case `uname` in ;; esac -if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # normalize path back to Windows path - NPX_CLI_JS=`wslpath -w "$NPX_CLI_JS"` +if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # run the corresponding cmd instead + cmd.exe /c `wslpath -w "$basedir/npx.cmd"` "$@" + return fi "$NODE_EXE" "$NPX_CLI_JS" "$@" From b3e243ce3e7ed5f325436ca21d36362eba76abaa Mon Sep 17 00:00:00 2001 From: joan xie Date: Mon, 23 Sep 2019 10:03:09 +0800 Subject: [PATCH 6/7] windows: front the wsl condition --- bin/npm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bin/npm b/bin/npm index 0a6bace5c4c56..737d1f1706489 100755 --- a/bin/npm +++ b/bin/npm @@ -2,15 +2,15 @@ (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix basedir=`dirname "$0"` -isexe=0 case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac NODE_EXE="$basedir/node.exe" -if [ -x "$NODE_EXE" ]; then - isexe=1 +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" @@ -38,9 +38,4 @@ case `uname` in ;; esac -if [ isexe==1 ] && [ -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"` "$@" - return -fi - "$NODE_EXE" "$NPM_CLI_JS" "$@" From baa091a27188d9ad49252adfd715c8ea231f9373 Mon Sep 17 00:00:00 2001 From: joan xie Date: Mon, 23 Sep 2019 10:05:57 +0800 Subject: [PATCH 7/7] windows: ditto for npx --- bin/npx | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bin/npx b/bin/npx index 632931ddc530f..3516c8c415dba 100644 --- a/bin/npx +++ b/bin/npx @@ -2,15 +2,15 @@ (set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix basedir=`dirname "$0"` -isexe=0 case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac NODE_EXE="$basedir/node.exe" -if [ -x "$NODE_EXE" ]; then - isexe=1 +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 @@ -36,9 +36,4 @@ case `uname` in ;; esac -if [ isexe==1 ] && [ -f "/bin/wslpath" ]; then # run the corresponding cmd instead - cmd.exe /c `wslpath -w "$basedir/npx.cmd"` "$@" - return -fi - "$NODE_EXE" "$NPX_CLI_JS" "$@"