Skip to content

Commit

Permalink
windows: use process.env.USERPROFILE for 'home'
Browse files Browse the repository at this point in the history
Credit: @elidoran
Reviewed-By: @othiym23
PR-URL: #77
  • Loading branch information
elidoran authored and othiym23 committed Dec 13, 2016
1 parent 326ffff commit 20b4d56
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/nopt.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ function validatePath (data, k, val) {
if (val === null) return true

val = String(val)
var homePattern = process.platform === 'win32' ? /^~(\/|\\)/ : /^~\//
if (val.match(homePattern) && process.env.HOME) {
val = path.resolve(process.env.HOME, val.substr(2))

var isWin = process.platform === 'win32'
, homePattern = isWin ? /^~(\/|\\)/ : /^~\//
, home = isWin ? process.env.USERPROFILE : process.env.HOME

if (home && val.match(homePattern)) {
data[k] = path.resolve(home, val.substr(2))
} else {
data[k] = path.resolve(val)
}
data[k] = path.resolve(String(val))
return true
}

Expand Down

0 comments on commit 20b4d56

Please # to comment.