Skip to content

Commit

Permalink
Merge branch 'patch-git-bash'
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 13, 2012
2 parents 80da8e3 + 497db97 commit 9d0168e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
6 changes: 6 additions & 0 deletions bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
if [ -x "`dirname "$0"`/node.exe" ]; then
"`dirname "$0"`/node.exe" "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@"
else
node "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@"
fi
6 changes: 0 additions & 6 deletions bin/npm-g.cmd

This file was deleted.

6 changes: 0 additions & 6 deletions bin/npm_g.cmd

This file was deleted.

46 changes: 42 additions & 4 deletions lib/utils/cmd-shim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// XXX Todo:
// XXX Todo:
// On windows, create a .cmd file.
// Read the #! in the file to see what it uses. The vast majority
// of the time, this will be either:
Expand Down Expand Up @@ -37,13 +37,14 @@ function cmdShim (from, to, cb) {
chain
( [ [fs, "stat", from]
, [rm, to + ".cmd"]
, [rm, to]
, [mkdir, path.dirname(to)]
, [writeShim, from, to] ]
, cb )
}

function writeShim (from, to, cb) {
// make a cmd file
// make a cmd file and a sh script
// First, check if the bin is a #! of some sort.
// If not, then assume it's something that'll be compiled, or some other
// sort of script, and just call it directly.
Expand All @@ -59,16 +60,23 @@ function writeShim (from, to, cb) {
}

function writeShim_ (from, to, prog, args, cb) {
var target = relativize(from, to).split("/").join("\\")
var shTarget = relativize(from, to)
, target = shTarget.split("/").join("\\")
, longProg
, shProg = prog
, shLongProg
args = args || ""
if (!prog) {
prog = "\"%~dp0\\" + target + "\""
shProg = "\"`dirname \"$0\"`/" + shTarget + "\""
args = ""
target = ""
shTarget = ""
} else {
longProg = "\"%~dp0\"\\\"" + prog + ".exe\""
shLongProg = "\"`dirname \"$0\"`/" + prog + "\""
target = "\"%~dp0\\" + target + "\""
shTarget = "\"`dirname \"$0\"`/" + shTarget + "\""
}

// @IF EXIST "%~dp0"\"node.exe" (
Expand All @@ -89,10 +97,40 @@ function writeShim_ (from, to, prog, args, cb) {

cmd = ":: Created by npm, please don't edit manually.\r\n" + cmd

// #!/bin/sh
// if [ -x "`dirname "$0"`/node.exe" ]; then
// "`dirname "$0"`/node.exe" "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@"
// else
// node "`dirname "$0"`/node_modules/npm/bin/npm-cli.js" "$@"
// fi
var sh = "#!/bin/sh\n"

if (shLongProg) {
sh = sh
+ "if [ -x "+shLongProg+" ]; then\n"
+ " " + shLongProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "else \n"
+ " " + shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ " ret=$?\n"
+ "fi\n"
+ "exit $ret\n"
} else {
sh = shProg + " " + args + " " + shTarget + " \"$@\"\n"
+ "exit $?\n"
}

fs.writeFile(to + ".cmd", cmd, "utf8", function (er) {
if (er) {
log.warn("Could not write "+to+".cmd", "cmdShim")
return cb(er)
}
cb(er)
fs.writeFile(to, sh, "utf8", function (er) {
if (er) {
log.warn("Could not write "+to, "shShim")
return cb(er)
}
fs.chmod(to, 0755, cb)
})
})
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
, "bin": "./bin"
}
, "main": "./lib/npm.js"
, "bin": { "npm": "./bin/npm-cli.js"
, "npm_g": "./bin/npm-cli.js"
, "npm-g": "./bin/npm-cli.js" }
, "bin": "./bin/npm-cli.js"

, "dependencies":
{ "semver": "1"
Expand Down

0 comments on commit 9d0168e

Please sign in to comment.