Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'no shebang' case #25

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
@@ -1,4 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.8"
- "4"
- "6"
- "8"
19 changes: 10 additions & 9 deletions index.js
Expand Up @@ -130,15 +130,15 @@ function writeShim_ (from, to, prog, args, 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"
+ " " + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
Expand All @@ -149,7 +149,8 @@ function writeShim_ (from, to, prog, args, 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