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,4 +1,11 @@
1
1
  import _ from 'lodash';
2
+ import type {
3
+ Args,
4
+ CliCommandSetup,
5
+ CliCommandSetupSubcommand,
6
+ CliExtensionCommand,
7
+ CliExtensionSubcommand,
8
+ } from 'appium/types';
2
9
  import {
3
10
  DESKTOP_BROWSERS,
4
11
  DESKTOP_DRIVERS,
@@ -6,7 +13,8 @@ import {
6
13
  } from '../constants';
7
14
  import {runExtensionCommand} from './extension';
8
15
  import { system, fs } from '@appium/support';
9
- import log from '../logger';
16
+ import {log} from '../logger';
17
+ import type {ExtensionConfig} from '../extension/extension-config';
10
18
 
11
19
  /**
12
20
  * Subcommands of preset for setup
@@ -20,13 +28,11 @@ export const SUBCOMMAND_RESET = 'reset';
20
28
  * Pairs of preset subcommand and driver candidates.
21
29
  * Driver names listed in KNOWN_DRIVERS to install by default
22
30
  */
23
- const PRESET_PAIRS = Object.freeze(
24
- /** @type {const} */ ({
25
- mobile: _.keys(MOBILE_DRIVERS),
26
- desktop: _.keys(DESKTOP_DRIVERS),
27
- browser: _.keys(DESKTOP_BROWSERS)
28
- }),
29
- );
31
+ const PRESET_PAIRS = Object.freeze({
32
+ mobile: _.keys(MOBILE_DRIVERS),
33
+ desktop: _.keys(DESKTOP_DRIVERS),
34
+ browser: _.keys(DESKTOP_BROWSERS),
35
+ } as const);
30
36
  const DRIVERS_ONLY_MACOS = ['xcuitest', 'safari', 'mac2'];
31
37
 
32
38
  const DRIVERS_ONLY_WINDOWS = ['windows'];
@@ -36,12 +42,14 @@ const DRIVERS_ONLY_WINDOWS = ['windows'];
36
42
  */
37
43
  export const DEFAULT_PLUGINS = ['images', 'inspector'];
38
44
 
45
+ type DriverConfig = ExtensionConfig<'driver'>;
46
+ type PluginConfig = ExtensionConfig<'plugin'>;
47
+ type CliExtArgs = Args<CliExtensionCommand, CliExtensionSubcommand>;
48
+
39
49
  /**
40
50
  * Return a list of drivers available for current host platform.
41
- * @param {import('appium/types').CliCommandSetupSubcommand} presetName
42
- * @returns {Array<string>}
43
51
  */
44
- export function getPresetDrivers(presetName) {
52
+ export function getPresetDrivers(presetName: CliCommandSetupSubcommand): string[] {
45
53
  return _.filter(PRESET_PAIRS[presetName], (driver) => {
46
54
  if (_.includes(DRIVERS_ONLY_MACOS, driver)) {
47
55
  return system.isMac();
@@ -58,9 +66,8 @@ export function getPresetDrivers(presetName) {
58
66
 
59
67
  /**
60
68
  * Return desktop platform name for setup command description.
61
- * @returns {string}
62
69
  */
63
- export function determinePlatformName() {
70
+ export function determinePlatformName(): string {
64
71
  if (system.isMac()) {
65
72
  return 'macOS';
66
73
  } else if (system.isWindows()) {
@@ -70,14 +77,16 @@ export function determinePlatformName() {
70
77
  }
71
78
 
72
79
  /**
73
- * Run 'setup' command to install drivers/plugins into the given appium home.
74
- * @template {import('appium/types').CliCommandSetup} SetupCmd
75
- * @param {import('appium/types').Args<SetupCmd>} preConfigArgs
76
- * @param {DriverConfig} driverConfig
77
- * @param {PluginConfig} pluginConfig
78
- * @returns {Promise<void>}
79
- */
80
- export async function runSetupCommand(preConfigArgs, driverConfig, pluginConfig) {
80
+ * Runs the `setup` command and applies the selected preset.
81
+ *
82
+ * Depending on the subcommand, this installs mobile/desktop/browser presets or
83
+ * removes all installed extensions and manifests via `reset`.
84
+ */
85
+ export async function runSetupCommand(
86
+ preConfigArgs: Args<CliCommandSetup>,
87
+ driverConfig: DriverConfig,
88
+ pluginConfig: PluginConfig
89
+ ): Promise<void> {
81
90
  switch (preConfigArgs.setupCommand) {
82
91
  case SUBCOMMAND_DESKTOP:
83
92
  await setupDesktopAppDrivers(driverConfig);
@@ -99,22 +108,19 @@ export async function runSetupCommand(preConfigArgs, driverConfig, pluginConfig)
99
108
 
100
109
  /**
101
110
  * Resets all installed drivers and extensions
102
- *
103
- * @param {DriverConfig} driverConfig
104
- * @param {PluginConfig} pluginConfig
105
- * @returns {Promise<void>}
106
111
  */
107
- async function resetAllExtensions(driverConfig, pluginConfig) {
108
- for (const [command, config] of [
112
+ async function resetAllExtensions(driverConfig: DriverConfig, pluginConfig: PluginConfig): Promise<void> {
113
+ const commandConfigs: [CliExtensionCommand, DriverConfig | PluginConfig][] = [
109
114
  ['driver', driverConfig],
110
115
  ['plugin', pluginConfig],
111
- ]) {
112
- for (const extensionName of _.keys(/** @type {DriverConfig|PluginConfig} */ (config).installedExtensions)) {
116
+ ];
117
+ for (const [command, config] of commandConfigs) {
118
+ for (const extensionName of _.keys(config.installedExtensions)) {
113
119
  try {
114
120
  await uninstallExtension(
115
121
  extensionName,
116
- extensionCommandArgs(/** @type {CliExtensionCommand} */ (command), extensionName, 'uninstall'),
117
- /** @type {DriverConfig|PluginConfig} */ (config)
122
+ extensionCommandArgs(command, extensionName, 'uninstall'),
123
+ config
118
124
  );
119
125
  } catch (e) {
120
126
  log.warn(
@@ -124,8 +130,8 @@ async function resetAllExtensions(driverConfig, pluginConfig) {
124
130
  }
125
131
  }
126
132
 
127
- const manifestPath = /** @type {DriverConfig|PluginConfig} */ (config).manifestPath;
128
- if (!await fs.exists(manifestPath)) {
133
+ const manifestPath = config.manifestPath;
134
+ if (!manifestPath || !await fs.exists(manifestPath)) {
129
135
  continue;
130
136
  }
131
137
 
@@ -140,38 +146,29 @@ async function resetAllExtensions(driverConfig, pluginConfig) {
140
146
 
141
147
  /**
142
148
  * Install drivers listed in DEFAULT_DRIVERS.
143
- * @param {DriverConfig} driverConfig
144
- * @returns {Promise<void>}
145
149
  */
146
- async function setupMobileDrivers(driverConfig) {
150
+ async function setupMobileDrivers(driverConfig: DriverConfig): Promise<void> {
147
151
  await installDrivers(SUBCOMMAND_MOBILE, driverConfig);
148
152
  }
149
153
 
150
154
  /**
151
155
  * Install all of known drivers listed in BROWSER_DRIVERS.
152
- * @param {DriverConfig} driverConfig
153
- * @returns {Promise<void>}
154
156
  */
155
- async function setupBrowserDrivers(driverConfig) {
157
+ async function setupBrowserDrivers(driverConfig: DriverConfig): Promise<void> {
156
158
  await installDrivers(SUBCOMMAND_BROWSER, driverConfig);
157
159
  }
158
160
 
159
161
  /**
160
162
  * Install all of known drivers listed in DESKTOP_APP_DRIVERS.
161
- * @param {DriverConfig} driverConfig
162
- * @returns {Promise<void>}
163
163
  */
164
- async function setupDesktopAppDrivers(driverConfig) {
164
+ async function setupDesktopAppDrivers(driverConfig: DriverConfig): Promise<void> {
165
165
  await installDrivers(SUBCOMMAND_DESKTOP, driverConfig);
166
166
  }
167
167
 
168
168
  /**
169
169
  * Install the given driver name. It skips the installation if the given driver name was already installed.
170
- * @param {import('appium/types').CliCommandSetupSubcommand} subcommand
171
- * @param {DriverConfig} driverConfig
172
- * @returns {Promise<void>}
173
170
  */
174
- async function installDrivers(subcommand, driverConfig) {
171
+ async function installDrivers(subcommand: CliCommandSetupSubcommand, driverConfig: DriverConfig): Promise<void> {
175
172
  for (const driverName of getPresetDrivers(subcommand)) {
176
173
  await installExtension(driverName, extensionCommandArgs('driver', driverName, 'install'), driverConfig);
177
174
  }
@@ -179,10 +176,8 @@ async function installDrivers(subcommand, driverConfig) {
179
176
 
180
177
  /**
181
178
  * Install plugins listed in DEFAULT_PLUGINS.
182
- * @param {PluginConfig} pluginConfig
183
- * @returns {Promise<void>}
184
179
  */
185
- async function setupDefaultPlugins(pluginConfig) {
180
+ async function setupDefaultPlugins(pluginConfig: PluginConfig): Promise<void> {
186
181
  for (const pluginName of DEFAULT_PLUGINS) {
187
182
  await installExtension(pluginName, extensionCommandArgs('plugin', pluginName, 'install'), pluginConfig);
188
183
  }
@@ -190,12 +185,12 @@ async function setupDefaultPlugins(pluginConfig) {
190
185
 
191
186
  /**
192
187
  * Run the given extensionConfigArgs command after checking if the given extensionName was already installed.
193
- * @param {string} extensionName
194
- * @param {Args} extensionConfigArgs
195
- * @param {DriverConfig|PluginConfig} extensionConfig
196
- * @returns {Promise<void>}
197
188
  */
198
- async function installExtension(extensionName, extensionConfigArgs, extensionConfig) {
189
+ async function installExtension(
190
+ extensionName: string,
191
+ extensionConfigArgs: CliExtArgs,
192
+ extensionConfig: DriverConfig | PluginConfig
193
+ ): Promise<void> {
199
194
  if (_.keys(extensionConfig.installedExtensions).includes(extensionName)) {
200
195
  log.info(`${extensionName} (${extensionConfig.installedExtensions[extensionName].version}) is already installed. ` +
201
196
  `Skipping the installation.`);
@@ -206,12 +201,12 @@ async function installExtension(extensionName, extensionConfigArgs, extensionCon
206
201
 
207
202
  /**
208
203
  * Run the given extensionConfigArgs command after checking if the given extensionName was already installed.
209
- * @param {string} extensionName
210
- * @param {Args} extensionConfigArgs
211
- * @param {DriverConfig|PluginConfig} extensionConfig
212
- * @returns {Promise<void>}
213
204
  */
214
- async function uninstallExtension(extensionName, extensionConfigArgs, extensionConfig) {
205
+ async function uninstallExtension(
206
+ extensionName: string,
207
+ extensionConfigArgs: CliExtArgs,
208
+ extensionConfig: DriverConfig | PluginConfig
209
+ ): Promise<void> {
215
210
  if (!_.keys(extensionConfig.installedExtensions).includes(extensionName)) {
216
211
  log.info(`${extensionName} (${extensionConfig.installedExtensions[extensionName].version}) is not installed. ` +
217
212
  `Skipping its uninstall.`);
@@ -222,24 +217,14 @@ async function uninstallExtension(extensionName, extensionConfigArgs, extensionC
222
217
 
223
218
  /**
224
219
  * Return the command config for driver or plugin.
225
- * @param {CliExtensionCommand} extensionCommand
226
- * @param {string} extensionName
227
- * @param {CliExtensionSubcommand} command
228
- * @returns {Args}
229
220
  */
230
- function extensionCommandArgs(extensionCommand, extensionName, command) {
221
+ function extensionCommandArgs(
222
+ extensionCommand: CliExtensionCommand,
223
+ extensionName: string,
224
+ command: CliExtensionSubcommand
225
+ ): CliExtArgs {
231
226
  return (extensionCommand === 'plugin')
232
227
  ? {'subcommand': 'plugin', 'pluginCommand': command, 'plugin': extensionName}
233
228
  : {'subcommand': 'driver', 'driverCommand': command, 'driver': extensionName};
234
229
  }
235
230
 
236
- /**
237
- * @typedef {import('appium/types').CliExtensionCommand} CliExtensionCommand
238
- * @typedef {import('appium/types').CliExtensionSubcommand} CliExtensionSubcommand
239
- * @typedef {import('../extension/extension-config').ExtensionConfig<CliExtensionCommand>} PluginConfig
240
- * @typedef {import('../extension/extension-config').ExtensionConfig<CliExtensionCommand>} DriverConfig
241
- */
242
-
243
- /**
244
- * @typedef {import('appium/types').Args<CliExtensionCommand, CliExtensionSubcommand>} Args
245
- */
@@ -0,0 +1,97 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import ora from 'ora';
4
+
5
+ export const JSON_SPACES = 4;
6
+
7
+ type ErrorLike = Error & {stderr?: unknown};
8
+
9
+ export class RingBuffer<T = any> {
10
+ private readonly size: number;
11
+ private readonly buffer: T[] = [];
12
+
13
+ constructor(size = 50) {
14
+ this.size = size;
15
+ }
16
+
17
+ /**
18
+ * Get the current buffer contents.
19
+ */
20
+ getBuff(): T[] {
21
+ return this.buffer;
22
+ }
23
+
24
+ /**
25
+ * Add an item to the buffer.
26
+ */
27
+ enqueue(item: T): void {
28
+ if (this.buffer.length >= this.size) {
29
+ this.dequeue();
30
+ }
31
+ this.buffer.push(item);
32
+ }
33
+
34
+ /**
35
+ * Remove the oldest item from the buffer.
36
+ */
37
+ dequeue(): void {
38
+ this.buffer.shift();
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Log an error to the console and exit the process.
44
+ *
45
+ * @param json - whether we should log json or text
46
+ * @param msg - error message, object, Error instance, etc.
47
+ */
48
+ export function errAndQuit(json: boolean, msg: unknown): never {
49
+ if (json) {
50
+ console.log(JSON.stringify({error: String(msg)}, null, JSON_SPACES));
51
+ } else {
52
+ console.error((String(msg) as any).red);
53
+ if ((msg as ErrorLike)?.stderr) {
54
+ console.error((String((msg as ErrorLike).stderr) as any).red);
55
+ }
56
+ }
57
+ process.exit(1);
58
+ }
59
+
60
+ /**
61
+ * Conditionally log something to the console.
62
+ *
63
+ * @param json - whether we are in json mode (and should therefore not log)
64
+ * @param msg - string to log
65
+ */
66
+ export function log(json: boolean, msg: string): void {
67
+ if (!json) {
68
+ console.log(msg);
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Start a spinner, execute an async function, and then stop the spinner.
74
+ *
75
+ * @param json - whether we are in json mode (and should therefore not log)
76
+ * @param msg - string to log
77
+ * @param fn - function to wrap with spinning
78
+ * @returns result of `fn`
79
+ */
80
+ export async function spinWith<T>(
81
+ json: boolean,
82
+ msg: string,
83
+ fn: () => T | Promise<T>
84
+ ): Promise<T> {
85
+ if (json) {
86
+ return await fn();
87
+ }
88
+ const spinner = ora(msg).start();
89
+ try {
90
+ const res = await fn();
91
+ spinner.succeed();
92
+ return res;
93
+ } catch (err) {
94
+ spinner.fail();
95
+ throw err;
96
+ }
97
+ }
@@ -20,7 +20,6 @@ export const SERVER_SUBCOMMAND = 'server';
20
20
  */
21
21
  export const SETUP_SUBCOMMAND = 'setup';
22
22
 
23
-
24
23
  /**
25
24
  * The value of `--use-plugins` if _all_ plugins should be loaded
26
25
  */
@@ -30,51 +29,41 @@ export const USE_ALL_PLUGINS = 'all';
30
29
  // The plugins in this list will be available to the CLI so users can just
31
30
  // type 'appium plugin install 'name'', rather than having to specify the full
32
31
  // npm package. I.e., these are the officially recognized plugins.
33
- export const KNOWN_PLUGINS = Object.freeze(
34
- /** @type {const} */ ({
35
- 'execute-driver': '@appium/execute-driver-plugin',
36
- images: '@appium/images-plugin',
37
- inspector: 'appium-inspector-plugin',
38
- 'relaxed-caps': '@appium/relaxed-caps-plugin',
39
- storage: '@appium/storage-plugin',
40
- 'universal-xml': '@appium/universal-xml-plugin',
41
- }),
42
- );
43
-
44
- export const MOBILE_DRIVERS = Object.freeze(
45
- /** @type {const} */ ({
46
- uiautomator2: 'appium-uiautomator2-driver',
47
- xcuitest: 'appium-xcuitest-driver',
48
- espresso: 'appium-espresso-driver',
49
- }),
50
- );
51
-
52
- export const DESKTOP_DRIVERS = Object.freeze(
53
- /** @type {const} */ ({
54
- mac2: 'appium-mac2-driver',
55
- windows: 'appium-windows-driver',
56
- }),
57
- );
58
-
59
- export const DESKTOP_BROWSERS = Object.freeze(
60
- /** @type {const} */ ({
61
- safari: 'appium-safari-driver',
62
- gecko: 'appium-geckodriver',
63
- chromium: 'appium-chromium-driver',
64
- }),
65
- );
32
+ export const KNOWN_PLUGINS = Object.freeze({
33
+ 'execute-driver': '@appium/execute-driver-plugin',
34
+ images: '@appium/images-plugin',
35
+ inspector: 'appium-inspector-plugin',
36
+ 'relaxed-caps': '@appium/relaxed-caps-plugin',
37
+ storage: '@appium/storage-plugin',
38
+ 'universal-xml': '@appium/universal-xml-plugin',
39
+ } as const);
40
+
41
+ export const MOBILE_DRIVERS = Object.freeze({
42
+ uiautomator2: 'appium-uiautomator2-driver',
43
+ xcuitest: 'appium-xcuitest-driver',
44
+ espresso: 'appium-espresso-driver',
45
+ } as const);
46
+
47
+ export const DESKTOP_DRIVERS = Object.freeze({
48
+ mac2: 'appium-mac2-driver',
49
+ windows: 'appium-windows-driver',
50
+ } as const);
51
+
52
+ export const DESKTOP_BROWSERS = Object.freeze({
53
+ safari: 'appium-safari-driver',
54
+ gecko: 'appium-geckodriver',
55
+ chromium: 'appium-chromium-driver',
56
+ } as const);
66
57
 
67
58
  // This is a map of driver names to npm packages representing those drivers.
68
59
  // The drivers in this list will be available to the CLI so users can just
69
60
  // type 'appium driver install 'name'', rather than having to specify the full
70
61
  // npm package. I.e., these are the officially recognized drivers.
71
- export const KNOWN_DRIVERS = Object.freeze(
72
- /** @type {const} */ ({
73
- ...MOBILE_DRIVERS,
74
- ...DESKTOP_DRIVERS,
75
- ...DESKTOP_BROWSERS,
76
- }),
77
- );
62
+ export const KNOWN_DRIVERS = Object.freeze({
63
+ ...MOBILE_DRIVERS,
64
+ ...DESKTOP_DRIVERS,
65
+ ...DESKTOP_BROWSERS,
66
+ } as const);
78
67
 
79
68
  /**
80
69
  * Relative path to directory containing any Appium internal files