'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var path = require('path'); var node_child_process = require('node:child_process'); var require$$1 = require('tty'); var require$$1$1 = require('util'); var require$$0 = require('os'); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise, SuppressedError, Symbol */ function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { var e = new Error(message); return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; function winBatAdapt(cmd) { if (process.platform === 'win32' && (cmd.endsWith('sdkmanager') || cmd.endsWith('avdmanager'))) { return `${cmd}.bat`; } return cmd; } function transformCommand(command) { const [cmd, ...args] = command.split(' '); return { cmd: winBatAdapt(cmd), args: args.filter((arg) => arg) }; } /** * Run a shell command. */ function spawnExec(command, timeout = 300000) { return new Promise((resolve, reject) => { const { cmd, args } = transformCommand(command); const proc = node_child_process.spawn(cmd, args); const clock = setTimeout(() => { proc.kill(); reject(Error('Execution timeout')); }, timeout); let output = ''; proc.stdout.setEncoding('utf8'); proc.stdout.on('data', (data) => { output += data; }); let error = ''; proc.stderr.setEncoding('utf8'); proc.stderr.on('data', (err) => { error += err; }); proc.on('close', (code) => { clearTimeout(clock); if (code) { reject(Error(error)); } else { proc.output = output; resolve(proc); } }); }); } /** * Execute a shell command synchronously. */ function spwanSyncExec(command, timeout = 300000) { var _a; const { cmd, args } = transformCommand(command); const clock = setTimeout(() => { throw Error('Execution timeout'); }, timeout); const res = node_child_process.spawnSync(cmd, args, { encoding: 'utf8' }); clearTimeout(clock); return (_a = res.output.find((item) => item)) !== null && _a !== void 0 ? _a : ''; } /** * Execute a shell command until a matching output is found. */ function spawnWaitFor(command, regex, timeout = 600000) { return new Promise((resolve, reject) => { const { cmd, args } = transformCommand(command); const proc = node_child_process.spawn(cmd, args, { stdio: ['ignore', 'pipe', 'ignore'] }); const clock = setTimeout(() => { proc.kill(); reject(Error('Execution timeout')); }, timeout); let output = ''; proc.stdout.setEncoding('utf8'); proc.stdout.on('data', (data) => { output += data; const matches = data.match(regex); if (matches) { clearTimeout(clock); resolve({ process: proc, matches: matches, line: data }); } }); proc.on('close', () => { clearTimeout(clock); reject(Error(output)); }); }); } /** * Whether to execute the expected matching result. * @param cmd command * @param regex expected result match */ function isExecExpectedResult(cmd, regex) { try { const res = spwanSyncExec(cmd); return regex.test(res); } catch (error) { return false; } } /** * Retry executing a certain operation until the condition is met. * @param execFunc The executed function. * @param retries The maximum number of executions, defaulting to 10. */ function retry(execFunc, retries = 10) { return __awaiter(this, void 0, void 0, function* () { const res = yield Promise.resolve(execFunc()); if (res) return; if (retries > 1) { yield new Promise((resolve) => setTimeout(() => { resolve(undefined); }, 1000)); yield retry(execFunc, retries - 1); } else { throw Error('Already reached maximum retry times.'); } }); } function processKeyValueGroups(str) { const lines = str.split('\n'); let currentKey = {}; const results = []; lines.forEach(function (line) { const matches = line.match(/(\w+):\s(.*)/); if (matches === null) { return; } const key = matches[1]; const value = matches[2]; if (typeof currentKey[key] !== 'undefined') { results.push(currentKey); currentKey = {}; } currentKey[key] = value; }); if (Object.keys(currentKey).length) { results.push(currentKey); } return results; } function filterGroupImages(output) { const lines = output.split('\n'); const localArch = getLocalArch(); return lines .map((line) => line.split('|')[0].trim()) .filter((line) => line.startsWith('system-images;')) .map((name) => { const [type, sdk, target, arch] = name.split(';'); return { name, type, sdk, target, arch }; }) .filter((item) => { return item.arch === localArch; }); } function getLocalArch() { if (process.arch === 'arm') return 'armeabi-v7a'; if (process.arch === 'arm64') return 'arm64-v8a'; if (process.arch === 'ia32') return 'x86'; if (process.arch === 'x64') return 'x86_64'; return ''; } function params2Cmd(options = {}) { const opts = []; for (const key in options) { const val = options[key]; const cliKey = '-' + key.replace(/[A-Z]/g, (matched) => `-${matched.toLocaleLowerCase()}`); if (val === true) { opts.push(cliKey); } else if (val) { opts.push(cliKey, val); } } return opts.join(' '); } function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } var src = {exports: {}}; var browser = {exports: {}}; /** * Helpers. */ var ms; var hasRequiredMs; function requireMs () { if (hasRequiredMs) return ms; hasRequiredMs = 1; var s = 1000; var m = s * 60; var h = m * 60; var d = h * 24; var w = d * 7; var y = d * 365.25; /** * Parse or format the given `val`. * * Options: * * - `long` verbose formatting [false] * * @param {String|Number} val * @param {Object} [options] * @throws {Error} throw an error if val is not a non-empty string or a number * @return {String|Number} * @api public */ ms = function(val, options) { options = options || {}; var type = typeof val; if (type === 'string' && val.length > 0) { return parse(val); } else if (type === 'number' && isFinite(val)) { return options.long ? fmtLong(val) : fmtShort(val); } throw new Error( 'val is not a non-empty string or a valid number. val=' + JSON.stringify(val) ); }; /** * Parse the given `str` and return milliseconds. * * @param {String} str * @return {Number} * @api private */ function parse(str) { str = String(str); if (str.length > 100) { return; } var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { return; } var n = parseFloat(match[1]); var type = (match[2] || 'ms').toLowerCase(); switch (type) { case 'years': case 'year': case 'yrs': case 'yr': case 'y': return n * y; case 'weeks': case 'week': case 'w': return n * w; case 'days': case 'day': case 'd': return n * d; case 'hours': case 'hour': case 'hrs': case 'hr': case 'h': return n * h; case 'minutes': case 'minute': case 'mins': case 'min': case 'm': return n * m; case 'seconds': case 'second': case 'secs': case 'sec': case 's': return n * s; case 'milliseconds': case 'millisecond': case 'msecs': case 'msec': case 'ms': return n; default: return undefined; } } /** * Short format for `ms`. * * @param {Number} ms * @return {String} * @api private */ function fmtShort(ms) { var msAbs = Math.abs(ms); if (msAbs >= d) { return Math.round(ms / d) + 'd'; } if (msAbs >= h) { return Math.round(ms / h) + 'h'; } if (msAbs >= m) { return Math.round(ms / m) + 'm'; } if (msAbs >= s) { return Math.round(ms / s) + 's'; } return ms + 'ms'; } /** * Long format for `ms`. * * @param {Number} ms * @return {String} * @api private */ function fmtLong(ms) { var msAbs = Math.abs(ms); if (msAbs >= d) { return plural(ms, msAbs, d, 'day'); } if (msAbs >= h) { return plural(ms, msAbs, h, 'hour'); } if (msAbs >= m) { return plural(ms, msAbs, m, 'minute'); } if (msAbs >= s) { return plural(ms, msAbs, s, 'second'); } return ms + ' ms'; } /** * Pluralization helper. */ function plural(ms, msAbs, n, name) { var isPlural = msAbs >= n * 1.5; return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : ''); } return ms; } var common; var hasRequiredCommon; function requireCommon () { if (hasRequiredCommon) return common; hasRequiredCommon = 1; /** * This is the common logic for both the Node.js and web browser * implementations of `debug()`. */ function setup(env) { createDebug.debug = createDebug; createDebug.default = createDebug; createDebug.coerce = coerce; createDebug.disable = disable; createDebug.enable = enable; createDebug.enabled = enabled; createDebug.humanize = requireMs(); createDebug.destroy = destroy; Object.keys(env).forEach(key => { createDebug[key] = env[key]; }); /** * The currently active debug mode names, and names to skip. */ createDebug.names = []; createDebug.skips = []; /** * Map of special "%n" handling functions, for the debug "format" argument. * * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N". */ createDebug.formatters = {}; /** * Selects a color for a debug namespace * @param {String} namespace The namespace string for the debug instance to be colored * @return {Number|String} An ANSI color code for the given namespace * @api private */ function selectColor(namespace) { let hash = 0; for (let i = 0; i < namespace.length; i++) { hash = ((hash << 5) - hash) + namespace.charCodeAt(i); hash |= 0; // Convert to 32bit integer } return createDebug.colors[Math.abs(hash) % createDebug.colors.length]; } createDebug.selectColor = selectColor; /** * Create a debugger with the given `namespace`. * * @param {String} namespace * @return {Function} * @api public */ function createDebug(namespace) { let prevTime; let enableOverride = null; let namespacesCache; let enabledCache; function debug(...args) { // Disabled? if (!debug.enabled) { return; } const self = debug; // Set `diff` timestamp const curr = Number(new Date()); const ms = curr - (prevTime || curr); self.diff = ms; self.prev = prevTime; self.curr = curr; prevTime = curr; args[0] = createDebug.coerce(args[0]); if (typeof args[0] !== 'string') { // Anything else let's inspect with %O args.unshift('%O'); } // Apply any `formatters` transformations let index = 0; args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { // If we encounter an escaped % then don't increase the array index if (match === '%%') { return '%'; } index++; const formatter = createDebug.formatters[format]; if (typeof formatter === 'function') { const val = args[index]; match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format` args.splice(index, 1); index--; } return match; }); // Apply env-specific formatting (colors, etc.) createDebug.formatArgs.call(self, args); const logFn = self.log || createDebug.log; logFn.apply(self, args); } debug.namespace = namespace; debug.useColors = createDebug.useColors(); debug.color = createDebug.selectColor(namespace); debug.extend = extend; debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release. Object.defineProperty(debug, 'enabled', { enumerable: true, configurable: false, get: () => { if (enableOverride !== null) { return enableOverride; } if (namespacesCache !== createDebug.namespaces) { namespacesCache = createDebug.namespaces; enabledCache = createDebug.enabled(namespace); } return enabledCache; }, set: v => { enableOverride = v; } }); // Env-specific initialization logic for debug instances if (typeof createDebug.init === 'function') { createDebug.init(debug); } return debug; } function extend(namespace, delimiter) { const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace); newDebug.log = this.log; return newDebug; } /** * Enables a debug mode by namespaces. This can include modes * separated by a colon and wildcards. * * @param {String} namespaces * @api public */ function enable(namespaces) { createDebug.save(namespaces); createDebug.namespaces = namespaces; createDebug.names = []; createDebug.skips = []; let i; const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/); const len = split.length; for (i = 0; i < len; i++) { if (!split[i]) { // ignore empty strings continue; } namespaces = split[i].replace(/\*/g, '.*?'); if (namespaces[0] === '-') { createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$')); } else { createDebug.names.push(new RegExp('^' + namespaces + '$')); } } } /** * Disable debug output. * * @return {String} namespaces * @api public */ function disable() { const namespaces = [ ...createDebug.names.map(toNamespace), ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace) ].join(','); createDebug.enable(''); return namespaces; } /** * Returns true if the given mode name is enabled, false otherwise. * * @param {String} name * @return {Boolean} * @api public */ function enabled(name) { if (name[name.length - 1] === '*') { return true; } let i; let len; for (i = 0, len = createDebug.skips.length; i < len; i++) { if (createDebug.skips[i].test(name)) { return false; } } for (i = 0, len = createDebug.names.length; i < len; i++) { if (createDebug.names[i].test(name)) { return true; } } return false; } /** * Convert regexp to namespace * * @param {RegExp} regxep * @return {String} namespace * @api private */ function toNamespace(regexp) { return regexp.toString() .substring(2, regexp.toString().length - 2) .replace(/\.\*\?$/, '*'); } /** * Coerce `val`. * * @param {Mixed} val * @return {Mixed} * @api private */ function coerce(val) { if (val instanceof Error) { return val.stack || val.message; } return val; } /** * XXX DO NOT USE. This is a temporary stub function. * XXX It WILL be removed in the next major release. */ function destroy() { console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); } createDebug.enable(createDebug.load()); return createDebug; } common = setup; return common; } /* eslint-env browser */ var hasRequiredBrowser; function requireBrowser () { if (hasRequiredBrowser) return browser.exports; hasRequiredBrowser = 1; (function (module, exports) { /** * This is the web browser implementation of `debug()`. */ exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.storage = localstorage(); exports.destroy = (() => { let warned = false; return () => { if (!warned) { warned = true; console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'); } }; })(); /** * Colors. */ exports.colors = [ '#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33' ]; /** * Currently only WebKit-based Web Inspectors, Firefox >= v31, * and the Firebug extension (any Firefox version) are known * to support "%c" CSS customizations. * * TODO: add a `localStorage` variable to explicitly enable/disable colors */ // eslint-disable-next-line complexity function useColors() { // NB: In an Electron preload script, document will be defined but not fully // initialized. Since we know we're in Chrome, we'll just detect this case // explicitly if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { return true; } // Internet Explorer and Edge do not support colors. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { return false; } // Is webkit? http://stackoverflow.com/a/16459606/376773 // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632 return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) || // Is firebug? http://stackoverflow.com/a/398120/376773 (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) || // Is firefox >= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) || // Double check webkit in userAgent just in case we are in a worker (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)); } /** * Colorize log arguments if enabled. * * @api public */ function formatArgs(args) { args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff); if (!this.useColors) { return; } const c = 'color: ' + this.color; args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other // arguments passed either before or after the %c, so we need to // figure out the correct index to insert the CSS into let index = 0; let lastC = 0; args[0].replace(/%[a-zA-Z%]/g, match => { if (match === '%%') { return; } index++; if (match === '%c') { // We only are interested in the *last* %c // (the user may have provided their own) lastC = index; } }); args.splice(lastC, 0, c); } /** * Invokes `console.debug()` when available. * No-op when `console.debug` is not a "function". * If `console.debug` is not available, falls back * to `console.log`. * * @api public */ exports.log = console.debug || console.log || (() => {}); /** * Save `namespaces`. * * @param {String} namespaces * @api private */ function save(namespaces) { try { if (namespaces) { exports.storage.setItem('debug', namespaces); } else { exports.storage.removeItem('debug'); } } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } } /** * Load `namespaces`. * * @return {String} returns the previously persisted debug modes * @api private */ function load() { let r; try { r = exports.storage.getItem('debug'); } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } // If debug isn't set in LS, and we're in Electron, try to load $DEBUG if (!r && typeof process !== 'undefined' && 'env' in process) { r = process.env.DEBUG; } return r; } /** * Localstorage attempts to return the localstorage. * * This is necessary because safari throws * when a user disables cookies/localstorage * and you attempt to access it. * * @return {LocalStorage} * @api private */ function localstorage() { try { // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context // The Browser also has localStorage in the global context. return localStorage; } catch (error) { // Swallow // XXX (@Qix-) should we be logging these? } } module.exports = requireCommon()(exports); const {formatters} = module.exports; /** * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. */ formatters.j = function (v) { try { return JSON.stringify(v); } catch (error) { return '[UnexpectedJSONParseError]: ' + error.message; } }; } (browser, browser.exports)); return browser.exports; } var node = {exports: {}}; var hasFlag; var hasRequiredHasFlag; function requireHasFlag () { if (hasRequiredHasFlag) return hasFlag; hasRequiredHasFlag = 1; hasFlag = (flag, argv = process.argv) => { const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); const position = argv.indexOf(prefix + flag); const terminatorPosition = argv.indexOf('--'); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); }; return hasFlag; } var supportsColor_1; var hasRequiredSupportsColor; function requireSupportsColor () { if (hasRequiredSupportsColor) return supportsColor_1; hasRequiredSupportsColor = 1; const os = require$$0; const tty = require$$1; const hasFlag = requireHasFlag(); const {env} = process; let forceColor; if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) { forceColor = 0; } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) { forceColor = 1; } if ('FORCE_COLOR' in env) { if (env.FORCE_COLOR === 'true') { forceColor = 1; } else if (env.FORCE_COLOR === 'false') { forceColor = 0; } else { forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3); } } function translateLevel(level) { if (level === 0) { return false; } return { level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; } function supportsColor(haveStream, streamIsTTY) { if (forceColor === 0) { return 0; } if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) { return 3; } if (hasFlag('color=256')) { return 2; } if (haveStream && !streamIsTTY && forceColor === undefined) { return 0; } const min = forceColor || 0; if (env.TERM === 'dumb') { return min; } if (process.platform === 'win32') { // Windows 10 build 10586 is the first Windows release that supports 256 colors. // Windows 10 build 14931 is the first release that supports 16m/TrueColor. const osRelease = os.release().split('.'); if ( Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586 ) { return Number(osRelease[2]) >= 14931 ? 3 : 2; } return 1; } if ('CI' in env) { if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') { return 1; } return min; } if ('TEAMCITY_VERSION' in env) { return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; } if (env.COLORTERM === 'truecolor') { return 3; } if ('TERM_PROGRAM' in env) { const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); switch (env.TERM_PROGRAM) { case 'iTerm.app': return version >= 3 ? 3 : 2; case 'Apple_Terminal': return 2; // No default } } if (/-256(color)?$/i.test(env.TERM)) { return 2; } if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } if ('COLORTERM' in env) { return 1; } return min; } function getSupportLevel(stream) { const level = supportsColor(stream, stream && stream.isTTY); return translateLevel(level); } supportsColor_1 = { supportsColor: getSupportLevel, stdout: translateLevel(supportsColor(true, tty.isatty(1))), stderr: translateLevel(supportsColor(true, tty.isatty(2))) }; return supportsColor_1; } /** * Module dependencies. */ var hasRequiredNode; function requireNode () { if (hasRequiredNode) return node.exports; hasRequiredNode = 1; (function (module, exports) { const tty = require$$1; const util = require$$1$1; /** * This is the Node.js implementation of `debug()`. */ exports.init = init; exports.log = log; exports.formatArgs = formatArgs; exports.save = save; exports.load = load; exports.useColors = useColors; exports.destroy = util.deprecate( () => {}, 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.' ); /** * Colors. */ exports.colors = [6, 2, 3, 4, 5, 1]; try { // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json) // eslint-disable-next-line import/no-extraneous-dependencies const supportsColor = requireSupportsColor(); if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) { exports.colors = [ 20, 21, 26, 27, 32, 33, 38, 39, 40, 41, 42, 43, 44, 45, 56, 57, 62, 63, 68, 69, 74, 75, 76, 77, 78, 79, 80, 81, 92, 93, 98, 99, 112, 113, 128, 129, 134, 135, 148, 149, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 178, 179, 184, 185, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 214, 215, 220, 221 ]; } } catch (error) { // Swallow - we only care if `supports-color` is available; it doesn't have to be. } /** * Build up the default `inspectOpts` object from the environment variables. * * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js */ exports.inspectOpts = Object.keys(process.env).filter(key => { return /^debug_/i.test(key); }).reduce((obj, key) => { // Camel-case const prop = key .substring(6) .toLowerCase() .replace(/_([a-z])/g, (_, k) => { return k.toUpperCase(); }); // Coerce string value into JS value let val = process.env[key]; if (/^(yes|on|true|enabled)$/i.test(val)) { val = true; } else if (/^(no|off|false|disabled)$/i.test(val)) { val = false; } else if (val === 'null') { val = null; } else { val = Number(val); } obj[prop] = val; return obj; }, {}); /** * Is stdout a TTY? Colored output is enabled when `true`. */ function useColors() { return 'colors' in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd); } /** * Adds ANSI color escape codes if enabled. * * @api public */ function formatArgs(args) { const {namespace: name, useColors} = this; if (useColors) { const c = this.color; const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c); const prefix = ` ${colorCode};1m${name} \u001B[0m`; args[0] = prefix + args[0].split('\n').join('\n' + prefix); args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m'); } else { args[0] = getDate() + name + ' ' + args[0]; } } function getDate() { if (exports.inspectOpts.hideDate) { return ''; } return new Date().toISOString() + ' '; } /** * Invokes `util.format()` with the specified arguments and writes to stderr. */ function log(...args) { return process.stderr.write(util.format(...args) + '\n'); } /** * Save `namespaces`. * * @param {String} namespaces * @api private */ function save(namespaces) { if (namespaces) { process.env.DEBUG = namespaces; } else { // If you set a process.env field to null or undefined, it gets cast to the // string 'null' or 'undefined'. Just delete instead. delete process.env.DEBUG; } } /** * Load `namespaces`. * * @return {String} returns the previously persisted debug modes * @api private */ function load() { return process.env.DEBUG; } /** * Init logic for `debug` instances. * * Create a new `inspectOpts` object in case `useColors` is set * differently for a particular `debug` instance. */ function init(debug) { debug.inspectOpts = {}; const keys = Object.keys(exports.inspectOpts); for (let i = 0; i < keys.length; i++) { debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]]; } } module.exports = requireCommon()(exports); const {formatters} = module.exports; /** * Map %o to `util.inspect()`, all on a single line. */ formatters.o = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts) .split('\n') .map(str => str.trim()) .join(' '); }; /** * Map %O to `util.inspect()`, allowing multiple lines if needed. */ formatters.O = function (v) { this.inspectOpts.colors = this.useColors; return util.inspect(v, this.inspectOpts); }; } (node, node.exports)); return node.exports; } /** * Detect Electron renderer / nwjs process, which is node, but we should * treat as a browser. */ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) { src.exports = requireBrowser(); } else { src.exports = requireNode(); } var srcExports = src.exports; var Debug = /*@__PURE__*/getDefaultExportFromCjs(srcExports); Debug.enable('android-tools'); const log = Debug('android-tools'); class Android { constructor(props) { var _a, _b, _c, _d; /** The location of the `adb` executable file */ this.adbBin = (_a = process.env.adbBin) !== null && _a !== void 0 ? _a : ''; /** The location of the `avdmanager` executable file */ this.avdmanagerBin = (_b = process.env.avdmanagerBin) !== null && _b !== void 0 ? _b : ''; /** The location of the `sdkmanager` executable file */ this.sdkmanagerBin = (_c = process.env.sdkmanagerBin) !== null && _c !== void 0 ? _c : ''; /** The location of the `emulator` executable file */ this.emulatorBin = (_d = process.env.emulatorBin) !== null && _d !== void 0 ? _d : ''; if (!(props === null || props === void 0 ? void 0 : props.debug)) Debug.disable(); this.setAdbBinPath(props === null || props === void 0 ? void 0 : props.adb); this.setAvdmanagerBinPath(props === null || props === void 0 ? void 0 : props.avdmanager); this.setSdkmanagerBinPath(props === null || props === void 0 ? void 0 : props.sdkmanager); this.setEmulatorBinPath(props === null || props === void 0 ? void 0 : props.emulator); } /** * Set the location of the `adb` executable file * @param execPath The location of the `adb` executable file relative to `ANDROID_HOME` */ setAdbBinPath(execPath) { log('setAdbBinPath: %s', JSON.stringify({ execPath })); if (process.env.ANDROID_HOME) { if (execPath) { this.adbBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.adbBin) { this.adbBin = path.resolve(process.env.ANDROID_HOME, './platform-tools/adb'); } } const regex = /Android Debug Bridge/; if (!this.adbBin || !isExecExpectedResult(this.adbBin, regex)) { if (isExecExpectedResult('adb', regex)) { this.adbBin = 'adb'; } } } /** * Set the location of the `avdmanager` executable file * @param execPath The location of the `avdmanager` executable file relative to `ANDROID_HOME` */ setAvdmanagerBinPath(execPath) { log('setAvdmanagerBinPath: %s', JSON.stringify({ execPath })); if (process.env.ANDROID_HOME) { if (execPath) { this.avdmanagerBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.avdmanagerBin) { this.avdmanagerBin = path.resolve(process.env.ANDROID_HOME, './cmdline-tools/latest/bin/avdmanager'); } } const regex = /Usage:/; if (!this.avdmanagerBin || !isExecExpectedResult(this.avdmanagerBin, regex)) { if (isExecExpectedResult('avdmanager', regex)) { this.avdmanagerBin = 'avdmanager'; } } } /** * Set the location of the `sdkmanager` executable file * @param execPath The location of the `sdkmanager` executable file relative to `ANDROID_HOME` */ setSdkmanagerBinPath(execPath) { log('setSdkmanagerBinPath: %s', JSON.stringify({ execPath })); if (process.env.ANDROID_HOME) { if (execPath) { this.sdkmanagerBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.sdkmanagerBin) { this.sdkmanagerBin = path.resolve(process.env.ANDROID_HOME, './cmdline-tools/latest/bin/sdkmanager'); } } const regex = /Usage:/; if (!this.sdkmanagerBin || !isExecExpectedResult(this.sdkmanagerBin, regex)) { if (isExecExpectedResult('sdkmanager', regex)) { this.sdkmanagerBin = 'sdkmanager'; } } } /** * Set the location of the `emulator` executable file * @param execPath The location of the `emulator` executable file relative to `ANDROID_HOME` */ setEmulatorBinPath(execPath) { log('setEmulatorBinPath: %s', JSON.stringify({ execPath })); if (process.env.ANDROID_HOME) { if (execPath) { this.emulatorBin = path.resolve(process.env.ANDROID_HOME, execPath); } else if (!this.emulatorBin) { this.emulatorBin = path.resolve(process.env.ANDROID_HOME, './emulator/emulator'); } } const regex = /Android Emulator usage:/; if (!this.emulatorBin || !isExecExpectedResult(`${this.emulatorBin} --help`, regex)) { if (isExecExpectedResult('emulator --help', regex)) { this.emulatorBin = 'emulator'; } } } /** * Start the emulator using the AVD supplied through with `avdName`. * Returns a promise that is resolved with an object that has the following properties. * @param options */ start(options) { return __awaiter(this, void 0, void 0, function* () { log('start: %s', JSON.stringify(options)); options.verbose = true; const cmd = params2Cmd(options); const res = yield spawnWaitFor(`${this.emulatorBin} ${cmd}`, / control console listening on port (\d+), ADB on port \d+/); return { process: res.process, id: 'emulator-' + res.matches[1] }; }); } /** * Waiting for the simulator device to become available. * @param emulatorId id of emulator */ waitForDevice(emulatorId) { return __awaiter(this, void 0, void 0, function* () { log('waitForDevice: %s', JSON.stringify({ emulatorId })); yield this.adb(emulatorId, 'wait-for-device'); }); } /** * ensure device has been started and ready. * @param emulatorId id of emulator */ ensureReady(emulatorId) { return __awaiter(this, void 0, void 0, function* () { log('ensureReady: %s', JSON.stringify({ emulatorId })); yield this.waitForDevice(emulatorId); yield retry(() => __awaiter(this, void 0, void 0, function* () { const proc = yield this.adb(emulatorId, 'shell getprop sys.boot_completed'); return proc.output.trim() === '1'; }), 1200); }); } /** * create a AVD based upon `image` * @param image android system image * @param name name of AVD */ createAVD(options) { return __awaiter(this, void 0, void 0, function* () { log('createAVD: %s', JSON.stringify(options)); if (!options.name) return Promise.reject(Error('Missing name parameter.')); if (!options.package && !options.apiLevel) return Promise.reject(Error('Either the parameter "package" or "apiLevel" must be present.')); const systemImage = options.package || `system-images;android-${options.apiLevel};${options.target || 'default'};${options.arch || getLocalArch()}`; // Downloading the SDK takes a lot of time, so it's best to download it in advance. yield this.sdkmanager(`--install ${systemImage}`, 600000); let cmdParams = `-n ${options.name} -k ${systemImage}`; if (options.force) cmdParams += ' -f'; return yield this.avdmanager(`-s create avd ${cmdParams}`); }); } /** * Check if a specific AVD has been created on this machine. * @param avdName Name of AVD. */ hasAVD(avdName) { return __awaiter(this, void 0, void 0, function* () { log('hasAVD: %s', JSON.stringify({ avdName })); const avds = yield this.listAVDs(); return (avds.filter((avd) => { return avd.Name.toLowerCase() === avdName.toLowerCase(); }).length > 0); }); } /** * Stop a certain emulator. * @param emulatorId Id of emulator. */ stop(emulatorId) { return __awaiter(this, void 0, void 0, function* () { log('stop: %s', JSON.stringify({ emulatorId })); return yield this.adb(emulatorId, 'emu kill'); }); } /** * Wait until the device is stopped. */ waitForStop(emulatorId) { return __awaiter(this, void 0, void 0, function* () { log('waitForStop: %s', JSON.stringify({ emulatorId })); yield retry(() => __awaiter(this, void 0, void 0, function* () { yield this.stop(emulatorId); const devices = yield this.devices(); return !devices.some((device) => device.name === emulatorId && device.status === 'device'); }), 1200); }); } /** * Check the package specified with `packageName` is installed or not. * @param emulatorId id of emulator * @param packageName name of package */ isInstalled(emulatorId, packageName) { return __awaiter(this, void 0, void 0, function* () { log('isInstalled: %s, %s', JSON.stringify({ emulatorId, packageName })); const packages = yield this.listPackages(emulatorId); const isInstalled = packages.includes(packageName); return isInstalled; }); } /** * Install an APK located by absolute URI `apkPath` onto device with `emulatorId`. * @param emulatorId id of emulator * @param apkPath path of apk file */ install(emulatorId, apkPath, options) { return __awaiter(this, void 0, void 0, function* () { log('install: %s, %s', JSON.stringify({ emulatorId, apkPath })); const cmdParams = params2Cmd(options); const process = yield this.adb(emulatorId, `install ${cmdParams} ${apkPath}`); if (process.output.match(/Success/)) return; throw new Error('Could not parse output of adb command'); }); } /** * adb shell input keyevent * @param emulatorId Id of emulator * @param key https://developer.android.com/reference/android/view/KeyEvent */ inputKeyEvent(emulatorId, key) { return __awaiter(this, void 0, void 0, function* () { log('inputKeyEvent: %s, %d', JSON.stringify({ emulatorId, key })); return yield this.adb(emulatorId, 'shell input keyevent ' + key); }); } /** * List connected devices */ devices() { return __awaiter(this, void 0, void 0, function* () { log('devices: '); const proc = yield this.adb('devices'); const lines = proc.output.split('\n'); lines.shift(); return lines .map((line) => { const matches = line.match(/([^\s]+)\s+([^\s]+)/); if (matches === null) return null; return { name: matches[1], status: matches[2] }; }) .filter((x) => x !== null); }); } /** * List packages installed on the emulator with `emulatorId`. * @param emulatorId id of emulator */ listPackages(emulatorId) { return __awaiter(this, void 0, void 0, function* () { log('listPackages: %s', JSON.stringify({ emulatorId })); const proc = yield this.adb(emulatorId, 'shell pm list packages'); const lines = proc.output.split('\n'); return lines .map((line) => { return line.split(':')[1]; }) .filter((pkg) => { return pkg; }) .map((pkg) => { return pkg.trim(); }); }); } /** * List the available device list for creating emulators in the current system. */ listDevices() { return __awaiter(this, void 0, void 0, function* () { log('listDevices: '); const proc = yield this.avdmanager('list device'); return processKeyValueGroups(proc.output); }); } /** * List all AVDs created on this machine. */ listAVDs() { return __awaiter(this, void 0, void 0, function* () { log('listAVDs: '); const proc = yield this.avdmanager('list avd'); return processKeyValueGroups(proc.output); }); } /** * List available Android targets. */ listTargets() { return __awaiter(this, void 0, void 0, function* () { log('listTargets: '); const proc = yield this.avdmanager('list target'); return processKeyValueGroups(proc.output); }); } /** * List available Android images on this machine. */ listImages() { return __awaiter(this, void 0, void 0, function* () { log('listImages: '); const proc = yield this.sdkmanager('--list'); return filterGroupImages(proc.output); }); } /** * List installed Android images on this machine. */ listInstalledImages() { return __awaiter(this, void 0, void 0, function* () { log('listInstalledImages: '); const proc = yield this.sdkmanager('--list_installed'); return filterGroupImages(proc.output); }); } /** * Use `adb` to execute commands. * @param emulatorId id of emulator * @param cmd command * @param timeout Execution timeout */ adb(emulatorId, cmd, timeout) { return __awaiter(this, void 0, void 0, function* () { log('adb: %s', JSON.stringify({ emulatorId, cmd, timeout })); if (cmd) return yield spawnExec(`${this.adbBin} -s ${emulatorId} ${cmd}`, timeout); return yield spawnExec(`${this.adbBin} ${emulatorId}`, timeout); }); } /** * Use `avdmanager` to execute commands. * @param cmd command * @param timeout Execution timeout */ avdmanager(cmd, timeout) { return __awaiter(this, void 0, void 0, function* () { log('avdmanager: %s', JSON.stringify({ cmd, timeout })); return yield spawnExec(`${this.avdmanagerBin} ${cmd}`, timeout); }); } /** * Use `sdkmanager` to execute commands. * @param cmd command * @param timeout Execution timeout */ sdkmanager(cmd, timeout) { return __awaiter(this, void 0, void 0, function* () { log('sdkmanager: %s', JSON.stringify({ cmd, timeout })); return yield spawnExec(`${this.sdkmanagerBin} ${cmd}`, timeout); }); } /** * Use `emulator` to execute commands. * @param cmd command * @param timeout Execution timeout */ emulator(cmd, timeout) { return __awaiter(this, void 0, void 0, function* () { log('emulator: %s', JSON.stringify({ cmd, timeout })); return yield spawnExec(`${this.emulatorBin} ${cmd}`, timeout); }); } } exports.default = Android; exports.filterGroupImages = filterGroupImages; exports.getLocalArch = getLocalArch; exports.isExecExpectedResult = isExecExpectedResult; exports.params2Cmd = params2Cmd; exports.processKeyValueGroups = processKeyValueGroups; exports.retry = retry; exports.spawnExec = spawnExec; exports.spawnWaitFor = spawnWaitFor; exports.spwanSyncExec = spwanSyncExec; exports.transformCommand = transformCommand; exports.winBatAdapt = winBatAdapt;