appium 2.0.0-beta.25 → 2.0.0-beta.28
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/build/lib/appium.d.ts +215 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +94 -101
- package/build/lib/cli/args.d.ts +20 -0
- package/build/lib/cli/args.d.ts.map +1 -0
- package/build/lib/cli/args.js +19 -39
- package/build/lib/cli/driver-command.d.ts +36 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -0
- package/build/lib/cli/driver-command.js +10 -13
- package/build/lib/cli/extension-command.d.ts +345 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +117 -94
- package/build/lib/cli/extension.d.ts +14 -0
- package/build/lib/cli/extension.d.ts.map +1 -0
- package/build/lib/cli/extension.js +14 -22
- package/build/lib/cli/parser.d.ts +79 -0
- package/build/lib/cli/parser.d.ts.map +1 -0
- package/build/lib/cli/parser.js +9 -19
- package/build/lib/cli/plugin-command.d.ts +39 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -0
- package/build/lib/cli/plugin-command.js +9 -14
- 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 +2 -4
- 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 +2 -4
- package/build/lib/config.d.ts +40 -0
- package/build/lib/config.d.ts.map +1 -0
- package/build/lib/config.js +8 -7
- package/build/lib/constants.d.ts +48 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +60 -0
- package/build/lib/extension/driver-config.d.ts +84 -0
- package/build/lib/extension/driver-config.d.ts.map +1 -0
- package/build/lib/extension/driver-config.js +190 -0
- package/build/lib/extension/extension-config.d.ts +170 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +297 -0
- package/build/lib/extension/index.d.ts +39 -0
- package/build/lib/extension/index.d.ts.map +1 -0
- package/build/lib/extension/index.js +77 -0
- package/build/lib/extension/manifest.d.ts +174 -0
- package/build/lib/extension/manifest.d.ts.map +1 -0
- package/build/lib/extension/manifest.js +246 -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 +68 -0
- package/build/lib/extension/plugin-config.d.ts +62 -0
- package/build/lib/extension/plugin-config.d.ts.map +1 -0
- package/build/lib/extension/plugin-config.js +87 -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 +2 -4
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +2 -4
- package/build/lib/logsink.d.ts +4 -0
- package/build/lib/logsink.d.ts.map +1 -0
- package/build/lib/logsink.js +2 -4
- package/build/lib/main.d.ts +51 -0
- package/build/lib/main.d.ts.map +1 -0
- package/build/lib/main.js +40 -68
- 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 +11 -14
- 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 +2 -4
- 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 +2 -4
- 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 +2 -4
- 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 +2 -4
- 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 +57 -39
- package/build/lib/utils.d.ts +66 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +6 -35
- package/build/tsconfig.tsbuildinfo +1 -0
- package/lib/appium.js +188 -117
- package/lib/cli/args.js +19 -24
- package/lib/cli/driver-command.js +19 -8
- package/lib/cli/extension-command.js +314 -184
- package/lib/cli/extension.js +18 -16
- package/lib/cli/parser.js +7 -16
- package/lib/cli/plugin-command.js +16 -7
- package/lib/cli/utils.js +1 -1
- package/lib/config-file.js +6 -7
- package/lib/config.js +17 -12
- package/lib/constants.js +78 -0
- package/lib/extension/driver-config.js +249 -0
- package/lib/extension/extension-config.js +458 -0
- package/lib/extension/index.js +102 -0
- package/lib/extension/manifest.js +486 -0
- package/lib/extension/package-changed.js +63 -0
- package/lib/extension/plugin-config.js +113 -0
- package/lib/grid-register.js +4 -4
- package/lib/logsink.js +4 -0
- package/lib/main.js +54 -92
- package/lib/schema/arg-spec.js +11 -7
- package/lib/schema/cli-args.js +1 -1
- package/lib/schema/cli-transformers.js +0 -1
- package/lib/schema/keywords.js +1 -2
- package/lib/schema/schema.js +62 -31
- package/lib/utils.js +48 -45
- package/package.json +30 -24
- package/{postinstall.js → scripts/postinstall.js} +1 -1
- package/types/appium-manifest.d.ts +61 -0
- package/types/cli.d.ts +134 -0
- package/types/extension.d.ts +56 -0
- package/types/external-manifest.d.ts +58 -0
- package/types/index.d.ts +7 -0
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/check-npm-pack-files.js +0 -23
- package/build/commands-yml/parse.js +0 -319
- package/build/commands-yml/validator.js +0 -130
- package/build/index.js +0 -19
- package/build/lib/appium-config.schema.json +0 -0
- package/build/lib/cli/npm.js +0 -220
- package/build/lib/driver-config.js +0 -100
- package/build/lib/drivers.js +0 -100
- package/build/lib/ext-config-io.js +0 -165
- package/build/lib/extension-config.js +0 -320
- package/build/lib/plugin-config.js +0 -69
- package/build/lib/plugins.js +0 -18
- package/build/lib/schema/appium-config-schema.js +0 -253
- package/build/postinstall.js +0 -90
- package/build/test/cli/cli-e2e-specs.js +0 -221
- package/build/test/cli/cli-helpers.js +0 -86
- package/build/test/cli/cli-specs.js +0 -71
- package/build/test/cli/fixtures/test-driver/package.json +0 -27
- package/build/test/cli/schema-args-specs.js +0 -48
- package/build/test/cli/schema-e2e-specs.js +0 -47
- package/build/test/config-e2e-specs.js +0 -112
- package/build/test/config-file-e2e-specs.js +0 -191
- package/build/test/config-file-specs.js +0 -281
- package/build/test/config-specs.js +0 -258
- package/build/test/driver-e2e-specs.js +0 -435
- package/build/test/driver-specs.js +0 -386
- package/build/test/ext-config-io-specs.js +0 -181
- package/build/test/extension-config-specs.js +0 -365
- package/build/test/fixtures/allow-feat.txt +0 -5
- package/build/test/fixtures/caps.json +0 -3
- package/build/test/fixtures/config/allow-insecure.txt +0 -3
- package/build/test/fixtures/config/appium.config.bad-nodeconfig.json +0 -5
- package/build/test/fixtures/config/appium.config.bad.json +0 -32
- package/build/test/fixtures/config/appium.config.ext-good.json +0 -9
- package/build/test/fixtures/config/appium.config.ext-unknown-props.json +0 -10
- package/build/test/fixtures/config/appium.config.good.js +0 -40
- package/build/test/fixtures/config/appium.config.good.json +0 -33
- package/build/test/fixtures/config/appium.config.good.yaml +0 -30
- package/build/test/fixtures/config/appium.config.invalid.json +0 -31
- package/build/test/fixtures/config/appium.config.security-array.json +0 -5
- package/build/test/fixtures/config/appium.config.security-delimited.json +0 -5
- package/build/test/fixtures/config/appium.config.security-path.json +0 -5
- package/build/test/fixtures/config/driver-fake.config.json +0 -8
- package/build/test/fixtures/config/nodeconfig.json +0 -3
- package/build/test/fixtures/config/plugin-fake.config.json +0 -0
- package/build/test/fixtures/default-args.js +0 -35
- package/build/test/fixtures/deny-feat.txt +0 -5
- package/build/test/fixtures/driver.schema.js +0 -20
- package/build/test/fixtures/extensions.yaml +0 -27
- package/build/test/fixtures/flattened-schema.js +0 -532
- package/build/test/fixtures/plugin.schema.js +0 -20
- package/build/test/fixtures/schema-with-extensions.js +0 -28
- package/build/test/grid-register-specs.js +0 -74
- package/build/test/helpers.js +0 -75
- package/build/test/logger-specs.js +0 -76
- package/build/test/npm-specs.js +0 -20
- package/build/test/parser-specs.js +0 -319
- package/build/test/plugin-e2e-specs.js +0 -316
- package/build/test/schema/arg-spec-specs.js +0 -70
- package/build/test/schema/cli-args-specs.js +0 -408
- package/build/test/schema/schema-specs.js +0 -407
- package/build/test/utils-specs.js +0 -288
- package/lib/cli/npm.js +0 -251
- package/lib/driver-config.js +0 -101
- package/lib/drivers.js +0 -84
- package/lib/ext-config-io.js +0 -287
- package/lib/extension-config.js +0 -366
- package/lib/plugin-config.js +0 -63
- package/lib/plugins.js +0 -13
- package/lib/schema/appium-config-schema.js +0 -287
- package/types/appium-config.d.ts +0 -197
- package/types/types.d.ts +0 -206
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/// <reference path="../../types/appium-manifest.d.ts" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Module containing {@link Manifest} which handles reading & writing of extension config files.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { env, fs } from '@appium/support';
|
|
8
|
+
import _ from 'lodash';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import YAML from 'yaml';
|
|
11
|
+
import { DRIVER_TYPE, PLUGIN_TYPE } from '../constants';
|
|
12
|
+
import log from '../logger';
|
|
13
|
+
import { INSTALL_TYPE_NPM } from './extension-config';
|
|
14
|
+
import { packageDidChange } from './package-changed';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Default depth to search in directory tree for whatever it is we're looking for.
|
|
18
|
+
*
|
|
19
|
+
* It's 4 because smaller numbers didn't work.
|
|
20
|
+
*/
|
|
21
|
+
const DEFAULT_SEARCH_DEPTH = 4;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Default options for {@link findExtensions}.
|
|
25
|
+
* @type {Readonly<import('klaw').Options>}
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_FIND_EXTENSIONS_OPTS = Object.freeze({
|
|
28
|
+
depthLimit: DEFAULT_SEARCH_DEPTH,
|
|
29
|
+
/* istanbul ignore next */
|
|
30
|
+
filter: (filepath) => !path.basename(filepath).startsWith('.'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Current configuration schema revision!
|
|
35
|
+
*/
|
|
36
|
+
const CONFIG_SCHEMA_REV = 2;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The name of the prop (`drivers`) used in `extensions.yaml` for drivers.
|
|
40
|
+
* @type {`${typeof DRIVER_TYPE}s`}
|
|
41
|
+
*/
|
|
42
|
+
const CONFIG_DATA_DRIVER_KEY = `${DRIVER_TYPE}s`;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The name of the prop (`plugins`) used in `extensions.yaml` for plugins.
|
|
46
|
+
* @type {`${typeof PLUGIN_TYPE}s`}
|
|
47
|
+
*/
|
|
48
|
+
const CONFIG_DATA_PLUGIN_KEY = `${PLUGIN_TYPE}s`;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @type {Readonly<ManifestData>}
|
|
52
|
+
*/
|
|
53
|
+
const INITIAL_MANIFEST_DATA = Object.freeze({
|
|
54
|
+
[CONFIG_DATA_DRIVER_KEY]: Object.freeze({}),
|
|
55
|
+
[CONFIG_DATA_PLUGIN_KEY]: Object.freeze({}),
|
|
56
|
+
schemaRev: CONFIG_SCHEMA_REV,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Given a `package.json` return `true` if it represents an Appium Extension (either a driver or plugin).
|
|
61
|
+
*
|
|
62
|
+
* The `package.json` must have an `appium` property which is an object.
|
|
63
|
+
* @param {any} value
|
|
64
|
+
* @returns {value is ExtPackageJson<ExtensionType>}
|
|
65
|
+
*/
|
|
66
|
+
function isExtension (value) {
|
|
67
|
+
return (
|
|
68
|
+
_.isPlainObject(value) &&
|
|
69
|
+
_.isPlainObject(value.appium) &&
|
|
70
|
+
_.isString(value.name) &&
|
|
71
|
+
_.isString(value.version)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Given a `package.json`, return `true` if it represents an Appium Driver.
|
|
76
|
+
*
|
|
77
|
+
* To be considered a driver, a `package.json` must have a fields
|
|
78
|
+
* `appium.driverName`, `appium.automationName` and `appium.platformNames`.
|
|
79
|
+
* @param {any} value - Value to test
|
|
80
|
+
* @returns {value is ExtPackageJson<DriverType>}
|
|
81
|
+
*/
|
|
82
|
+
function isDriver (value) {
|
|
83
|
+
return (
|
|
84
|
+
isExtension(value) &&
|
|
85
|
+
_.isString(_.get(value, 'appium.driverName')) &&
|
|
86
|
+
_.isString(_.get(value, 'appium.automationName')) &&
|
|
87
|
+
_.isArray(_.get(value, 'appium.platformNames'))
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Given a `package.json`, return `true` if it represents an Appium Plugin.
|
|
93
|
+
*
|
|
94
|
+
* To be considered a plugin, a `package.json` must have an `appium.pluginName` field.
|
|
95
|
+
* @param {any} value - Value to test
|
|
96
|
+
* @returns {value is ExtPackageJson<PluginType>}
|
|
97
|
+
*/
|
|
98
|
+
function isPlugin (value) {
|
|
99
|
+
return isExtension(value) && _.isString(_.get(value, 'appium.pluginName'));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Handles reading & writing of extension config files.
|
|
104
|
+
*
|
|
105
|
+
* Only one instance of this class exists per value of `APPIUM_HOME`.
|
|
106
|
+
*/
|
|
107
|
+
export class Manifest {
|
|
108
|
+
/**
|
|
109
|
+
* The entire contents of a parsed YAML extension config file.
|
|
110
|
+
*
|
|
111
|
+
* Contains proxies for automatic persistence on disk
|
|
112
|
+
* @type {ManifestData}
|
|
113
|
+
* @private
|
|
114
|
+
*/
|
|
115
|
+
_data;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Path to `APPIUM_HOME`.
|
|
119
|
+
* @private
|
|
120
|
+
* @type {Readonly<string>}
|
|
121
|
+
*/
|
|
122
|
+
_appiumHome;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Path to `extensions.yaml`
|
|
126
|
+
* @type {string}
|
|
127
|
+
* Not set until {@link Manifest.read} is called.
|
|
128
|
+
*/
|
|
129
|
+
_manifestPath;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Helps avoid writing multiple times.
|
|
133
|
+
*
|
|
134
|
+
* If this is `undefined`, calling {@link Manifest.write} will cause it to be
|
|
135
|
+
* set to a `Promise`. When the call to `write()` is complete, the `Promise`
|
|
136
|
+
* will resolve and then this value will be set to `undefined`. Concurrent calls
|
|
137
|
+
* made while this value is a `Promise` will return the `Promise` itself.
|
|
138
|
+
* @private
|
|
139
|
+
* @type {Promise<boolean>|undefined}
|
|
140
|
+
*/
|
|
141
|
+
_writing;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Helps avoid reading multiple times.
|
|
145
|
+
*
|
|
146
|
+
* If this is `undefined`, calling {@link Manifest.read} will cause it to be
|
|
147
|
+
* set to a `Promise`. When the call to `read()` is complete, the `Promise`
|
|
148
|
+
* will resolve and then this value will be set to `undefined`. Concurrent calls
|
|
149
|
+
* made while this value is a `Promise` will return the `Promise` itself.
|
|
150
|
+
* @private
|
|
151
|
+
* @type {Promise<void>|undefined}
|
|
152
|
+
*/
|
|
153
|
+
_reading;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Sets internal data to a fresh clone of {@link INITIAL_MANIFEST_DATA}
|
|
157
|
+
*
|
|
158
|
+
* Use {@link Manifest.getInstance} instead.
|
|
159
|
+
* @param {string} appiumHome
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
constructor (appiumHome) {
|
|
163
|
+
this._appiumHome = appiumHome;
|
|
164
|
+
this._data = _.cloneDeep(INITIAL_MANIFEST_DATA);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Returns a new or existing {@link Manifest} instance, based on the value of `appiumHome`.
|
|
169
|
+
*
|
|
170
|
+
* Maintains one instance per value of `appiumHome`.
|
|
171
|
+
* @param {string} appiumHome - Path to `APPIUM_HOME`
|
|
172
|
+
* @returns {Manifest}
|
|
173
|
+
*/
|
|
174
|
+
static getInstance = _.memoize(function _getInstance (
|
|
175
|
+
appiumHome,
|
|
176
|
+
) {
|
|
177
|
+
return new Manifest(appiumHome);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Searches `APPIUM_HOME` for installed extensions and adds them to the manifest.
|
|
182
|
+
* @param {SyncWithInstalledExtensionsOpts} opts
|
|
183
|
+
* @returns {Promise<boolean>} `true` if any extensions were added, `false` otherwise.
|
|
184
|
+
*/
|
|
185
|
+
async syncWithInstalledExtensions ({depthLimit = DEFAULT_SEARCH_DEPTH} = {}) {
|
|
186
|
+
const walkOpts = _.defaults({depthLimit}, DEFAULT_FIND_EXTENSIONS_OPTS);
|
|
187
|
+
// this could be parallelized, but we can't use fs.walk as an async iterator
|
|
188
|
+
let didChange = false;
|
|
189
|
+
for await (const {stats, path: filepath} of fs.walk(
|
|
190
|
+
this._appiumHome,
|
|
191
|
+
walkOpts,
|
|
192
|
+
)) {
|
|
193
|
+
if (filepath !== this._appiumHome && stats.isDirectory()) {
|
|
194
|
+
try {
|
|
195
|
+
const pkg = await env.readPackageInDir(filepath);
|
|
196
|
+
if (pkg && isExtension(pkg)) {
|
|
197
|
+
// it's possible that this extension already exists in the manifest,
|
|
198
|
+
// so only update `didChange` if it's new.
|
|
199
|
+
const added = this.addExtensionFromPackage(
|
|
200
|
+
pkg,
|
|
201
|
+
path.join(filepath, 'package.json'),
|
|
202
|
+
);
|
|
203
|
+
didChange = didChange || added;
|
|
204
|
+
}
|
|
205
|
+
} catch {}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return didChange;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Returns `true` if driver with name `name` is registered.
|
|
213
|
+
* @param {string} name - Driver name
|
|
214
|
+
* @returns {boolean}
|
|
215
|
+
*/
|
|
216
|
+
hasDriver (name) {
|
|
217
|
+
return Boolean(this._data.drivers[name]);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Returns `true` if plugin with name `name` is registered.
|
|
222
|
+
* @param {string} name - Plugin name
|
|
223
|
+
* @returns {boolean}
|
|
224
|
+
*/
|
|
225
|
+
hasPlugin (name) {
|
|
226
|
+
return Boolean(this._data.plugins[name]);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Given a path to a `package.json`, add it as either a driver or plugin to the manifest.
|
|
231
|
+
*
|
|
232
|
+
* Will _not_ overwrite existing entries.
|
|
233
|
+
* @template {ExtensionType} ExtType
|
|
234
|
+
* @param {ExtPackageJson<ExtType>} pkgJson
|
|
235
|
+
* @param {string} pkgPath
|
|
236
|
+
* @returns {boolean} - `true` upon success, `false` if the extension is already registered.
|
|
237
|
+
*/
|
|
238
|
+
addExtensionFromPackage (pkgJson, pkgPath) {
|
|
239
|
+
/**
|
|
240
|
+
* @type {InternalMetadata}
|
|
241
|
+
*/
|
|
242
|
+
const internal = {
|
|
243
|
+
pkgName: pkgJson.name,
|
|
244
|
+
version: pkgJson.version,
|
|
245
|
+
installType: INSTALL_TYPE_NPM,
|
|
246
|
+
installSpec: `${pkgJson.name}@${pkgJson.version}`,
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
if (isDriver(pkgJson)) {
|
|
250
|
+
if (!this.hasDriver(pkgJson.appium.driverName)) {
|
|
251
|
+
this.addExtension(DRIVER_TYPE, pkgJson.appium.driverName, {
|
|
252
|
+
..._.omit(pkgJson.appium, 'driverName'),
|
|
253
|
+
...internal
|
|
254
|
+
});
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
} else if (isPlugin(pkgJson)) {
|
|
259
|
+
if (!this.hasPlugin(pkgJson.appium.pluginName)) {
|
|
260
|
+
this.addExtension(PLUGIN_TYPE, pkgJson.appium.pluginName, {
|
|
261
|
+
..._.omit(pkgJson.appium, 'pluginName'),
|
|
262
|
+
...internal,
|
|
263
|
+
});
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
return false;
|
|
267
|
+
} else {
|
|
268
|
+
throw new TypeError(
|
|
269
|
+
`The extension in ${path.dirname(
|
|
270
|
+
pkgPath,
|
|
271
|
+
)} is neither a valid driver nor a valid plugin.`,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Adds an extension to the manifest as was installed by the `appium` CLI. The
|
|
278
|
+
* `extData`, `extType`, and `extName` have already been determined.
|
|
279
|
+
*
|
|
280
|
+
* See {@link Manifest.addExtensionFromPackage} for adding an extension from an on-disk package.
|
|
281
|
+
* @template {ExtensionType} ExtType
|
|
282
|
+
* @param {ExtType} extType - `driver` or `plugin`
|
|
283
|
+
* @param {string} extName - Name of extension
|
|
284
|
+
* @param {ExtManifest<ExtType>} extData - Extension metadata
|
|
285
|
+
* @returns {void}
|
|
286
|
+
*/
|
|
287
|
+
addExtension (extType, extName, extData) {
|
|
288
|
+
this._data[`${extType}s`][extName] = extData;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Returns the APPIUM_HOME path
|
|
293
|
+
*/
|
|
294
|
+
get appiumHome () {
|
|
295
|
+
return this._appiumHome;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Returns the path to the manifest file
|
|
300
|
+
*/
|
|
301
|
+
get manifestPath () {
|
|
302
|
+
return this._manifestPath;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Returns extension data for a particular type.
|
|
307
|
+
*
|
|
308
|
+
* @template {ExtensionType} ExtType
|
|
309
|
+
* @param {ExtType} extType
|
|
310
|
+
* @returns {ExtRecord<ExtType>}
|
|
311
|
+
*/
|
|
312
|
+
getExtensionData (extType) {
|
|
313
|
+
return this._data[/** @type {string} */ (`${extType}s`)];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Reads manifest from disk and _overwrites_ the internal data.
|
|
318
|
+
*
|
|
319
|
+
* If the manifest does not exist on disk, an {@link INITIAL_MANIFEST_DATA "empty"} manifest file will be created.
|
|
320
|
+
*
|
|
321
|
+
* If `APPIUM_HOME` contains a `package.json` with an `appium` dependency, then a hash of the `package.json` will be taken. If this hash differs from the last hash, the contents of `APPIUM_HOME/node_modules` will be scanned for extensions that may have been installed outside of the `appium` CLI. Any found extensions will be added to the manifest file, and if so, the manifest file will be written to disk.
|
|
322
|
+
*
|
|
323
|
+
* Only one read operation should happen at a time. This is controlled via the {@link Manifest._reading} property.
|
|
324
|
+
* @returns {Promise<ManifestData>} The data
|
|
325
|
+
*/
|
|
326
|
+
async read () {
|
|
327
|
+
if (this._reading) {
|
|
328
|
+
await this._reading;
|
|
329
|
+
return this._data;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
this._reading = (async () => {
|
|
333
|
+
/** @type {ManifestData} */
|
|
334
|
+
let data;
|
|
335
|
+
let isNewFile = false;
|
|
336
|
+
await this._setManifestPath();
|
|
337
|
+
try {
|
|
338
|
+
log.debug(`Reading ${this._manifestPath}...`);
|
|
339
|
+
const yaml = await fs.readFile(this._manifestPath, 'utf8');
|
|
340
|
+
data = YAML.parse(yaml);
|
|
341
|
+
} catch (err) {
|
|
342
|
+
if (err.code === 'ENOENT') {
|
|
343
|
+
data = _.cloneDeep(INITIAL_MANIFEST_DATA);
|
|
344
|
+
isNewFile = true;
|
|
345
|
+
} else {
|
|
346
|
+
if (this._manifestPath) {
|
|
347
|
+
throw new Error(
|
|
348
|
+
`Appium had trouble loading the extension installation ` +
|
|
349
|
+
`cache file (${this._manifestPath}). It may be invalid YAML. Specific error: ${err.message}`,
|
|
350
|
+
);
|
|
351
|
+
} else {
|
|
352
|
+
throw new Error(
|
|
353
|
+
`Appium encountered an unknown problem. Specific error: ${err.message}`,
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
this._data = data;
|
|
360
|
+
let installedExtensionsChanged = false;
|
|
361
|
+
if (
|
|
362
|
+
await env.hasAppiumDependency(this.appiumHome) &&
|
|
363
|
+
(await packageDidChange(this.appiumHome))
|
|
364
|
+
) {
|
|
365
|
+
installedExtensionsChanged = await this.syncWithInstalledExtensions();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (isNewFile || installedExtensionsChanged) {
|
|
369
|
+
await this.write();
|
|
370
|
+
}
|
|
371
|
+
})();
|
|
372
|
+
try {
|
|
373
|
+
await this._reading;
|
|
374
|
+
return this._data;
|
|
375
|
+
} finally {
|
|
376
|
+
this._reading = undefined;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Ensures {@link Manifest._manifestPath} is set.
|
|
382
|
+
*
|
|
383
|
+
* Creates the directory if necessary.
|
|
384
|
+
* @private
|
|
385
|
+
* @returns {Promise<string>}
|
|
386
|
+
*/
|
|
387
|
+
async _setManifestPath () {
|
|
388
|
+
if (!this._manifestPath) {
|
|
389
|
+
this._manifestPath = await env.resolveManifestPath(this._appiumHome);
|
|
390
|
+
|
|
391
|
+
/* istanbul ignore if */
|
|
392
|
+
if (path.relative(this._appiumHome, this._manifestPath).startsWith('.')) {
|
|
393
|
+
throw new Error(
|
|
394
|
+
`Mismatch between location of APPIUM_HOME and manifest file. APPIUM_HOME: ${this.appiumHome}, manifest file: ${this._manifestPath}`,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return this._manifestPath;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Writes the data if it need s writing.
|
|
404
|
+
*
|
|
405
|
+
* If the `schemaRev` prop needs updating, the file will be written.
|
|
406
|
+
*
|
|
407
|
+
* @todo If this becomes too much of a bottleneck, throttle it.
|
|
408
|
+
* @returns {Promise<boolean>} Whether the data was written
|
|
409
|
+
*/
|
|
410
|
+
async write () {
|
|
411
|
+
if (this._writing) {
|
|
412
|
+
return this._writing;
|
|
413
|
+
}
|
|
414
|
+
this._writing = (async () => {
|
|
415
|
+
await this._setManifestPath();
|
|
416
|
+
try {
|
|
417
|
+
await fs.mkdirp(path.dirname(this._manifestPath));
|
|
418
|
+
} catch (err) {
|
|
419
|
+
throw new Error(
|
|
420
|
+
`Appium could not create the directory for the manifest file: ${path.dirname(
|
|
421
|
+
this._manifestPath,
|
|
422
|
+
)}. Original error: ${err.message}`,
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
await fs.writeFile(
|
|
427
|
+
this._manifestPath,
|
|
428
|
+
YAML.stringify(this._data),
|
|
429
|
+
'utf8',
|
|
430
|
+
);
|
|
431
|
+
return true;
|
|
432
|
+
} catch (err) {
|
|
433
|
+
throw new Error(
|
|
434
|
+
`Appium could not write to manifest at ${this._manifestPath} using APPIUM_HOME ${this._appiumHome}. ` +
|
|
435
|
+
`Please ensure it is writable. Original error: ${err.message}`,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
})();
|
|
439
|
+
try {
|
|
440
|
+
return await this._writing;
|
|
441
|
+
} finally {
|
|
442
|
+
this._writing = undefined;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Type of the string referring to a driver (typically as a key or type string)
|
|
449
|
+
* @typedef {import('../../types').DriverType} DriverType
|
|
450
|
+
*/
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* Type of the string referring to a plugin (typically as a key or type string)
|
|
454
|
+
* @typedef {import('../../types').PluginType} PluginType
|
|
455
|
+
*/
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @typedef SyncWithInstalledExtensionsOpts
|
|
459
|
+
* @property {number} [depthLimit] - Maximum depth to recurse into subdirectories
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* @typedef {import('../../types/appium-manifest').ManifestData} ManifestData
|
|
464
|
+
* @typedef {import('../../types/appium-manifest').InternalMetadata} InternalMetadata
|
|
465
|
+
*/
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @template T
|
|
469
|
+
* @typedef {import('../../types/external-manifest').ExtPackageJson<T>} ExtPackageJson
|
|
470
|
+
*/
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @template T
|
|
474
|
+
* @typedef {import('../../types/appium-manifest').ExtManifest<T>} ExtManifest
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* @template T
|
|
479
|
+
* @typedef {import('../../types/appium-manifest').ExtRecord<T>} ExtRecord
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Either `driver` or `plugin` rn
|
|
484
|
+
* @typedef {import('../../types').ExtensionType} ExtensionType
|
|
485
|
+
*/
|
|
486
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
|
|
2
|
+
import { fs } from '@appium/support';
|
|
3
|
+
import { isPackageChanged } from 'package-changed';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { PKG_HASHFILE_RELATIVE_PATH } from '../constants';
|
|
6
|
+
import log from '../logger';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Determines if extensions have changed, and updates a hash the `package.json` in `appiumHome` if so.
|
|
10
|
+
*
|
|
11
|
+
* If they have, we need to sync them with the `extensions.yaml` manifest.
|
|
12
|
+
*
|
|
13
|
+
* _Warning: this makes a blocking call to `writeFileSync`._
|
|
14
|
+
* @param {string} appiumHome
|
|
15
|
+
* @returns {Promise<boolean>} `true` if `package.json` `appiumHome` changed
|
|
16
|
+
*/
|
|
17
|
+
export async function packageDidChange (appiumHome) {
|
|
18
|
+
const hashFilename = path.join(appiumHome, PKG_HASHFILE_RELATIVE_PATH);
|
|
19
|
+
|
|
20
|
+
// XXX: the types in `package-changed` seem to be wrong.
|
|
21
|
+
|
|
22
|
+
/** @type {boolean} */
|
|
23
|
+
let isChanged;
|
|
24
|
+
/** @type {() => void} */
|
|
25
|
+
let writeHash;
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
let hash;
|
|
28
|
+
/** @type {string|undefined} */
|
|
29
|
+
let oldHash;
|
|
30
|
+
|
|
31
|
+
// first mkdirp the target dir.
|
|
32
|
+
const hashFilenameDir = path.dirname(hashFilename);
|
|
33
|
+
log.debug(`Creating hash file directory: ${hashFilenameDir}`);
|
|
34
|
+
try {
|
|
35
|
+
await fs.mkdirp(hashFilenameDir);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Appium could not create the directory for hash file: ${hashFilenameDir}. Original error: ${err.message}`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
({isChanged, writeHash, oldHash, hash} = await isPackageChanged({
|
|
44
|
+
cwd: appiumHome,
|
|
45
|
+
hashFilename: PKG_HASHFILE_RELATIVE_PATH,
|
|
46
|
+
}));
|
|
47
|
+
} catch {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (isChanged) {
|
|
52
|
+
try {
|
|
53
|
+
writeHash();
|
|
54
|
+
log.debug(`Updated hash of ${appiumHome}/package.json from: ${oldHash ?? '(none)'} to: ${hash}`);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Appium could not write hash file: ${hashFilenameDir}. Original error: ${err.message}`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return isChanged;
|
|
63
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import {ExtensionConfig} from './extension-config';
|
|
4
|
+
import log from '../logger';
|
|
5
|
+
import {PLUGIN_TYPE} from '../constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @extends {ExtensionConfig<PluginType>}
|
|
9
|
+
*/
|
|
10
|
+
export class PluginConfig extends ExtensionConfig {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A mapping of {@link Manifest} instances to {@link PluginConfig} instances.
|
|
14
|
+
*
|
|
15
|
+
* `Manifest` and {@link ExtensionConfig} have a one-to-many relationship; each `Manifest` should be associated with a `DriverConfig` and a `PluginConfig`; no more, no less.
|
|
16
|
+
*
|
|
17
|
+
* This variable tracks the `Manifest`-to-`PluginConfig` portion.
|
|
18
|
+
*
|
|
19
|
+
* @type {WeakMap<Manifest,PluginConfig>}
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
static _instances = new WeakMap();
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Call {@link PluginConfig.create} instead.
|
|
26
|
+
*
|
|
27
|
+
* Just calls the superclass' constructor with the correct extension type
|
|
28
|
+
* @private
|
|
29
|
+
* @param {Manifest} manifest - IO object
|
|
30
|
+
* @param {PluginConfigOptions} [opts]
|
|
31
|
+
*/
|
|
32
|
+
constructor (manifest, {extData, logFn} = {}) {
|
|
33
|
+
super(PLUGIN_TYPE, manifest, logFn);
|
|
34
|
+
|
|
35
|
+
if (extData) {
|
|
36
|
+
this.validate(extData);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new {@link PluginConfig} instance for a {@link Manifest} instance.
|
|
42
|
+
*
|
|
43
|
+
* @param {Manifest} manifest
|
|
44
|
+
* @param {PluginConfigOptions} [opts]
|
|
45
|
+
* @throws If `manifest` already associated with a `PluginConfig`
|
|
46
|
+
* @returns {PluginConfig}
|
|
47
|
+
*/
|
|
48
|
+
static create (manifest, {extData, logFn} = {}) {
|
|
49
|
+
const instance = new PluginConfig(manifest, {logFn, extData});
|
|
50
|
+
if (PluginConfig.getInstance(manifest)) {
|
|
51
|
+
throw new Error(`Manifest with APPIUM_HOME ${manifest.appiumHome} already has a PluginConfig; use PluginConfig.getInstance() to retrieve it.`);
|
|
52
|
+
}
|
|
53
|
+
PluginConfig._instances.set(manifest, instance);
|
|
54
|
+
return instance;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns a PluginConfig associated with a Manifest
|
|
59
|
+
* @param {Manifest} manifest
|
|
60
|
+
* @returns {PluginConfig|undefined}
|
|
61
|
+
*/
|
|
62
|
+
static getInstance (manifest) {
|
|
63
|
+
return PluginConfig._instances.get(manifest);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {string} pluginName
|
|
68
|
+
* @param {import('../../types/appium-manifest').ExtManifest<PluginType>} pluginData
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
extensionDesc (pluginName, {version}) {
|
|
72
|
+
return `${pluginName}@${version}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @param {(keyof PluginRecord)[]} activeNames
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
print (activeNames) {
|
|
81
|
+
const pluginNames = Object.keys(this.installedExtensions);
|
|
82
|
+
|
|
83
|
+
if (_.isEmpty(pluginNames)) {
|
|
84
|
+
log.info(`No plugins have been installed. Use the "appium plugin" ` +
|
|
85
|
+
'command to install the one(s) you want to use.');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
log.info(`Available plugins:`);
|
|
90
|
+
for (const [pluginName, pluginData] of _.toPairs(this.installedExtensions)) {
|
|
91
|
+
const activeTxt = _.includes(activeNames, pluginName) ? ' (ACTIVE)' : '';
|
|
92
|
+
log.info(` - ${this.extensionDesc(pluginName, pluginData)}${activeTxt}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (_.isEmpty(activeNames)) {
|
|
96
|
+
log.info('No plugins activated. Use the --use-plugins flag with names of plugins to activate');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @typedef PluginConfigOptions
|
|
103
|
+
* @property {import('./extension-config').ExtensionLogFn} [logFn] - Optional logging function
|
|
104
|
+
* @property {import('../../types/appium-manifest').PluginRecord} [extData] - Extension data
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @typedef {import('../../types/appium-manifest').PluginRecord} PluginRecord
|
|
110
|
+
* @typedef {import('../../types').PluginType} PluginType
|
|
111
|
+
* @typedef {import('../../types/external-manifest').ExtMetadata<PluginType>} PluginMetadata
|
|
112
|
+
* @typedef {import('./manifest').Manifest} Manifest
|
|
113
|
+
*/
|
package/lib/grid-register.js
CHANGED
|
@@ -11,10 +11,10 @@ const hubUri = (config) => {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Registers a new node with a selenium grid
|
|
14
|
-
* @param {string|object} data - Path or object representing selenium grid node config file
|
|
15
|
-
* @param {string} addr - Bind to this address
|
|
16
|
-
* @param {number} port - Bind to this port
|
|
17
|
-
* @param {string} basePath - Base path for the grid
|
|
14
|
+
* @param {string|object} data - Path or object representing selenium grid node config file. If a `string`, all subsequent arguments are required!
|
|
15
|
+
* @param {string} [addr] - Bind to this address
|
|
16
|
+
* @param {number} [port] - Bind to this port
|
|
17
|
+
* @param {string} [basePath] - Base path for the grid
|
|
18
18
|
*/
|
|
19
19
|
async function registerNode (data, addr, port, basePath) {
|
|
20
20
|
let configFilePath;
|
package/lib/logsink.js
CHANGED
|
@@ -66,6 +66,8 @@ const stripColorFormat = format(function stripColor (info) {
|
|
|
66
66
|
|
|
67
67
|
function createConsoleTransport (args, logLvl) {
|
|
68
68
|
return new (transports.Console)({
|
|
69
|
+
// `name` is unsupported per winston's type declarations
|
|
70
|
+
// @ts-expect-error
|
|
69
71
|
name: 'console',
|
|
70
72
|
handleExceptions: true,
|
|
71
73
|
exitOnError: false,
|
|
@@ -92,6 +94,7 @@ function createConsoleTransport (args, logLvl) {
|
|
|
92
94
|
|
|
93
95
|
function createFileTransport (args, logLvl) {
|
|
94
96
|
return new (transports.File)({
|
|
97
|
+
// @ts-expect-error
|
|
95
98
|
name: 'file',
|
|
96
99
|
filename: args.logFile,
|
|
97
100
|
maxFiles: 1,
|
|
@@ -120,6 +123,7 @@ function createHttpTransport (args, logLvl) {
|
|
|
120
123
|
}
|
|
121
124
|
|
|
122
125
|
return new (transports.Http)({
|
|
126
|
+
// @ts-expect-error
|
|
123
127
|
name: 'http',
|
|
124
128
|
host,
|
|
125
129
|
port,
|