appium-mac2-driver 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.2.1](https://github.com/appium/appium-mac2-driver/compare/v3.2.0...v3.2.1) (2025-11-12)
2
+
3
+
4
+ ### Miscellaneous Chores
5
+
6
+ * Port lib/wda-mac.js to Typescript ([#348](https://github.com/appium/appium-mac2-driver/issues/348)) ([0a5a78a](https://github.com/appium/appium-mac2-driver/commit/0a5a78ac0e615b5af30da1128a9ac83b007d324d))
7
+
1
8
  ## [3.2.0](https://github.com/appium/appium-mac2-driver/compare/v3.1.0...v3.2.0) (2025-11-11)
2
9
 
3
10
 
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.Mac2Driver = void 0;
40
40
  const lodash_1 = __importDefault(require("lodash"));
41
41
  const driver_1 = require("appium/driver");
42
- const wda_mac_1 = __importDefault(require("./wda-mac"));
42
+ const wda_mac_1 = require("./wda-mac");
43
43
  const desired_caps_1 = require("./desired-caps");
44
44
  const appManagemenetCommands = __importStar(require("./commands/app-management"));
45
45
  const appleScriptCommands = __importStar(require("./commands/applescript"));
@@ -139,7 +139,7 @@ class Mac2Driver extends driver_1.BaseDriver {
139
139
  async createSession(...args) {
140
140
  // @ts-ignore TODO: make args typed
141
141
  const [sessionId, caps] = await super.createSession(...args);
142
- this.wda = wda_mac_1.default;
142
+ this.wda = wda_mac_1.WDA_MAC_SERVER;
143
143
  try {
144
144
  if (caps.prerun) {
145
145
  if (!lodash_1.default.isString(caps.prerun.command) && !lodash_1.default.isString(caps.prerun.script)) {
@@ -1 +1 @@
1
- {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../lib/driver.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAuB;AACvB,0CAA2D;AAC3D,wDAAuC;A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AG,iBAAiB,CAAC,iBAAiB,CAAC;IACxD,iBAAiB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC;IAExD,aAAa,GAAG,kBAAkB,CAAC,aAAa,CAAC;IAEjD,oBAAoB,GAAG,oBAAoB,CAAC,oBAAoB,CAAC;IACjE,mBAAmB,GAAG,oBAAoB,CAAC,mBAAmB,CAAC;IAE/D,+BAA+B,GAAG,6BAA6B,CAAC,+BAA+B,CAAC;IAChG,iCAAiC,GAAG,6BAA6B,CAAC,iCAAiC,CAAC;IACpG,8BAA8B,GAAG,6BAA6B,CAAC,8BAA8B,CAAC;IAC9F,iBAAiB,GAAG,6BAA6B,CAAC,iBAAiB,CAAC;IAEpE,gBAAgB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC;IAEvD,WAAW,GAAG,cAAc,CAAC,WAAW,CAAC;;AA/L3C,gCAgMC;AAED,kBAAe,UAAU,CAAC"}
@@ -1,80 +1,38 @@
1
- export class WDAMacProxy extends JWProxy {
2
- /** @type {boolean|undefined} */
3
- didProcessExit: boolean | undefined;
4
- proxyCommand(url: any, method: any, body?: null): Promise<[import("@appium/types").ProxyResponse<any>, any]>;
1
+ import { JWProxy } from 'appium/driver';
2
+ import type { HTTPMethod, HTTPBody, ProxyResponse } from '@appium/types';
3
+ export interface SessionOptions {
4
+ reqBasePath?: string;
5
5
  }
6
- export class WDAMacServer {
7
- /** @type {WDAMacProxy} */
8
- proxy: WDAMacProxy;
9
- process: WDAMacProcess | null;
10
- serverStartupTimeoutMs: number;
11
- isProxyingToRemoteServer: boolean;
12
- isProxyReady(throwOnExit?: boolean): Promise<boolean>;
13
- /**
14
- * @typedef {Object} ProxyProperties
15
- *
16
- * @property {string} scheme - The scheme proxy to.
17
- * @property {string} host - The host name proxy to.
18
- * @property {number} port - The port number proxy to.
19
- * @property {string} path - The path proxy to.
20
- */
6
+ export declare class WDAMacProxy extends JWProxy {
7
+ didProcessExit: boolean;
8
+ proxyCommand(url: string, method: HTTPMethod, body?: HTTPBody): Promise<[ProxyResponse, HTTPBody]>;
9
+ }
10
+ export declare class WDAMacServer {
11
+ private _proxy;
12
+ private _process;
13
+ private _serverStartupTimeoutMs;
14
+ private _isProxyingToRemoteServer;
15
+ get proxy(): WDAMacProxy;
16
+ startSession(caps: StartSessionCapabilities, opts?: SessionOptions): Promise<void>;
17
+ stopSession(): Promise<void>;
18
+ private isProxyReady;
21
19
  /**
22
20
  * Returns proxy information where WDAMacServer proxy to.
23
21
  *
24
- * @param {Object} caps - The capabilities in the session.
25
- * @return {ProxyProperties}
22
+ * @param caps - The capabilities in the session.
23
+ * @return ProxyProperties
26
24
  * @throws Error if 'webDriverAgentMacUrl' had invalid URL
27
25
  */
28
- parseProxyProperties(caps: any): {
29
- /**
30
- * - The scheme proxy to.
31
- */
32
- scheme: string;
33
- /**
34
- * - The host name proxy to.
35
- */
36
- host: string;
37
- /**
38
- * - The port number proxy to.
39
- */
40
- port: number;
41
- /**
42
- * - The path proxy to.
43
- */
44
- path: string;
45
- };
46
- /**
47
- *
48
- * @param {import('@appium/types').StringRecord} caps
49
- * @param {SessionOptions} [opts={}]
50
- */
51
- startSession(caps: import("@appium/types").StringRecord, opts?: SessionOptions): Promise<void>;
52
- stopSession(): Promise<void>;
26
+ private parseProxyProperties;
53
27
  }
54
- export default WDA_MAC_SERVER;
55
- export type SessionOptions = {
56
- reqBasePath?: string | undefined;
57
- };
58
- import { JWProxy } from 'appium/driver';
59
- declare class WDAMacProcess {
60
- showServerLogs: boolean;
61
- port: number;
62
- host: string;
63
- bootstrapRoot: string;
64
- proc: any;
65
- get isRunning(): boolean;
66
- get pid(): any;
67
- listChildrenPids(): Promise<string[]>;
68
- cleanupProjectIfFresh(): Promise<void>;
69
- hasSameOpts({ showServerLogs, systemPort, systemHost, bootstrapRoot }: {
70
- showServerLogs: any;
71
- systemPort: any;
72
- systemHost: any;
73
- bootstrapRoot: any;
74
- }): boolean;
75
- init(opts?: {}): Promise<boolean>;
76
- stop(): Promise<void>;
77
- kill(): Promise<void>;
28
+ export declare const WDA_MAC_SERVER: WDAMacServer;
29
+ interface StartSessionCapabilities {
30
+ webDriverAgentMacUrl?: string;
31
+ systemHost?: string;
32
+ systemPort?: number;
33
+ serverStartupTimeout?: number;
34
+ reqBasePath?: string;
35
+ [key: string]: unknown;
78
36
  }
79
- declare const WDA_MAC_SERVER: WDAMacServer;
37
+ export {};
80
38
  //# sourceMappingURL=wda-mac.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wda-mac.d.ts","sourceRoot":"","sources":["../../lib/wda-mac.js"],"names":[],"mappings":"AAoDA;IACE,gCAAgC;IAChC,gBADW,OAAO,GAAC,SAAS,CACb;IAEf,6GAOC;CACF;AAuOD;IACE,0BAA0B;IAC1B,OADW,WAAW,CAChB;IAGJ,8BAAmB;IACnB,+BAAgD;IAKhD,kCAAqC;IAGvC,sDAcC;IAGD;;;;;;;OAOG;IAEH;;;;;;OAMG;IACH;;;;gBAbc,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;;;;cACN,MAAM;MAuCnB;IAED;;;;OAIG;IACH,mBAHW,OAAO,eAAe,EAAE,YAAY,SACpC,cAAc,iBAsFxB;IAED,6BAaC;CACF;;;;;wBAzd+B,eAAe;AA6D/C;IAEI,wBAA8C;IAC9C,aAA+B;IAC/B,aAA+B;IAC/B,sBAAqC;IACrC,UAAgB;IAGlB,yBAEC;IAED,eAEC;IAED,sCAEC;IAED,uCAyDC;IAED;;;;;gBAmBC;IAED,kCA+FC;IAED,sBAYC;IAED,sBAcC;CACF;AA2LD,2CAA0C"}
1
+ {"version":3,"file":"wda-mac.d.ts","sourceRoot":"","sources":["../../lib/wda-mac.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AAOhD,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,aAAa,EAEd,MAAM,eAAe,CAAC;AAmBvB,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,WAAY,SAAQ,OAAO;IAC/B,cAAc,EAAE,OAAO,CAAS;IAExB,YAAY,CACzB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU,EAClB,IAAI,GAAE,QAAe,GACpB,OAAO,CAAC,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;CAStC;AAuOD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,yBAAyB,CAAkB;IAEnD,IAAI,KAAK,IAAK,WAAW,CAKxB;IAEK,YAAY,CAAE,IAAI,EAAE,wBAAwB,EAAE,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuFvF,WAAW,IAAK,OAAO,CAAC,IAAI,CAAC;YAerB,YAAY;IAgB1B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;CA8B7B;AAED,eAAO,MAAM,cAAc,cAAqB,CAAC;AAsCjD,UAAU,wBAAwB;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WDAMacServer = exports.WDAMacProxy = void 0;
6
+ exports.WDA_MAC_SERVER = exports.WDAMacServer = exports.WDAMacProxy = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const url_1 = __importDefault(require("url"));
@@ -31,29 +31,8 @@ const DEFAULT_SHOW_SERVER_LOGS = false;
31
31
  const RUNNING_PROCESS_IDS = [];
32
32
  const RECENT_UPGRADE_TIMESTAMP_PATH = path_1.default.join('.appium', 'webdriveragent_mac', 'upgrade.time');
33
33
  const RECENT_MODULE_VERSION_ITEM_NAME = 'recentWdaModuleVersion';
34
- async function cleanupObsoleteProcesses() {
35
- if (!lodash_1.default.isEmpty(RUNNING_PROCESS_IDS)) {
36
- log.debug(`Cleaning up ${RUNNING_PROCESS_IDS.length} obsolete ` +
37
- support_1.util.pluralize('process', RUNNING_PROCESS_IDS.length, false));
38
- try {
39
- await (0, teen_process_1.exec)('kill', ['-9', ...RUNNING_PROCESS_IDS]);
40
- }
41
- catch { }
42
- lodash_1.default.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
43
- }
44
- }
45
- process.once('exit', () => {
46
- if (!lodash_1.default.isEmpty(RUNNING_PROCESS_IDS)) {
47
- try {
48
- (0, child_process_1.execSync)(`kill -9 ${RUNNING_PROCESS_IDS.join(' ')}`);
49
- }
50
- catch { }
51
- lodash_1.default.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
52
- }
53
- });
54
34
  class WDAMacProxy extends driver_1.JWProxy {
55
- /** @type {boolean|undefined} */
56
- didProcessExit;
35
+ didProcessExit = false;
57
36
  async proxyCommand(url, method, body = null) {
58
37
  if (this.didProcessExit) {
59
38
  throw new driver_1.errors.InvalidContextError(`'${method} ${url}' cannot be proxied to Mac2 Driver server because ` +
@@ -64,13 +43,11 @@ class WDAMacProxy extends driver_1.JWProxy {
64
43
  }
65
44
  exports.WDAMacProxy = WDAMacProxy;
66
45
  class WDAMacProcess {
67
- constructor() {
68
- this.showServerLogs = DEFAULT_SHOW_SERVER_LOGS;
69
- this.port = DEFAULT_SYSTEM_PORT;
70
- this.host = DEFAULT_SYSTEM_HOST;
71
- this.bootstrapRoot = DEFAULT_WDA_ROOT;
72
- this.proc = null;
73
- }
46
+ port = DEFAULT_SYSTEM_PORT;
47
+ host = DEFAULT_SYSTEM_HOST;
48
+ bootstrapRoot = DEFAULT_WDA_ROOT;
49
+ proc = null;
50
+ _showServerLogs = DEFAULT_SHOW_SERVER_LOGS;
74
51
  get isRunning() {
75
52
  return !!(this.proc?.isRunning);
76
53
  }
@@ -138,31 +115,11 @@ class WDAMacProcess {
138
115
  log.warn(`Cannot perform project cleanup. Original error: ${e.stderr || e.message}`);
139
116
  }
140
117
  }
141
- hasSameOpts({ showServerLogs, systemPort, systemHost, bootstrapRoot }) {
142
- if (lodash_1.default.isBoolean(showServerLogs) && this.showServerLogs !== showServerLogs
143
- || lodash_1.default.isNil(showServerLogs) && this.showServerLogs !== DEFAULT_SHOW_SERVER_LOGS) {
144
- return false;
145
- }
146
- if (systemPort && this.port !== systemPort
147
- || !systemPort && this.port !== DEFAULT_SYSTEM_PORT) {
148
- return false;
149
- }
150
- if (systemHost && this.host !== systemHost
151
- || !systemHost && this.host !== DEFAULT_SYSTEM_HOST) {
152
- return false;
153
- }
154
- if (bootstrapRoot && this.bootstrapRoot !== bootstrapRoot
155
- || !bootstrapRoot && this.bootstrapRoot !== DEFAULT_WDA_ROOT) {
156
- return false;
157
- }
158
- return true;
159
- }
160
118
  async init(opts = {}) {
161
- // @ts-ignore TODO: Make opts typed
162
119
  if (this.isRunning && this.hasSameOpts(opts)) {
163
120
  return false;
164
121
  }
165
- this.showServerLogs = opts.showServerLogs ?? this.showServerLogs;
122
+ this._showServerLogs = opts.showServerLogs ?? this._showServerLogs;
166
123
  this.port = opts.systemPort ?? this.port;
167
124
  this.host = opts.systemHost ?? this.host;
168
125
  this.bootstrapRoot = opts.bootstrapRoot ?? this.bootstrapRoot;
@@ -226,13 +183,13 @@ class WDAMacProcess {
226
183
  cwd: this.bootstrapRoot,
227
184
  env,
228
185
  });
229
- if (!this.showServerLogs) {
186
+ if (!this._showServerLogs) {
230
187
  log.info(`Mac2Driver host process logging is disabled. ` +
231
188
  `All the ${XCODEBUILD} output is going to be suppressed. ` +
232
189
  `Set the 'showServerLogs' capability to 'true' if this is an undesired behavior`);
233
190
  }
234
191
  this.proc.on('output', (stdout, stderr) => {
235
- if (!this.showServerLogs) {
192
+ if (!this._showServerLogs) {
236
193
  return;
237
194
  }
238
195
  const line = lodash_1.default.trim(stdout || stderr);
@@ -276,101 +233,57 @@ class WDAMacProcess {
276
233
  }
277
234
  catch { }
278
235
  }
279
- }
280
- class WDAMacServer {
281
- /** @type {WDAMacProxy} */
282
- proxy;
283
- constructor() {
284
- this.process = null;
285
- this.serverStartupTimeoutMs = STARTUP_TIMEOUT_MS;
286
- // @ts-ignore this is ok
287
- this.proxy = null;
288
- // To handle if the WDAMac server is proxying requests to a remote WDAMac app instance
289
- this.isProxyingToRemoteServer = false;
290
- }
291
- async isProxyReady(throwOnExit = true) {
292
- if (!this.proxy) {
236
+ hasSameOpts(opts) {
237
+ const { showServerLogs, systemPort, systemHost, bootstrapRoot } = opts;
238
+ if (lodash_1.default.isBoolean(showServerLogs) && this._showServerLogs !== showServerLogs
239
+ || lodash_1.default.isNil(showServerLogs) && this._showServerLogs !== DEFAULT_SHOW_SERVER_LOGS) {
293
240
  return false;
294
241
  }
295
- try {
296
- await this.proxy.command('/status', 'GET');
297
- return true;
298
- }
299
- catch (err) {
300
- if (throwOnExit && this.proxy.didProcessExit) {
301
- throw new Error(err.message);
302
- }
242
+ if (systemPort && this.port !== systemPort
243
+ || !systemPort && this.port !== DEFAULT_SYSTEM_PORT) {
303
244
  return false;
304
245
  }
305
- }
306
- /**
307
- * @typedef {Object} ProxyProperties
308
- *
309
- * @property {string} scheme - The scheme proxy to.
310
- * @property {string} host - The host name proxy to.
311
- * @property {number} port - The port number proxy to.
312
- * @property {string} path - The path proxy to.
313
- */
314
- /**
315
- * Returns proxy information where WDAMacServer proxy to.
316
- *
317
- * @param {Object} caps - The capabilities in the session.
318
- * @return {ProxyProperties}
319
- * @throws Error if 'webDriverAgentMacUrl' had invalid URL
320
- */
321
- parseProxyProperties(caps) {
322
- let scheme = 'http';
323
- if (!caps.webDriverAgentMacUrl) {
324
- return {
325
- scheme,
326
- host: (this.process?.host ?? caps.systemHost) ?? DEFAULT_SYSTEM_HOST,
327
- port: (this.process?.port ?? caps.systemPort) ?? DEFAULT_SYSTEM_PORT,
328
- path: ''
329
- };
330
- }
331
- let parsedUrl;
332
- try {
333
- parsedUrl = new url_1.default.URL(caps.webDriverAgentMacUrl);
334
- }
335
- catch (e) {
336
- throw new Error(`webDriverAgentMacUrl, '${caps.webDriverAgentMacUrl}', ` +
337
- `in the capabilities is invalid. ${e.message}`);
246
+ if (systemHost && this.host !== systemHost
247
+ || !systemHost && this.host !== DEFAULT_SYSTEM_HOST) {
248
+ return false;
338
249
  }
339
- const { protocol, hostname, port, pathname } = parsedUrl;
340
- if (lodash_1.default.isString(protocol)) {
341
- scheme = protocol.split(':')[0];
250
+ if (bootstrapRoot && this.bootstrapRoot !== bootstrapRoot
251
+ || !bootstrapRoot && this.bootstrapRoot !== DEFAULT_WDA_ROOT) {
252
+ return false;
342
253
  }
343
- return {
344
- scheme,
345
- host: hostname ?? DEFAULT_SYSTEM_HOST,
346
- port: lodash_1.default.isEmpty(port) ? DEFAULT_SYSTEM_PORT : lodash_1.default.parseInt(port),
347
- path: pathname === '/' ? '' : pathname
348
- };
254
+ return true;
255
+ }
256
+ }
257
+ class WDAMacServer {
258
+ _proxy = null;
259
+ _process = null;
260
+ _serverStartupTimeoutMs = STARTUP_TIMEOUT_MS;
261
+ _isProxyingToRemoteServer = false;
262
+ get proxy() {
263
+ if (!this._proxy) {
264
+ throw new Error('Proxy is not initialized. Did you call startSession()?');
265
+ }
266
+ return this._proxy;
349
267
  }
350
- /**
351
- *
352
- * @param {import('@appium/types').StringRecord} caps
353
- * @param {SessionOptions} [opts={}]
354
- */
355
268
  async startSession(caps, opts = {}) {
356
- this.serverStartupTimeoutMs = caps.serverStartupTimeout ?? this.serverStartupTimeoutMs;
357
- this.isProxyingToRemoteServer = !!caps.webDriverAgentMacUrl;
269
+ this._serverStartupTimeoutMs = caps.serverStartupTimeout ?? this._serverStartupTimeoutMs;
270
+ this._isProxyingToRemoteServer = !!caps.webDriverAgentMacUrl;
358
271
  let wasProcessInitNecessary;
359
- if (this.isProxyingToRemoteServer) {
360
- if (this.process) {
361
- await this.process.kill();
272
+ if (this._isProxyingToRemoteServer) {
273
+ if (this._process) {
274
+ await this._process.kill();
362
275
  await cleanupObsoleteProcesses();
363
- this.process = null;
276
+ this._process = null;
364
277
  }
365
278
  wasProcessInitNecessary = false;
366
279
  }
367
280
  else {
368
- if (!this.process) {
369
- this.process = new WDAMacProcess();
281
+ if (!this._process) {
282
+ this._process = new WDAMacProcess();
370
283
  }
371
- wasProcessInitNecessary = await this.process.init(caps);
284
+ wasProcessInitNecessary = await this._process.init(caps);
372
285
  }
373
- if (wasProcessInitNecessary || this.isProxyingToRemoteServer || !this.proxy) {
286
+ if (wasProcessInitNecessary || this._isProxyingToRemoteServer || !this._proxy) {
374
287
  const { scheme, host, port, path } = this.parseProxyProperties(caps);
375
288
  const proxyOpts = {
376
289
  scheme,
@@ -382,50 +295,52 @@ class WDAMacServer {
382
295
  if (caps.reqBasePath) {
383
296
  proxyOpts.reqBasePath = opts.reqBasePath;
384
297
  }
385
- this.proxy = new WDAMacProxy(proxyOpts);
386
- this.proxy.didProcessExit = false;
387
- if (this.process?.proc) {
388
- this.process.proc.on('exit', () => {
389
- if (this.proxy) {
390
- this.proxy.didProcessExit = true;
298
+ this._proxy = new WDAMacProxy(proxyOpts);
299
+ this._proxy.didProcessExit = false;
300
+ if (this._process?.proc) {
301
+ this._process.proc.on('exit', () => {
302
+ if (this._proxy) {
303
+ this._proxy.didProcessExit = true;
391
304
  }
392
305
  });
393
306
  }
394
307
  const timer = new support_1.timing.Timer().start();
395
308
  try {
396
309
  await (0, asyncbox_1.waitForCondition)(async () => await this.isProxyReady(), {
397
- waitMs: this.serverStartupTimeoutMs,
310
+ waitMs: this._serverStartupTimeoutMs,
398
311
  intervalMs: 1000,
399
312
  });
400
313
  }
401
314
  catch (e) {
402
- if (this.process?.isRunning) {
315
+ if (this._process?.isRunning) {
403
316
  // avoid "frozen" processes,
404
- await this.process.kill();
317
+ await this._process.kill();
405
318
  }
406
319
  if (/Condition unmet/.test(e.message)) {
407
- const msg = this.isProxyingToRemoteServer
408
- ? `No response from '${scheme}://${host}:${port}${path}' within ${this.serverStartupTimeoutMs}ms timeout.` +
320
+ const msg = this._isProxyingToRemoteServer
321
+ ? `No response from '${scheme}://${host}:${port}${path}' within ${this._serverStartupTimeoutMs}ms timeout.` +
409
322
  `Please make sure the remote server is running and accessible by Appium`
410
- : `Mac2Driver server is not listening within ${this.serverStartupTimeoutMs}ms timeout. ` +
323
+ : `Mac2Driver server is not listening within ${this._serverStartupTimeoutMs}ms timeout. ` +
411
324
  `Try to increase the value of 'serverStartupTimeout' capability, check the server logs ` +
412
325
  `and make sure the ${XCODEBUILD} host process could be started manually from a terminal`;
413
326
  throw new Error(msg);
414
327
  }
415
328
  throw e;
416
329
  }
417
- if (this.process) {
418
- const pid = this.process.pid;
419
- const childrenPids = await this.process.listChildrenPids();
420
- RUNNING_PROCESS_IDS.push(...childrenPids, pid);
421
- this.process.proc?.on('exit', () => void lodash_1.default.pull(RUNNING_PROCESS_IDS, pid));
330
+ if (this._process) {
331
+ const pid = this._process.pid;
332
+ const childrenPids = await this._process.listChildrenPids();
333
+ if (pid !== null) {
334
+ RUNNING_PROCESS_IDS.push(...childrenPids, pid);
335
+ this._process.proc?.on('exit', () => void lodash_1.default.pull(RUNNING_PROCESS_IDS, pid));
336
+ }
422
337
  log.info(`The host process is ready within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
423
338
  }
424
339
  }
425
340
  else {
426
341
  log.info('The host process has already been listening. Proceeding with session creation');
427
342
  }
428
- await this.proxy.command('/session', 'POST', {
343
+ await this._proxy.command('/session', 'POST', {
429
344
  capabilities: {
430
345
  firstMatch: [{}],
431
346
  alwaysMatch: caps,
@@ -433,25 +348,92 @@ class WDAMacServer {
433
348
  });
434
349
  }
435
350
  async stopSession() {
436
- if (!this.isProxyingToRemoteServer && !(this.process?.isRunning)) {
351
+ if (!this._isProxyingToRemoteServer && !(this._process?.isRunning)) {
437
352
  log.info(`Mac2Driver session cannot be stopped, because the server is not running`);
438
353
  return;
439
354
  }
440
- if (this.proxy?.sessionId) {
355
+ if (this._proxy?.sessionId) {
441
356
  try {
442
- await this.proxy.command(`/session/${this.proxy.sessionId}`, 'DELETE');
357
+ await this._proxy.command(`/session/${this._proxy.sessionId}`, 'DELETE');
443
358
  }
444
359
  catch (e) {
445
360
  log.info(`Mac2Driver session cannot be deleted. Original error: ${e.message}`);
446
361
  }
447
362
  }
448
363
  }
364
+ async isProxyReady(throwOnExit = true) {
365
+ if (!this._proxy) {
366
+ return false;
367
+ }
368
+ try {
369
+ await this._proxy.command('/status', 'GET');
370
+ return true;
371
+ }
372
+ catch (err) {
373
+ if (throwOnExit && this._proxy.didProcessExit) {
374
+ throw new Error(err.message);
375
+ }
376
+ return false;
377
+ }
378
+ }
379
+ /**
380
+ * Returns proxy information where WDAMacServer proxy to.
381
+ *
382
+ * @param caps - The capabilities in the session.
383
+ * @return ProxyProperties
384
+ * @throws Error if 'webDriverAgentMacUrl' had invalid URL
385
+ */
386
+ parseProxyProperties(caps) {
387
+ let scheme = 'http';
388
+ if (!caps.webDriverAgentMacUrl) {
389
+ return {
390
+ scheme,
391
+ host: (this._process?.host ?? caps.systemHost) ?? DEFAULT_SYSTEM_HOST,
392
+ port: (this._process?.port ?? caps.systemPort) ?? DEFAULT_SYSTEM_PORT,
393
+ path: ''
394
+ };
395
+ }
396
+ let parsedUrl;
397
+ try {
398
+ parsedUrl = new url_1.default.URL(caps.webDriverAgentMacUrl);
399
+ }
400
+ catch (e) {
401
+ throw new Error(`webDriverAgentMacUrl, '${caps.webDriverAgentMacUrl}', ` +
402
+ `in the capabilities is invalid. ${e.message}`);
403
+ }
404
+ const { protocol, hostname, port, pathname } = parsedUrl;
405
+ if (lodash_1.default.isString(protocol)) {
406
+ scheme = protocol.split(':')[0];
407
+ }
408
+ return {
409
+ scheme,
410
+ host: hostname ?? DEFAULT_SYSTEM_HOST,
411
+ port: lodash_1.default.isEmpty(port) ? DEFAULT_SYSTEM_PORT : lodash_1.default.parseInt(port),
412
+ path: pathname === '/' ? '' : pathname
413
+ };
414
+ }
449
415
  }
450
416
  exports.WDAMacServer = WDAMacServer;
451
- const WDA_MAC_SERVER = new WDAMacServer();
452
- exports.default = WDA_MAC_SERVER;
453
- /**
454
- * @typedef {Object} SessionOptions
455
- * @property {string} [reqBasePath]
456
- */
417
+ exports.WDA_MAC_SERVER = new WDAMacServer();
418
+ // Private functions
419
+ async function cleanupObsoleteProcesses() {
420
+ if (!lodash_1.default.isEmpty(RUNNING_PROCESS_IDS)) {
421
+ log.debug(`Cleaning up ${RUNNING_PROCESS_IDS.length} obsolete ` +
422
+ support_1.util.pluralize('process', RUNNING_PROCESS_IDS.length, false));
423
+ try {
424
+ await (0, teen_process_1.exec)('kill', ['-9', ...RUNNING_PROCESS_IDS.map(String)]);
425
+ }
426
+ catch { }
427
+ lodash_1.default.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
428
+ }
429
+ }
430
+ process.once('exit', () => {
431
+ if (!lodash_1.default.isEmpty(RUNNING_PROCESS_IDS)) {
432
+ try {
433
+ (0, child_process_1.execSync)(`kill -9 ${RUNNING_PROCESS_IDS.map(String).join(' ')}`);
434
+ }
435
+ catch { }
436
+ lodash_1.default.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
437
+ }
438
+ });
457
439
  //# sourceMappingURL=wda-mac.js.map