appium 2.0.0-beta.4 → 2.0.0-beta.42

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 (153) hide show
  1. package/README.md +10 -11
  2. package/build/lib/appium.d.ts +204 -0
  3. package/build/lib/appium.d.ts.map +1 -0
  4. package/build/lib/appium.js +256 -131
  5. package/build/lib/cli/args.d.ts +17 -0
  6. package/build/lib/cli/args.d.ts.map +1 -0
  7. package/build/lib/cli/args.js +96 -282
  8. package/build/lib/cli/driver-command.d.ts +37 -0
  9. package/build/lib/cli/driver-command.d.ts.map +1 -0
  10. package/build/lib/cli/driver-command.js +27 -18
  11. package/build/lib/cli/extension-command.d.ts +376 -0
  12. package/build/lib/cli/extension-command.d.ts.map +1 -0
  13. package/build/lib/cli/extension-command.js +287 -156
  14. package/build/lib/cli/extension.d.ts +22 -0
  15. package/build/lib/cli/extension.d.ts.map +1 -0
  16. package/build/lib/cli/extension.js +31 -17
  17. package/build/lib/cli/parser.d.ts +84 -0
  18. package/build/lib/cli/parser.d.ts.map +1 -0
  19. package/build/lib/cli/parser.js +164 -94
  20. package/build/lib/cli/plugin-command.d.ts +34 -0
  21. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  22. package/build/lib/cli/plugin-command.js +26 -19
  23. package/build/lib/cli/utils.d.ts +29 -0
  24. package/build/lib/cli/utils.d.ts.map +1 -0
  25. package/build/lib/cli/utils.js +27 -3
  26. package/build/lib/config-file.d.ts +100 -0
  27. package/build/lib/config-file.d.ts.map +1 -0
  28. package/build/lib/config-file.js +136 -0
  29. package/build/lib/config.d.ts +49 -0
  30. package/build/lib/config.d.ts.map +1 -0
  31. package/build/lib/config.js +119 -96
  32. package/build/lib/constants.d.ts +48 -0
  33. package/build/lib/constants.d.ts.map +1 -0
  34. package/build/lib/constants.js +60 -0
  35. package/build/lib/extension/driver-config.d.ts +81 -0
  36. package/build/lib/extension/driver-config.d.ts.map +1 -0
  37. package/build/lib/extension/driver-config.js +177 -0
  38. package/build/lib/extension/extension-config.d.ts +242 -0
  39. package/build/lib/extension/extension-config.d.ts.map +1 -0
  40. package/build/lib/extension/extension-config.js +436 -0
  41. package/build/lib/extension/index.d.ts +48 -0
  42. package/build/lib/extension/index.d.ts.map +1 -0
  43. package/build/lib/extension/index.js +75 -0
  44. package/build/lib/extension/manifest.d.ts +174 -0
  45. package/build/lib/extension/manifest.d.ts.map +1 -0
  46. package/build/lib/extension/manifest.js +256 -0
  47. package/build/lib/extension/package-changed.d.ts +11 -0
  48. package/build/lib/extension/package-changed.d.ts.map +1 -0
  49. package/build/lib/extension/package-changed.js +66 -0
  50. package/build/lib/extension/plugin-config.d.ts +57 -0
  51. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  52. package/build/lib/extension/plugin-config.js +78 -0
  53. package/build/lib/grid-register.d.ts +10 -0
  54. package/build/lib/grid-register.d.ts.map +1 -0
  55. package/build/lib/grid-register.js +21 -25
  56. package/build/lib/logger.d.ts +3 -0
  57. package/build/lib/logger.d.ts.map +1 -0
  58. package/build/lib/logger.js +4 -6
  59. package/build/lib/logsink.d.ts +4 -0
  60. package/build/lib/logsink.d.ts.map +1 -0
  61. package/build/lib/logsink.js +14 -17
  62. package/build/lib/main.d.ts +55 -0
  63. package/build/lib/main.d.ts.map +1 -0
  64. package/build/lib/main.js +183 -91
  65. package/build/lib/schema/arg-spec.d.ts +143 -0
  66. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  67. package/build/lib/schema/arg-spec.js +119 -0
  68. package/build/lib/schema/cli-args.d.ts +19 -0
  69. package/build/lib/schema/cli-args.d.ts.map +1 -0
  70. package/build/lib/schema/cli-args.js +178 -0
  71. package/build/lib/schema/cli-transformers.d.ts +5 -0
  72. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  73. package/build/lib/schema/cli-transformers.js +74 -0
  74. package/build/lib/schema/index.d.ts +3 -0
  75. package/build/lib/schema/index.d.ts.map +1 -0
  76. package/build/lib/schema/index.js +34 -0
  77. package/build/lib/schema/keywords.d.ts +24 -0
  78. package/build/lib/schema/keywords.d.ts.map +1 -0
  79. package/build/lib/schema/keywords.js +70 -0
  80. package/build/lib/schema/schema.d.ts +259 -0
  81. package/build/lib/schema/schema.d.ts.map +1 -0
  82. package/build/lib/schema/schema.js +450 -0
  83. package/build/lib/utils.d.ts +66 -0
  84. package/build/lib/utils.d.ts.map +1 -0
  85. package/build/lib/utils.js +35 -139
  86. package/build/tsconfig.tsbuildinfo +1 -0
  87. package/build/types/appium-manifest.d.ts +59 -0
  88. package/build/types/appium-manifest.d.ts.map +1 -0
  89. package/build/types/cli.d.ts +123 -0
  90. package/build/types/cli.d.ts.map +1 -0
  91. package/build/types/extension-manifest.d.ts +55 -0
  92. package/build/types/extension-manifest.d.ts.map +1 -0
  93. package/build/types/index.d.ts +16 -0
  94. package/build/types/index.d.ts.map +1 -0
  95. package/driver.d.ts +1 -0
  96. package/driver.js +14 -0
  97. package/index.js +11 -0
  98. package/lib/appium.js +520 -186
  99. package/lib/cli/args.js +267 -422
  100. package/lib/cli/driver-command.js +58 -23
  101. package/lib/cli/extension-command.js +613 -260
  102. package/lib/cli/extension.js +47 -17
  103. package/lib/cli/parser.js +263 -83
  104. package/lib/cli/plugin-command.js +48 -20
  105. package/lib/cli/utils.js +24 -10
  106. package/lib/config-file.js +219 -0
  107. package/lib/config.js +243 -110
  108. package/lib/constants.js +69 -0
  109. package/lib/extension/driver-config.js +249 -0
  110. package/lib/extension/extension-config.js +677 -0
  111. package/lib/extension/index.js +116 -0
  112. package/lib/extension/manifest.js +475 -0
  113. package/lib/extension/package-changed.js +64 -0
  114. package/lib/extension/plugin-config.js +113 -0
  115. package/lib/grid-register.js +49 -35
  116. package/lib/logger.js +1 -2
  117. package/lib/logsink.js +38 -33
  118. package/lib/main.js +308 -100
  119. package/lib/schema/arg-spec.js +229 -0
  120. package/lib/schema/cli-args.js +238 -0
  121. package/lib/schema/cli-transformers.js +115 -0
  122. package/lib/schema/index.js +2 -0
  123. package/lib/schema/keywords.js +136 -0
  124. package/lib/schema/schema.js +717 -0
  125. package/lib/utils.js +121 -140
  126. package/package.json +85 -85
  127. package/plugin.d.ts +1 -0
  128. package/plugin.js +13 -0
  129. package/scripts/autoinstall-extensions.js +185 -0
  130. package/support.d.ts +1 -0
  131. package/support.js +13 -0
  132. package/test.d.ts +7 -0
  133. package/test.js +13 -0
  134. package/types/appium-manifest.ts +73 -0
  135. package/types/cli.ts +150 -0
  136. package/types/extension-manifest.ts +64 -0
  137. package/types/index.ts +21 -0
  138. package/CHANGELOG.md +0 -3515
  139. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  140. package/build/lib/cli/npm.js +0 -206
  141. package/build/lib/cli/parser-helpers.js +0 -82
  142. package/build/lib/driver-config.js +0 -77
  143. package/build/lib/drivers.js +0 -96
  144. package/build/lib/extension-config.js +0 -253
  145. package/build/lib/plugin-config.js +0 -59
  146. package/build/lib/plugins.js +0 -14
  147. package/lib/cli/npm.js +0 -183
  148. package/lib/cli/parser-helpers.js +0 -79
  149. package/lib/driver-config.js +0 -46
  150. package/lib/drivers.js +0 -81
  151. package/lib/extension-config.js +0 -209
  152. package/lib/plugin-config.js +0 -34
  153. package/lib/plugins.js +0 -10
package/lib/main.js CHANGED
@@ -1,42 +1,55 @@
1
1
  #!/usr/bin/env node
2
- // transpile:main
3
2
 
4
- import { init as logsinkInit } from './logsink';
5
- import logger from './logger'; // logger needs to remain first of imports
3
+ import {init as logsinkInit} from './logsink'; // this import needs to come first since it sets up global npmlog
4
+ import logger from './logger'; // logger needs to remain second
5
+ // @ts-ignore
6
+ import {routeConfiguringFunction as makeRouter, server as baseServer} from '@appium/base-driver';
7
+ import {logger as logFactory, util, env} from '@appium/support';
8
+ import {asyncify} from 'asyncbox';
6
9
  import _ from 'lodash';
7
- import { server as baseServer, routeConfiguringFunction as makeRouter } from 'appium-base-driver';
8
- import { asyncify } from 'asyncbox';
9
- import { default as getParser, getDefaultServerArgs } from './cli/parser';
10
- import { USE_ALL_PLUGINS } from './cli/args';
11
- import { logger as logFactory, util } from 'appium-support';
10
+ import {AppiumDriver} from './appium';
11
+ import {runExtensionCommand} from './cli/extension';
12
+ import {getParser} from './cli/parser';
12
13
  import {
13
- showConfig, checkNodeOk, validateServerArgs,
14
- warnNodeDeprecations, validateTmpDir, getNonDefaultArgs,
15
- getGitRev, APPIUM_VER
14
+ APPIUM_VER,
15
+ checkNodeOk,
16
+ getGitRev,
17
+ getNonDefaultServerArgs,
18
+ showConfig,
19
+ showBuildInfo,
20
+ validateTmpDir,
21
+ warnNodeDeprecations,
22
+ checkNpmOk,
16
23
  } from './config';
17
- import DriverConfig from './driver-config';
18
- import PluginConfig from './plugin-config';
19
- import { DRIVER_TYPE, PLUGIN_TYPE } from './extension-config';
20
- import { runExtensionCommand } from './cli/extension';
21
- import { AppiumDriver } from './appium';
24
+ import {readConfigFile} from './config-file';
25
+ import {loadExtensions, getActivePlugins, getActiveDrivers} from './extension';
26
+ import {DRIVER_TYPE, PLUGIN_TYPE, SERVER_SUBCOMMAND} from './constants';
22
27
  import registerNode from './grid-register';
23
- import { inspectObject } from './utils';
28
+ import {getDefaultsForSchema, validate} from './schema/schema';
29
+ import {inspect} from './utils';
24
30
 
31
+ const {resolveAppiumHome} = env;
25
32
 
26
- async function preflightChecks ({parser, args, driverConfig, pluginConfig, throwInsteadOfExit = false}) {
33
+ /**
34
+ *
35
+ * @param {ParsedArgs} args
36
+ * @param {boolean} [throwInsteadOfExit]
37
+ */
38
+ async function preflightChecks(args, throwInsteadOfExit = false) {
27
39
  try {
28
40
  checkNodeOk();
41
+ await checkNpmOk();
29
42
  if (args.longStacktrace) {
30
43
  require('longjohn').async_trace_limit = -1;
31
44
  }
32
- if (args.showConfig) {
33
- await showConfig();
45
+ if (args.showBuildInfo) {
46
+ await showBuildInfo();
34
47
  process.exit(0);
35
48
  }
36
49
  warnNodeDeprecations();
37
- validateServerArgs(parser, args);
38
- await driverConfig.read();
39
- await pluginConfig.read();
50
+
51
+ validate(args);
52
+
40
53
  if (args.tmpDir) {
41
54
  await validateTmpDir(args.tmpDir);
42
55
  }
@@ -50,18 +63,29 @@ async function preflightChecks ({parser, args, driverConfig, pluginConfig, throw
50
63
  }
51
64
  }
52
65
 
53
- function logNonDefaultArgsWarning (args) {
66
+ /**
67
+ * @param {Args} args
68
+ */
69
+ function logNonDefaultArgsWarning(args) {
54
70
  logger.info('Non-default server args:');
55
- inspectObject(args);
71
+ inspect(args);
56
72
  }
57
73
 
58
- function logDefaultCapabilitiesWarning (caps) {
59
- logger.info('Default capabilities, which will be added to each request ' +
60
- 'unless overridden by desired capabilities:');
61
- inspectObject(caps);
74
+ /**
75
+ * @param {Args['defaultCapabilities']} caps
76
+ */
77
+ function logDefaultCapabilitiesWarning(caps) {
78
+ logger.info(
79
+ 'Default capabilities, which will be added to each request ' +
80
+ 'unless overridden by desired capabilities:'
81
+ );
82
+ inspect(caps);
62
83
  }
63
84
 
64
- async function logStartupInfo (parser, args) {
85
+ /**
86
+ * @param {ParsedArgs} args
87
+ */
88
+ async function logStartupInfo(args) {
65
89
  let welcome = `Welcome to Appium v${APPIUM_VER}`;
66
90
  let appiumRev = await getGitRev();
67
91
  if (appiumRev) {
@@ -69,7 +93,7 @@ async function logStartupInfo (parser, args) {
69
93
  }
70
94
  logger.info(welcome);
71
95
 
72
- let showArgs = getNonDefaultArgs(parser, args);
96
+ let showArgs = getNonDefaultServerArgs(args);
73
97
  if (_.size(showArgs)) {
74
98
  logNonDefaultArgsWarning(showArgs);
75
99
  }
@@ -83,20 +107,79 @@ async function logStartupInfo (parser, args) {
83
107
  // }
84
108
  }
85
109
 
86
- function logServerPort (address, port) {
87
- let logMessage = `Appium REST http interface listener started on ` +
88
- `${address}:${port}`;
110
+ /**
111
+ * Logs the address and port the server is listening on
112
+ * @param {string} address - Address
113
+ * @param {number} port - Port
114
+ * @returns {void}
115
+ */
116
+ function logServerPort(address, port) {
117
+ let logMessage = `Appium REST http interface listener started on ` + `${address}:${port}`;
89
118
  logger.info(logMessage);
90
119
  }
91
120
 
92
- async function main (args = null) {
93
- let parser = getParser();
121
+ /**
122
+ * Gets a list of `updateServer` functions from all extensions
123
+ * @param {DriverNameMap} driverClasses
124
+ * @param {PluginNameMap} pluginClasses
125
+ * @returns {import('@appium/types').UpdateServerCallback[]}
126
+ */
127
+ function getServerUpdaters(driverClasses, pluginClasses) {
128
+ return _.compact(_.map([...driverClasses.keys(), ...pluginClasses.keys()], 'updateServer'));
129
+ }
130
+
131
+ /**
132
+ * Makes a big `MethodMap` from all the little `MethodMap`s in the extensions
133
+ * @param {DriverNameMap} driverClasses
134
+ * @param {PluginNameMap} pluginClasses
135
+ * @returns {import('@appium/types').MethodMap}
136
+ */
137
+ function getExtraMethodMap(driverClasses, pluginClasses) {
138
+ return [...driverClasses.keys(), ...pluginClasses.keys()].reduce(
139
+ (map, klass) => ({
140
+ ...map,
141
+ ...(klass.newMethodMap ?? {}),
142
+ }),
143
+ {}
144
+ );
145
+ }
146
+
147
+ /**
148
+ * @template [T=WithServerSubcommand]
149
+ * @param {Args<T>} args
150
+ * @returns {args is Args<WithServerSubcommand>}
151
+ */
152
+ function areServerCommandArgs(args) {
153
+ return args.subcommand === SERVER_SUBCOMMAND;
154
+ }
155
+
156
+ /**
157
+ * Initializes Appium, but does not start the server.
158
+ *
159
+ * Use this to get at the configuration schema.
160
+ *
161
+ * If `args` contains a non-empty `subcommand` which is not `server`, this function will return an empty object.
162
+ *
163
+ * @template [T=WithServerSubcommand]
164
+ * @param {Args<T>} [args] - Partial args (progammatic usage only)
165
+ * @returns {Promise<ServerInitResult | ExtCommandInitResult>}
166
+ * @example
167
+ * import {init, getSchema} from 'appium';
168
+ * const options = {}; // config object
169
+ * await init(options);
170
+ * const schema = getSchema(); // entire config schema including plugins and drivers
171
+ */
172
+ async function init(args) {
173
+ const appiumHome = args?.appiumHome ?? (await resolveAppiumHome());
174
+
175
+ const {driverConfig, pluginConfig} = await loadExtensions(appiumHome);
176
+
177
+ const parser = getParser();
94
178
  let throwInsteadOfExit = false;
95
- if (args) {
96
- // a containing package passed in their own args, let's fill them out
97
- // with defaults
98
- args = Object.assign({}, getDefaultServerArgs(), args);
179
+ /** @type {Args<T>} */
180
+ let preConfigArgs;
99
181
 
182
+ if (args) {
100
183
  // if we have a containing package instead of running as a CLI process,
101
184
  // that package might not appreciate us calling 'process.exit' willy-
102
185
  // nilly, so give it the option to have us throw instead of exit
@@ -105,80 +188,164 @@ async function main (args = null) {
105
188
  // but remove it since it's not a real server arg per se
106
189
  delete args.throwInsteadOfExit;
107
190
  }
191
+ preConfigArgs = {...args, subcommand: args.subcommand ?? SERVER_SUBCOMMAND};
108
192
  } else {
109
193
  // otherwise parse from CLI
110
- args = parser.parseArgs();
194
+ preConfigArgs = /** @type {Args<T>} */ (parser.parseArgs());
111
195
  }
112
- await logsinkInit(args);
113
196
 
114
- // if the user has requested the 'driver' CLI, don't run the normal server,
115
- // but instead pass control to the driver CLI
116
- if (args.subcommand === DRIVER_TYPE || args.subcommand === PLUGIN_TYPE) {
117
- await runExtensionCommand(args, args.subcommand);
118
- process.exit();
197
+ const configResult = await readConfigFile(preConfigArgs.configFile);
198
+
199
+ if (!_.isEmpty(configResult.errors)) {
200
+ throw new Error(
201
+ `Errors in config file ${configResult.filepath}:\n ${
202
+ configResult.reason ?? configResult.errors
203
+ }`
204
+ );
119
205
  }
120
206
 
121
- if (args.logFilters) {
122
- const {issues, rules} = await logFactory.loadSecureValuesPreprocessingRules(args.logFilters);
123
- if (!_.isEmpty(issues)) {
124
- throw new Error(`The log filtering rules config '${args.logFilters}' has issues: ` +
125
- JSON.stringify(issues, null, 2));
207
+ // merge config and apply defaults.
208
+ // the order of precendece is:
209
+ // 1. command line args
210
+ // 2. config file
211
+ // 3. defaults from config file.
212
+ if (areServerCommandArgs(preConfigArgs)) {
213
+ const defaults = getDefaultsForSchema(false);
214
+
215
+ /** @type {ParsedArgs} */
216
+ const serverArgs = _.defaultsDeep(preConfigArgs, configResult.config?.server, defaults);
217
+
218
+ if (preConfigArgs.showConfig) {
219
+ showConfig(getNonDefaultServerArgs(preConfigArgs), configResult, defaults, serverArgs);
220
+ return {};
126
221
  }
127
- if (_.isEmpty(rules)) {
128
- logger.warn(`Found no log filtering rules in '${args.logFilters}'. Is that expected?`);
129
- } else {
130
- logger.info(`Loaded ${util.pluralize('filtering rule', rules.length, true)} from '${args.logFilters}'`);
222
+
223
+ await logsinkInit(serverArgs);
224
+
225
+ if (serverArgs.logFilters) {
226
+ const {issues, rules} = await logFactory.loadSecureValuesPreprocessingRules(
227
+ serverArgs.logFilters
228
+ );
229
+ if (!_.isEmpty(issues)) {
230
+ throw new Error(
231
+ `The log filtering rules config '${serverArgs.logFilters}' has issues: ` +
232
+ JSON.stringify(issues, null, 2)
233
+ );
234
+ }
235
+ if (_.isEmpty(rules)) {
236
+ logger.warn(
237
+ `Found no log filtering rules in '${serverArgs.logFilters}'. Is that expected?`
238
+ );
239
+ } else {
240
+ logger.info(
241
+ `Loaded ${util.pluralize('filtering rule', rules.length, true)} from '${
242
+ serverArgs.logFilters
243
+ }'`
244
+ );
245
+ }
131
246
  }
247
+
248
+ const appiumDriver = new AppiumDriver(serverArgs);
249
+ // set the config on the umbrella driver so it can match drivers to caps
250
+ appiumDriver.driverConfig = driverConfig;
251
+ await preflightChecks(serverArgs, throwInsteadOfExit);
252
+
253
+ return /** @type {ServerInitResult} */ ({
254
+ appiumDriver,
255
+ parsedArgs: serverArgs,
256
+ driverConfig,
257
+ pluginConfig,
258
+ });
259
+ } else {
260
+ const extensionCommandArgs = /** @type {Args<import('appium/types').WithExtSubcommand>} */ (
261
+ preConfigArgs
262
+ );
263
+ // if the user has requested the 'driver' CLI, don't run the normal server,
264
+ // but instead pass control to the driver CLI
265
+ if (preConfigArgs.subcommand === DRIVER_TYPE) {
266
+ await runExtensionCommand(extensionCommandArgs, driverConfig);
267
+ return {};
268
+ }
269
+ if (preConfigArgs.subcommand === PLUGIN_TYPE) {
270
+ await runExtensionCommand(extensionCommandArgs, pluginConfig);
271
+ return {};
272
+ }
273
+ /* istanbul ignore next */
274
+ return {}; // should never happen
132
275
  }
276
+ }
277
+
278
+ /**
279
+ * Initializes Appium's config. Starts server if appropriate and resolves the
280
+ * server instance if so; otherwise resolves w/ `undefined`.
281
+ * @template [T=WithServerSubcommand]
282
+ * @param {Args<T>} [args] - Arguments from CLI or otherwise
283
+ * @returns {Promise<import('@appium/types').AppiumServer|undefined>}
284
+ */
285
+ async function main(args) {
286
+ const {appiumDriver, parsedArgs, pluginConfig, driverConfig} = /** @type {ServerInitResult} */ (
287
+ await init(args)
288
+ );
133
289
 
134
- let appiumDriver = new AppiumDriver(args);
135
- const driverConfig = new DriverConfig(args.appiumHome);
136
- const pluginConfig = new PluginConfig(args.appiumHome);
137
- appiumDriver.driverConfig = driverConfig;
138
- await preflightChecks({parser, args, driverConfig, pluginConfig, throwInsteadOfExit});
139
- await logStartupInfo(parser, args);
290
+ if (!appiumDriver || !parsedArgs || !pluginConfig || !driverConfig) {
291
+ // if this branch is taken, we've run a different subcommand, so there's nothing
292
+ // left to do here.
293
+ return;
294
+ }
295
+
296
+ const pluginClasses = getActivePlugins(pluginConfig, parsedArgs.usePlugins);
297
+ // set the active plugins on the umbrella driver so it can use them for commands
298
+ appiumDriver.pluginClasses = pluginClasses;
299
+
300
+ await logStartupInfo(parsedArgs);
140
301
  let routeConfiguringFunction = makeRouter(appiumDriver);
141
302
 
142
- // find any plugin name which has been installed, and which has been requested for activation by
143
- // using the --plugins flag, and turn each one into an instantiated plugin object, so we can send
144
- // them as objects to the server init. we also want to send/assign them to the umbrella driver so
145
- // it can use them to wrap command execution
146
- const plugins = Object.keys(pluginConfig.installedExtensions).filter((pluginName) =>
147
- _.includes(args.plugins, pluginName) ||
148
- (args.plugins.length === 1 && args.plugins[0] === USE_ALL_PLUGINS)
149
- ).map((pluginName) => {
150
- try {
151
- const PluginClass = pluginConfig.require(pluginName);
152
- return new PluginClass(pluginName);
153
- } catch (err) {
154
- logger.error(`Could not load plugin '${pluginName}', so it will not be available. Error ` +
155
- `in loading the plugin was: ${err}`);
156
- return false;
157
- }
158
- }).filter(Boolean);
159
- appiumDriver.plugins = plugins;
303
+ const driverClasses = getActiveDrivers(driverConfig, parsedArgs.useDrivers);
304
+ const serverUpdaters = getServerUpdaters(driverClasses, pluginClasses);
305
+ const extraMethodMap = getExtraMethodMap(driverClasses, pluginClasses);
160
306
 
161
- let server = await baseServer({
307
+ const serverOpts = {
162
308
  routeConfiguringFunction,
163
- port: args.port,
164
- hostname: args.address,
165
- allowCors: args.allowCors,
166
- basePath: args.basePath,
167
- plugins,
168
- });
169
- if (args.allowCors) {
170
- logger.warn('You have enabled CORS requests from any host. Be careful not ' +
171
- 'to visit sites which could maliciously try to start Appium ' +
172
- 'sessions on your machine');
309
+ port: parsedArgs.port,
310
+ hostname: parsedArgs.address,
311
+ allowCors: parsedArgs.allowCors,
312
+ basePath: parsedArgs.basePath,
313
+ serverUpdaters,
314
+ extraMethodMap,
315
+ };
316
+ if (parsedArgs.keepAliveTimeout) {
317
+ serverOpts.keepAliveTimeout = parsedArgs.keepAliveTimeout * 1000;
173
318
  }
174
- appiumDriver.server = server;
319
+ let server;
175
320
  try {
176
- // TODO prelaunch if args.launch is set
177
- // TODO: startAlertSocket(server, appiumServer);
321
+ server = await baseServer(serverOpts);
322
+ } catch (err) {
323
+ logger.error(
324
+ `Could not configure Appium server. It's possible that a driver or plugin tried ` +
325
+ `to update the server and failed. Original error: ${err.message}`
326
+ );
327
+ logger.debug(err.stack);
328
+ return process.exit(1);
329
+ }
178
330
 
331
+ if (parsedArgs.allowCors) {
332
+ logger.warn(
333
+ 'You have enabled CORS requests from any host. Be careful not ' +
334
+ 'to visit sites which could maliciously try to start Appium ' +
335
+ 'sessions on your machine'
336
+ );
337
+ }
338
+ appiumDriver.server = server;
339
+ try {
179
340
  // configure as node on grid, if necessary
180
- if (args.nodeconfig !== null) {
181
- await registerNode(args.nodeconfig, args.address, args.port, args.basePath);
341
+ // falsy values should not cause this to run
342
+ if (parsedArgs.nodeconfig) {
343
+ await registerNode(
344
+ parsedArgs.nodeconfig,
345
+ parsedArgs.address,
346
+ parsedArgs.port,
347
+ parsedArgs.basePath
348
+ );
182
349
  }
183
350
  } catch (err) {
184
351
  await server.close();
@@ -186,7 +353,7 @@ async function main (args = null) {
186
353
  }
187
354
 
188
355
  for (const signal of ['SIGINT', 'SIGTERM']) {
189
- process.once(signal, async function onSignal () {
356
+ process.once(signal, async function onSignal() {
190
357
  logger.info(`Received ${signal} - shutting down`);
191
358
  try {
192
359
  await appiumDriver.deleteAllSessions({
@@ -202,15 +369,56 @@ async function main (args = null) {
202
369
  });
203
370
  }
204
371
 
205
- logServerPort(args.address, args.port);
372
+ logServerPort(parsedArgs.address, parsedArgs.port);
206
373
  driverConfig.print();
207
- pluginConfig.print(plugins);
374
+ pluginConfig.print([...pluginClasses.values()]);
208
375
 
209
376
  return server;
210
377
  }
211
378
 
379
+ // NOTE: this is here for backwards compat for any scripts referencing `main.js` directly
380
+ // (more specifically, `build/lib/main.js`)
381
+ // the executable is now `../index.js`, so that module will typically be `require.main`.
212
382
  if (require.main === module) {
213
383
  asyncify(main);
214
384
  }
215
385
 
216
- export { main };
386
+ // everything below here is intended to be a public API.
387
+ export {readConfigFile} from './config-file';
388
+ export {finalizeSchema, getSchema, validate} from './schema/schema';
389
+ export {main, init, resolveAppiumHome};
390
+
391
+ /**
392
+ * @typedef {import('@appium/types').DriverType} DriverType
393
+ * @typedef {import('@appium/types').PluginType} PluginType
394
+ * @typedef {import('@appium/types').DriverClass} DriverClass
395
+ * @typedef {import('@appium/types').PluginClass} PluginClass
396
+ * @typedef {import('appium/types').WithServerSubcommand} WithServerSubcommand
397
+ * @typedef {import('./extension').DriverNameMap} DriverNameMap
398
+ * @typedef {import('./extension').PluginNameMap} PluginNameMap
399
+ */
400
+
401
+ /**
402
+ * Literally an empty object
403
+ * @typedef { {} } ExtCommandInitResult
404
+ */
405
+
406
+ /**
407
+ * @typedef ServerInitData
408
+ * @property {import('./appium').AppiumDriver} appiumDriver - The Appium driver
409
+ * @property {import('appium/types').ParsedArgs} parsedArgs - The parsed arguments
410
+ */
411
+
412
+ /**
413
+ * @typedef {ServerInitData & import('./extension').ExtensionConfigs} ServerInitResult
414
+ */
415
+
416
+ /**
417
+ * @template [T=WithServerSubcommand]
418
+ * @typedef {import('appium/types').Args<T>} Args
419
+ */
420
+
421
+ /**
422
+ * @template [T=WithServerSubcommand]
423
+ * @typedef {import('appium/types').ParsedArgs<T>} ParsedArgs
424
+ */