Skip to content

Commit

Permalink
Bump which to v4 (#139)
Browse files Browse the repository at this point in the history
* Update `which`

* Fix mocks
  • Loading branch information
fregante authored Aug 30, 2024
1 parent 9c8dcd7 commit b31bbca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
10 changes: 2 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var which = require("which");
* @return {Promise}
*/
function normalizeBinary (binaryPath, platform, arch) {
return new Promise(function(resolve, reject) {
return new Promise(function(resolve) {
platform = platform || os.platform();
arch = arch || os.arch();
binaryPath = binaryPath || process.env.JPM_FIREFOX_BINARY || "firefox";
Expand Down Expand Up @@ -66,13 +66,7 @@ function normalizeBinary (binaryPath, platform, arch) {
// On linux but no path yet, use which to try and find the binary
else if (platform.indexOf("linux") !== -1) {
binaryPath = normalizeBinary.appNames[binaryPath + " on linux"] || binaryPath;
which(binaryPath, function(err, resolvedPath) {
if (err) {
reject(err);
} else {
resolve(resolvedPath);
}
});
resolve(which(binaryPath));
return;
}
// No action needed on windows if it's an executable already
Expand Down
28 changes: 7 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"commander": "^12.1.0",
"shell-quote": "1.8.1",
"which": "1.2.4",
"which": "^4.0.0",
"winreg": "0.0.12"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions test/run/test.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var sandbox = require('sandboxed-module');
var binary = utils.normalizeBinary;

sandbox.configure({
requires: {
// sandboxed-module is unable to find this module directly
"fs/promises": require("fs/promises"),
},
globals: {
// As of Node 12.x, the process global is no longer an enumerable property of the global.
// https://github.com/nodejs/node/pull/26882
Expand Down Expand Up @@ -160,9 +164,7 @@ describe("lib/utils", function () {

var binary = sandbox.require("../../lib/utils", {
requires: {
which: function(bin, callback) {
callback(null, "/usr/bin/" + bin);
}
which: async (bin) => "/usr/bin/" + bin
}
}).normalizeBinary;

Expand Down Expand Up @@ -247,9 +249,7 @@ describe("lib/utils", function () {

var binary = sandbox.require("../../lib/utils", {
requires: {
which: function(bin, callback) {
callback(null, "/usr/bin/" + bin);
}
which: async (bin) => "/usr/bin/" + bin
}
}).normalizeBinary;

Expand Down

0 comments on commit b31bbca

Please # to comment.