* Resolves the Selenium Manager binary for the running platform. * * `SE_MANAGER_PATH` wins when set, matching how every binding already lets users * point at a manager they built or vendored themselves. * * @return {string} the absolute path of the binary. * @throws {Error} if the platform is
()
| 52 | * @throws {Error} if the platform is unsupported or its package is missing. |
| 53 | */ |
| 54 | function binaryPath() { |
| 55 | if (process.env.SE_MANAGER_PATH) { |
| 56 | return process.env.SE_MANAGER_PATH |
| 57 | } |
| 58 | |
| 59 | const pkgName = PLATFORM_PACKAGES[`${platform}-${arch}`] ?? PLATFORM_PACKAGES[platform] |
| 60 | if (!pkgName) { |
| 61 | throw new Error(`Unsupported platform: ${platform} ${arch}. Supported: linux (x64, arm64), darwin, win32`) |
| 62 | } |
| 63 | |
| 64 | const isWindows = platform === 'win32' || platform === 'cygwin' |
| 65 | const binaryName = isWindows ? 'selenium-manager.exe' : 'selenium-manager' |
| 66 | |
| 67 | let pkgJsonPath |
| 68 | try { |
| 69 | pkgJsonPath = require.resolve(`${pkgName}/package.json`) |
| 70 | } catch (_) { |
| 71 | throw new Error(`Platform package ${pkgName} is not installed. Run: npm install ${pkgName}`) |
| 72 | } |
| 73 | |
| 74 | const binPath = path.join(path.dirname(pkgJsonPath), 'bin', binaryName) |
| 75 | if (!fs.existsSync(binPath)) { |
| 76 | throw new Error(`Binary not found at expected path: ${binPath}`) |
| 77 | } |
| 78 | return binPath |
| 79 | } |
| 80 | |
| 81 | module.exports = { binaryPath, PLATFORM_PACKAGES } |