From 49f0c1318fd384e0031c3fd43801f0e22e1e555f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 21 Jun 2018 09:52:50 +0200 Subject: [PATCH] Fix generated shell scripts for MSYS2/MINGW It has been reported tons and tons of times that the generated shell scripts simply fail in Git Bash of the Git for Windows project. The reason is that the Cygwin-specific basedir workaround is also required for MSYS2 (which is used internally by the Git Bash). Let's be nice to everybody and include support for MSYS2. As MSYS2 distinguishes between MSYS/MINGW modes, triggered by setting the environment variable MSYSTEM to the values MSYS, MINGW32 and MINGW64, and as those modes are reflected in the output of `uname -s`, we need to look not only for MSYS but also for MINGW in the output of `uname`. This addresses https://github.com/yarnpkg/yarn/issues/5349 among other issues. Signed-off-by: Johannes Schindelin PR-URL: https://github.com/npm/cmd-shim/pull/30 Credit: @dscho Close: #30 Reviewed-by: @isaacs --- index.js | 4 ++-- package.json | 2 +- test/basic.js | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 0949162..cfdc45c 100644 --- a/index.js +++ b/index.js @@ -132,7 +132,7 @@ function writeShim_ (from, to, prog, args, variables, cb) { // basedir=`dirname "$0"` // // case `uname` in - // *CYGWIN*) basedir=`cygpath -w "$basedir"`;; + // *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;; // esac // // if [ -x "$basedir/node.exe" ]; then @@ -150,7 +150,7 @@ function writeShim_ (from, to, prog, args, variables, cb) { + "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n" + "\n" + "case `uname` in\n" - + " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n" + + " *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;\n" + "esac\n" + "\n" diff --git a/package.json b/package.json index 94a1c49..7766f5b 100644 --- a/package.json +++ b/package.json @@ -18,4 +18,4 @@ "rimraf": "~2.2.8", "tap": "^1.2.0" } -} \ No newline at end of file +} diff --git a/test/basic.js b/test/basic.js index 8b8cdf0..001c2d0 100755 --- a/test/basic.js +++ b/test/basic.js @@ -17,7 +17,7 @@ test('no shebang', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ "\n"+ "\ncase `uname` in"+ - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ "\nesac"+ "\n"+ "\n\"$basedir/from.exe\" \"$@\"\nexit $?\n") @@ -39,7 +39,7 @@ test('env shebang', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n" + "\ncase `uname` in" + - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + "\nesac" + "\n" + "\nif [ -x \"$basedir/node\" ]; then" + @@ -80,7 +80,7 @@ test('env shebang with args', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+ "\n"+ "\ncase `uname` in"+ - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ "\nesac"+ "\n"+ "\nif [ -x \"$basedir/node\" ]; then"+ @@ -121,7 +121,7 @@ test('env shebang with variables', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n"+ "\ncase `uname` in"+ - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+ + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;"+ "\nesac"+ "\n"+ "\nif [ -x \"$basedir/node\" ]; then"+ @@ -162,7 +162,7 @@ test('explicit shebang', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n" + "\ncase `uname` in" + - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + "\nesac" + "\n" + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" + @@ -204,7 +204,7 @@ test('explicit shebang with args', function (t) { "\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")" + "\n" + "\ncase `uname` in" + - "\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;" + + "\n *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w \"$basedir\"`;;" + "\nesac" + "\n" + "\nif [ -x \"$basedir//usr/bin/sh\" ]; then" +