Skip to content

Commit 2d277f8

Browse files
igorklopovisaacs
authored andcommitted
fixes 'no shebang' case
PR-URL: #25 Credit: @igorklopov Close: #25 Reviewed-by: @isaacs Close: #36 Fix: #35
1 parent 1f5829c commit 2d277f8

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ function writeShim_ (from, to, prog, args, variables, cb) {
140140

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

143-
if (shLongProg) {
144-
sh = sh
145-
+ "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
146-
+ "\n"
147-
+ "case `uname` in\n"
148-
+ " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
149-
+ "esac\n"
150-
+ "\n"
143+
sh = sh
144+
+ "basedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")\n"
145+
+ "\n"
146+
+ "case `uname` in\n"
147+
+ " *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;\n"
148+
+ "esac\n"
149+
+ "\n"
151150

151+
if (shLongProg) {
152152
sh = sh
153153
+ "if [ -x "+shLongProg+" ]; then\n"
154154
+ " " + variables + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
@@ -159,7 +159,8 @@ function writeShim_ (from, to, prog, args, variables, cb) {
159159
+ "fi\n"
160160
+ "exit $ret\n"
161161
} else {
162-
sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
162+
sh = sh
163+
+ shProg + " " + args + " " + shTarget + " \"$@\"\n"
163164
+ "exit $?\n"
164165
}
165166

test/basic.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,14 @@ test('no shebang', function (t) {
1313
if (er)
1414
throw er
1515
t.equal(fs.readFileSync(to, 'utf8'),
16-
"\"$basedir/from.exe\" \"$@\"\nexit $?\n")
16+
"#!/bin/sh"+
17+
"\nbasedir=$(dirname \"$(echo \"$0\" | sed -e 's,\\\\,/,g')\")"+
18+
"\n"+
19+
"\ncase `uname` in"+
20+
"\n *CYGWIN*) basedir=`cygpath -w \"$basedir\"`;;"+
21+
"\nesac"+
22+
"\n"+
23+
"\n\"$basedir/from.exe\" \"$@\"\nexit $?\n")
1724
t.equal(fs.readFileSync(to + '.cmd', 'utf8'),
1825
"@\"%~dp0\\from.exe\" %*\r\n")
1926
t.end()

0 commit comments

Comments
 (0)