diff --git a/package-lock.json b/package-lock.json index 8c4683e81..2225d11e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "check-password-strength": "^2.0.5", "cheerio": "~1.0.0-rc.12", "chroma-js": "~2.4.2", - "command-exists-promise": "~2.0.2", + "command-exists": "~1.2.9", "compare-versions": "~3.6.0", "compression": "~1.7.4", "country-flag-emoji-polyfill": "^0.1.8", @@ -6892,15 +6892,6 @@ "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", "license": "MIT" }, - "node_modules/command-exists-promise": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/command-exists-promise/-/command-exists-promise-2.0.2.tgz", - "integrity": "sha512-T6PB6vdFrwnHXg/I0kivM3DqaCGZLjjYSOe0a5WgFKcz1sOnmOeIjnhQPXVXX3QjVbLyTJ85lJkX6lUpukTzaA==", - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/commander": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", diff --git a/package.json b/package.json index 46686ef37..16837fa8a 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "check-password-strength": "^2.0.5", "cheerio": "~1.0.0-rc.12", "chroma-js": "~2.4.2", - "command-exists-promise": "~2.0.2", + "command-exists": "~1.2.9", "compare-versions": "~3.6.0", "compression": "~1.7.4", "country-flag-emoji-polyfill": "^0.1.8", diff --git a/server/monitor-types/real-browser-monitor-type.js b/server/monitor-types/real-browser-monitor-type.js index 8226d9dd0..1491d6c00 100644 --- a/server/monitor-types/real-browser-monitor-type.js +++ b/server/monitor-types/real-browser-monitor-type.js @@ -2,13 +2,13 @@ const { MonitorType } = require("./monitor-type"); const { chromium } = require("playwright-core"); const { UP, log } = require("../../src/util"); const { Settings } = require("../settings"); -const commandExists = require("command-exists-promise"); const childProcess = require("child_process"); const path = require("path"); const Database = require("../database"); const jwt = require("jsonwebtoken"); const config = require("../config"); const { RemoteBrowser } = require("../remote-browser"); +const { commandExists } = require("../util-server"); /** * Cached instance of a browser diff --git a/server/notification.js b/server/notification.js index d80140d76..4e9c9c4db 100644 --- a/server/notification.js +++ b/server/notification.js @@ -77,6 +77,7 @@ const SendGrid = require("./notification-providers/send-grid"); const YZJ = require("./notification-providers/yzj"); const SMSPlanet = require("./notification-providers/sms-planet"); const SpugPush = require("./notification-providers/spugpush"); +const { commandExists } = require("./util-server"); class Notification { @@ -262,7 +263,6 @@ class Notification { * @returns {Promise} Does the command apprise exist? */ static async checkApprise() { - const commandExists = require("command-exists-promise"); return await commandExists("apprise"); } diff --git a/server/util-server.js b/server/util-server.js index 08df728ed..e54a01d63 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -1096,3 +1096,19 @@ module.exports.axiosAbortSignal = (timeoutMs) => { } } }; + +/** + * By default, command-exists will throw a null error if the command does not exist, which is ugly. The function makes it better. + * Read more: https://github.com/mathisonian/command-exists/issues/22 + * @param {string} command Command to check + * @returns {Promise} True if command exists, false otherwise + */ +async function commandExists(command) { + try { + await require("command-exists")(command); + return true; + } catch (e) { + return false; + } +} +module.exports.commandExists = commandExists;