Comparing version 1.0.13 to 1.1.0
@@ -77,4 +77,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
// this is used when reading the registry goes wrong. | ||
function fallBack () { | ||
resolve(getPathToExe(Winreg.HKCU, appName).catch(function() { | ||
return getPathToExe(Winreg.HKLM, appName); | ||
}).catch(function() { | ||
// Neither registry hive has the correct keys | ||
var programFilesVar = "ProgramFiles"; | ||
@@ -85,33 +87,31 @@ if (arch === "(64)") { | ||
} | ||
resolve(path.join(process.env[programFilesVar], appName, "firefox.exe")); | ||
} | ||
return path.join(process.env[programFilesVar], appName, "firefox.exe"); | ||
})); | ||
}); | ||
} | ||
var rootKey = "\\Software\\Mozilla\\"; | ||
rootKey = path.join(rootKey, appName); | ||
// Returns a promise to get Firefox's PathToExe from a registry hive | ||
function getPathToExe(hive, appName) { | ||
const rootKey = path.join("\\Software\\Mozilla\\", appName); | ||
return when.promise(function(resolve, reject) { | ||
var versionKey = new Winreg({ | ||
hive: Winreg.HKLM, | ||
key: rootKey | ||
}); | ||
versionKey.get("CurrentVersion", function(err, key) { | ||
var isOk = key && !err; | ||
return isOk ? resolve(key.value) : reject(); | ||
}); | ||
}).then(function(version) { | ||
var mainKey = new Winreg({ | ||
hive: Winreg.HKLM, | ||
key: path.join(rootKey, version, "Main") | ||
}); | ||
mainKey.get("PathToExe", function(err, key) { | ||
if (err) { | ||
fallBack(); | ||
return; | ||
} | ||
resolve(key.value); | ||
}); | ||
}, fallBack); | ||
return getRegistryValue(hive, rootKey, "CurrentVersion").then(function(version) { | ||
return getRegistryValue(hive, path.join(rootKey, version, "Main"), "PathToExe"); | ||
}); | ||
} | ||
// Returns a promise to get a single registry value | ||
function getRegistryValue(hive, key, name) { | ||
return when.promise(function(resolve, reject) { | ||
const registry = new Winreg({ hive, key }); | ||
registry.get(name, function(error, resultKey) { | ||
if (resultKey && !error) { | ||
resolve(resultKey.value); | ||
} else { | ||
reject(error); | ||
} | ||
}); | ||
}); | ||
} | ||
normalizeBinary.paths = { | ||
@@ -118,0 +118,0 @@ "firefox on osx": "/Applications/Firefox.app/Contents/MacOS/firefox-bin", |
{ | ||
"name": "fx-runner", | ||
"version": "1.0.13", | ||
"version": "1.1.0", | ||
"description": "A node cli to control Firefox", | ||
@@ -36,7 +36,7 @@ "main": "index.js", | ||
"devDependencies": { | ||
"async": "0.9.0", | ||
"chai": "1.10.0", | ||
"dive": "0.3.1", | ||
"mocha": "^8.0.1", | ||
"sandboxed-module": "2.0.0" | ||
"async": "3.2.0", | ||
"chai": "4.3.1", | ||
"dive": "0.5.0", | ||
"mocha": "8.3.0", | ||
"sandboxed-module": "2.0.4" | ||
}, | ||
@@ -43,0 +43,0 @@ "maintainers": [ |
# Firefox Runner | ||
[![Build Status](https://img.shields.io/travis/mozilla-jetpack/node-fx-runner.svg?style=flat-square)](https://travis-ci.org/mozilla-jetpack/node-fx-runner) | ||
[![Build Status](https://img.shields.io/npm/v/fx-runner.svg?style=flat-square)](https://www.npmjs.org/package/fx-runner) | ||
[![CircleCI](https://circleci.com/gh/mozilla/node-fx-runner.svg?style=svg)](https://circleci.com/gh/mozilla/node-fx-runner) | ||
[![npm version](https://badge.fury.io/js/fx-runner.svg)](https://badge.fury.io/js/fx-runner) | ||
[![NPM](https://nodei.co/npm/fx-runner.png?stars&downloads)](https://nodei.co/npm/fx-runner/) | ||
[![NPM](https://nodei.co/npm-dl/fx-runner.png)](https://nodei.co/npm/fx-runner) | ||
## API | ||
@@ -10,0 +7,0 @@ |
@@ -38,10 +38,66 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
var expected = "fake\\binary\\path"; | ||
// see ./mock-winreg.js | ||
// Only mock keys in HKLM (local machine) hive. | ||
// This test case checks the basic functionality if the user does not have a newer version of | ||
// Firefox installed meaning the HKCU keys are not present. | ||
var winreg = function(options) { | ||
this.get = function(_, fn) { | ||
if (options.hive === winreg.HKLM) { | ||
fn(null, {value: expected}); | ||
} else { | ||
fn("Failed", null); | ||
} | ||
}; | ||
}; | ||
winreg.HKLM = "HKLM"; | ||
var binary = sandbox.require("../../lib/utils", { | ||
requires: { winreg } | ||
}).normalizeBinary; | ||
var promises = [ | ||
[null, "windows", "x86"], | ||
[null, "windows", "x86_64"] | ||
].map(function(args) { | ||
var promise = binary.apply(binary, args); | ||
return promise.then(function(actual) { | ||
expect(actual).to.be.equal(expected); | ||
}); | ||
}); | ||
all(promises).then(done.bind(null, null), done); | ||
}); | ||
it("normalizeBinary() prefers HKCU registry hive over HKLM on Windows", function(done) { | ||
// Skip this test for now, to get Travis running. | ||
if (!/win/i.test(os.platform)) { | ||
done(); | ||
return; | ||
} | ||
// Provide different paths depending on hive. | ||
// This test case checks that in order to find recent versions of Firefox, HKCU is tried | ||
// before falling back on HKCU as in the test above. | ||
var expected = "fake\\binary\\path"; | ||
var oldPath = "fake\\old\\binary\\path"; | ||
// see ./mock-winreg.js | ||
var winreg = function(options) { | ||
this.get = function(_, fn) { | ||
if (options.hive === winreg.HKCU) { | ||
fn(null, {value: expected}); | ||
} else if (options.hive === winreg.HKLM) { | ||
fn(null, {value: oldPath}); | ||
} else { | ||
fn("Failed", null); | ||
} | ||
}; | ||
}; | ||
// Differentiate hives | ||
winreg.HKLM = "HKLM"; | ||
winreg.HKCU = "HKCU"; | ||
var binary = sandbox.require("../../lib/utils", { | ||
requires: {"winreg": function() { | ||
this.get = function(_, fn) { | ||
fn(null, {value: expected}); | ||
}; | ||
}} | ||
requires: { winreg } | ||
}).normalizeBinary; | ||
@@ -48,0 +104,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52783
16
695
45