use path join for platform agnostic absolute path

This commit is contained in:
Stephen Birarda 2016-01-07 17:44:55 -08:00
parent f569ebb0a9
commit 39e95837ec

View file

@ -1,4 +1,5 @@
var fs = require('fs'); var fs = require('fs');
var path = require('path');
exports.searchPaths = function(name, binaryType) { exports.searchPaths = function(name, binaryType) {
function platformExtension(name) { function platformExtension(name) {
@ -29,7 +30,7 @@ exports.searchPaths = function(name, binaryType) {
} else { } else {
// check directly beside the binary // check directly beside the binary
paths = [ paths = [
process.execPath + "/" + name + extension, path.join(process.execPath, name + extension)
]; ];
// check if we're inside an app bundle on OS X // check if we're inside an app bundle on OS X
@ -53,17 +54,17 @@ exports.searchPaths = function(name, binaryType) {
exports.discoveredPath = function (name, binaryType) { exports.discoveredPath = function (name, binaryType) {
function binaryFromPaths(name, paths) { function binaryFromPaths(name, paths) {
for (var i = 0; i < paths.length; i++) { for (var i = 0; i < paths.length; i++) {
var path = paths[i]; var testPath = paths[i];
try { try {
var stats = fs.lstatSync(path); var stats = fs.lstatSync(testPath);
if (stats.isFile() || (stats.isDirectory() && extension == ".app")) { if (stats.isFile() || (stats.isDirectory() && extension == ".app")) {
console.log("Found " + name + " at " + path); console.log("Found " + name + " at " + testPath);
return path; return testPath;
} }
} catch (e) { } catch (e) {
console.log("Executable with name " + name + " not found at path " + path); console.log("Executable with name " + name + " not found at path " + testPath);
} }
} }