1
|
'use strict';
|
2
|
var os = require('os');
|
3
|
|
4
|
function homedir() {
|
5
|
var env = process.env;
|
6
|
var home = env.HOME;
|
7
|
var user = env.LOGNAME || env.USER || env.LNAME || env.USERNAME;
|
8
|
|
9
|
if (process.platform === 'win32') {
|
10
|
return env.USERPROFILE || env.HOMEDRIVE + env.HOMEPATH || home || null;
|
11
|
}
|
12
|
|
13
|
if (process.platform === 'darwin') {
|
14
|
return home || (user ? '/Users/' + user : null);
|
15
|
}
|
16
|
|
17
|
if (process.platform === 'linux') {
|
18
|
return home || (process.getuid() === 0 ? '/root' : (user ? '/home/' + user : null));
|
19
|
}
|
20
|
|
21
|
return home || null;
|
22
|
}
|
23
|
|
24
|
module.exports = typeof os.homedir === 'function' ? os.homedir : homedir;
|