UNPKG

edge-location

Version:

Approximates the current location of the Edge browser across platforms.

52 lines (51 loc) 1.83 kB
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs"; import * as __WEBPACK_EXTERNAL_MODULE_userhome__ from "userhome"; import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs"; import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path"; import * as __WEBPACK_EXTERNAL_MODULE_process__ from "process"; import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which"; function scanOsxPath() { const defaultPath = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'; const alternativePath = (0, __WEBPACK_EXTERNAL_MODULE_userhome__["default"])(defaultPath.slice(1)); if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(defaultPath)) return defaultPath; return alternativePath; } const { env } = __WEBPACK_EXTERNAL_MODULE_process__; function scanWindowsPath() { let browserPath = null; const prefixes = [ env.LOCALAPPDATA, env.PROGRAMFILES, env['PROGRAMFILES(X86)'] ]; const suffix = '\\Microsoft\\Edge\\Application\\msedge.exe'; for (const prefix of prefixes){ if (!prefix) continue; const exe = __WEBPACK_EXTERNAL_MODULE_path__.join(prefix, suffix); if (__WEBPACK_EXTERNAL_MODULE_fs__.existsSync(exe)) { browserPath = exe; break; } } return browserPath; } function scanUnknownPlatform() { let browserPath = null; try { browserPath = __WEBPACK_EXTERNAL_MODULE_which__["default"].sync('microsoft-edge'); } catch (err) { browserPath = null; } return browserPath; } function locateEdge() { switch(process.platform){ case 'darwin': return scanOsxPath(); case 'win32': return scanWindowsPath(); default: return scanUnknownPlatform(); } } export { locateEdge as default };