Skip to content

Commit

Permalink
Handle lower-case 'env.Path' on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 10, 2015
1 parent 9cbdf59 commit ff956d8
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions which.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,22 @@ function which (cmd, opt, cb) {
}

var colon = opt.colon || COLON
var pathEnv = (opt.path || process.env.PATH || '').split(colon)
var pathEnv = opt.path || process.env.PATH || ''
var pathExt = ['']

// On windows, env.Path is common.
if (process.platform === 'win32' && !pathEnv) {
var k = Object.keys(process.env)
for (var p = 0; p < k.length; p++) {
if (p.toLowerCase() === 'path') {
pathEnv = process.env[p]
break
}
}
}

pathEnv = pathEnv.split(colon)

if (process.platform === 'win32') {
pathEnv.push(process.cwd())
pathExt = opt.pathExt || (process.env.PATHEXT || '.EXE').split(colon)
Expand Down Expand Up @@ -66,9 +79,22 @@ function whichSync (cmd, opt) {

var colon = opt.colon || COLON

var pathEnv = (opt.path || process.env.PATH || '').split(colon)
var pathEnv = opt.path || process.env.PATH || ''
var pathExt = ['']

// On windows, env.Path is common.
if (process.platform === 'win32' && !pathEnv) {
var k = Object.keys(process.env)
for (var p = 0; p < k.length; p++) {
if (p.toLowerCase() === 'path') {
pathEnv = process.env[p]
break
}
}
}

pathEnv = pathEnv.split(colon)

if (process.platform === 'win32') {
pathEnv.push(process.cwd())
pathExt = (opt.pathExt || process.env.PATHEXT || '.EXE').split(colon)
Expand Down

0 comments on commit ff956d8

Please sign in to comment.