Use os-homedir for older node.js versions

This commit is contained in:
Ian Scott 2016-01-28 14:51:16 -08:00
parent e90c1fd239
commit 582bd1a1b2
2 changed files with 6 additions and 3 deletions

View file

@ -49,17 +49,17 @@ function parseXauth( buf )
return auth; return auth;
} }
var os = require('os'); var homedir = require('os-homedir');
var path = require('path'); var path = require('path');
function readXauthority(cb) { function readXauthority(cb) {
var filename = process.env.XAUTHORITY || path.join(os.homedir(), '.Xauthority'); var filename = process.env.XAUTHORITY || path.join(homedir(), '.Xauthority');
fs.readFile(filename, function(err, data) { fs.readFile(filename, function(err, data) {
if (!err) if (!err)
return cb(null, data); return cb(null, data);
if(err.code == 'ENOENT') { if(err.code == 'ENOENT') {
// Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name // Xming/windows uses %HOME%/Xauthority ( .Xauthority with no dot ) - try with this name
filename = process.env.XAUTHORITY || path.join(os.homedir(), 'Xauthority'); filename = process.env.XAUTHORITY || path.join(homedir(), 'Xauthority');
return fs.readFile(filename, cb); return fs.readFile(filename, cb);
} else { } else {
cb(err); cb(err);

View file

@ -49,5 +49,8 @@
"scripts": { "scripts": {
"test": "node test-runner.js", "test": "node test-runner.js",
"prepublish": "npm prune" "prepublish": "npm prune"
},
"dependencies": {
"os-homedir": "^1.0.1"
} }
} }