appium 2.0.0-beta.5 → 2.0.0-beta.53
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.
- package/README.md +156 -63
- package/build/lib/appium.d.ts +226 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +694 -439
- package/build/lib/appium.js.map +1 -0
- package/build/lib/cli/args.d.ts +17 -0
- package/build/lib/cli/args.d.ts.map +1 -0
- package/build/lib/cli/args.js +253 -319
- package/build/lib/cli/args.js.map +1 -0
- package/build/lib/cli/driver-command.d.ts +102 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -0
- package/build/lib/cli/driver-command.js +126 -81
- package/build/lib/cli/driver-command.js.map +1 -0
- package/build/lib/cli/extension-command.d.ts +385 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +731 -383
- package/build/lib/cli/extension-command.js.map +1 -0
- package/build/lib/cli/extension.d.ts +23 -0
- package/build/lib/cli/extension.d.ts.map +1 -0
- package/build/lib/cli/extension.js +71 -54
- package/build/lib/cli/extension.js.map +1 -0
- package/build/lib/cli/parser.d.ts +84 -0
- package/build/lib/cli/parser.d.ts.map +1 -0
- package/build/lib/cli/parser.js +240 -128
- package/build/lib/cli/parser.js.map +1 -0
- package/build/lib/cli/plugin-command.d.ts +99 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -0
- package/build/lib/cli/plugin-command.js +120 -81
- package/build/lib/cli/plugin-command.js.map +1 -0
- package/build/lib/cli/utils.d.ts +29 -0
- package/build/lib/cli/utils.d.ts.map +1 -0
- package/build/lib/cli/utils.js +72 -51
- package/build/lib/cli/utils.js.map +1 -0
- package/build/lib/config-file.d.ts +100 -0
- package/build/lib/config-file.d.ts.map +1 -0
- package/build/lib/config-file.js +207 -0
- package/build/lib/config-file.js.map +1 -0
- package/build/lib/config.d.ts +49 -0
- package/build/lib/config.d.ts.map +1 -0
- package/build/lib/config.js +265 -201
- package/build/lib/config.js.map +1 -0
- package/build/lib/constants.d.ts +49 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +66 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/extension/driver-config.d.ts +82 -0
- package/build/lib/extension/driver-config.d.ts.map +1 -0
- package/build/lib/extension/driver-config.js +212 -0
- package/build/lib/extension/driver-config.js.map +1 -0
- package/build/lib/extension/extension-config.d.ts +249 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +581 -0
- package/build/lib/extension/extension-config.js.map +1 -0
- package/build/lib/extension/index.d.ts +48 -0
- package/build/lib/extension/index.d.ts.map +1 -0
- package/build/lib/extension/index.js +105 -0
- package/build/lib/extension/index.js.map +1 -0
- package/build/lib/extension/manifest-migrations.d.ts +27 -0
- package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
- package/build/lib/extension/manifest-migrations.js +118 -0
- package/build/lib/extension/manifest-migrations.js.map +1 -0
- package/build/lib/extension/manifest.d.ts +145 -0
- package/build/lib/extension/manifest.d.ts.map +1 -0
- package/build/lib/extension/manifest.js +521 -0
- package/build/lib/extension/manifest.js.map +1 -0
- package/build/lib/extension/package-changed.d.ts +11 -0
- package/build/lib/extension/package-changed.d.ts.map +1 -0
- package/build/lib/extension/package-changed.js +62 -0
- package/build/lib/extension/package-changed.js.map +1 -0
- package/build/lib/extension/plugin-config.d.ts +56 -0
- package/build/lib/extension/plugin-config.d.ts.map +1 -0
- package/build/lib/extension/plugin-config.js +102 -0
- package/build/lib/extension/plugin-config.js.map +1 -0
- package/build/lib/grid-register.d.ts +10 -0
- package/build/lib/grid-register.d.ts.map +1 -0
- package/build/lib/grid-register.js +122 -144
- package/build/lib/grid-register.js.map +1 -0
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +5 -17
- package/build/lib/logger.js.map +1 -0
- package/build/lib/logsink.d.ts +4 -0
- package/build/lib/logsink.d.ts.map +1 -0
- package/build/lib/logsink.js +190 -187
- package/build/lib/logsink.js.map +1 -0
- package/build/lib/main.d.ts +62 -0
- package/build/lib/main.d.ts.map +1 -0
- package/build/lib/main.js +348 -228
- package/build/lib/main.js.map +1 -0
- package/build/lib/schema/arg-spec.d.ts +143 -0
- package/build/lib/schema/arg-spec.d.ts.map +1 -0
- package/build/lib/schema/arg-spec.js +164 -0
- package/build/lib/schema/arg-spec.js.map +1 -0
- package/build/lib/schema/cli-args.d.ts +19 -0
- package/build/lib/schema/cli-args.d.ts.map +1 -0
- package/build/lib/schema/cli-args.js +217 -0
- package/build/lib/schema/cli-args.js.map +1 -0
- package/build/lib/schema/cli-transformers.d.ts +5 -0
- package/build/lib/schema/cli-transformers.d.ts.map +1 -0
- package/build/lib/schema/cli-transformers.js +124 -0
- package/build/lib/schema/cli-transformers.js.map +1 -0
- package/build/lib/schema/index.d.ts +3 -0
- package/build/lib/schema/index.d.ts.map +1 -0
- package/build/lib/schema/index.js +19 -0
- package/build/lib/schema/index.js.map +1 -0
- package/build/lib/schema/keywords.d.ts +24 -0
- package/build/lib/schema/keywords.d.ts.map +1 -0
- package/build/lib/schema/keywords.js +128 -0
- package/build/lib/schema/keywords.js.map +1 -0
- package/build/lib/schema/schema.d.ts +259 -0
- package/build/lib/schema/schema.d.ts.map +1 -0
- package/build/lib/schema/schema.js +615 -0
- package/build/lib/schema/schema.js.map +1 -0
- package/build/lib/utils.d.ts +121 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +351 -273
- package/build/lib/utils.js.map +1 -0
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/types/cli.d.ts +134 -0
- package/build/types/cli.d.ts.map +1 -0
- package/build/types/cli.js +3 -0
- package/build/types/cli.js.map +1 -0
- package/build/types/index.d.ts +15 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +19 -0
- package/build/types/index.js.map +1 -0
- package/build/types/manifest/base.d.ts +135 -0
- package/build/types/manifest/base.d.ts.map +1 -0
- package/build/types/manifest/base.js +3 -0
- package/build/types/manifest/base.js.map +1 -0
- package/build/types/manifest/index.d.ts +19 -0
- package/build/types/manifest/index.d.ts.map +1 -0
- package/build/types/manifest/index.js +40 -0
- package/build/types/manifest/index.js.map +1 -0
- package/build/types/manifest/v3.d.ts +139 -0
- package/build/types/manifest/v3.d.ts.map +1 -0
- package/build/types/manifest/v3.js +3 -0
- package/build/types/manifest/v3.js.map +1 -0
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/index.js +11 -0
- package/lib/appium.js +535 -186
- package/lib/cli/args.js +267 -422
- package/lib/cli/driver-command.js +126 -23
- package/lib/cli/extension-command.js +679 -271
- package/lib/cli/extension.js +48 -17
- package/lib/cli/parser.js +263 -83
- package/lib/cli/plugin-command.js +115 -20
- package/lib/cli/utils.js +24 -10
- package/lib/config-file.js +220 -0
- package/lib/config.js +244 -110
- package/lib/constants.js +71 -0
- package/lib/extension/driver-config.js +250 -0
- package/lib/extension/extension-config.js +682 -0
- package/lib/extension/index.js +116 -0
- package/lib/extension/manifest-migrations.js +120 -0
- package/lib/extension/manifest.js +573 -0
- package/lib/extension/package-changed.js +64 -0
- package/lib/extension/plugin-config.js +112 -0
- package/lib/grid-register.js +49 -35
- package/lib/logger.js +1 -2
- package/lib/logsink.js +64 -38
- package/lib/main.js +321 -101
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +238 -0
- package/lib/schema/cli-transformers.js +119 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/keywords.js +136 -0
- package/lib/schema/schema.js +722 -0
- package/lib/utils.js +291 -167
- package/package.json +83 -84
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +237 -0
- package/support.d.ts +1 -0
- package/support.js +13 -0
- package/tsconfig.json +25 -0
- package/types/cli.ts +193 -0
- package/types/index.ts +20 -0
- package/types/manifest/README.md +30 -0
- package/types/manifest/base.ts +158 -0
- package/types/manifest/index.ts +27 -0
- package/types/manifest/v3.ts +161 -0
- package/CHANGELOG.md +0 -3515
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/npm.js +0 -208
- package/build/lib/cli/parser-helpers.js +0 -82
- package/build/lib/driver-config.js +0 -77
- package/build/lib/drivers.js +0 -96
- package/build/lib/extension-config.js +0 -253
- package/build/lib/plugin-config.js +0 -59
- package/build/lib/plugins.js +0 -14
- package/lib/cli/npm.js +0 -184
- package/lib/cli/parser-helpers.js +0 -79
- package/lib/driver-config.js +0 -46
- package/lib/drivers.js +0 -81
- package/lib/extension-config.js +0 -209
- package/lib/plugin-config.js +0 -34
- package/lib/plugins.js +0 -10
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import betterAjvErrors from '@sidvind/better-ajv-errors';
|
|
2
|
+
import {lilconfig} from 'lilconfig';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import yaml from 'yaml';
|
|
5
|
+
import {getSchema, validate} from './schema/schema';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* lilconfig loader to handle `.yaml` files
|
|
9
|
+
* @type {import('lilconfig').LoaderSync}
|
|
10
|
+
*/
|
|
11
|
+
function yamlLoader(filepath, content) {
|
|
12
|
+
return yaml.parse(content);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A cache of the raw config file (a JSON string) at a filepath.
|
|
17
|
+
* This is used for better error reporting.
|
|
18
|
+
* Note that config files needn't be JSON, but it helps if they are.
|
|
19
|
+
* @type {Map<string,RawJson>}
|
|
20
|
+
*/
|
|
21
|
+
const rawConfig = new Map();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Custom JSON loader that caches the raw config file (for use with `better-ajv-errors`).
|
|
25
|
+
* If it weren't for this cache, this would be unnecessary.
|
|
26
|
+
* @type {import('lilconfig').LoaderSync}
|
|
27
|
+
*/
|
|
28
|
+
function jsonLoader(filepath, content) {
|
|
29
|
+
rawConfig.set(filepath, content);
|
|
30
|
+
return JSON.parse(content);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Loads a config file from an explicit path
|
|
35
|
+
* @param {LilconfigAsyncSearcher} lc - lilconfig instance
|
|
36
|
+
* @param {string} filepath - Path to config file
|
|
37
|
+
* @returns {Promise<import('lilconfig').LilconfigResult>}
|
|
38
|
+
*/
|
|
39
|
+
async function loadConfigFile(lc, filepath) {
|
|
40
|
+
try {
|
|
41
|
+
// removing "await" will cause any rejection to _not_ be caught in this block!
|
|
42
|
+
return await lc.load(filepath);
|
|
43
|
+
} catch (/** @type {unknown} */ err) {
|
|
44
|
+
if (/** @type {NodeJS.ErrnoException} */ (err).code === 'ENOENT') {
|
|
45
|
+
/** @type {NodeJS.ErrnoException} */ (
|
|
46
|
+
err
|
|
47
|
+
).message = `Config file not found at user-provided path: ${filepath}`;
|
|
48
|
+
throw err;
|
|
49
|
+
} else if (err instanceof SyntaxError) {
|
|
50
|
+
// generally invalid JSON
|
|
51
|
+
err.message = `Config file at user-provided path ${filepath} is invalid:\n${err.message}`;
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Searches for a config file
|
|
60
|
+
* @param {LilconfigAsyncSearcher} lc - lilconfig instance
|
|
61
|
+
* @returns {Promise<import('lilconfig').LilconfigResult>}
|
|
62
|
+
*/
|
|
63
|
+
async function searchConfigFile(lc) {
|
|
64
|
+
return await lc.search();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Given an array of errors and the result of loading a config file, generate a
|
|
69
|
+
* helpful string for the user.
|
|
70
|
+
*
|
|
71
|
+
* - If `opts` contains a `json` property, this should be the original JSON
|
|
72
|
+
* _string_ of the config file. This is only applicable if the config file
|
|
73
|
+
* was in JSON format. If present, it will associate line numbers with errors.
|
|
74
|
+
* - If `errors` happens to be empty, this will throw.
|
|
75
|
+
* @param {import('ajv').ErrorObject[]} errors - Non-empty array of errors. Required.
|
|
76
|
+
* @param {ReadConfigFileResult['config']|any} [config] -
|
|
77
|
+
* Configuration & metadata
|
|
78
|
+
* @param {FormatConfigErrorsOptions} [opts]
|
|
79
|
+
* @throws {TypeError} If `errors` is empty
|
|
80
|
+
* @returns {string}
|
|
81
|
+
*/
|
|
82
|
+
export function formatErrors(errors = [], config = {}, opts = {}) {
|
|
83
|
+
if (errors && !errors.length) {
|
|
84
|
+
throw new TypeError('Array of errors must be non-empty');
|
|
85
|
+
}
|
|
86
|
+
return betterAjvErrors(getSchema(opts.schemaId), config, errors, {
|
|
87
|
+
json: opts.json,
|
|
88
|
+
format: 'cli',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Given an optional path, read a config file. Validates the config file.
|
|
94
|
+
*
|
|
95
|
+
* Call {@link validate} if you already have a config object.
|
|
96
|
+
* @param {string} [filepath] - Path to config file, if we have one
|
|
97
|
+
* @param {ReadConfigFileOptions} [opts] - Options
|
|
98
|
+
* @public
|
|
99
|
+
* @returns {Promise<ReadConfigFileResult>} Contains config and filepath, if found, and any errors
|
|
100
|
+
*/
|
|
101
|
+
export async function readConfigFile(filepath, opts = {}) {
|
|
102
|
+
const lc = lilconfig('appium', {
|
|
103
|
+
loaders: {
|
|
104
|
+
'.yaml': yamlLoader,
|
|
105
|
+
'.yml': yamlLoader,
|
|
106
|
+
'.json': jsonLoader,
|
|
107
|
+
noExt: jsonLoader,
|
|
108
|
+
},
|
|
109
|
+
packageProp: 'appiumConfig',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const result = filepath ? await loadConfigFile(lc, filepath) : await searchConfigFile(lc);
|
|
113
|
+
|
|
114
|
+
if (result?.filepath && !result?.isEmpty) {
|
|
115
|
+
const {pretty = true} = opts;
|
|
116
|
+
try {
|
|
117
|
+
let configResult;
|
|
118
|
+
const errors = validate(result.config);
|
|
119
|
+
if (_.isEmpty(errors)) {
|
|
120
|
+
configResult = {...result, errors};
|
|
121
|
+
} else {
|
|
122
|
+
const reason = formatErrors(errors, result.config, {
|
|
123
|
+
json: rawConfig.get(result.filepath),
|
|
124
|
+
pretty,
|
|
125
|
+
});
|
|
126
|
+
configResult = reason ? {...result, errors, reason} : {...result, errors};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// normalize (to camel case) all top-level property names of the config file
|
|
130
|
+
configResult.config = normalizeConfig(/** @type {AppiumConfig} */ (configResult.config));
|
|
131
|
+
|
|
132
|
+
return configResult;
|
|
133
|
+
} finally {
|
|
134
|
+
// clean up the raw config file cache, which is only kept to better report errors.
|
|
135
|
+
rawConfig.delete(result.filepath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return result ?? {};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Convert schema property names to either a) the value of the `appiumCliDest` property, if any; or b) camel-case
|
|
143
|
+
* @param {AppiumConfig} config - Configuration object
|
|
144
|
+
* @returns {NormalizedAppiumConfig} New object with camel-cased keys (or `dest` keys).
|
|
145
|
+
*/
|
|
146
|
+
export function normalizeConfig(config) {
|
|
147
|
+
const schema = getSchema();
|
|
148
|
+
/**
|
|
149
|
+
* @param {AppiumConfig} config
|
|
150
|
+
* @param {string} [section] - Keypath (lodash `_.get()` style) to section of config. If omitted, assume root Appium config schema
|
|
151
|
+
* @todo Rewrite as a loop
|
|
152
|
+
* @returns Normalized section of config
|
|
153
|
+
*/
|
|
154
|
+
const normalize = (config, section) => {
|
|
155
|
+
const obj = _.isUndefined(section) ? config : _.get(config, section, config);
|
|
156
|
+
|
|
157
|
+
const mappedObj = _.mapKeys(obj, (__, prop) =>
|
|
158
|
+
_.get(schema, `properties.server.properties[${prop}].appiumCliDest`, _.camelCase(prop))
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return _.mapValues(mappedObj, (value, property) => {
|
|
162
|
+
const nextSection = section ? `${section}.${property}` : property;
|
|
163
|
+
return isSchemaTypeObject(schema.properties?.[property])
|
|
164
|
+
? normalize(config, nextSection)
|
|
165
|
+
: value;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Returns `true` if the schema prop references an object, or if it's an object itself
|
|
171
|
+
* @param {import('ajv').SchemaObject|object} schema - Referencing schema object
|
|
172
|
+
*/
|
|
173
|
+
const isSchemaTypeObject = (schema) => Boolean(schema?.properties || schema?.type === 'object');
|
|
174
|
+
|
|
175
|
+
return normalize(config);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Result of calling {@link readConfigFile}.
|
|
180
|
+
* @typedef ReadConfigFileResult
|
|
181
|
+
* @property {import('ajv').ErrorObject[]} [errors] - Validation errors
|
|
182
|
+
* @property {string} [filepath] - The path to the config file, if found
|
|
183
|
+
* @property {boolean} [isEmpty] - If `true`, the config file exists but is empty
|
|
184
|
+
* @property {NormalizedAppiumConfig} [config] - The parsed configuration
|
|
185
|
+
* @property {string|import('@sidvind/better-ajv-errors').IOutputError[]} [reason] - Human-readable error messages and suggestions. If the `pretty` option is `true`, this will be a nice string to print.
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Options for {@link readConfigFile}.
|
|
190
|
+
* @typedef ReadConfigFileOptions
|
|
191
|
+
* @property {boolean} [pretty=true] If `false`, do not use color and fancy formatting in the `reason` property of the {@link ReadConfigFileResult}. The value of `reason` is then suitable for machine-reading.
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* This is an `AsyncSearcher` which is inexplicably _not_ exported by the `lilconfig` type definition.
|
|
196
|
+
* @typedef {ReturnType<import('lilconfig')["lilconfig"]>} LilconfigAsyncSearcher
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The contents of an Appium config file. Generated from schema
|
|
201
|
+
* @typedef {import('@appium/types').AppiumConfig} AppiumConfig
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* The contents of an Appium config file with camelcased property names (and using `appiumCliDest` value if present). Generated from {@link AppiumConfig}
|
|
206
|
+
* @typedef {import('@appium/types').NormalizedAppiumConfig} NormalizedAppiumConfig
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The string should be a raw JSON string.
|
|
211
|
+
* @typedef {string} RawJson
|
|
212
|
+
*/
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Options for {@link formatErrors}.
|
|
216
|
+
* @typedef FormatConfigErrorsOptions
|
|
217
|
+
* @property {import('./config-file').RawJson} [json] - Raw JSON config (as string)
|
|
218
|
+
* @property {boolean} [pretty=true] - Whether to format errors as a CLI-friendly string
|
|
219
|
+
* @property {string} [schemaId] - Specific ID of a prop; otherwise entire schema
|
|
220
|
+
*/
|
package/lib/config.js
CHANGED
|
@@ -1,46 +1,78 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import _ from 'lodash';
|
|
2
|
-
import
|
|
3
|
-
import { mkdirp, fs, system } from 'appium-support';
|
|
3
|
+
import {system, fs} from '@appium/support';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
-
import {
|
|
6
|
-
import { rootDir } from './utils';
|
|
7
|
-
import logger from './logger';
|
|
5
|
+
import {exec} from 'teen_process';
|
|
8
6
|
import semver from 'semver';
|
|
7
|
+
import findUp from 'find-up';
|
|
8
|
+
import {getDefaultsForSchema, getAllArgSpecs} from './schema/schema';
|
|
9
9
|
|
|
10
|
+
const npmPackage = fs.readPackageJsonFrom(__dirname);
|
|
10
11
|
|
|
11
|
-
const npmPackage = require(path.resolve(rootDir, 'package.json'));
|
|
12
12
|
const APPIUM_VER = npmPackage.version;
|
|
13
13
|
const MIN_NODE_VERSION = npmPackage.engines.node;
|
|
14
|
+
const MIN_NPM_VERSION = npmPackage.engines.npm;
|
|
14
15
|
|
|
15
16
|
const GIT_META_ROOT = '.git';
|
|
16
17
|
const GIT_BINARY = `git${system.isWindows() ? '.exe' : ''}`;
|
|
17
18
|
const GITHUB_API = 'https://api.github.com/repos/appium/appium';
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @type {import('appium/types').BuildInfo}
|
|
22
|
+
*/
|
|
19
23
|
const BUILD_INFO = {
|
|
20
24
|
version: APPIUM_VER,
|
|
21
25
|
};
|
|
22
26
|
|
|
23
|
-
function getNodeVersion
|
|
24
|
-
return semver.coerce(process.version);
|
|
27
|
+
function getNodeVersion() {
|
|
28
|
+
return /** @type {import('semver').SemVer} */ (semver.coerce(process.version));
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Returns version of `npm`
|
|
33
|
+
* @returns {Promise<string>}
|
|
34
|
+
*/
|
|
35
|
+
async function getNpmVersion() {
|
|
36
|
+
const {stdout} = await exec(system.isWindows() ? 'npm.cmd' : 'npm', ['--version']);
|
|
37
|
+
return stdout.trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {boolean} [useGithubApiFallback]
|
|
42
|
+
*/
|
|
43
|
+
async function updateBuildInfo(useGithubApiFallback = false) {
|
|
28
44
|
const sha = await getGitRev(useGithubApiFallback);
|
|
29
45
|
if (!sha) {
|
|
30
46
|
return;
|
|
31
47
|
}
|
|
32
48
|
BUILD_INFO['git-sha'] = sha;
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
BUILD_INFO.built =
|
|
49
|
+
const buildTimestamp = await getGitTimestamp(sha, useGithubApiFallback);
|
|
50
|
+
if (buildTimestamp) {
|
|
51
|
+
BUILD_INFO.built = buildTimestamp;
|
|
36
52
|
}
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
/**
|
|
56
|
+
* Finds the Git metadata dir (see `GIT_META_ROOT`)
|
|
57
|
+
*
|
|
58
|
+
* This is needed because Appium cannot assume `package.json` and `.git` are in the same
|
|
59
|
+
* directory. Monorepos, see?
|
|
60
|
+
* @returns {Promise<string|undefined>} Path to dir or `undefined` if not found
|
|
61
|
+
*/
|
|
62
|
+
async function findGitRoot() {
|
|
63
|
+
return await findUp(GIT_META_ROOT, {cwd: rootDir, type: 'directory'});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {boolean} [useGithubApiFallback]
|
|
68
|
+
* @returns {Promise<string?>}
|
|
69
|
+
*/
|
|
70
|
+
async function getGitRev(useGithubApiFallback = false) {
|
|
71
|
+
const gitRoot = await findGitRoot();
|
|
72
|
+
if (gitRoot) {
|
|
41
73
|
try {
|
|
42
74
|
const {stdout} = await exec(GIT_BINARY, ['rev-parse', 'HEAD'], {
|
|
43
|
-
cwd:
|
|
75
|
+
cwd: gitRoot,
|
|
44
76
|
});
|
|
45
77
|
return stdout.trim();
|
|
46
78
|
} catch (ign) {}
|
|
@@ -50,28 +82,31 @@ async function getGitRev (useGithubApiFallback = false) {
|
|
|
50
82
|
return null;
|
|
51
83
|
}
|
|
52
84
|
|
|
85
|
+
// If the package folder is not a valid git repository
|
|
86
|
+
// then fetch the corresponding tag info from GitHub
|
|
53
87
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (name === `v${APPIUM_VER}` && commit && commit.sha) {
|
|
62
|
-
return commit.sha;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
88
|
+
return (
|
|
89
|
+
await axios.get(`${GITHUB_API}/git/refs/tags/appium@${APPIUM_VER}`, {
|
|
90
|
+
headers: {
|
|
91
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
).data?.object?.sha;
|
|
66
95
|
} catch (ign) {}
|
|
67
96
|
return null;
|
|
68
97
|
}
|
|
69
98
|
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
/**
|
|
100
|
+
* @param {string} commitSha
|
|
101
|
+
* @param {boolean} [useGithubApiFallback]
|
|
102
|
+
* @returns {Promise<string?>}
|
|
103
|
+
*/
|
|
104
|
+
async function getGitTimestamp(commitSha, useGithubApiFallback = false) {
|
|
105
|
+
const gitRoot = await findGitRoot();
|
|
106
|
+
if (gitRoot) {
|
|
72
107
|
try {
|
|
73
108
|
const {stdout} = await exec(GIT_BINARY, ['show', '-s', '--format=%ci', commitSha], {
|
|
74
|
-
cwd:
|
|
109
|
+
cwd: gitRoot,
|
|
75
110
|
});
|
|
76
111
|
return stdout.trim();
|
|
77
112
|
} catch (ign) {}
|
|
@@ -82,46 +117,51 @@ async function getGitTimestamp (commitSha, useGithubApiFallback = false) {
|
|
|
82
117
|
}
|
|
83
118
|
|
|
84
119
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return resBodyObj.commit.committer.date;
|
|
93
|
-
}
|
|
94
|
-
if (resBodyObj.commit.author && resBodyObj.commit.author.date) {
|
|
95
|
-
return resBodyObj.commit.author.date;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
120
|
+
return (
|
|
121
|
+
await axios.get(`${GITHUB_API}/git/tags/${commitSha}`, {
|
|
122
|
+
headers: {
|
|
123
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
).data?.tagger?.date;
|
|
98
127
|
} catch (ign) {}
|
|
99
128
|
return null;
|
|
100
129
|
}
|
|
101
130
|
|
|
102
131
|
/**
|
|
103
|
-
*
|
|
132
|
+
* Mutable object containing Appium build information. By default it
|
|
104
133
|
* only contains the Appium version, but is updated with the build timestamp
|
|
105
134
|
* and git commit hash asynchronously as soon as `updateBuildInfo` is called
|
|
106
135
|
* and succeeds.
|
|
136
|
+
* @returns {import('appium/types').BuildInfo}
|
|
107
137
|
*/
|
|
108
|
-
function getBuildInfo
|
|
138
|
+
function getBuildInfo() {
|
|
109
139
|
return BUILD_INFO;
|
|
110
140
|
}
|
|
111
141
|
|
|
112
|
-
function checkNodeOk
|
|
142
|
+
function checkNodeOk() {
|
|
113
143
|
const version = getNodeVersion();
|
|
114
144
|
if (!semver.satisfies(version, MIN_NODE_VERSION)) {
|
|
115
|
-
|
|
145
|
+
throw new Error(
|
|
146
|
+
`Node version must be at least ${MIN_NODE_VERSION}; current is ${version.version}`
|
|
147
|
+
);
|
|
116
148
|
}
|
|
117
149
|
}
|
|
118
150
|
|
|
119
|
-
function
|
|
151
|
+
export async function checkNpmOk() {
|
|
152
|
+
const npmVersion = await getNpmVersion();
|
|
153
|
+
if (!semver.satisfies(npmVersion, MIN_NPM_VERSION)) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`npm version must be at least ${MIN_NPM_VERSION}; current is ${npmVersion}. Run "npm install -g npm" to upgrade.`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function warnNodeDeprecations() {
|
|
120
161
|
/**
|
|
121
162
|
* Uncomment this section to get node version deprecation warnings
|
|
122
163
|
* Also add test cases to config-specs.js to cover the cases added
|
|
123
164
|
**/
|
|
124
|
-
|
|
125
165
|
// const version = getNodeVersion();
|
|
126
166
|
// if (version.major < 8) {
|
|
127
167
|
// logger.warn(`Appium support for versions of node < ${version.major} has been ` +
|
|
@@ -130,83 +170,177 @@ function warnNodeDeprecations () {
|
|
|
130
170
|
// }
|
|
131
171
|
}
|
|
132
172
|
|
|
133
|
-
async function
|
|
173
|
+
async function showBuildInfo() {
|
|
134
174
|
await updateBuildInfo(true);
|
|
135
175
|
console.log(JSON.stringify(getBuildInfo())); // eslint-disable-line no-console
|
|
136
176
|
}
|
|
137
177
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
178
|
+
/**
|
|
179
|
+
* Returns k/v pairs of server arguments which are _not_ the defaults.
|
|
180
|
+
* @param {Args} parsedArgs
|
|
181
|
+
* @returns {Args}
|
|
182
|
+
*/
|
|
183
|
+
function getNonDefaultServerArgs(parsedArgs) {
|
|
184
|
+
/**
|
|
185
|
+
* Flattens parsed args into a single level object for comparison with
|
|
186
|
+
* flattened defaults across server args and extension args.
|
|
187
|
+
* @param {Args} args
|
|
188
|
+
* @returns {Record<string, { value: any, argSpec: ArgSpec }>}
|
|
189
|
+
*/
|
|
190
|
+
const flatten = (args) => {
|
|
191
|
+
const argSpecs = getAllArgSpecs();
|
|
192
|
+
const flattened = _.reduce(
|
|
193
|
+
[...argSpecs.values()],
|
|
194
|
+
(acc, argSpec) => {
|
|
195
|
+
if (_.has(args, argSpec.dest)) {
|
|
196
|
+
acc[argSpec.dest] = {value: _.get(args, argSpec.dest), argSpec};
|
|
197
|
+
}
|
|
198
|
+
return acc;
|
|
199
|
+
},
|
|
200
|
+
/** @type {Record<string, { value: any, argSpec: ArgSpec }>} */ ({})
|
|
201
|
+
);
|
|
148
202
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
logger.error(`Port '${portName}' must be greater than 0 and less than 65536. Currently ${port}`);
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
203
|
+
return flattened;
|
|
204
|
+
};
|
|
154
205
|
|
|
155
|
-
|
|
156
|
-
// arguments that cannot both be set
|
|
157
|
-
let exclusives = [
|
|
158
|
-
['noReset', 'fullReset'],
|
|
159
|
-
['ipa', 'safari'],
|
|
160
|
-
['app', 'safari'],
|
|
161
|
-
['forceIphone', 'forceIpad'],
|
|
162
|
-
['deviceName', 'defaultDevice']
|
|
163
|
-
];
|
|
164
|
-
|
|
165
|
-
for (let exSet of exclusives) {
|
|
166
|
-
let numFoundInArgs = 0;
|
|
167
|
-
for (let opt of exSet) {
|
|
168
|
-
if (_.has(args, opt) && args[opt]) {
|
|
169
|
-
numFoundInArgs++;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (numFoundInArgs > 1) {
|
|
173
|
-
throw new Error(`You can't pass in more than one argument from the ` +
|
|
174
|
-
`set ${JSON.stringify(exSet)}, since they are ` +
|
|
175
|
-
`mutually exclusive`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
206
|
+
const args = flatten(parsedArgs);
|
|
178
207
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
};
|
|
208
|
+
// hopefully these function names are descriptive enough
|
|
209
|
+
const typesDiffer = /** @param {string} dest */ (dest) =>
|
|
210
|
+
typeof args[dest].value !== typeof defaultsFromSchema[dest];
|
|
211
|
+
|
|
212
|
+
const defaultValueIsArray = /** @param {string} dest */ (dest) =>
|
|
213
|
+
_.isArray(defaultsFromSchema[dest]);
|
|
214
|
+
|
|
215
|
+
const argsValueIsArray = /** @param {string} dest */ (dest) => _.isArray(args[dest].value);
|
|
216
|
+
|
|
217
|
+
const arraysDiffer = /** @param {string} dest */ (dest) =>
|
|
218
|
+
_.gt(_.size(_.difference(args[dest].value, defaultsFromSchema[dest])), 0);
|
|
219
|
+
|
|
220
|
+
const valuesDiffer = /** @param {string} dest */ (dest) =>
|
|
221
|
+
args[dest].value !== defaultsFromSchema[dest];
|
|
187
222
|
|
|
188
|
-
const
|
|
223
|
+
const defaultIsDefined = /** @param {string} dest */ (dest) =>
|
|
224
|
+
!_.isUndefined(defaultsFromSchema[dest]);
|
|
189
225
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
226
|
+
// note that `_.overEvery` is like an "AND", and `_.overSome` is like an "OR"
|
|
227
|
+
|
|
228
|
+
const argValueNotArrayOrArraysDiffer = _.overSome([_.negate(argsValueIsArray), arraysDiffer]);
|
|
229
|
+
|
|
230
|
+
const defaultValueNotArrayAndValuesDiffer = _.overEvery([
|
|
231
|
+
_.negate(defaultValueIsArray),
|
|
232
|
+
valuesDiffer,
|
|
233
|
+
]);
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* This used to be a hideous conditional, but it's broken up into a hideous function instead.
|
|
237
|
+
* hopefully this makes things a little more understandable.
|
|
238
|
+
* - checks if the default value is defined
|
|
239
|
+
* - if so, and the default is not an array:
|
|
240
|
+
* - ensures the types are the same
|
|
241
|
+
* - ensures the values are equal
|
|
242
|
+
* - if so, and the default is an array:
|
|
243
|
+
* - ensures the args value is an array
|
|
244
|
+
* - ensures the args values do not differ from the default values
|
|
245
|
+
* @type {(dest: string) => boolean}
|
|
246
|
+
*/
|
|
247
|
+
const isNotDefault = _.overEvery([
|
|
248
|
+
defaultIsDefined,
|
|
249
|
+
_.overSome([
|
|
250
|
+
typesDiffer,
|
|
251
|
+
_.overEvery([defaultValueIsArray, argValueNotArrayOrArraysDiffer]),
|
|
252
|
+
defaultValueNotArrayAndValuesDiffer,
|
|
253
|
+
]),
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
const defaultsFromSchema = getDefaultsForSchema(true);
|
|
257
|
+
|
|
258
|
+
return _.reduce(
|
|
259
|
+
_.pickBy(args, (__, key) => isNotDefault(key)),
|
|
260
|
+
// explodes the flattened object back into nested one
|
|
261
|
+
(acc, {value, argSpec}) => _.set(acc, argSpec.dest, value),
|
|
262
|
+
/** @type {Args} */ ({})
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Compacts an object for {@link showConfig}:
|
|
268
|
+
* 1. Removes `subcommand` key/value
|
|
269
|
+
* 2. Removes `undefined` values
|
|
270
|
+
* 3. Removes empty objects (but not `false` values)
|
|
271
|
+
* Does not operate recursively.
|
|
272
|
+
*/
|
|
273
|
+
const compactConfig = _.partial(
|
|
274
|
+
_.omitBy,
|
|
275
|
+
_,
|
|
276
|
+
(value, key) =>
|
|
277
|
+
key === 'subcommand' || _.isUndefined(value) || (_.isObject(value) && _.isEmpty(value))
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Shows a breakdown of the current config after CLI params, config file loaded & defaults applied.
|
|
282
|
+
*
|
|
283
|
+
* The actual shape of `preConfigParsedArgs` and `defaults` does not matter for the purposes of this function,
|
|
284
|
+
* but it's intended to be called with values of type {@link ParsedArgs} and `DefaultValues<true>`, respectively.
|
|
285
|
+
*
|
|
286
|
+
* @param {Partial<ParsedArgs>} nonDefaultPreConfigParsedArgs - Parsed CLI args (or param to `init()`) before config & defaults applied
|
|
287
|
+
* @param {import('./config-file').ReadConfigFileResult} configResult - Result of attempting to load a config file. _Must_ be normalized
|
|
288
|
+
* @param {Partial<ParsedArgs>} defaults - Configuration defaults from schemas
|
|
289
|
+
* @param {ParsedArgs} parsedArgs - Entire parsed args object
|
|
290
|
+
*/
|
|
291
|
+
function showConfig(nonDefaultPreConfigParsedArgs, configResult, defaults, parsedArgs) {
|
|
292
|
+
console.log('Appium Configuration\n');
|
|
293
|
+
console.log('from defaults:\n');
|
|
294
|
+
console.dir(compactConfig(defaults));
|
|
295
|
+
if (configResult.config) {
|
|
296
|
+
console.log(`\nfrom config file at ${configResult.filepath}:\n`);
|
|
297
|
+
console.dir(compactConfig(configResult.config));
|
|
298
|
+
} else {
|
|
299
|
+
console.log(`\n(no configuration file loaded)`);
|
|
300
|
+
}
|
|
301
|
+
const compactedNonDefaultPreConfigArgs = compactConfig(nonDefaultPreConfigParsedArgs);
|
|
302
|
+
if (_.isEmpty(compactedNonDefaultPreConfigArgs)) {
|
|
303
|
+
console.log(`\n(no CLI parameters provided)`);
|
|
304
|
+
} else {
|
|
305
|
+
console.log('\nvia CLI or function call:\n');
|
|
306
|
+
console.dir(compactedNonDefaultPreConfigArgs);
|
|
196
307
|
}
|
|
308
|
+
console.log('\nfinal configuration:\n');
|
|
309
|
+
console.dir(compactConfig(parsedArgs));
|
|
197
310
|
}
|
|
198
311
|
|
|
199
|
-
|
|
312
|
+
/**
|
|
313
|
+
* @param {string} tmpDir
|
|
314
|
+
*/
|
|
315
|
+
async function validateTmpDir(tmpDir) {
|
|
200
316
|
try {
|
|
201
|
-
await mkdirp(tmpDir);
|
|
317
|
+
await fs.mkdirp(tmpDir);
|
|
202
318
|
} catch (e) {
|
|
203
|
-
throw new Error(
|
|
204
|
-
|
|
319
|
+
throw new Error(
|
|
320
|
+
`We could not ensure that the temp dir you specified ` +
|
|
321
|
+
`(${tmpDir}) exists. Please make sure it's writeable.`
|
|
322
|
+
);
|
|
205
323
|
}
|
|
206
324
|
}
|
|
207
325
|
|
|
326
|
+
const rootDir = fs.findRoot(__dirname);
|
|
327
|
+
|
|
208
328
|
export {
|
|
209
|
-
getBuildInfo,
|
|
210
|
-
|
|
211
|
-
|
|
329
|
+
getBuildInfo,
|
|
330
|
+
checkNodeOk,
|
|
331
|
+
showBuildInfo,
|
|
332
|
+
warnNodeDeprecations,
|
|
333
|
+
validateTmpDir,
|
|
334
|
+
getNonDefaultServerArgs,
|
|
335
|
+
getGitRev,
|
|
336
|
+
APPIUM_VER,
|
|
337
|
+
updateBuildInfo,
|
|
338
|
+
showConfig,
|
|
339
|
+
rootDir,
|
|
212
340
|
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @typedef {import('appium/types').ParsedArgs} ParsedArgs
|
|
344
|
+
* @typedef {import('appium/types').Args} Args
|
|
345
|
+
* @typedef {import('./schema/arg-spec').ArgSpec} ArgSpec
|
|
346
|
+
*/
|