@appium/support 2.58.0 → 2.59.0

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 (67) hide show
  1. package/build/lib/console.d.ts +110 -0
  2. package/build/lib/console.d.ts.map +1 -0
  3. package/build/lib/console.js +113 -0
  4. package/build/lib/env.d.ts.map +1 -1
  5. package/build/lib/env.js +1 -1
  6. package/build/lib/fs.d.ts.map +1 -1
  7. package/build/lib/fs.js +1 -1
  8. package/build/lib/image-util.d.ts.map +1 -1
  9. package/build/lib/image-util.js +1 -1
  10. package/build/lib/index.d.ts +3 -1
  11. package/build/lib/index.js +8 -3
  12. package/build/lib/log-internal.d.ts.map +1 -1
  13. package/build/lib/log-internal.js +1 -1
  14. package/build/lib/logger.d.ts +1 -1
  15. package/build/lib/logger.d.ts.map +1 -1
  16. package/build/lib/logger.js +1 -1
  17. package/build/lib/logging.d.ts +11 -4
  18. package/build/lib/logging.d.ts.map +1 -1
  19. package/build/lib/logging.js +7 -6
  20. package/build/lib/mjpeg.d.ts.map +1 -1
  21. package/build/lib/mjpeg.js +1 -1
  22. package/build/lib/mkdirp.js +1 -1
  23. package/build/lib/net.d.ts +5 -2
  24. package/build/lib/net.d.ts.map +1 -1
  25. package/build/lib/net.js +1 -1
  26. package/build/lib/node.d.ts.map +1 -1
  27. package/build/lib/node.js +1 -1
  28. package/build/lib/npm.d.ts.map +1 -1
  29. package/build/lib/npm.js +1 -1
  30. package/build/lib/plist.d.ts +1 -1
  31. package/build/lib/plist.d.ts.map +1 -1
  32. package/build/lib/plist.js +1 -1
  33. package/build/lib/process.d.ts.map +1 -1
  34. package/build/lib/process.js +1 -1
  35. package/build/lib/system.js +1 -1
  36. package/build/lib/tempdir.d.ts.map +1 -1
  37. package/build/lib/tempdir.js +1 -1
  38. package/build/lib/timing.d.ts.map +1 -1
  39. package/build/lib/timing.js +1 -1
  40. package/build/lib/util.d.ts +19 -2
  41. package/build/lib/util.d.ts.map +1 -1
  42. package/build/lib/util.js +3 -7
  43. package/build/lib/zip.d.ts +5 -5
  44. package/build/lib/zip.d.ts.map +1 -1
  45. package/build/lib/zip.js +2 -2
  46. package/build/tsconfig.tsbuildinfo +1 -1
  47. package/lib/console.js +173 -0
  48. package/lib/env.js +12 -14
  49. package/lib/fs.js +87 -62
  50. package/lib/image-util.js +50 -32
  51. package/lib/index.js +39 -8
  52. package/lib/log-internal.js +16 -11
  53. package/lib/logger.js +1 -1
  54. package/lib/logging.js +32 -30
  55. package/lib/mjpeg.js +32 -27
  56. package/lib/mkdirp.js +3 -3
  57. package/lib/net.js +60 -52
  58. package/lib/node.js +22 -17
  59. package/lib/npm.js +50 -47
  60. package/lib/plist.js +34 -18
  61. package/lib/process.js +8 -6
  62. package/lib/system.js +8 -8
  63. package/lib/tempdir.js +14 -9
  64. package/lib/timing.js +12 -15
  65. package/lib/util.js +121 -72
  66. package/lib/zip.js +88 -92
  67. package/package.json +9 -8
package/lib/util.js CHANGED
@@ -1,5 +1,3 @@
1
- // @ts-check
2
-
3
1
  import B from 'bluebird';
4
2
  import _ from 'lodash';
5
3
  import os from 'os';
@@ -13,43 +11,52 @@ import {
13
11
  } from 'shell-quote';
14
12
  import pluralizeLib from 'pluralize';
15
13
  import stream from 'stream';
16
- import { Base64Encode } from 'base64-stream';
14
+ import {Base64Encode} from 'base64-stream';
17
15
  import {
18
16
  // https://www.npmjs.com/package/uuid
19
- v1 as uuidV1, v3 as uuidV3,
20
- v4 as uuidV4, v5 as uuidV5
17
+ v1 as uuidV1,
18
+ v3 as uuidV3,
19
+ v4 as uuidV4,
20
+ v5 as uuidV5,
21
21
  } from 'uuid';
22
22
  import _lockfile from 'lockfile';
23
23
 
24
-
25
24
  const W3C_WEB_ELEMENT_IDENTIFIER = 'element-6066-11e4-a52e-4f735466cecf';
26
25
  const KiB = 1024;
27
26
  const MiB = KiB * 1024;
28
27
  const GiB = MiB * 1024;
29
28
 
30
- export function hasContent (val) {
29
+ /**
30
+ * @template {string} T
31
+ * @param {T} val
32
+ * @returns {val is NonEmptyString<T>}
33
+ */
34
+ export function hasContent(val) {
31
35
  return _.isString(val) && val !== '';
32
36
  }
33
37
 
34
- // return true if the the value is not undefined, null, or NaN.
35
- function hasValue (val) {
36
- let hasVal = false;
38
+ /**
39
+ * return true if the the value is not `undefined`, `null`, or `NaN`.
40
+ *
41
+ * XXX: `NaN` is not expressible in TypeScript.
42
+ * @template T
43
+ * @param {T} val
44
+ * @returns {val is NonNullable<T>}
45
+ */
46
+ function hasValue(val) {
37
47
  // avoid incorrectly evaluating `0` as false
38
48
  if (_.isNumber(val)) {
39
- hasVal = !_.isNaN(val);
40
- } else {
41
- hasVal = !_.isUndefined(val) && !_.isNull(val);
49
+ return !_.isNaN(val);
42
50
  }
43
-
44
- return hasVal;
51
+ return !_.isUndefined(val) && !_.isNull(val);
45
52
  }
46
53
 
47
54
  // escape spaces in string, for commandline calls
48
- function escapeSpace (str) {
55
+ function escapeSpace(str) {
49
56
  return str.split(/ /).join('\\ ');
50
57
  }
51
58
 
52
- function escapeSpecialChars (str, quoteEscape) {
59
+ function escapeSpecialChars(str, quoteEscape) {
53
60
  if (typeof str !== 'string') {
54
61
  return str;
55
62
  }
@@ -73,13 +80,13 @@ function escapeSpecialChars (str, quoteEscape) {
73
80
  return str;
74
81
  }
75
82
 
76
- function localIp () {
83
+ function localIp() {
77
84
  let ip = _.chain(os.networkInterfaces())
78
85
  .values()
79
86
  .flatten()
80
87
  // @ts-ignore
81
88
  .filter(function (val) {
82
- return (val.family === 'IPv4' && val.internal === false);
89
+ return val.family === 'IPv4' && val.internal === false;
83
90
  })
84
91
  .map('address')
85
92
  .first()
@@ -91,7 +98,7 @@ function localIp () {
91
98
  * Creates a promise that is cancellable, and will timeout
92
99
  * after `ms` delay
93
100
  */
94
- function cancellableDelay (ms) {
101
+ function cancellableDelay(ms) {
95
102
  let timer;
96
103
  let resolve;
97
104
  let reject;
@@ -113,14 +120,14 @@ function cancellableDelay (ms) {
113
120
  return delay;
114
121
  }
115
122
 
116
- function multiResolve (roots, ...args) {
123
+ function multiResolve(roots, ...args) {
117
124
  return roots.map((root) => path.resolve(root, ...args));
118
125
  }
119
126
 
120
127
  /*
121
128
  * Parses an object if possible. Otherwise returns the object without parsing.
122
129
  */
123
- function safeJsonParse (obj) {
130
+ function safeJsonParse(obj) {
124
131
  try {
125
132
  return JSON.parse(obj);
126
133
  } catch (ign) {
@@ -141,7 +148,7 @@ function safeJsonParse (obj) {
141
148
  * string for readability purposes. Defaults to 2
142
149
  * returns {string} - the JSON object serialized as a string
143
150
  */
144
- function jsonStringify (obj, replacer, space = 2) {
151
+ function jsonStringify(obj, replacer, space = 2) {
145
152
  // if no replacer is passed, or it is not a function, just use a pass-through
146
153
  if (!_.isFunction(replacer)) {
147
154
  replacer = (k, v) => v;
@@ -151,12 +158,14 @@ function jsonStringify (obj, replacer, space = 2) {
151
158
  const bufferToJSON = Buffer.prototype.toJSON;
152
159
  delete Buffer.prototype.toJSON;
153
160
  try {
154
- return JSON.stringify(obj, (key, value) => {
155
- const updatedValue = Buffer.isBuffer(value)
156
- ? value.toString('utf8')
157
- : value;
158
- return replacer(key, updatedValue);
159
- }, space);
161
+ return JSON.stringify(
162
+ obj,
163
+ (key, value) => {
164
+ const updatedValue = Buffer.isBuffer(value) ? value.toString('utf8') : value;
165
+ return replacer(key, updatedValue);
166
+ },
167
+ space
168
+ );
160
169
  } finally {
161
170
  // restore the function, so as to not break further serialization
162
171
  Buffer.prototype.toJSON = bufferToJSON;
@@ -168,7 +177,7 @@ function jsonStringify (obj, replacer, space = 2) {
168
177
  * { ELEMENT: 4 } becomes 4
169
178
  * { element-6066-11e4-a52e-4f735466cecf: 5 } becomes 5
170
179
  */
171
- function unwrapElement (el) {
180
+ function unwrapElement(el) {
172
181
  for (const propName of [W3C_WEB_ELEMENT_IDENTIFIER, 'ELEMENT']) {
173
182
  if (_.has(el, propName)) {
174
183
  return el[propName];
@@ -177,7 +186,7 @@ function unwrapElement (el) {
177
186
  return el;
178
187
  }
179
188
 
180
- function wrapElement (elementId) {
189
+ function wrapElement(elementId) {
181
190
  return {
182
191
  ELEMENT: elementId,
183
192
  [W3C_WEB_ELEMENT_IDENTIFIER]: elementId,
@@ -192,7 +201,7 @@ function wrapElement (elementId) {
192
201
  * * a scalar - it will test all properties' values against that value
193
202
  * * a function - it will pass each value and the original object into the function
194
203
  */
195
- function filterObject (obj, predicate) {
204
+ function filterObject(obj, predicate) {
196
205
  let newObj = _.clone(obj);
197
206
  if (_.isUndefined(predicate)) {
198
207
  // remove any element from the object whose value is undefined
@@ -219,7 +228,7 @@ function filterObject (obj, predicate) {
219
228
  * @throws {Error} If bytes count cannot be converted to an integer or
220
229
  * if it is less than zero.
221
230
  */
222
- function toReadableSizeString (bytes) {
231
+ function toReadableSizeString(bytes) {
223
232
  const intBytes = parseInt(String(bytes), 10);
224
233
  if (isNaN(intBytes) || intBytes < 0) {
225
234
  throw new Error(`Cannot convert '${bytes}' to a readable size format`);
@@ -244,7 +253,7 @@ function toReadableSizeString (bytes) {
244
253
  * @returns {boolean} true if the given original path is the subpath of the root folder
245
254
  * @throws {Error} if any of the given paths is not absolute
246
255
  */
247
- function isSubPath (originalPath, root, forcePosix = null) {
256
+ function isSubPath(originalPath, root, forcePosix = null) {
248
257
  const pathObj = forcePosix ? path.posix : path;
249
258
  for (const p of [originalPath, root]) {
250
259
  if (!pathObj.isAbsolute(p)) {
@@ -265,20 +274,23 @@ function isSubPath (originalPath, root, forcePosix = null) {
265
274
  * @param {...string} pathN - Zero or more absolute or relative paths to files/folders
266
275
  * @returns {Promise<boolean>} true if all paths are pointing to the same file system item
267
276
  */
268
- async function isSameDestination (path1, path2, ...pathN) {
277
+ async function isSameDestination(path1, path2, ...pathN) {
269
278
  const allPaths = [path1, path2, ...pathN];
270
- if (!await B.reduce(allPaths, async (a, b) => a && await fs.exists(b), true)) {
279
+ if (!(await B.reduce(allPaths, async (a, b) => a && (await fs.exists(b)), true))) {
271
280
  return false;
272
281
  }
273
282
 
274
- const areAllItemsEqual = (arr) => !!arr.reduce((a, b) => a === b ? a : NaN);
283
+ const areAllItemsEqual = (arr) => !!arr.reduce((a, b) => (a === b ? a : NaN));
275
284
  if (areAllItemsEqual(allPaths)) {
276
285
  return true;
277
286
  }
278
287
 
279
- let mapCb = async (x) => (await fs.stat(x, {
280
- bigint: true,
281
- })).ino;
288
+ let mapCb = async (x) =>
289
+ (
290
+ await fs.stat(x, {
291
+ bigint: true,
292
+ })
293
+ ).ino;
282
294
  return areAllItemsEqual(await B.map(allPaths, mapCb));
283
295
  }
284
296
 
@@ -293,12 +305,12 @@ async function isSameDestination (path1, path2, ...pathN) {
293
305
  * coerced and strict mode is disabled
294
306
  * @throws {Error} if strict mode is enabled and `ver` cannot be coerced
295
307
  */
296
- function coerceVersion (ver, strict = /** @type {Strict} */(true)) {
308
+ function coerceVersion(ver, strict = /** @type {Strict} */ (true)) {
297
309
  const result = semver.valid(semver.coerce(`${ver}`));
298
310
  if (strict && !result) {
299
311
  throw new Error(`'${ver}' cannot be coerced to a valid version number`);
300
312
  }
301
- return /** @type {Strict extends true ? string : string?} */(result);
313
+ return /** @type {Strict extends true ? string : string?} */ (result);
302
314
  }
303
315
 
304
316
  const SUPPORTED_OPERATORS = ['==', '!=', '>', '<', '>=', '<=', '='];
@@ -316,10 +328,12 @@ const SUPPORTED_OPERATORS = ['==', '!=', '>', '<', '>=', '<=', '='];
316
328
  * @throws {Error} if an unsupported operator is supplied or any of the supplied
317
329
  * version strings cannot be coerced
318
330
  */
319
- function compareVersions (ver1, operator, ver2) {
331
+ function compareVersions(ver1, operator, ver2) {
320
332
  if (!SUPPORTED_OPERATORS.includes(operator)) {
321
- throw new Error(`The '${operator}' comparison operator is not supported. ` +
322
- `Only '${JSON.stringify(SUPPORTED_OPERATORS)}' operators are supported`);
333
+ throw new Error(
334
+ `The '${operator}' comparison operator is not supported. ` +
335
+ `Only '${JSON.stringify(SUPPORTED_OPERATORS)}' operators are supported`
336
+ );
323
337
  }
324
338
 
325
339
  const semverOperator = ['==', '!='].includes(operator) ? '=' : operator;
@@ -334,7 +348,7 @@ function compareVersions (ver1, operator, ver2) {
334
348
  * @param {string|string[]} args - The arguments that will be parsed
335
349
  * @returns {string} - The arguments, quoted
336
350
  */
337
- function quote (args) {
351
+ function quote(args) {
338
352
  return shellQuote(_.castArray(args));
339
353
  }
340
354
 
@@ -346,11 +360,10 @@ function quote (args) {
346
360
  * @param {*} s - The string to unleak
347
361
  * @return {string} Either the unleaked string or the original object converted to string
348
362
  */
349
- function unleakString (s) {
363
+ function unleakString(s) {
350
364
  return ` ${s}`.substr(1);
351
365
  }
352
366
 
353
-
354
367
  /**
355
368
  * @typedef PluralizeOptions
356
369
  * @property {boolean} [inclusive=false] - Whether to prefix with the number (e.g., 3 ducks)
@@ -365,7 +378,7 @@ function unleakString (s) {
365
378
  * or a boolean indicating the options.inclusive property
366
379
  * @returns {string} The word pluralized according to the number
367
380
  */
368
- function pluralize (word, count, options = {}) {
381
+ function pluralize(word, count, options = {}) {
369
382
  let inclusive = false;
370
383
  if (_.isBoolean(options)) {
371
384
  // if passed in as a boolean
@@ -397,14 +410,12 @@ function pluralize (word, count, options = {}) {
397
410
  * @throws {Error} if there was an error while reading the source file
398
411
  * or the source file is too
399
412
  */
400
- async function toInMemoryBase64 (srcPath, opts = {}) {
413
+ async function toInMemoryBase64(srcPath, opts = {}) {
401
414
  if (!(await fs.exists(srcPath)) || (await fs.stat(srcPath)).isDirectory()) {
402
415
  throw new Error(`No such file: ${srcPath}`);
403
416
  }
404
417
 
405
- const {
406
- maxSize = 1 * GiB,
407
- } = opts;
418
+ const {maxSize = 1 * GiB} = opts;
408
419
  const resultBuffers = [];
409
420
  let resultBuffersSize = 0;
410
421
  const resultWriteStream = new stream.Writable({
@@ -412,8 +423,13 @@ async function toInMemoryBase64 (srcPath, opts = {}) {
412
423
  resultBuffers.push(buffer);
413
424
  resultBuffersSize += buffer.length;
414
425
  if (maxSize > 0 && resultBuffersSize > maxSize) {
415
- resultWriteStream.emit('error', new Error(`The size of the resulting ` +
416
- `buffer must not be greater than ${toReadableSizeString(maxSize)}`));
426
+ resultWriteStream.emit(
427
+ 'error',
428
+ new Error(
429
+ `The size of the resulting ` +
430
+ `buffer must not be greater than ${toReadableSizeString(maxSize)}`
431
+ )
432
+ );
417
433
  }
418
434
  next();
419
435
  },
@@ -432,8 +448,9 @@ async function toInMemoryBase64 (srcPath, opts = {}) {
432
448
  });
433
449
  const readStreamPromise = new B((resolve, reject) => {
434
450
  readerStream.once('close', resolve);
435
- readerStream.once('error', (e) => reject(
436
- new Error(`Failed to read '${srcPath}': ${e.message}`)));
451
+ readerStream.once('error', (e) =>
452
+ reject(new Error(`Failed to read '${srcPath}': ${e.message}`))
453
+ );
437
454
  });
438
455
  readerStream.pipe(base64EncoderStream);
439
456
  base64EncoderStream.pipe(resultWriteStream);
@@ -460,13 +477,12 @@ async function toInMemoryBase64 (srcPath, opts = {}) {
460
477
  * @returns async function that takes another async function defining the locked
461
478
  * behavior
462
479
  */
463
- function getLockFileGuard (lockFile, opts = {}) {
464
- const {
465
- timeout = 120,
466
- tryRecovery = false,
467
- } = opts;
480
+ function getLockFileGuard(lockFile, opts = {}) {
481
+ const {timeout = 120, tryRecovery = false} = opts;
468
482
 
469
- const lock = /** @type {(lockfile: string, opts: import('lockfile').Options)=>B<void>} */(B.promisify(_lockfile.lock));
483
+ const lock = /** @type {(lockfile: string, opts: import('lockfile').Options)=>B<void>} */ (
484
+ B.promisify(_lockfile.lock)
485
+ );
470
486
  const check = B.promisify(_lockfile.check);
471
487
  const unlock = B.promisify(_lockfile.unlock);
472
488
 
@@ -495,10 +511,12 @@ function getLockFileGuard (lockFile, opts = {}) {
495
511
  triedRecovery = true;
496
512
  continue;
497
513
  }
498
- throw new Error(`Could not acquire lock on '${lockFile}' after ${timeout}s. ` +
499
- `Original error: ${e.message}`);
514
+ throw new Error(
515
+ `Could not acquire lock on '${lockFile}' after ${timeout}s. ` +
516
+ `Original error: ${e.message}`
517
+ );
500
518
  }
501
- // eslint-disable-next-line no-constant-condition
519
+ // eslint-disable-next-line no-constant-condition
502
520
  } while (true);
503
521
  try {
504
522
  return await behavior();
@@ -514,10 +532,41 @@ function getLockFileGuard (lockFile, opts = {}) {
514
532
  }
515
533
 
516
534
  export {
517
- hasValue, escapeSpace, escapeSpecialChars, localIp, cancellableDelay,
518
- multiResolve, safeJsonParse, wrapElement, unwrapElement, filterObject,
519
- toReadableSizeString, isSubPath, W3C_WEB_ELEMENT_IDENTIFIER,
520
- isSameDestination, compareVersions, coerceVersion, quote, unleakString,
521
- jsonStringify, pluralize, GiB, MiB, KiB, toInMemoryBase64,
522
- uuidV1, uuidV3, uuidV4, uuidV5, shellParse, getLockFileGuard
535
+ hasValue,
536
+ escapeSpace,
537
+ escapeSpecialChars,
538
+ localIp,
539
+ cancellableDelay,
540
+ multiResolve,
541
+ safeJsonParse,
542
+ wrapElement,
543
+ unwrapElement,
544
+ filterObject,
545
+ toReadableSizeString,
546
+ isSubPath,
547
+ W3C_WEB_ELEMENT_IDENTIFIER,
548
+ isSameDestination,
549
+ compareVersions,
550
+ coerceVersion,
551
+ quote,
552
+ unleakString,
553
+ jsonStringify,
554
+ pluralize,
555
+ GiB,
556
+ MiB,
557
+ KiB,
558
+ toInMemoryBase64,
559
+ uuidV1,
560
+ uuidV3,
561
+ uuidV4,
562
+ uuidV5,
563
+ shellParse,
564
+ getLockFileGuard,
523
565
  };
566
+
567
+ /**
568
+ * A `string` which is never `''`.
569
+ *
570
+ * @template {string} T
571
+ * @typedef {T extends '' ? never : T} NonEmptyString
572
+ */