appium-mac2-driver 3.3.0 → 3.3.2

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/build/lib/commands/execute.d.ts.map +1 -1
  3. package/build/lib/commands/execute.js +1 -5
  4. package/build/lib/commands/execute.js.map +1 -1
  5. package/build/lib/commands/gestures.d.ts.map +1 -1
  6. package/build/lib/commands/gestures.js +6 -7
  7. package/build/lib/commands/gestures.js.map +1 -1
  8. package/build/lib/commands/helpers.d.ts.map +1 -1
  9. package/build/lib/commands/helpers.js +1 -5
  10. package/build/lib/commands/helpers.js.map +1 -1
  11. package/build/lib/commands/native-record-screen.d.ts.map +1 -1
  12. package/build/lib/commands/native-record-screen.js +6 -6
  13. package/build/lib/commands/native-record-screen.js.map +1 -1
  14. package/build/lib/commands/record-screen.d.ts +33 -2
  15. package/build/lib/commands/record-screen.d.ts.map +1 -1
  16. package/build/lib/commands/record-screen.js +24 -6
  17. package/build/lib/commands/record-screen.js.map +1 -1
  18. package/build/lib/driver.d.ts +4 -2
  19. package/build/lib/driver.d.ts.map +1 -1
  20. package/build/lib/driver.js +7 -6
  21. package/build/lib/driver.js.map +1 -1
  22. package/build/lib/execute-method-map.d.ts +2 -2
  23. package/build/lib/execute-method-map.js +2 -2
  24. package/build/lib/execute-method-map.js.map +1 -1
  25. package/build/lib/utils.d.ts +4 -8
  26. package/build/lib/utils.d.ts.map +1 -1
  27. package/build/lib/utils.js +33 -10
  28. package/build/lib/utils.js.map +1 -1
  29. package/build/lib/wda-mac.d.ts.map +1 -1
  30. package/build/lib/wda-mac.js +14 -13
  31. package/build/lib/wda-mac.js.map +1 -1
  32. package/lib/commands/execute.ts +1 -2
  33. package/lib/commands/gestures.ts +8 -4
  34. package/lib/commands/helpers.ts +1 -2
  35. package/lib/commands/native-record-screen.ts +6 -6
  36. package/lib/commands/record-screen.ts +69 -7
  37. package/lib/driver.ts +7 -6
  38. package/lib/execute-method-map.ts +2 -2
  39. package/lib/utils.ts +33 -7
  40. package/lib/wda-mac.ts +15 -14
  41. package/npm-shrinkwrap.json +133 -221
  42. package/package.json +1 -3
@@ -177,7 +177,7 @@ export const executeMethodMap = {
177
177
  },
178
178
  },
179
179
  'macos: startRecordingScreen': {
180
- command: 'startRecordingScreen',
180
+ command: 'macosStartRecordingScreen',
181
181
  params: {
182
182
  required: ['deviceId'],
183
183
  optional: [
@@ -192,7 +192,7 @@ export const executeMethodMap = {
192
192
  },
193
193
  },
194
194
  'macos: stopRecordingScreen': {
195
- command: 'stopRecordingScreen',
195
+ command: 'macosStopRecordingScreen',
196
196
  params: {
197
197
  optional: ['remotePath', 'user', 'pass', 'method', 'headers', 'fileFieldName', 'formFields'],
198
198
  },
package/lib/utils.ts CHANGED
@@ -1,4 +1,3 @@
1
- import _ from 'lodash';
2
1
  import {exec} from 'teen_process';
3
2
  import {node} from 'appium/support';
4
3
 
@@ -10,13 +9,19 @@ const MODULE_NAME = 'appium-mac2-driver';
10
9
  * @returns The full path to module root
11
10
  * @throws If the current module root folder cannot be determined
12
11
  */
13
- export const getModuleRoot = _.memoize(function getModuleRoot(): string {
12
+ let moduleRootCache: string | null = null;
13
+
14
+ export const getModuleRoot = function getModuleRoot(): string {
15
+ if (moduleRootCache) {
16
+ return moduleRootCache;
17
+ }
14
18
  const root = node.getModuleRootSync(MODULE_NAME, __filename);
15
19
  if (!root) {
16
20
  throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
17
21
  }
18
- return root;
19
- });
22
+ moduleRootCache = root;
23
+ return moduleRootCache;
24
+ };
20
25
 
21
26
  /**
22
27
  * Retrieves process ids of all the children processes created by the given
@@ -31,11 +36,32 @@ export async function listChildrenProcessIds(parentPid: number | string): Promis
31
36
  // USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND PPID
32
37
  return stdout
33
38
  .split('\n')
34
- .filter(_.trim)
39
+ .map((line) => line.trim())
40
+ .filter(Boolean)
35
41
  .map((line: string) => {
36
- const [, pid, ...rest] = line.split(/\s+/).filter(_.trim);
37
- return [pid, _.last(rest)];
42
+ const [, pid, ...rest] = line.split(/\s+/).filter(Boolean);
43
+ return [pid, rest.at(-1)];
38
44
  })
39
45
  .filter(([, ppid]) => ppid === `${parentPid}`)
40
46
  .map(([pid]) => String(pid));
41
47
  }
48
+
49
+ export function clearArray<T>(items: T[]): void {
50
+ items.length = 0;
51
+ }
52
+
53
+ export function removeAllOccurrences<T>(items: T[], value: T): void {
54
+ let index = items.indexOf(value);
55
+ while (index >= 0) {
56
+ items.splice(index, 1);
57
+ index = items.indexOf(value);
58
+ }
59
+ }
60
+
61
+ export function isPlainObject(value: unknown): value is Record<string, unknown> {
62
+ if (value === null || typeof value !== 'object') {
63
+ return false;
64
+ }
65
+ const proto = Object.getPrototypeOf(value);
66
+ return proto === Object.prototype || proto === null;
67
+ }
package/lib/wda-mac.ts CHANGED
@@ -1,4 +1,3 @@
1
- import _ from 'lodash';
2
1
  import path from 'node:path';
3
2
  import url from 'node:url';
4
3
  import axios from 'axios';
@@ -11,7 +10,7 @@ import {waitForCondition} from 'asyncbox';
11
10
  import {checkPortStatus} from 'portscanner';
12
11
  import {execSync} from 'node:child_process';
13
12
  import type {HTTPMethod, HTTPBody, ProxyResponse, ProxyOptions} from '@appium/types';
14
- import {listChildrenProcessIds, getModuleRoot} from './utils';
13
+ import {listChildrenProcessIds, getModuleRoot, clearArray, removeAllOccurrences} from './utils';
15
14
 
16
15
  const log = logger.getLogger('WebDriverAgentMac');
17
16
 
@@ -232,7 +231,7 @@ class WDAMacProcess {
232
231
  return;
233
232
  }
234
233
 
235
- const line = _.trim(stdout || stderr);
234
+ const line = (stdout ?? stderr ?? '').trim();
236
235
  if (line) {
237
236
  log.debug(`[${XCODEBUILD}] ${line}`);
238
237
  }
@@ -251,7 +250,7 @@ class WDAMacProcess {
251
250
  }
252
251
 
253
252
  const childrenPids = await this.listChildrenPids();
254
- if (!_.isEmpty(childrenPids)) {
253
+ if (childrenPids.length > 0) {
255
254
  try {
256
255
  await exec('kill', childrenPids);
257
256
  } catch {}
@@ -265,7 +264,7 @@ class WDAMacProcess {
265
264
  }
266
265
 
267
266
  const childrenPids = await this.listChildrenPids();
268
- if (!_.isEmpty(childrenPids)) {
267
+ if (childrenPids.length > 0) {
269
268
  try {
270
269
  await exec('kill', ['-9', ...childrenPids]);
271
270
  } catch {}
@@ -278,8 +277,8 @@ class WDAMacProcess {
278
277
  private hasSameOpts(opts: WDAMacProcessInitOptions): boolean {
279
278
  const {showServerLogs, systemPort, systemHost, bootstrapRoot} = opts;
280
279
  if (
281
- (_.isBoolean(showServerLogs) && this._showServerLogs !== showServerLogs) ||
282
- (_.isNil(showServerLogs) && this._showServerLogs !== DEFAULT_SHOW_SERVER_LOGS)
280
+ (typeof showServerLogs === 'boolean' && this._showServerLogs !== showServerLogs) ||
281
+ (showServerLogs == null && this._showServerLogs !== DEFAULT_SHOW_SERVER_LOGS)
283
282
  ) {
284
283
  return false;
285
284
  }
@@ -390,7 +389,9 @@ export class WDAMacServer {
390
389
  const childrenPids = await this._process.listChildrenPids();
391
390
  if (pid !== null) {
392
391
  RUNNING_PROCESS_IDS.push(...childrenPids, pid);
393
- this._process.proc?.on('exit', () => void _.pull(RUNNING_PROCESS_IDS, pid));
392
+ this._process.proc?.on('exit', () => {
393
+ removeAllOccurrences(RUNNING_PROCESS_IDS, pid);
394
+ });
394
395
  }
395
396
  log.info(
396
397
  `The host process is ready within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
@@ -468,13 +469,13 @@ export class WDAMacServer {
468
469
  }
469
470
 
470
471
  const {protocol, hostname, port, pathname} = parsedUrl;
471
- if (_.isString(protocol)) {
472
+ if (typeof protocol === 'string') {
472
473
  scheme = protocol.split(':')[0];
473
474
  }
474
475
  return {
475
476
  scheme,
476
477
  host: hostname ?? DEFAULT_SYSTEM_HOST,
477
- port: _.isEmpty(port) ? DEFAULT_SYSTEM_PORT : _.parseInt(port),
478
+ port: port.length === 0 ? DEFAULT_SYSTEM_PORT : Number.parseInt(port, 10),
478
479
  path: pathname === '/' ? '' : pathname,
479
480
  };
480
481
  }
@@ -484,7 +485,7 @@ export const WDA_MAC_SERVER = new WDAMacServer();
484
485
 
485
486
  // Private functions
486
487
  async function cleanupObsoleteProcesses(): Promise<void> {
487
- if (!_.isEmpty(RUNNING_PROCESS_IDS)) {
488
+ if (RUNNING_PROCESS_IDS.length > 0) {
488
489
  log.debug(
489
490
  `Cleaning up ${RUNNING_PROCESS_IDS.length} obsolete ` +
490
491
  util.pluralize('process', RUNNING_PROCESS_IDS.length, false),
@@ -492,16 +493,16 @@ async function cleanupObsoleteProcesses(): Promise<void> {
492
493
  try {
493
494
  await exec('kill', ['-9', ...RUNNING_PROCESS_IDS.map(String)]);
494
495
  } catch {}
495
- _.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
496
+ clearArray(RUNNING_PROCESS_IDS);
496
497
  }
497
498
  }
498
499
 
499
500
  process.once('exit', () => {
500
- if (!_.isEmpty(RUNNING_PROCESS_IDS)) {
501
+ if (RUNNING_PROCESS_IDS.length > 0) {
501
502
  try {
502
503
  execSync(`kill -9 ${RUNNING_PROCESS_IDS.map(String).join(' ')}`);
503
504
  } catch {}
504
- _.pullAll(RUNNING_PROCESS_IDS, RUNNING_PROCESS_IDS);
505
+ clearArray(RUNNING_PROCESS_IDS);
505
506
  }
506
507
  });
507
508