Skip to content

Commit

Permalink
fixes 'no shebang' case
Browse files Browse the repository at this point in the history
PR-URL: #25
Credit: @igorklopov
Close: #25
Reviewed-by: @isaacs
Close: #36
Fix: #35
  • Loading branch information
igorklopov authored and isaacs committed Aug 12, 2019
1 parent 1f5829c commit 2d277f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
19 changes: 10 additions & 9 deletions index.js
Expand Up @@ -140,15 +140,15 @@ function writeShim_ (from, to, prog, args, variables, cb) {

var sh = "#!/bin/sh\n"

if (shLongProg) {
sh = sh
+ "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
+ "\n"
+ "case `uname` in\n"
+ " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
+ "esac\n"
+ "\n"
sh = sh
+ "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
+ "\n"
+ "case `uname` in\n"
+ " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
+ "esac\n"
+ "\n"

if (shLongProg) {
sh = sh
+ "if [ -x "+shLongProg+" ]; then\n"
+ " " + variables + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
Expand All @@ -159,7 +159,8 @@ function writeShim_ (from, to, prog, args, variables, cb) {
+ "fi\n"
+ "exit $ret\n"
} else {
sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
sh = sh
+ shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ "exit $?\n"
}

Expand Down
9 changes: 8 additions & 1 deletion test/basic.js
Expand Up @@ -13,7 +13,14 @@ test('no shebang', function (t) {
if (er)
throw er
t.equal(fs.readFileSync(to, 'utf8'),
"\"$basedir/from.exe\" \"$@\"\nexit $?\n")
"#!/bin/sh"+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
"\n"+
"\ncase `uname` in"+
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
"\nesac"+
"\n"+
"\n\"$basedir/from.exe\" \"$@\"\nexit $?\n")
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
"@\"%~dp0\\from.exe\" %*\r\n")
t.end()
Expand Down

0 comments on commit 2d277f8

Please sign in to comment.