UNPKG

@appium/support

Version:

Support libs used across Appium packages

87 lines 2.65 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.arch = exports.system = void 0; exports.isWindows = isWindows; exports.isMac = isMac; exports.isLinux = isLinux; exports.isOSWin64 = isOSWin64; exports.macOsxVersion = macOsxVersion; const teen_process_1 = require("teen_process"); const lodash_1 = __importDefault(require("lodash")); const node_os_1 = __importDefault(require("node:os")); const VERSION_PATTERN = /^(\d+\.\d+)/m; /** * Whether the current OS is Windows. */ function isWindows() { return node_os_1.default.type() === 'Windows_NT'; } /** * Whether the current OS is macOS (Darwin). */ function isMac() { return node_os_1.default.type() === 'Darwin'; } /** * Whether the current OS is Linux (i.e. not Windows and not macOS). */ function isLinux() { return !isWindows() && !isMac(); } /** * Whether the current Windows process is 64-bit (or WOW64). */ function isOSWin64() { return process.arch === 'x64' || lodash_1.default.has(process.env, 'PROCESSOR_ARCHITEW6432'); } /** * Detects the major.minor macOS version (e.g. "10.12") via `sw_vers -productVersion`. * * @returns The major.minor version string. * @throws {Error} If `sw_vers` fails or output cannot be parsed. */ async function macOsxVersion() { let stdout; try { stdout = (await (0, teen_process_1.exec)('sw_vers', ['-productVersion'])).stdout.trim(); } catch (err) { throw new Error(`Could not detect Mac OS X Version: ${err}`); } const versionMatch = VERSION_PATTERN.exec(stdout); if (!versionMatch) { throw new Error(`Could not detect Mac OS X Version from sw_vers output: '${stdout}'`); } return versionMatch[1]; } /** * System detection helpers (platform, architecture, macOS version). * Use this object when you need `arch()` to call other helpers via `this` (e.g. for testing). */ exports.system = { isWindows, isMac, isLinux, isOSWin64, arch: archImpl, macOsxVersion, }; /** * Resolves the process architecture as `'32'` or `'64'` (uname on Unix, process.arch/env on Windows). */ exports.arch = exports.system.arch; async function archImpl() { if (this.isLinux() || this.isMac()) { const { stdout } = await (0, teen_process_1.exec)('uname', ['-m']); return stdout.trim() === 'i686' ? '32' : '64'; } else if (this.isWindows()) { return this.isOSWin64() ? '64' : '32'; } return '64'; } // #endregion //# sourceMappingURL=system.js.map