Skip to content

Commit b7019a3

Browse files
committed
added homedir polyfil
1 parent 934520d commit b7019a3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/LocalBinary.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function LocalBinary(){
2121
}
2222

2323
this.orderedPaths = [
24-
path.join(os.homedir(), '.browserstack'),
24+
path.join(this.homedir(), '.browserstack'),
2525
process.cwd(),
2626
os.tmpdir()
2727
];
@@ -82,6 +82,28 @@ function LocalBinary(){
8282
return false;
8383
}
8484
};
85+
86+
this.homedir = function() {
87+
if(typeof os.homedir === 'function') return os.homedir();
88+
89+
var env = process.env;
90+
var home = env.HOME;
91+
var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME;
92+
93+
if (process.platform === 'win32') {
94+
return env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home || null;
95+
}
96+
97+
if (process.platform === 'darwin') {
98+
return home || (user ? '/Users/' + user : null);
99+
}
100+
101+
if (process.platform === 'linux') {
102+
return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null));
103+
}
104+
105+
return home || null;
106+
}
85107
}
86108

87109
module.exports = LocalBinary;

0 commit comments

Comments
 (0)