Skip to content

Commit

Permalink
Fix generated shell scripts for MSYS2/MINGW
Browse files Browse the repository at this point in the history
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 yarnpkg/yarn#5349 among other
issues.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>

PR-URL: #30
Credit: @dscho
Close: #30
Reviewed-by: @isaacs
  • Loading branch information
dscho authored and isaacs committed Aug 12, 2019
1 parent adaf20b commit 49f0c13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"rimraf": "~2.2.8",
"tap": "^1.2.0"
}
}
}
12 changes: 6 additions & 6 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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" +
Expand Down Expand Up @@ -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"+
Expand Down Expand Up @@ -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"+
Expand Down Expand Up @@ -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" +
Expand Down Expand Up @@ -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" +
Expand Down

0 comments on commit 49f0c13

Please sign in to comment.