@appium/support 2.61.1 → 3.0.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 (59) hide show
  1. package/build/lib/console.d.ts +1 -1
  2. package/build/lib/console.js +169 -105
  3. package/build/lib/console.js.map +1 -1
  4. package/build/lib/env.js +142 -117
  5. package/build/lib/env.js.map +1 -1
  6. package/build/lib/fs.d.ts +9 -2
  7. package/build/lib/fs.d.ts.map +1 -1
  8. package/build/lib/fs.js +358 -246
  9. package/build/lib/fs.js.map +1 -1
  10. package/build/lib/image-util.js +139 -124
  11. package/build/lib/image-util.js.map +1 -1
  12. package/build/lib/index.js +64 -103
  13. package/build/lib/index.js.map +1 -1
  14. package/build/lib/log-internal.d.ts +4 -27
  15. package/build/lib/log-internal.d.ts.map +1 -1
  16. package/build/lib/log-internal.js +141 -123
  17. package/build/lib/log-internal.js.map +1 -1
  18. package/build/lib/logger.d.ts +1 -1
  19. package/build/lib/logger.d.ts.map +1 -1
  20. package/build/lib/logger.js +5 -14
  21. package/build/lib/logger.js.map +1 -1
  22. package/build/lib/logging.d.ts +3 -4
  23. package/build/lib/logging.d.ts.map +1 -1
  24. package/build/lib/logging.js +139 -110
  25. package/build/lib/logging.js.map +1 -1
  26. package/build/lib/mjpeg.js +169 -141
  27. package/build/lib/mjpeg.js.map +1 -1
  28. package/build/lib/mkdirp.js +7 -13
  29. package/build/lib/mkdirp.js.map +1 -1
  30. package/build/lib/net.d.ts.map +1 -1
  31. package/build/lib/net.js +278 -254
  32. package/build/lib/net.js.map +1 -1
  33. package/build/lib/node.js +203 -192
  34. package/build/lib/node.js.map +1 -1
  35. package/build/lib/npm.d.ts +19 -4
  36. package/build/lib/npm.d.ts.map +1 -1
  37. package/build/lib/npm.js +277 -228
  38. package/build/lib/npm.js.map +1 -1
  39. package/build/lib/plist.js +145 -136
  40. package/build/lib/plist.js.map +1 -1
  41. package/build/lib/process.js +41 -42
  42. package/build/lib/process.js.map +1 -1
  43. package/build/lib/system.js +39 -56
  44. package/build/lib/system.js.map +1 -1
  45. package/build/lib/tempdir.js +112 -73
  46. package/build/lib/tempdir.js.map +1 -1
  47. package/build/lib/timing.js +99 -84
  48. package/build/lib/timing.js.map +1 -1
  49. package/build/lib/util.js +454 -356
  50. package/build/lib/util.js.map +1 -1
  51. package/build/lib/zip.js +469 -423
  52. package/build/lib/zip.js.map +1 -1
  53. package/build/tsconfig.tsbuildinfo +1 -1
  54. package/lib/fs.js +15 -1
  55. package/lib/log-internal.js +12 -16
  56. package/lib/logging.js +2 -3
  57. package/lib/net.js +15 -6
  58. package/lib/npm.js +28 -18
  59. package/package.json +19 -18
package/lib/logging.js CHANGED
@@ -137,10 +137,9 @@ function getLogger(prefix = null) {
137
137
  * appear in Appium logs.
138
138
  * Each call to this method replaces the previously loaded rules if any existed.
139
139
  *
140
- * @param {string|string[]|import('./log-internal').Rule[]} rulesJsonPath The full path to the JSON file containing
140
+ * @param {string|string[]|import('@appium/types').LogFiltersConfig} rulesJsonPath The full path to the JSON file containing
141
141
  * the replacement rules. Each rule could either be a string to be replaced
142
- * or an object with predefined properties. See the `Rule` type definition in
143
- * `log-internals.js` to get more details on its format.
142
+ * or an object with predefined properties.
144
143
  * @throws {Error} If the given file cannot be loaded
145
144
  * @returns {Promise<LoadResult>}
146
145
  */
package/lib/net.js CHANGED
@@ -10,19 +10,28 @@ import FormData from 'form-data';
10
10
 
11
11
  const DEFAULT_TIMEOUT_MS = 4 * 60 * 1000;
12
12
 
13
+ /**
14
+ * Type guard for param to {@linkcode toAxiosAuth}
15
+ * @param {any} value
16
+ * @returns {value is AuthCredentials | import('axios').AxiosBasicCredentials}
17
+ */
18
+ function isAxiosAuth(value) {
19
+ return _.isPlainObject(value);
20
+ }
21
+
13
22
  /**
14
23
  * Converts {@linkcode AuthCredentials} to credentials understood by {@linkcode axios}.
15
24
  * @param {AuthCredentials | import('axios').AxiosBasicCredentials} [auth]
16
25
  * @returns {import('axios').AxiosBasicCredentials?}
17
26
  */
18
27
  function toAxiosAuth(auth) {
19
- if (!_.isPlainObject(auth)) {
28
+ if (!isAxiosAuth(auth)) {
20
29
  return null;
21
30
  }
22
31
 
23
32
  const axiosAuth = {
24
- username: _.get(auth, 'username', _.get(auth, 'user')),
25
- password: _.get(auth, 'password', _.get(auth, 'pass')),
33
+ username: 'username' in auth ? auth.username : auth.user,
34
+ password: 'password' in auth ? auth.password : auth.pass,
26
35
  };
27
36
  return axiosAuth.username && axiosAuth.password ? axiosAuth : null;
28
37
  }
@@ -136,7 +145,7 @@ async function uploadFileToFtp(
136
145
  */
137
146
  function isHttpUploadOptions(opts, url) {
138
147
  try {
139
- const {protocol} = new URL(url);
148
+ const {protocol} = url;
140
149
  return protocol === 'http:' || protocol === 'https:';
141
150
  } catch {
142
151
  return false;
@@ -151,7 +160,7 @@ function isHttpUploadOptions(opts, url) {
151
160
  */
152
161
  function isNotHttpUploadOptions(opts, url) {
153
162
  try {
154
- const {protocol} = new URL(url);
163
+ const {protocol} = url;
155
164
  return protocol === 'ftp:';
156
165
  } catch {
157
166
  return false;
@@ -243,7 +252,7 @@ async function downloadFile(
243
252
  try {
244
253
  const writer = fs.createWriteStream(dstPath);
245
254
  const {data: responseStream, headers: responseHeaders} = await axios(requestOpts);
246
- responseLength = parseInt(responseHeaders['content-length'], 10);
255
+ responseLength = parseInt(responseHeaders['content-length'] || '0', 10);
247
256
  responseStream.pipe(writer);
248
257
 
249
258
  await new B((resolve, reject) => {
package/lib/npm.js CHANGED
@@ -41,13 +41,13 @@ export class NPM {
41
41
  * @param {string} cmd
42
42
  * @param {string[]} args
43
43
  * @param {ExecOpts} opts
44
- * @param {Omit<import('teen_process').ExecOptions, 'cwd'>} [execOpts]
44
+ * @param {Omit<TeenProcessExecOptions, 'cwd'>} [execOpts]
45
45
  */
46
46
  async exec(cmd, args, opts, execOpts = {}) {
47
47
  let {cwd, json, lockFile} = opts;
48
48
 
49
49
  // make sure we perform the current operation in cwd
50
- /** @type {import('teen_process').ExecOptions} */
50
+ /** @type {TeenProcessExecOptions} */
51
51
  const teenProcessExecOpts = {...execOpts, cwd};
52
52
 
53
53
  args.unshift(cmd);
@@ -62,7 +62,7 @@ export class NPM {
62
62
  runner = async () => await acquireLock(_runner);
63
63
  }
64
64
 
65
- /** @type {import('teen_process').ExecResult<string> & {json?: any}} */
65
+ /** @type {import('teen_process').TeenProcessExecResult<string> & {json?: any}} */
66
66
  let ret;
67
67
  try {
68
68
  const {stdout, stderr, code} = await runner();
@@ -156,14 +156,14 @@ export class NPM {
156
156
  */
157
157
  getLatestSafeUpgradeFromVersions(curVersion, allVersions) {
158
158
  let safeUpgradeVer = null;
159
- const curSemver = semver.parse(curVersion);
159
+ const curSemver = semver.parse(curVersion) ?? semver.parse(semver.coerce(curVersion));
160
160
  if (curSemver === null) {
161
161
  throw new Error(`Could not parse current version '${curVersion}'`);
162
162
  }
163
163
  for (const testVer of allVersions) {
164
- const testSemver = semver.parse(testVer);
164
+ const testSemver = semver.parse(testVer) ?? semver.parse(semver.coerce(testVer));
165
165
  if (testSemver === null) {
166
- throw new Error(`Could not parse version to test against: '${testVer}'`);
166
+ continue;
167
167
  }
168
168
  // if the test version is a prerelease, ignore it
169
169
  if (testSemver.prerelease.length > 0) {
@@ -194,9 +194,9 @@ export class NPM {
194
194
  * @param {string} cwd
195
195
  * @param {string} pkgName
196
196
  * @param {InstallPackageOpts} [opts]
197
- * @returns {Promise<import('type-fest').PackageJson>}
197
+ * @returns {Promise<NpmInstallReceipt>}
198
198
  */
199
- async installPackage(cwd, pkgName, {pkgVer} = {}) {
199
+ async installPackage(cwd, pkgName, {pkgVer, installType}) {
200
200
  /** @type {any} */
201
201
  let dummyPkgJson;
202
202
  const dummyPkgPath = path.join(cwd, 'package.json');
@@ -219,15 +219,12 @@ export class NPM {
219
219
  installOpts.push('--save-exact', '--global-style', '--no-package-lock');
220
220
  }
221
221
 
222
- const res = await this.exec(
223
- 'install',
224
- [...installOpts, pkgVer ? `${pkgName}@${pkgVer}` : pkgName],
225
- {
226
- cwd,
227
- json: true,
228
- lockFile: this._getInstallLockfilePath(cwd),
229
- }
230
- );
222
+ const cmd = installType === 'local' ? 'link' : 'install';
223
+ const res = await this.exec(cmd, [...installOpts, pkgVer ? `${pkgName}@${pkgVer}` : pkgName], {
224
+ cwd,
225
+ json: true,
226
+ lockFile: this._getInstallLockfilePath(cwd),
227
+ });
231
228
 
232
229
  if (res.json) {
233
230
  // we parsed a valid json response, so if we got an error here, return that
@@ -243,7 +240,9 @@ export class NPM {
243
240
  // (even on Windows!)
244
241
  const pkgJsonPath = resolveFrom(cwd, `${pkgName}/package.json`);
245
242
  try {
246
- return require(pkgJsonPath);
243
+ const pkgJson = await fs.readFile(pkgJsonPath, 'utf8');
244
+ const pkg = JSON.parse(pkgJson);
245
+ return {installPath: path.dirname(pkgJsonPath), pkg};
247
246
  } catch {
248
247
  throw new Error(
249
248
  'The package was not downloaded correctly; its package.json ' +
@@ -270,6 +269,7 @@ export const npm = new NPM();
270
269
  /**
271
270
  * Options for {@link NPM.installPackage}
272
271
  * @typedef InstallPackageOpts
272
+ * @property {import('type-fest').LiteralUnion<'local', string>} [installType] - whether to install from a local path or from npm
273
273
  * @property {string} [pkgVer] - the version of the package to install
274
274
  */
275
275
 
@@ -280,3 +280,13 @@ export const npm = new NPM();
280
280
  * @property {boolean} [json] - If `true`, supply `--json` flag to npm and resolve w/ parsed JSON
281
281
  * @property {string} [lockFile] - Path to lockfile to use
282
282
  */
283
+
284
+ /**
285
+ * @typedef {import('teen_process').TeenProcessExecOptions} TeenProcessExecOptions
286
+ */
287
+
288
+ /**
289
+ * @typedef NpmInstallReceipt
290
+ * @property {string} installPath - Path to installed package
291
+ * @property {import('type-fest').PackageJson} pkg - Package data
292
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/support",
3
- "version": "2.61.1",
3
+ "version": "3.0.0",
4
4
  "description": "Support libs used across appium packages",
5
5
  "keywords": [
6
6
  "automation",
@@ -33,18 +33,13 @@
33
33
  "build"
34
34
  ],
35
35
  "scripts": {
36
- "build": "babel lib --root-mode=upward --out-dir=build/lib",
37
- "dev": "npm run build -- --watch",
38
- "fix": "npm run lint -- --fix",
39
- "lint": "eslint -c ../../.eslintrc --ignore-path ../../.eslintignore .",
40
- "prepare": "npm run build",
41
36
  "test": "npm run test:unit",
42
37
  "test:e2e": "mocha --timeout 20s --slow 10s \"./test/e2e/**/*.spec.js\"",
43
38
  "test:smoke": "node ./index.js",
44
39
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
45
40
  },
46
41
  "dependencies": {
47
- "@appium/types": "^0.5.0",
42
+ "@appium/types": "^0.6.0",
48
43
  "@colors/colors": "1.5.0",
49
44
  "@types/archiver": "5.3.1",
50
45
  "@types/base64-stream": "1.0.2",
@@ -59,13 +54,13 @@
59
54
  "@types/pluralize": "0.0.29",
60
55
  "@types/pngjs": "6.0.1",
61
56
  "@types/rimraf": "3.0.2",
62
- "@types/semver": "7.3.12",
57
+ "@types/semver": "7.3.13",
63
58
  "@types/shell-quote": "1.7.1",
64
59
  "@types/supports-color": "8.1.1",
65
- "@types/teen_process": "1.16.1",
66
- "@types/uuid": "8.3.4",
60
+ "@types/teen_process": "2.0.0",
61
+ "@types/uuid": "9.0.0",
67
62
  "archiver": "5.3.1",
68
- "axios": "0.27.2",
63
+ "axios": "1.2.1",
69
64
  "base64-stream": "1.0.0",
70
65
  "bluebird": "3.7.2",
71
66
  "bplist-creator": "0.1.1",
@@ -75,14 +70,14 @@
75
70
  "glob": "8.0.3",
76
71
  "jimp": "0.16.2",
77
72
  "jsftp": "2.1.3",
78
- "klaw": "3.0.0",
73
+ "klaw": "4.0.1",
79
74
  "lockfile": "1.0.4",
80
75
  "lodash": "4.17.21",
81
76
  "log-symbols": "4.1.0",
82
77
  "moment": "2.29.4",
83
78
  "mv": "2.1.1",
84
79
  "ncp": "2.0.0",
85
- "npmlog": "6.0.2",
80
+ "npmlog": "7.0.1",
86
81
  "opencv-bindings": "4.5.5",
87
82
  "pkg-dir": "5.0.0",
88
83
  "plist": "3.0.6",
@@ -97,17 +92,23 @@
97
92
  "source-map-support": "0.5.21",
98
93
  "supports-color": "8.1.1",
99
94
  "teen_process": "2.0.2",
100
- "type-fest": "3.1.0",
101
- "uuid": "8.3.2",
102
- "which": "2.0.2",
95
+ "type-fest": "3.3.0",
96
+ "uuid": "9.0.0",
97
+ "which": "3.0.0",
103
98
  "yauzl": "2.10.0"
104
99
  },
105
100
  "engines": {
106
- "node": ">=14",
101
+ "node": "^14.17.0 || ^16.13.0 || >=18.0.0",
107
102
  "npm": ">=8"
108
103
  },
109
104
  "publishConfig": {
110
105
  "access": "public"
111
106
  },
112
- "gitHead": "6b3cc1a8743f78c1f50320364f25f3011d2b2136"
107
+ "gitHead": "0823f0b60e40395cd1dc3b72cfa3c0092bc81302",
108
+ "typedoc": {
109
+ "entryPoint": "./build/lib/index.js"
110
+ },
111
+ "overrides": {
112
+ "jpeg-js": "0.4.4"
113
+ }
113
114
  }