appium 3.2.2 → 3.3.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.
Files changed (250) hide show
  1. package/build/lib/appium.d.ts +147 -205
  2. package/build/lib/appium.d.ts.map +1 -1
  3. package/build/lib/appium.js +169 -282
  4. package/build/lib/appium.js.map +1 -1
  5. package/build/lib/bidi-commands.d.ts.map +1 -1
  6. package/build/lib/bidi-commands.js +11 -11
  7. package/build/lib/bidi-commands.js.map +1 -1
  8. package/build/lib/bootstrap/appium-initializer.d.ts +21 -0
  9. package/build/lib/bootstrap/appium-initializer.d.ts.map +1 -0
  10. package/build/lib/bootstrap/appium-initializer.js +146 -0
  11. package/build/lib/bootstrap/appium-initializer.js.map +1 -0
  12. package/build/lib/bootstrap/appium-main-runner.d.ts +22 -0
  13. package/build/lib/bootstrap/appium-main-runner.d.ts.map +1 -0
  14. package/build/lib/bootstrap/appium-main-runner.js +109 -0
  15. package/build/lib/bootstrap/appium-main-runner.js.map +1 -0
  16. package/build/lib/bootstrap/config-file.d.ts +37 -0
  17. package/build/lib/bootstrap/config-file.d.ts.map +1 -0
  18. package/build/lib/{config-file.js → bootstrap/config-file.js} +62 -138
  19. package/build/lib/bootstrap/config-file.js.map +1 -0
  20. package/build/lib/bootstrap/grid-v3-register.d.ts +20 -0
  21. package/build/lib/bootstrap/grid-v3-register.d.ts.map +1 -0
  22. package/build/lib/bootstrap/grid-v3-register.js +185 -0
  23. package/build/lib/bootstrap/grid-v3-register.js.map +1 -0
  24. package/build/lib/bootstrap/init-types.d.ts +16 -0
  25. package/build/lib/bootstrap/init-types.d.ts.map +1 -0
  26. package/build/lib/bootstrap/init-types.js +3 -0
  27. package/build/lib/bootstrap/init-types.js.map +1 -0
  28. package/build/lib/bootstrap/main-helpers.d.ts +55 -0
  29. package/build/lib/bootstrap/main-helpers.d.ts.map +1 -0
  30. package/build/lib/bootstrap/main-helpers.js +187 -0
  31. package/build/lib/bootstrap/main-helpers.js.map +1 -0
  32. package/build/lib/bootstrap/node-helpers.d.ts +32 -0
  33. package/build/lib/bootstrap/node-helpers.d.ts.map +1 -0
  34. package/build/lib/bootstrap/node-helpers.js +201 -0
  35. package/build/lib/bootstrap/node-helpers.js.map +1 -0
  36. package/build/lib/bootstrap/startup-config.d.ts +22 -0
  37. package/build/lib/bootstrap/startup-config.d.ts.map +1 -0
  38. package/build/lib/bootstrap/startup-config.js +111 -0
  39. package/build/lib/bootstrap/startup-config.js.map +1 -0
  40. package/build/lib/cli/args.d.ts +16 -12
  41. package/build/lib/cli/args.d.ts.map +1 -1
  42. package/build/lib/cli/args.js +20 -40
  43. package/build/lib/cli/args.js.map +1 -1
  44. package/build/lib/cli/driver-command.d.ts +51 -93
  45. package/build/lib/cli/driver-command.d.ts.map +1 -1
  46. package/build/lib/cli/driver-command.js +11 -66
  47. package/build/lib/cli/driver-command.js.map +1 -1
  48. package/build/lib/cli/extension-command.d.ts +173 -377
  49. package/build/lib/cli/extension-command.d.ts.map +1 -1
  50. package/build/lib/cli/extension-command.js +387 -656
  51. package/build/lib/cli/extension-command.js.map +1 -1
  52. package/build/lib/cli/extension.d.ts +10 -15
  53. package/build/lib/cli/extension.d.ts.map +1 -1
  54. package/build/lib/cli/extension.js +15 -33
  55. package/build/lib/cli/extension.js.map +1 -1
  56. package/build/lib/cli/parser.d.ts +37 -66
  57. package/build/lib/cli/parser.d.ts.map +1 -1
  58. package/build/lib/cli/parser.js +69 -104
  59. package/build/lib/cli/parser.js.map +1 -1
  60. package/build/lib/cli/plugin-command.d.ts +50 -90
  61. package/build/lib/cli/plugin-command.d.ts.map +1 -1
  62. package/build/lib/cli/plugin-command.js +11 -63
  63. package/build/lib/cli/plugin-command.js.map +1 -1
  64. package/build/lib/cli/setup-command.d.ts +21 -26
  65. package/build/lib/cli/setup-command.d.ts.map +1 -1
  66. package/build/lib/cli/setup-command.js +19 -61
  67. package/build/lib/cli/setup-command.js.map +1 -1
  68. package/build/lib/cli/utils.d.ts +33 -35
  69. package/build/lib/cli/utils.d.ts.map +1 -1
  70. package/build/lib/cli/utils.js +48 -50
  71. package/build/lib/cli/utils.js.map +1 -1
  72. package/build/lib/constants.d.ts +23 -23
  73. package/build/lib/constants.d.ts.map +1 -1
  74. package/build/lib/constants.js +10 -15
  75. package/build/lib/constants.js.map +1 -1
  76. package/build/lib/doctor/doctor.d.ts +40 -57
  77. package/build/lib/doctor/doctor.d.ts.map +1 -1
  78. package/build/lib/doctor/doctor.js +31 -62
  79. package/build/lib/doctor/doctor.js.map +1 -1
  80. package/build/lib/extension/driver-config.d.ts +18 -77
  81. package/build/lib/extension/driver-config.d.ts.map +1 -1
  82. package/build/lib/extension/driver-config.js +37 -125
  83. package/build/lib/extension/driver-config.js.map +1 -1
  84. package/build/lib/extension/extension-config.d.ts +103 -210
  85. package/build/lib/extension/extension-config.d.ts.map +1 -1
  86. package/build/lib/extension/extension-config.js +180 -342
  87. package/build/lib/extension/extension-config.js.map +1 -1
  88. package/build/lib/extension/index.d.ts +12 -29
  89. package/build/lib/extension/index.d.ts.map +1 -1
  90. package/build/lib/extension/index.js +33 -75
  91. package/build/lib/extension/index.js.map +1 -1
  92. package/build/lib/extension/manifest-migrations.d.ts +3 -20
  93. package/build/lib/extension/manifest-migrations.d.ts.map +1 -1
  94. package/build/lib/extension/manifest-migrations.js +20 -101
  95. package/build/lib/extension/manifest-migrations.js.map +1 -1
  96. package/build/lib/extension/manifest.d.ts +61 -107
  97. package/build/lib/extension/manifest.d.ts.map +1 -1
  98. package/build/lib/extension/manifest.js +181 -356
  99. package/build/lib/extension/manifest.js.map +1 -1
  100. package/build/lib/extension/package-changed.d.ts +1 -3
  101. package/build/lib/extension/package-changed.d.ts.map +1 -1
  102. package/build/lib/extension/package-changed.js +8 -15
  103. package/build/lib/extension/package-changed.js.map +1 -1
  104. package/build/lib/extension/plugin-config.d.ts +10 -52
  105. package/build/lib/extension/plugin-config.d.ts.map +1 -1
  106. package/build/lib/extension/plugin-config.js +11 -63
  107. package/build/lib/extension/plugin-config.js.map +1 -1
  108. package/build/lib/helpers/build.d.ts +22 -0
  109. package/build/lib/helpers/build.d.ts.map +1 -0
  110. package/build/lib/helpers/build.js +109 -0
  111. package/build/lib/helpers/build.js.map +1 -0
  112. package/build/lib/helpers/capability.d.ts +38 -0
  113. package/build/lib/helpers/capability.d.ts.map +1 -0
  114. package/build/lib/helpers/capability.js +128 -0
  115. package/build/lib/helpers/capability.js.map +1 -0
  116. package/build/lib/helpers/network.d.ts +14 -0
  117. package/build/lib/helpers/network.d.ts.map +1 -0
  118. package/build/lib/helpers/network.js +35 -0
  119. package/build/lib/helpers/network.js.map +1 -0
  120. package/build/lib/insecure-features.js +6 -6
  121. package/build/lib/insecure-features.js.map +1 -1
  122. package/build/lib/inspector-commands.d.ts +6 -0
  123. package/build/lib/inspector-commands.d.ts.map +1 -1
  124. package/build/lib/inspector-commands.js +6 -0
  125. package/build/lib/inspector-commands.js.map +1 -1
  126. package/build/lib/logger.d.ts +2 -3
  127. package/build/lib/logger.d.ts.map +1 -1
  128. package/build/lib/logger.js +2 -3
  129. package/build/lib/logger.js.map +1 -1
  130. package/build/lib/logsink.d.ts +13 -22
  131. package/build/lib/logsink.d.ts.map +1 -1
  132. package/build/lib/logsink.js +48 -103
  133. package/build/lib/logsink.js.map +1 -1
  134. package/build/lib/main.d.ts +15 -58
  135. package/build/lib/main.d.ts.map +1 -1
  136. package/build/lib/main.js +25 -425
  137. package/build/lib/main.js.map +1 -1
  138. package/build/lib/schema/arg-spec.d.ts +32 -107
  139. package/build/lib/schema/arg-spec.d.ts.map +1 -1
  140. package/build/lib/schema/arg-spec.js +11 -107
  141. package/build/lib/schema/arg-spec.js.map +1 -1
  142. package/build/lib/schema/cli-args-guards.d.ts +34 -0
  143. package/build/lib/schema/cli-args-guards.d.ts.map +1 -0
  144. package/build/lib/schema/cli-args-guards.js +49 -0
  145. package/build/lib/schema/cli-args-guards.js.map +1 -0
  146. package/build/lib/schema/cli-args.d.ts +3 -15
  147. package/build/lib/schema/cli-args.d.ts.map +1 -1
  148. package/build/lib/schema/cli-args.js +17 -107
  149. package/build/lib/schema/cli-args.js.map +1 -1
  150. package/build/lib/schema/cli-transformers.d.ts +15 -12
  151. package/build/lib/schema/cli-transformers.d.ts.map +1 -1
  152. package/build/lib/schema/cli-transformers.js +15 -45
  153. package/build/lib/schema/cli-transformers.js.map +1 -1
  154. package/build/lib/schema/format-errors.d.ts +28 -0
  155. package/build/lib/schema/format-errors.d.ts.map +1 -0
  156. package/build/lib/schema/format-errors.js +29 -0
  157. package/build/lib/schema/format-errors.js.map +1 -0
  158. package/build/lib/schema/index.d.ts +4 -2
  159. package/build/lib/schema/index.d.ts.map +1 -1
  160. package/build/lib/schema/index.js +2 -0
  161. package/build/lib/schema/index.js.map +1 -1
  162. package/build/lib/schema/keywords.d.ts +12 -20
  163. package/build/lib/schema/keywords.d.ts.map +1 -1
  164. package/build/lib/schema/keywords.js +6 -51
  165. package/build/lib/schema/keywords.js.map +1 -1
  166. package/build/lib/schema/schema.d.ts +106 -231
  167. package/build/lib/schema/schema.d.ts.map +1 -1
  168. package/build/lib/schema/schema.js +88 -358
  169. package/build/lib/schema/schema.js.map +1 -1
  170. package/build/lib/utils.d.ts +7 -267
  171. package/build/lib/utils.d.ts.map +1 -1
  172. package/build/lib/utils.js +10 -409
  173. package/build/lib/utils.js.map +1 -1
  174. package/lib/{appium.js → appium.ts} +297 -341
  175. package/lib/bidi-commands.ts +10 -14
  176. package/lib/bootstrap/appium-initializer.ts +212 -0
  177. package/lib/bootstrap/appium-main-runner.ts +172 -0
  178. package/lib/bootstrap/config-file.ts +178 -0
  179. package/lib/bootstrap/grid-v3-register.ts +250 -0
  180. package/lib/bootstrap/init-types.ts +31 -0
  181. package/lib/bootstrap/main-helpers.ts +223 -0
  182. package/lib/bootstrap/node-helpers.ts +180 -0
  183. package/lib/bootstrap/startup-config.ts +143 -0
  184. package/lib/cli/{args.js → args.ts} +45 -56
  185. package/lib/cli/driver-command.ts +122 -0
  186. package/lib/cli/{extension-command.js → extension-command.ts} +827 -906
  187. package/lib/cli/extension.ts +65 -0
  188. package/lib/cli/{parser.js → parser.ts} +93 -116
  189. package/lib/cli/plugin-command.ts +117 -0
  190. package/lib/cli/{setup-command.js → setup-command.ts} +59 -74
  191. package/lib/cli/utils.ts +97 -0
  192. package/lib/{constants.js → constants.ts} +30 -41
  193. package/lib/doctor/{doctor.js → doctor.ts} +82 -92
  194. package/lib/extension/driver-config.ts +165 -0
  195. package/lib/extension/{extension-config.js → extension-config.ts} +291 -405
  196. package/lib/extension/index.ts +143 -0
  197. package/lib/extension/manifest-migrations.ts +57 -0
  198. package/lib/extension/manifest.ts +369 -0
  199. package/lib/extension/{package-changed.js → package-changed.ts} +9 -18
  200. package/lib/extension/plugin-config.ts +62 -0
  201. package/lib/helpers/build.ts +111 -0
  202. package/lib/helpers/capability.ts +171 -0
  203. package/lib/helpers/network.ts +30 -0
  204. package/lib/insecure-features.ts +1 -1
  205. package/lib/inspector-commands.ts +6 -1
  206. package/lib/{logger.js → logger.ts} +1 -2
  207. package/lib/{logsink.js → logsink.ts} +91 -137
  208. package/lib/main.ts +60 -0
  209. package/lib/schema/arg-spec.ts +131 -0
  210. package/lib/schema/cli-args-guards.ts +67 -0
  211. package/lib/schema/cli-args.ts +171 -0
  212. package/lib/schema/cli-transformers.ts +83 -0
  213. package/lib/schema/format-errors.ts +43 -0
  214. package/lib/schema/index.ts +4 -0
  215. package/lib/schema/keywords.ts +96 -0
  216. package/lib/schema/schema.ts +448 -0
  217. package/lib/utils.ts +73 -0
  218. package/package.json +17 -18
  219. package/scripts/autoinstall-extensions.js +3 -0
  220. package/build/lib/config-file.d.ts +0 -100
  221. package/build/lib/config-file.d.ts.map +0 -1
  222. package/build/lib/config-file.js.map +0 -1
  223. package/build/lib/config.d.ts +0 -70
  224. package/build/lib/config.d.ts.map +0 -1
  225. package/build/lib/config.js +0 -390
  226. package/build/lib/config.js.map +0 -1
  227. package/build/lib/grid-register.d.ts +0 -10
  228. package/build/lib/grid-register.d.ts.map +0 -1
  229. package/build/lib/grid-register.js +0 -134
  230. package/build/lib/grid-register.js.map +0 -1
  231. package/lib/cli/driver-command.js +0 -174
  232. package/lib/cli/extension.js +0 -74
  233. package/lib/cli/plugin-command.js +0 -164
  234. package/lib/cli/utils.js +0 -91
  235. package/lib/config-file.js +0 -228
  236. package/lib/config.js +0 -389
  237. package/lib/extension/driver-config.js +0 -245
  238. package/lib/extension/index.js +0 -169
  239. package/lib/extension/manifest-migrations.js +0 -136
  240. package/lib/extension/manifest.js +0 -550
  241. package/lib/extension/plugin-config.js +0 -112
  242. package/lib/grid-register.js +0 -146
  243. package/lib/main.js +0 -545
  244. package/lib/schema/arg-spec.js +0 -229
  245. package/lib/schema/cli-args.js +0 -254
  246. package/lib/schema/cli-transformers.js +0 -113
  247. package/lib/schema/index.js +0 -2
  248. package/lib/schema/keywords.js +0 -136
  249. package/lib/schema/schema.js +0 -725
  250. package/lib/utils.js +0 -512
package/lib/utils.js DELETED
@@ -1,512 +0,0 @@
1
- import _ from 'lodash';
2
- import logger from './logger';
3
- import {
4
- processCapabilities,
5
- STANDARD_CAPS,
6
- errors,
7
- isW3cCaps,
8
- } from '@appium/base-driver';
9
- import {inspect as dump} from 'node:util';
10
- import {node, fs} from '@appium/support';
11
- import path from 'node:path';
12
- import {SERVER_SUBCOMMAND, DRIVER_TYPE, PLUGIN_TYPE, SETUP_SUBCOMMAND} from './constants';
13
- import os from 'node:os';
14
-
15
- const W3C_APPIUM_PREFIX = 'appium';
16
- const STANDARD_CAPS_LOWERCASE = new Set([...STANDARD_CAPS].map((cap) => cap.toLowerCase()));
17
- export const V4_BROADCAST_IP = '0.0.0.0';
18
- export const V6_BROADCAST_IP = '::';
19
- export const npmPackage = fs.readPackageJsonFrom(__dirname);
20
-
21
- /**
22
- *
23
- * If `stdout` is a TTY, this is `true`.
24
- *
25
- * Used for tighter control over log output.
26
- * @type {boolean}
27
- */
28
- const isStdoutTTY = process.stdout.isTTY;
29
-
30
- /**
31
- * Creates an error object in case a session gets incompatible capabilities as the input.
32
- *
33
- * @returns {Error}
34
- */
35
- export function makeNonW3cCapsError() {
36
- return new errors.SessionNotCreatedError(
37
- 'Session capabilities format must comply to the W3C standard. Make sure your client is up to date. ' +
38
- 'See https://www.w3.org/TR/webdriver/#new-session for more details.'
39
- );
40
- }
41
-
42
- /**
43
- * Dumps to value to the console using `info` logger.
44
- *
45
- * @todo May want to force color to be `false` if {@link isStdoutTTY} is `false`.
46
- */
47
- export const inspect = _.flow(
48
- _.partialRight(
49
- /** @type {(object: any, options: import('util').InspectOptions) => string} */ (dump),
50
- {colors: true, depth: null, compact: !isStdoutTTY}
51
- ),
52
- (...args) => {
53
- logger.info(...args);
54
- }
55
- );
56
-
57
- /**
58
- * Takes the caps that were provided in the request and translates them
59
- * into caps that can be used by the inner drivers.
60
- *
61
- * @template {Constraints} C
62
- * @param {W3CCapabilities<C>} w3cCapabilities
63
- * @param {C} constraints
64
- * @param {NSCapabilities<C>} [defaultCapabilities]
65
- * @returns {ParsedDriverCaps<C>|InvalidCaps<C>}
66
- */
67
- export function parseCapsForInnerDriver(
68
- w3cCapabilities,
69
- constraints = /** @type {C} */ ({}),
70
- defaultCapabilities = {}
71
- ) {
72
- if (!isW3cCaps(w3cCapabilities)) {
73
- return /** @type {InvalidCaps<C>} */ ({
74
- error: makeNonW3cCapsError(),
75
- });
76
- }
77
-
78
- let desiredCaps = /** @type {ParsedDriverCaps<C>['desiredCaps']} */ ({});
79
- /** @type {ParsedDriverCaps<C>['processedW3CCapabilities'] | undefined} */
80
- let processedW3CCapabilities;
81
-
82
- // Make sure we don't mutate the original arguments
83
- w3cCapabilities = _.cloneDeep(w3cCapabilities);
84
- defaultCapabilities = _.cloneDeep(defaultCapabilities);
85
-
86
- if (!_.isEmpty(defaultCapabilities)) {
87
- for (const [defaultCapKey, defaultCapValue] of _.toPairs(defaultCapabilities)) {
88
- let isCapAlreadySet = false;
89
- // Check if the key is already present in firstMatch entries
90
- for (const firstMatchEntry of w3cCapabilities.firstMatch ?? []) {
91
- if (
92
- _.isPlainObject(firstMatchEntry) &&
93
- _.has(removeAppiumPrefixes(firstMatchEntry), removeAppiumPrefix(defaultCapKey))
94
- ) {
95
- isCapAlreadySet = true;
96
- break;
97
- }
98
- }
99
- // Check if the key is already present in alwaysMatch entries
100
- isCapAlreadySet =
101
- isCapAlreadySet ||
102
- (_.isPlainObject(w3cCapabilities.alwaysMatch) &&
103
- _.has(
104
- removeAppiumPrefixes(w3cCapabilities.alwaysMatch),
105
- removeAppiumPrefix(defaultCapKey)
106
- ));
107
- if (isCapAlreadySet) {
108
- // Skip if the key is already present in the provided caps
109
- continue;
110
- }
111
-
112
- // Only add the default capability if it is not overridden
113
- if (_.isEmpty(w3cCapabilities.firstMatch)) {
114
- w3cCapabilities.firstMatch = /** @type {W3CCapabilities<C>['firstMatch']} */ ([
115
- {[defaultCapKey]: defaultCapValue},
116
- ]);
117
- } else {
118
- w3cCapabilities.firstMatch[0][defaultCapKey] = defaultCapValue;
119
- }
120
- }
121
- }
122
-
123
- // Call the process capabilities algorithm to find matching caps on the W3C
124
- // (see: https://github.com/jlipps/simple-wd-spec#processing-capabilities)
125
- try {
126
- desiredCaps = processCapabilities(w3cCapabilities, constraints, true);
127
- } catch (error) {
128
- logger.info(`Could not parse W3C capabilities: ${error.message}`);
129
- return /** @type {InvalidCaps<C>} */ ({
130
- desiredCaps,
131
- processedW3CCapabilities,
132
- error,
133
- });
134
- }
135
-
136
- // Create a new w3c capabilities payload that contains only the matching caps in `alwaysMatch`
137
- processedW3CCapabilities = {
138
- alwaysMatch: {...insertAppiumPrefixes(desiredCaps)},
139
- firstMatch: [{}],
140
- };
141
-
142
- return /** @type {ParsedDriverCaps<C>} */ ({
143
- desiredCaps,
144
- processedW3CCapabilities,
145
- });
146
- }
147
-
148
- /**
149
- * Takes a capabilities objects and prefixes capabilities with `appium:`
150
- * @template {Constraints} [C={}]
151
- * @param {Capabilities<C>} caps - Desired capabilities object
152
- * @returns {NSCapabilities<C>}
153
- */
154
- export function insertAppiumPrefixes(caps) {
155
- return /** @type {NSCapabilities<C>} */ (
156
- _.mapKeys(caps, (_, key) =>
157
- STANDARD_CAPS_LOWERCASE.has(key.toLowerCase()) || key.includes(':')
158
- ? key
159
- : `${W3C_APPIUM_PREFIX}:${key}`
160
- )
161
- );
162
- }
163
-
164
- /**
165
- * @template {Constraints} [C={}]
166
- * @param {NSCapabilities<C>} caps
167
- * @returns {Capabilities<C>}
168
- */
169
- export function removeAppiumPrefixes(caps) {
170
- return /** @type {Capabilities<C>} */ (_.mapKeys(caps, (_, key) => removeAppiumPrefix(key)));
171
- }
172
-
173
- /**
174
- * @param {string} key
175
- * @returns {string}
176
- */
177
- function removeAppiumPrefix(key) {
178
- const prefix = `${W3C_APPIUM_PREFIX}:`;
179
- return _.startsWith(key, prefix) ? key.substring(prefix.length) : key;
180
- }
181
-
182
- /**
183
- *
184
- * @param {string} pkgName
185
- * @returns {string|undefined}
186
- */
187
- export function getPackageVersion(pkgName) {
188
- const pkgInfo = require(`${pkgName}/package.json`) || {};
189
- return pkgInfo.version;
190
- }
191
-
192
- /**
193
- * Returns the root directory of the Appium module.
194
- *
195
- * @returns {string} - The absolute path to the Appium module root directory.
196
- * @throws {Error} - If the Appium module root cannot be determined.
197
- */
198
- export const getAppiumModuleRoot = _.memoize(function getAppiumModuleRoot() {
199
- const selfRoot = node.getModuleRootSync('appium', __filename);
200
- if (!selfRoot) {
201
- throw new Error('Cannot find the appium module root. This is likely a bug in Appium.');
202
- }
203
- return selfRoot;
204
- });
205
-
206
- /**
207
- * Adjusts NODE_PATH environment variable,
208
- * so CJS drivers and plugins could load their peer dependencies.
209
- * Read https://nodejs.org/api/modules.html#loading-from-the-global-folders
210
- * for more details.
211
- *
212
- * Unfortunately this hack does not work with ESM modules,
213
- * @returns {void}
214
- */
215
- export function adjustNodePath() {
216
- let appiumModuleSearchRoot;
217
- try {
218
- appiumModuleSearchRoot = path.dirname(getAppiumModuleRoot());
219
- } catch (error) {
220
- logger.warn(error.message);
221
- return;
222
- }
223
-
224
- const refreshRequirePaths = () => {
225
- try {
226
- // ! This hack allows us to avoid modification of import
227
- // ! statements in client modules. It uses a private API though,
228
- // ! so it could break (maybe, eventually).
229
- // See https://gist.github.com/branneman/8048520#7-the-hack
230
- // @ts-ignore see above comment
231
-
232
- require('node:module').Module._initPaths();
233
- return true;
234
- } catch {
235
- return false;
236
- }
237
- };
238
-
239
- if (!process.env.NODE_PATH) {
240
- process.env.NODE_PATH = appiumModuleSearchRoot;
241
- if (refreshRequirePaths()) {
242
- process.env.APPIUM_OMIT_PEER_DEPS = '1';
243
- } else {
244
- delete process.env.NODE_PATH;
245
- }
246
- return;
247
- }
248
-
249
- const nodePathParts = process.env.NODE_PATH.split(path.delimiter);
250
- if (nodePathParts.includes(appiumModuleSearchRoot)) {
251
- process.env.APPIUM_OMIT_PEER_DEPS = '1';
252
- return;
253
- }
254
-
255
- nodePathParts.push(appiumModuleSearchRoot);
256
- process.env.NODE_PATH = nodePathParts.join(path.delimiter);
257
- if (refreshRequirePaths()) {
258
- process.env.APPIUM_OMIT_PEER_DEPS = '1';
259
- } else {
260
- process.env.NODE_PATH = _.without(nodePathParts, appiumModuleSearchRoot).join(path.delimiter);
261
- }
262
- }
263
-
264
- /**
265
- * Pulls the initial values of Appium settings from the given capabilities argument.
266
- * Each setting item must satisfy the following format:
267
- * `settings[setting_name]: setting_value`
268
- * or
269
- * ```
270
- * settings = {
271
- * setting_name1: 'setting_value1',
272
- * setting_name2: 'setting_value2',
273
- * }
274
- * ```
275
- * The capabilities argument itself gets mutated, so it does not contain parsed
276
- * settings anymore to avoid further parsing issues.
277
- * Check
278
- * https://appium.io/docs/en/latest/guides/settings/
279
- * for more details on the available settings.
280
- *
281
- * @param {?Object} caps - Capabilities dictionary. It is mutated if
282
- * one or more settings have been pulled from it
283
- * @return {Object} - An empty dictionary if the given caps contains no
284
- * setting items or a dictionary containing parsed Appium setting names along with
285
- * their values.
286
- */
287
- export function pullSettings(caps) {
288
- if (!_.isPlainObject(caps) || _.isEmpty(caps)) {
289
- return {};
290
- }
291
-
292
- const result = {};
293
- const singleSettings = {};
294
- for (const [key, value] of _.toPairs(caps)) {
295
- let match;
296
- if (/^(s|appium:s)ettings$/.test(key) && _.isPlainObject(value)) {
297
- Object.assign(result, value);
298
- delete caps[key];
299
- } else if ((match = /^(s|appium:s)ettings\[(\S+)\]$/.exec(key))) {
300
- singleSettings[match[2]] = value;
301
- delete caps[key];
302
- }
303
- }
304
- if (!_.isEmpty(singleSettings)) {
305
- Object.assign(result, singleSettings);
306
- }
307
- return result;
308
- }
309
-
310
- /**
311
- * @template {CliCommand} [Cmd=ServerCommand]
312
- * @template {CliExtensionSubcommand|void} [SubCmd=void]
313
- * @param {Args<Cmd, SubCmd>} args
314
- * @returns {args is Args<ServerCommand>}
315
- */
316
- export function isServerCommandArgs(args) {
317
- return args.subcommand === SERVER_SUBCOMMAND;
318
- }
319
-
320
- /**
321
- * @template {CliCommand} Cmd
322
- * @template {CliExtensionSubcommand|CliCommandSetupSubcommand|void} [SubCmd=void]
323
- * @param {Args<Cmd, SubCmd>} args
324
- * @returns {args is Args<SetupCommand>}
325
- */
326
- export function isSetupCommandArgs(args) {
327
- return args.subcommand === SETUP_SUBCOMMAND;
328
- }
329
-
330
- /**
331
- * @template {CliCommand} [Cmd=ServerCommand]
332
- * @template {CliExtensionSubcommand|void} [SubCmd=void]
333
- * @param {Args<Cmd, SubCmd>} args
334
- * @returns {args is Args<CliExtensionCommand, SubCmd>}
335
- */
336
- export function isExtensionCommandArgs(args) {
337
- return args.subcommand === DRIVER_TYPE || args.subcommand === PLUGIN_TYPE;
338
- }
339
-
340
- /**
341
- * @template {CliCommand} Cmd
342
- * @template {CliExtensionSubcommand} SubCmd
343
- * @param {Args<Cmd, SubCmd>} args
344
- * @returns {args is Args<DriverCommand, SubCmd>}
345
- */
346
- export function isDriverCommandArgs(args) {
347
- return args.subcommand === DRIVER_TYPE;
348
- }
349
-
350
- /**
351
- * @template {CliCommand} Cmd
352
- * @template {CliExtensionSubcommand} SubCmd
353
- * @param {Args<Cmd, SubCmd>} args
354
- * @returns {args is Args<PluginCommand, SubCmd>}
355
- */
356
- export function isPluginCommandArgs(args) {
357
- return args.subcommand === PLUGIN_TYPE;
358
- }
359
-
360
- /**
361
- * Fetches the list of matched network interfaces of the current host.
362
- *
363
- * @param {4|6|null} family Either 4 to include ipv4 addresses only,
364
- * 6 to include ipv6 addresses only, or null to include all of them
365
- * @returns {os.NetworkInterfaceInfo[]} The list of matched interfaces
366
- */
367
- export function fetchInterfaces (family = null) {
368
- let familyValue = null;
369
- // 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
370
- if (family === 4) {
371
- familyValue = [4, 'IPv4'];
372
- } else if (family === 6) {
373
- familyValue = [6, 'IPv6'];
374
- }
375
- // @ts-ignore The linter does not understand the below filter
376
- return _.flatMap(_.values(os.networkInterfaces()).filter(Boolean))
377
- // @ts-ignore The linter does not understand the above filter
378
- .filter(({family}) => !familyValue || familyValue && familyValue.includes(family));
379
- }
380
-
381
- /**
382
- * https://github.com/SheetJS/js-adler32
383
- *
384
- * @param {string} str
385
- * @param {number?} [seed]
386
- * @returns {number}
387
- */
388
- export function adler32(str, seed = null) {
389
- let a = 1, b = 0, L = str.length, M = 0, c = 0, d = 0;
390
- if (typeof seed === 'number') {
391
- a = seed & 0xFFFF;
392
- b = seed >>> 16;
393
- }
394
- for (let i = 0; i < L;) {
395
- M = Math.min(L - i, 2918);
396
- while (M > 0) {
397
- c = str.charCodeAt(i++);
398
- if (c < 0x80) {
399
- a += c;
400
- } else if (c < 0x800) {
401
- a += 192 | ((c >> 6) & 31);
402
- b += a;
403
- --M;
404
- a += 128 | (c & 63);
405
- } else if (c >= 0xD800 && c < 0xE000) {
406
- c = (c & 1023) + 64;
407
- d = str.charCodeAt(i++) & 1023;
408
- a += 240 | ((c >> 8) & 7);
409
- b += a;
410
- --M;
411
- a += 128 | ((c >> 2) & 63);
412
- b += a;
413
- --M;
414
- a += 128 | ((d >> 6) & 15) | ((c & 3) << 4);
415
- b += a;
416
- --M;
417
- a += 128 | (d & 63);
418
- } else {
419
- a += 224 | ((c >> 12) & 15);
420
- b += a;
421
- --M;
422
- a += 128 | ((c >> 6) & 63);
423
- b += a;
424
- --M;
425
- a += 128 | (c & 63);
426
- }
427
- b += a;
428
- --M;
429
- }
430
- a = (15 * (a >>> 16) + (a & 65535));
431
- b = (15 * (b >>> 16) + (b & 65535));
432
- }
433
- return ((b % 65521) << 16) | (a % 65521);
434
- }
435
-
436
- /**
437
- * Checks if the provided address is a broadcast one.
438
- *
439
- * @param {string} address
440
- * @returns {boolean}
441
- */
442
- export function isBroadcastIp(address) {
443
- return [V4_BROADCAST_IP, V6_BROADCAST_IP, `[${V6_BROADCAST_IP}]`].includes(address);
444
- }
445
-
446
- /**
447
- * @typedef {import('@appium/types').StringRecord} StringRecord
448
- * @typedef {import('@appium/types').BaseDriverCapConstraints} BaseDriverCapConstraints
449
- */
450
-
451
- /**
452
- * @template {Constraints} [C=BaseDriverCapConstraints]
453
- * @typedef ParsedDriverCaps
454
- * @property {Capabilities<C>} desiredCaps
455
- * @property {W3CCapabilities<C>} processedW3CCapabilities
456
- */
457
-
458
- /**
459
- * @todo protocol is more specific
460
- * @template {Constraints} [C=BaseDriverCapConstraints]
461
- * @typedef InvalidCaps
462
- * @property {Error} error
463
- * @property {Capabilities<C>} [desiredCaps]
464
- * @property {W3CCapabilities<C>} [processedW3CCapabilities]
465
- */
466
-
467
- /**
468
- * @template {Constraints} C
469
- * @typedef {import('@appium/types').Capabilities<C>} Capabilities
470
- */
471
-
472
- /**
473
- * @template {Constraints} C
474
- * @typedef {import('@appium/types').W3CCapabilities<C>} W3CCapabilities
475
- */
476
-
477
- /**
478
- * @template {Constraints} C
479
- * @typedef {import('@appium/types').NSCapabilities<C>} NSCapabilities
480
- */
481
-
482
- /**
483
- * @template {Constraints} C
484
- * @typedef {import('@appium/types').ConstraintsToCaps<C>} ConstraintsToCaps
485
- */
486
-
487
- /**
488
- * @typedef {import('@appium/types').Constraints} Constraints
489
- */
490
-
491
- /**
492
- * @typedef {import('appium/types').CliCommand} CliCommand
493
- * @typedef {import('appium/types').CliExtensionSubcommand} CliExtensionSubcommand
494
- * @typedef {import('appium/types').CliExtensionCommand} CliExtensionCommand
495
- * @typedef {import('appium/types').CliCommandSetupSubcommand} CliCommandSetupSubcommand
496
- * @typedef {import('appium/types').CliCommandServer} ServerCommand
497
- * @typedef {import('appium/types').CliCommandDriver} DriverCommand
498
- * @typedef {import('appium/types').CliCommandPlugin} PluginCommand
499
- * @typedef {import('appium/types').CliCommandSetup} SetupCommand
500
- */
501
-
502
- /**
503
- * @template {CliCommand} [Cmd=ServerCommand]
504
- * @template {CliExtensionSubcommand|CliCommandSetupSubcommand|void} [SubCmd=void]
505
- * @typedef {import('appium/types').Args<Cmd, SubCmd>} Args
506
- */
507
-
508
- /**
509
- * @template {CliCommand} [Cmd=ServerCommand]
510
- * @template {CliExtensionSubcommand|CliCommandSetupSubcommand|void} [SubCmd=void]
511
- * @typedef {import('appium/types').ParsedArgs<Cmd, SubCmd>} ParsedArgs
512
- */