@appium/support 2.59.5 → 2.61.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 (50) hide show
  1. package/build/lib/console.js +3 -3
  2. package/build/lib/console.js.map +1 -0
  3. package/build/lib/env.d.ts +8 -18
  4. package/build/lib/env.d.ts.map +1 -1
  5. package/build/lib/env.js +57 -36
  6. package/build/lib/env.js.map +1 -0
  7. package/build/lib/fs.d.ts +39 -10
  8. package/build/lib/fs.d.ts.map +1 -1
  9. package/build/lib/fs.js +20 -4
  10. package/build/lib/fs.js.map +1 -0
  11. package/build/lib/image-util.js +3 -3
  12. package/build/lib/image-util.js.map +1 -0
  13. package/build/lib/index.js.map +1 -0
  14. package/build/lib/log-internal.js +3 -3
  15. package/build/lib/log-internal.js.map +1 -0
  16. package/build/lib/logger.js.map +1 -0
  17. package/build/lib/logging.js +3 -3
  18. package/build/lib/logging.js.map +1 -0
  19. package/build/lib/mjpeg.js +3 -3
  20. package/build/lib/mjpeg.js.map +1 -0
  21. package/build/lib/mkdirp.js.map +1 -0
  22. package/build/lib/net.js +3 -3
  23. package/build/lib/net.js.map +1 -0
  24. package/build/lib/node.d.ts +10 -0
  25. package/build/lib/node.d.ts.map +1 -1
  26. package/build/lib/node.js +27 -3
  27. package/build/lib/node.js.map +1 -0
  28. package/build/lib/npm.d.ts +3 -1
  29. package/build/lib/npm.d.ts.map +1 -1
  30. package/build/lib/npm.js +39 -14
  31. package/build/lib/npm.js.map +1 -0
  32. package/build/lib/plist.js +3 -3
  33. package/build/lib/plist.js.map +1 -0
  34. package/build/lib/process.js.map +1 -0
  35. package/build/lib/system.js +3 -3
  36. package/build/lib/system.js.map +1 -0
  37. package/build/lib/tempdir.js +3 -3
  38. package/build/lib/tempdir.js.map +1 -0
  39. package/build/lib/timing.js +3 -3
  40. package/build/lib/timing.js.map +1 -0
  41. package/build/lib/util.js +3 -3
  42. package/build/lib/util.js.map +1 -0
  43. package/build/lib/zip.js +3 -3
  44. package/build/lib/zip.js.map +1 -0
  45. package/build/tsconfig.tsbuildinfo +1 -1
  46. package/lib/env.js +63 -74
  47. package/lib/fs.js +34 -7
  48. package/lib/node.js +28 -1
  49. package/lib/npm.js +38 -27
  50. package/package.json +9 -10
package/lib/fs.js CHANGED
@@ -25,6 +25,7 @@ import sanitize from 'sanitize-filename';
25
25
  import which from 'which';
26
26
  import log from './logger';
27
27
  import Timer from './timing';
28
+ import {isWindows} from './system';
28
29
  import {pluralize} from './util';
29
30
 
30
31
  const ncpAsync =
@@ -36,13 +37,38 @@ const findRootCached = _.memoize(pkgDir.sync);
36
37
  const fs = {
37
38
  /**
38
39
  * Resolves `true` if `path` is _readable_, which differs from Node.js' default behavior of "can we see it?"
39
- * @param {import('fs').PathLike} path
40
+ *
41
+ * On Windows, ACLs are not supported, so this becomes a simple check for existence.
42
+ *
43
+ * This function will never reject.
44
+ * @param {PathLike} path
40
45
  * @returns {Promise<boolean>}
41
46
  */
42
47
  async hasAccess(path) {
43
48
  try {
44
49
  await fsPromises.access(path, constants.R_OK);
45
- } catch (err) {
50
+ } catch {
51
+ return false;
52
+ }
53
+ return true;
54
+ },
55
+
56
+ /**
57
+ * Resolves `true` if `path` is executable; `false` otherwise.
58
+ *
59
+ * On Windows, this function delegates to {@linkcode fs.hasAccess}.
60
+ *
61
+ * This function will never reject.
62
+ * @param {PathLike} path
63
+ * @returns {Promise<boolean>}
64
+ */
65
+ async isExecutable(path) {
66
+ try {
67
+ if (isWindows()) {
68
+ return await fs.hasAccess(path);
69
+ }
70
+ await fsPromises.access(path, constants.R_OK | constants.X_OK);
71
+ } catch {
46
72
  return false;
47
73
  }
48
74
  return true;
@@ -50,7 +76,7 @@ const fs = {
50
76
 
51
77
  /**
52
78
  * Alias for {@linkcode fs.hasAccess}
53
- * @param {import('fs').PathLike} path
79
+ * @param {PathLike} path
54
80
  */
55
81
  async exists(path) {
56
82
  return await fs.hasAccess(path);
@@ -104,7 +130,7 @@ const fs = {
104
130
 
105
131
  /**
106
132
  * Create an MD5 hash of a file.
107
- * @param {import('fs').PathLike} filePath
133
+ * @param {PathLike} filePath
108
134
  * @returns {Promise<string>}
109
135
  */
110
136
  async md5(filePath) {
@@ -136,7 +162,7 @@ const fs = {
136
162
 
137
163
  /**
138
164
  * Create a hex digest of some file at `filePath`
139
- * @param {import('fs').PathLike} filePath
165
+ * @param {PathLike} filePath
140
166
  * @param {string} [algorithm]
141
167
  * @returns {Promise<string>}
142
168
  */
@@ -170,7 +196,7 @@ const fs = {
170
196
 
171
197
  /**
172
198
  * Recursively create a directory.
173
- * @param {import('fs').PathLike} dir
199
+ * @param {PathLike} dir
174
200
  * @returns {Promise<string|undefined>}
175
201
  */
176
202
  async mkdirp(dir) {
@@ -305,7 +331,7 @@ const fs = {
305
331
  /**
306
332
  * Warning: this is a promisified {@linkcode open fs.open}.
307
333
  * It resolves w/a file descriptor instead of a {@linkcode fsPromises.FileHandle FileHandle} object, as {@linkcode fsPromises.open} does. Use {@linkcode fs.openFile} if you want a `FileHandle`.
308
- * @type {(path: import('fs').PathLike, flags: import('fs').OpenMode, mode?: import('fs').Mode) => Promise<number>}
334
+ * @type {(path: PathLike, flags: import('fs').OpenMode, mode?: import('fs').Mode) => Promise<number>}
309
335
  */
310
336
  open: B.promisify(open),
311
337
  openFile: fsPromises.open,
@@ -362,4 +388,5 @@ export default fs;
362
388
  /**
363
389
  * @typedef {import('glob')} glob
364
390
  * @typedef {import('mv')} mv
391
+ * @typedef {import('fs').PathLike} PathLike
365
392
  */
package/lib/node.js CHANGED
@@ -3,6 +3,7 @@ import log from './logger';
3
3
  import _ from 'lodash';
4
4
  import {exec} from 'teen_process';
5
5
  import path from 'path';
6
+ import _fs from 'fs';
6
7
  import {v4 as uuidV4} from 'uuid';
7
8
 
8
9
  const ECMA_SIZES = Object.freeze({
@@ -200,4 +201,30 @@ function deepFreeze(object) {
200
201
  return Object.freeze(object);
201
202
  }
202
203
 
203
- export {requirePackage, getObjectSize, getObjectId, deepFreeze};
204
+ /**
205
+ * Tries to synchronously detect the absolute path to the folder
206
+ * where the given `moduleName` is located.
207
+ *
208
+ * @param {string} moduleName The name of the module as it is written in package.json
209
+ * @param {string} filePath Full path to any of files that `moduleName` contains. Use
210
+ * `__filename` to find the root of the module where this helper is called.
211
+ * @returns {string?} Full path to the module root
212
+ */
213
+ function getModuleRootSync (moduleName, filePath) {
214
+ let currentDir = path.dirname(path.resolve(filePath));
215
+ let isAtFsRoot = false;
216
+ while (!isAtFsRoot) {
217
+ const manifestPath = path.join(currentDir, 'package.json');
218
+ try {
219
+ if (_fs.existsSync(manifestPath) &&
220
+ JSON.parse(_fs.readFileSync(manifestPath, 'utf8')).name === moduleName) {
221
+ return currentDir;
222
+ }
223
+ } catch (ign) {}
224
+ currentDir = path.dirname(currentDir);
225
+ isAtFsRoot = currentDir.length <= path.dirname(currentDir).length;
226
+ }
227
+ return null;
228
+ }
229
+
230
+ export {requirePackage, getObjectSize, getObjectId, deepFreeze, getModuleRootSync};
package/lib/npm.js CHANGED
@@ -92,29 +92,47 @@ export class NPM {
92
92
  /**
93
93
  * @param {string} cwd
94
94
  * @param {string} pkg
95
+ * @returns {Promise<string?>}
95
96
  */
96
97
  async getLatestVersion(cwd, pkg) {
97
- return (
98
- await this.exec('view', [pkg, 'dist-tags'], {
99
- json: true,
100
- cwd,
101
- })
102
- ).json?.latest;
98
+ try {
99
+ return (
100
+ (
101
+ await this.exec('view', [pkg, 'dist-tags'], {
102
+ json: true,
103
+ cwd,
104
+ })
105
+ ).json?.latest ?? null
106
+ );
107
+ } catch (err) {
108
+ if (!err?.message.includes('E404')) {
109
+ throw err;
110
+ }
111
+ return null;
112
+ }
103
113
  }
104
114
 
105
115
  /**
106
116
  * @param {string} cwd
107
117
  * @param {string} pkg
108
118
  * @param {string} curVersion
119
+ * @returns {Promise<string?>}
109
120
  */
110
121
  async getLatestSafeUpgradeVersion(cwd, pkg, curVersion) {
111
- const allVersions = (
112
- await this.exec('view', [pkg, 'versions'], {
113
- json: true,
114
- cwd,
115
- })
116
- ).json;
117
- return this.getLatestSafeUpgradeFromVersions(curVersion, allVersions);
122
+ try {
123
+ const allVersions = (
124
+ await this.exec('view', [pkg, 'versions'], {
125
+ json: true,
126
+ cwd,
127
+ })
128
+ ).json;
129
+ return this.getLatestSafeUpgradeFromVersions(curVersion, allVersions);
130
+ } catch (err) {
131
+ if (!err?.message.includes('E404')) {
132
+ throw err;
133
+ }
134
+ return null;
135
+ }
118
136
  }
119
137
 
120
138
  /**
@@ -193,20 +211,13 @@ export class NPM {
193
211
  }
194
212
  }
195
213
 
196
- /**
197
- * If we've found a `package.json` containined the `appiumCreated` property,
198
- * then we can do whatever we please with it, since we created it. This is
199
- * likely when `APPIUM_HOME` is the default (in `~/.appium`). In that case,
200
- * we want `--global-style` to avoid deduping, and we also do not need a
201
- * `package-lock.json`.
202
- *
203
- * If we _haven't_ found such a key, then this `package.json` isn't a
204
- * "dummy" and is controlled by the user. So we'll just add it as a dev
205
- * dep; whatever else it does is up to the user's npm config.
206
- */
207
- const installOpts = (await hasAppiumDependency(cwd))
208
- ? ['--save-dev']
209
- : ['--save-dev', '--save-exact', '--global-style', '--no-package-lock'];
214
+ const installOpts = ['--save-dev'];
215
+ if (!(await hasAppiumDependency(cwd))) {
216
+ if (process.env.APPIUM_OMIT_PEER_DEPS) {
217
+ installOpts.push('--omit=peer');
218
+ }
219
+ installOpts.push('--save-exact', '--global-style', '--no-package-lock');
220
+ }
210
221
 
211
222
  const res = await this.exec(
212
223
  'install',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appium/support",
3
- "version": "2.59.5",
3
+ "version": "2.61.0",
4
4
  "description": "Support libs used across appium packages",
5
5
  "keywords": [
6
6
  "automation",
@@ -44,13 +44,12 @@
44
44
  "test:unit": "mocha \"./test/unit/**/*.spec.js\""
45
45
  },
46
46
  "dependencies": {
47
- "@appium/types": "^0.4.0",
48
- "@babel/runtime": "7.18.9",
47
+ "@appium/types": "^0.5.0",
49
48
  "@colors/colors": "1.5.0",
50
49
  "@types/archiver": "5.3.1",
51
50
  "@types/base64-stream": "1.0.2",
52
51
  "@types/find-root": "1.1.2",
53
- "@types/glob": "7.2.0",
52
+ "@types/glob": "8.0.0",
54
53
  "@types/jsftp": "2.1.2",
55
54
  "@types/klaw": "3.0.3",
56
55
  "@types/lockfile": "1.0.2",
@@ -60,7 +59,7 @@
60
59
  "@types/pluralize": "0.0.29",
61
60
  "@types/pngjs": "6.0.1",
62
61
  "@types/rimraf": "3.0.2",
63
- "@types/semver": "7.3.10",
62
+ "@types/semver": "7.3.12",
64
63
  "@types/shell-quote": "1.7.1",
65
64
  "@types/supports-color": "8.1.1",
66
65
  "@types/teen_process": "1.16.1",
@@ -74,7 +73,7 @@
74
73
  "form-data": "4.0.0",
75
74
  "get-stream": "6.0.1",
76
75
  "glob": "8.0.3",
77
- "jimp": "0.16.1",
76
+ "jimp": "0.16.2",
78
77
  "jsftp": "2.1.3",
79
78
  "klaw": "3.0.0",
80
79
  "lockfile": "1.0.4",
@@ -93,12 +92,12 @@
93
92
  "resolve-from": "5.0.0",
94
93
  "rimraf": "3.0.2",
95
94
  "sanitize-filename": "1.6.3",
96
- "semver": "7.3.7",
95
+ "semver": "7.3.8",
97
96
  "shell-quote": "1.7.3",
98
97
  "source-map-support": "0.5.21",
99
98
  "supports-color": "8.1.1",
100
- "teen_process": "1.16.0",
101
- "type-fest": "2.18.0",
99
+ "teen_process": "2.0.2",
100
+ "type-fest": "3.1.0",
102
101
  "uuid": "8.3.2",
103
102
  "which": "2.0.2",
104
103
  "yauzl": "2.10.0"
@@ -110,5 +109,5 @@
110
109
  "publishConfig": {
111
110
  "access": "public"
112
111
  },
113
- "gitHead": "c58f32441daba3aae9768a57d0a412fe92f4b587"
112
+ "gitHead": "f545a6cde58d83f3289072f8957468793947ba66"
114
113
  }