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
@@ -1,245 +0,0 @@
1
- import _ from 'lodash';
2
- import {DRIVER_TYPE} from '../constants';
3
- import log from '../logger';
4
- import {ExtensionConfig} from './extension-config';
5
-
6
- /**
7
- * @extends {ExtensionConfig<DriverType>}
8
- */
9
- export class DriverConfig extends ExtensionConfig {
10
- /**
11
- * A set of unique automation names used by drivers.
12
- * @type {Set<string>}
13
- */
14
- knownAutomationNames;
15
-
16
- /**
17
- * A mapping of {@link Manifest} instances to {@link DriverConfig} instances.
18
- *
19
- * `Manifest` and `ExtensionConfig` have a one-to-many relationship; each `Manifest` should be associated with a `DriverConfig` and a `PluginConfig`; no more, no less.
20
- *
21
- * This variable tracks the `Manifest`-to-`DriverConfig` portion.
22
- *
23
- * @type {WeakMap<Manifest,DriverConfig>}
24
- * @private
25
- */
26
- static _instances = new WeakMap();
27
-
28
- /**
29
- * Call {@link DriverConfig.create} instead.
30
- * @private
31
- * @param {import('./manifest').Manifest} manifest - Manifest instance
32
- */
33
- constructor(manifest) {
34
- super(DRIVER_TYPE, manifest);
35
-
36
- this.knownAutomationNames = new Set();
37
- }
38
-
39
- /**
40
- * Creates a new {@link DriverConfig} instance for a {@link Manifest} instance.
41
- *
42
- * @param {Manifest} manifest
43
- * @throws If `manifest` already associated with a `DriverConfig`
44
- * @returns {DriverConfig}
45
- */
46
- static create(manifest) {
47
- const instance = new DriverConfig(manifest);
48
- if (DriverConfig.getInstance(manifest)) {
49
- throw new Error(
50
- `Manifest with APPIUM_HOME ${manifest.appiumHome} already has a DriverConfig; use DriverConfig.getInstance() to retrieve it.`
51
- );
52
- }
53
- DriverConfig._instances.set(manifest, instance);
54
- return instance;
55
- }
56
-
57
- /**
58
- * Returns a DriverConfig associated with a Manifest
59
- * @param {Manifest} manifest
60
- * @returns {DriverConfig|undefined}
61
- */
62
- static getInstance(manifest) {
63
- return DriverConfig._instances.get(manifest);
64
- }
65
-
66
- /**
67
- * Checks extensions for problems
68
- */
69
- async validate() {
70
- this.knownAutomationNames.clear();
71
- return await super._validate(this.manifest.getExtensionData(DRIVER_TYPE));
72
- }
73
-
74
- /**
75
- * @param {ExtManifest<DriverType>} extData
76
- * @returns {import('./extension-config').ExtManifestProblem[]}
77
- */
78
- getConfigProblems(extData) {
79
- const problems = [];
80
- const {platformNames, automationName} = extData;
81
-
82
- if (!_.isArray(platformNames)) {
83
- problems.push({
84
- err: 'Missing or incorrect supported platformNames list.',
85
- val: platformNames,
86
- });
87
- } else if (_.isEmpty(platformNames)) {
88
- problems.push({
89
- err: 'Empty platformNames list.',
90
- val: platformNames,
91
- });
92
- } else {
93
- for (const pName of platformNames) {
94
- if (!_.isString(pName)) {
95
- problems.push({
96
- err: 'Incorrectly formatted platformName.',
97
- val: pName,
98
- });
99
- }
100
- }
101
- }
102
-
103
- if (!_.isString(automationName)) {
104
- problems.push({
105
- err: 'Missing or incorrect automationName',
106
- val: automationName,
107
- });
108
- }
109
-
110
- if (this.knownAutomationNames.has(automationName)) {
111
- problems.push({
112
- err: 'Multiple drivers claim support for the same automationName',
113
- val: automationName,
114
- });
115
- }
116
-
117
- // should we retain the name at the end of this function, once we've checked there are no problems?
118
- this.knownAutomationNames.add(automationName);
119
-
120
- return problems;
121
- }
122
-
123
- /**
124
- * @param {ExtName<DriverType>} driverName
125
- * @param {ExtManifest<DriverType>} extData
126
- * @returns {string}
127
- */
128
- extensionDesc(driverName, {version, automationName}) {
129
- return `${driverName}@${version} (automationName '${automationName}')`;
130
- }
131
-
132
- /**
133
- * Given capabilities, find a matching driver within the config. Load its class and return it along with version and driver name.
134
- * @template {import('@appium/types').StringRecord} C
135
- * @param {C} caps
136
- * @returns {Promise<MatchedDriver>}
137
- */
138
- async findMatchingDriver({automationName, platformName}) {
139
- if (!_.isString(platformName)) {
140
- throw new Error('You must include a platformName capability');
141
- }
142
-
143
- if (!_.isString(automationName)) {
144
- throw new Error('You must include an automationName capability');
145
- }
146
-
147
- log.info(
148
- `Attempting to find matching driver for automationName ` +
149
- `'${automationName}' and platformName '${platformName}'`
150
- );
151
-
152
- try {
153
- const {driverName, mainClass, version} = this._getDriverBySupport(
154
- automationName,
155
- platformName
156
- );
157
- log.info(`The '${driverName}' driver was installed and matched caps.`);
158
- log.info(`Will require it at ${this.getInstallPath(driverName)}`);
159
- const driver = await this.requireAsync(driverName);
160
- if (!driver) {
161
- throw new Error(
162
- `Driver '${driverName}' did not export a class with name '${mainClass}'. Contact the author of the driver!`
163
- );
164
- }
165
- return {driver, version, driverName};
166
- } catch (err) {
167
- const msg =
168
- `Could not find a driver for automationName ` +
169
- `'${automationName}' and platformName '${platformName}'. ` +
170
- `Have you installed a driver that supports those ` +
171
- `capabilities? Run 'appium driver list --installed' to see. ` +
172
- `(Lower-level error: ${err.message})`;
173
- throw new Error(msg);
174
- }
175
- }
176
-
177
- /**
178
- * Given an automation name and platform name, find a suitable driver and return its extension data.
179
- * @param {string} matchAutomationName
180
- * @param {string} matchPlatformName
181
- * @returns {ExtMetadata<DriverType> & import('appium/types').InternalMetadata & import('appium/types').CommonExtMetadata}
182
- */
183
- _getDriverBySupport(matchAutomationName, matchPlatformName) {
184
- const drivers = this.installedExtensions;
185
- for (const [driverName, driverData] of _.toPairs(drivers)) {
186
- const {automationName, platformNames} = driverData;
187
- const aNameMatches = automationName.toLowerCase() === matchAutomationName.toLowerCase();
188
- const pNameMatches = _.includes(
189
- platformNames.map(_.toLower),
190
- matchPlatformName.toLowerCase()
191
- );
192
-
193
- if (aNameMatches && pNameMatches) {
194
- return {driverName, ...driverData};
195
- }
196
-
197
- if (aNameMatches) {
198
- throw new Error(
199
- `Driver '${driverName}' supports automationName ` +
200
- `'${automationName}', but Appium could not find ` +
201
- `support for platformName '${matchPlatformName}'. Supported ` +
202
- `platformNames are: ` +
203
- JSON.stringify(platformNames)
204
- );
205
- }
206
- }
207
-
208
- throw new Error(`Could not find installed driver to support given caps`);
209
- }
210
- }
211
-
212
- /**
213
- * @template {ExtensionType} T
214
- * @typedef {import('appium/types').ExtMetadata<T>} ExtMetadata
215
- */
216
-
217
- /**
218
- * @template {ExtensionType} T
219
- * @typedef {import('appium/types').ExtManifest<T>} ExtManifest
220
- */
221
-
222
- /**
223
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
224
- * @typedef {import('appium/types').ManifestData} ManifestData
225
- * @typedef {import('@appium/types').DriverType} DriverType
226
- * @typedef {import('./manifest').Manifest} Manifest
227
- */
228
-
229
- /**
230
- * @template {ExtensionType} T
231
- * @typedef {import('appium/types').ExtRecord<T>} ExtRecord
232
- */
233
-
234
- /**
235
- * @template {ExtensionType} T
236
- * @typedef {import('appium/types').ExtName<T>} ExtName
237
- */
238
-
239
- /**
240
- * Return value of {@linkcode DriverConfig.findMatchingDriver}
241
- * @typedef MatchedDriver
242
- * @property {import('@appium/types').DriverClass} driver
243
- * @property {string} version
244
- * @property {string} driverName
245
- */
@@ -1,169 +0,0 @@
1
- import _ from 'lodash';
2
- import {USE_ALL_PLUGINS} from '../constants';
3
- import log from '../logger';
4
- import {DriverConfig} from './driver-config';
5
- import {Manifest} from './manifest';
6
- import {timing} from '@appium/support';
7
- import {PluginConfig} from './plugin-config';
8
- import B from 'bluebird';
9
-
10
- /**
11
- * Loads extensions and creates `ExtensionConfig` instances.
12
- *
13
- * - Reads the manifest file, creating if necessary
14
- * - Using the parsed extension data, creates/gets the `ExtensionConfig` subclass instances
15
- * - Returns these instances
16
- *
17
- * If `appiumHome` is needed, use `resolveAppiumHome` from the `env` module in `@appium/support`.
18
- * @param {string} appiumHome
19
- * @returns {Promise<ExtensionConfigs>}
20
- */
21
- export async function loadExtensions(appiumHome) {
22
- const manifest = Manifest.getInstance(appiumHome);
23
- await manifest.read();
24
- const driverConfig = DriverConfig.getInstance(manifest) ?? DriverConfig.create(manifest);
25
- const pluginConfig = PluginConfig.getInstance(manifest) ?? PluginConfig.create(manifest);
26
-
27
- await B.all([driverConfig.validate(), pluginConfig.validate()]);
28
- return {driverConfig, pluginConfig};
29
- }
30
-
31
- /**
32
- * @template {'driver'|'plugin'} TExtType
33
- * @param {TExtType} extType
34
- * @param {import('./extension-config').ExtensionConfig} config
35
- * @param {string[]} extNames
36
- * @param {number} asyncImportChunkSize
37
- * @returns {Promise<[TExtType extends 'driver' ? DriverClass : PluginClass, string][]>}
38
- */
39
- async function importExtensions(extType, config, extNames, asyncImportChunkSize) {
40
- /** @type {B[]} */
41
- const allPromises = [];
42
- /** @type {B[]} */
43
- const activePromisesChunk = [];
44
- for (const extName of extNames) {
45
- _.remove(activePromisesChunk, (p) => p.isFulfilled());
46
- if (activePromisesChunk.length >= asyncImportChunkSize) {
47
- await B.any(activePromisesChunk);
48
- }
49
- const promise = B.resolve((async () => {
50
- log.info(`Attempting to load ${extType} ${extName}...`);
51
- const timer = new timing.Timer().start();
52
- try {
53
- const extClass = await config.requireAsync(extName);
54
- log.debug(`${extClass.name} has been successfully loaded in ${timer.getDuration().asSeconds.toFixed(3)}s`);
55
- return extClass;
56
- } catch (err) {
57
- log.error(
58
- `Could not load ${extType} '${extName}', so it will not be available. Error ` +
59
- `in loading the ${extType} was: ${err.message}`
60
- );
61
- log.debug(err.stack);
62
- }
63
- })());
64
- activePromisesChunk.push(promise);
65
- allPromises.push(promise);
66
- }
67
- return /** @type {[TExtType extends 'driver' ? DriverClass : PluginClass, string][]} */ (
68
- _.zip(await B.all(allPromises), extNames).filter(([extClass,]) => Boolean(extClass))
69
- );
70
- }
71
-
72
- /**
73
- * Find any plugin name which has been installed, and which has been requested for activation by
74
- * using the --use-plugins flag, and turn each one into its class, so we can send them as objects
75
- * to the server init. We also want to send/assign them to the umbrella driver so it can use them
76
- * to wrap command execution
77
- *
78
- * @param {import('./plugin-config').PluginConfig} pluginConfig - a plugin extension config
79
- * @param {number} maxParallelImports the maximum amount of plugins to import in parallel
80
- * @param {string[]} usePlugins
81
- * @returns {Promise<PluginNameMap>} Mapping of PluginClass to name
82
- */
83
- export async function getActivePlugins(pluginConfig, maxParallelImports, usePlugins = []) {
84
- if (_.isEmpty(usePlugins)) {
85
- return new Map();
86
- }
87
-
88
- /** @type {string[]} */
89
- let filteredPluginNames = [];
90
- if (usePlugins.length === 1 && usePlugins[0] === USE_ALL_PLUGINS) {
91
- filteredPluginNames = _.keys(pluginConfig.installedExtensions);
92
- } else {
93
- // It is important to load plugins in the same order that was used while enumerating them
94
- for (const pluginName of usePlugins) {
95
- if (pluginName in pluginConfig.installedExtensions) {
96
- filteredPluginNames.push(pluginName);
97
- } else if (pluginName === USE_ALL_PLUGINS) {
98
- throw new Error(
99
- `The reserved plugin name '${pluginName}' cannot be combined with other names.`
100
- );
101
- } else {
102
- const suffix = _.isEmpty(pluginConfig.installedExtensions)
103
- ? `You don't have any plugins installed yet.`
104
- : `Only the following ${_.size(pluginConfig.installedExtensions) === 1 ? `plugin is` : `plugins are`} ` +
105
- `available: ${_.keys(pluginConfig.installedExtensions)}`;
106
- throw new Error(
107
- `Could not load the plugin '${pluginName}' because it is not installed. ${suffix}`
108
- );
109
- }
110
- }
111
- }
112
- return new Map(await importExtensions('plugin', pluginConfig, filteredPluginNames, maxParallelImports));
113
- }
114
-
115
- /**
116
- * Find any driver name which has been installed, and turn each one into its class, so we can send
117
- * them as objects to the server init in case they need to add methods/routes or update the server.
118
- * If the --drivers flag was given, this method only loads the given drivers.
119
- *
120
- * @param {import('./driver-config').DriverConfig} driverConfig - a driver extension config
121
- * @param {number} maxParallelImports the maximum amount of plugins to import in parallel
122
- * @param {string[]} [useDrivers] - optional list of drivers to load
123
- * @returns {Promise<DriverNameMap>}
124
- */
125
- export async function getActiveDrivers(driverConfig, maxParallelImports, useDrivers = []) {
126
- /** @type {string[]} */
127
- let filteredDriverNames = [];
128
- if (_.isEmpty(useDrivers)) {
129
- // load all drivers if none are requested
130
- filteredDriverNames = _.keys(driverConfig.installedExtensions);
131
- } else {
132
- // Load drivers in the same order that was used while enumerating them
133
- for (const driverName of useDrivers) {
134
- if (driverName in driverConfig.installedExtensions) {
135
- filteredDriverNames.push(driverName);
136
- } else {
137
- const suffix = _.isEmpty(driverConfig.installedExtensions)
138
- ? `You don't have any drivers installed yet.`
139
- : `Only the following ${_.size(driverConfig.installedExtensions) === 1 ? `driver is` : `drivers are`} ` +
140
- `available: ${_.keys(driverConfig.installedExtensions)}`;
141
- throw new Error(
142
- `Could not load the driver '${driverName}' because it is not installed. ${suffix}`
143
- );
144
- }
145
- }
146
- }
147
- return new Map(await importExtensions('driver', driverConfig, filteredDriverNames, maxParallelImports));
148
- }
149
-
150
- /**
151
- * A mapping of {@linkcode PluginClass} classes to their names.
152
- * @typedef {Map<PluginClass,string>} PluginNameMap
153
- */
154
-
155
- /**
156
- * A mapping of {@linkcode DriverClass} classes to their names.
157
- * @typedef {Map<DriverClass,string>} DriverNameMap
158
- */
159
-
160
- /**
161
- * @typedef {import('@appium/types').PluginClass} PluginClass
162
- * @typedef {import('@appium/types').DriverClass} DriverClass
163
- */
164
-
165
- /**
166
- * @typedef ExtensionConfigs
167
- * @property {import('./driver-config').DriverConfig} driverConfig
168
- * @property {import('./plugin-config').PluginConfig} pluginConfig
169
- */
@@ -1,136 +0,0 @@
1
- import {CURRENT_SCHEMA_REV, DRIVER_TYPE, PLUGIN_TYPE} from '../constants';
2
- import log from '../logger';
3
-
4
- /**
5
- * This contains logic to migrate old versions of `extensions.yaml` to new versions.
6
- *
7
- * @module
8
- */
9
-
10
- /**
11
- * Constant for v3 of the schema rev.
12
- */
13
- const SCHEMA_REV_3 = 3;
14
-
15
- /**
16
- * Constant for v4 of the schema rev.
17
- */
18
- const SCHEMA_REV_4 = 4;
19
-
20
- /**
21
- * Collection of functions to migrate from one version to another.
22
- *
23
- * These functions _should not actually perform the migration_; rather, they
24
- * should return `true` if the migration should be performed. The migration
25
- * itself will happen within {@linkcode Manifest.syncWithInstalledExtensions}; the extensions
26
- * will be checked and the manifest file updated per the state of the filesystem.
27
- *
28
- * @type { {[P in keyof ManifestDataVersions]?: Migration} }
29
- */
30
- const Migrations = {
31
- /**
32
- * If `installPath` is missing from the `ExtManifest` for any extension, return `true`.
33
- *
34
- * We cannot easily determine the path of any given extension here, but returning `true`
35
- * will cause the `Manifest` to sync with the filesystem, which will populate the missing field.
36
- *
37
- * @type {Migration}
38
- */
39
- [SCHEMA_REV_3]: (manifest) => {
40
- /** @type {Array<ExtManifest<PluginType>|ExtManifest<DriverType>>} */
41
- const allExtData = [
42
- ...Object.values(manifest.getExtensionData(DRIVER_TYPE)),
43
- ...Object.values(manifest.getExtensionData(PLUGIN_TYPE)),
44
- ];
45
- return allExtData.some((metadata) => !('installPath' in metadata));
46
- },
47
- /**
48
- * Updates installed extensions to use `InstallType` of `dev` if appropriate.
49
- *
50
- * Previously, these types of extensions (automatically discovered) would use the default `InstallType` of `npm`, so we need
51
- * to refresh any with this install type.
52
- *
53
- * This should only happen once; we do not want to re-check everything with `npm` install type
54
- * every time.
55
- * @type {Migration}
56
- */
57
- [SCHEMA_REV_4]: (manifest) => {
58
- if (manifest.schemaRev < SCHEMA_REV_4) {
59
- const allExtData = [
60
- ...Object.values(manifest.getExtensionData(DRIVER_TYPE)),
61
- ...Object.values(manifest.getExtensionData(PLUGIN_TYPE)),
62
- ];
63
- return allExtData.some((metadata) => metadata.installType === 'npm');
64
- }
65
- return false;
66
- },
67
- };
68
-
69
- /**
70
- * Set `schemaRev` to a specific version.
71
- *
72
- * This _does_ mutate `data` in-place, unlike functions in
73
- * {@linkcode Migrations}.
74
- *
75
- * Again, returning `true` means that the manifest should be--at
76
- * minimum--persisted to disk, since we changed it.
77
- * @param {Readonly<Manifest>} manifest
78
- * @param {keyof ManifestDataVersions} version
79
- * @returns {boolean} Whether the data was modified
80
- */
81
- function setSchemaRev(manifest, version) {
82
- if ((manifest.schemaRev ?? 0) < version) {
83
- manifest.setSchemaRev(version);
84
- return true;
85
- }
86
- return false;
87
- }
88
-
89
- /**
90
- * Applies a series of migration functions to a manifest to update its manifest schema version.
91
- *
92
- * `data` is modified in-place.
93
- *
94
- * @param {Readonly<Manifest>} manifest
95
- * @returns {Promise<boolean>} If `true` existing packages should be synced from disk and the manifest should be persisted.
96
- */
97
- export async function migrate(manifest) {
98
- let didChange = false;
99
- for await (const migration of Object.values(Migrations)) {
100
- didChange = (await migration(manifest)) || didChange;
101
- }
102
- didChange = setSchemaRev(manifest, CURRENT_SCHEMA_REV) || didChange;
103
- if (didChange) {
104
- // this is not _technically_ true, since we don't actually write the file here.
105
- log.debug(`Upgraded extension manifest to schema v${manifest.schemaRev}`);
106
- }
107
-
108
- return didChange;
109
- }
110
-
111
- /**
112
- * A migration function. It will return `true` if a change _should be made_.
113
- *
114
- * A migration function should not modify `schemaRev`, as this is done automatically.
115
- *
116
- * Note that at the time of writing, we're not able to determine the version of the _current_ manifest file if there is no `schemaRev` prop present (and we may not want to trust it anyway).
117
- * @callback Migration
118
- * @param {Readonly<Manifest>} manifest - The `Manifest` instance
119
- * @returns {boolean|Promise<boolean>} If `true`, then something changed
120
- */
121
-
122
- /**
123
- * @typedef {import('appium/types').ManifestData} ManifestData
124
- * @typedef {import('@appium/types').DriverType} DriverType
125
- * @typedef {import('@appium/types').PluginType} PluginType
126
- * @typedef {import('appium/types').AnyManifestDataVersion} AnyManifestDataVersion
127
- * @typedef {import('appium/types').ManifestDataVersions} ManifestDataVersions
128
- * @typedef {import('@appium/types').ExtensionType} ExtensionType
129
- * @typedef {import('appium/types').ManifestV2.ManifestData} ManifestDataV2
130
- * @typedef {import('./manifest').Manifest} Manifest
131
- */
132
-
133
- /**
134
- * @template {ExtensionType} ExtType
135
- * @typedef {import('appium/types').ExtManifest<ExtType>} ExtManifest
136
- */