firefox-location2
Version:
Approximates the current location of the Firefox browser across platforms.
39 lines (38 loc) • 1.83 kB
JavaScript
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
import * as __WEBPACK_EXTERNAL_MODULE_os__ from "os";
import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which";
const osx = 'darwin' === process.platform;
const win = 'win32' === process.platform;
const other = !osx && !win;
function locateFirefox() {
if (other) try {
return __WEBPACK_EXTERNAL_MODULE_which__["default"].sync('firefox');
} catch (_) {
return null;
}
if (osx) {
const regPath = '/Applications/Firefox.app/Contents/MacOS/firefox';
const altPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(__WEBPACK_EXTERNAL_MODULE_os__["default"].homedir(), regPath.slice(1));
return __WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(regPath) ? regPath : __WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(altPath) ? altPath : null;
}
{
const suffix = __WEBPACK_EXTERNAL_MODULE_path__["default"].join('Mozilla Firefox', 'firefox.exe');
const possiblePaths = [
process.env.LOCALAPPDATA,
process.env.PROGRAMFILES,
process.env['PROGRAMFILES(X86)']
];
for (const prefix of possiblePaths)if (prefix) {
const exePath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(prefix, suffix);
if (__WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(exePath)) return exePath;
}
const defaultPaths = [
'C:\\Program Files\\Mozilla Firefox\\firefox.exe',
'C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe'
];
for (const defaultPath of defaultPaths)if (__WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(defaultPath)) return defaultPath;
return null;
}
}
export { locateFirefox as default };