appium 2.0.0-beta.5 → 2.0.0-beta.52

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 (199) hide show
  1. package/README.md +156 -63
  2. package/build/lib/appium.d.ts +226 -0
  3. package/build/lib/appium.d.ts.map +1 -0
  4. package/build/lib/appium.js +694 -439
  5. package/build/lib/appium.js.map +1 -0
  6. package/build/lib/cli/args.d.ts +17 -0
  7. package/build/lib/cli/args.d.ts.map +1 -0
  8. package/build/lib/cli/args.js +253 -319
  9. package/build/lib/cli/args.js.map +1 -0
  10. package/build/lib/cli/driver-command.d.ts +102 -0
  11. package/build/lib/cli/driver-command.d.ts.map +1 -0
  12. package/build/lib/cli/driver-command.js +126 -81
  13. package/build/lib/cli/driver-command.js.map +1 -0
  14. package/build/lib/cli/extension-command.d.ts +385 -0
  15. package/build/lib/cli/extension-command.d.ts.map +1 -0
  16. package/build/lib/cli/extension-command.js +731 -383
  17. package/build/lib/cli/extension-command.js.map +1 -0
  18. package/build/lib/cli/extension.d.ts +23 -0
  19. package/build/lib/cli/extension.d.ts.map +1 -0
  20. package/build/lib/cli/extension.js +71 -54
  21. package/build/lib/cli/extension.js.map +1 -0
  22. package/build/lib/cli/parser.d.ts +84 -0
  23. package/build/lib/cli/parser.d.ts.map +1 -0
  24. package/build/lib/cli/parser.js +240 -128
  25. package/build/lib/cli/parser.js.map +1 -0
  26. package/build/lib/cli/plugin-command.d.ts +99 -0
  27. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  28. package/build/lib/cli/plugin-command.js +120 -81
  29. package/build/lib/cli/plugin-command.js.map +1 -0
  30. package/build/lib/cli/utils.d.ts +29 -0
  31. package/build/lib/cli/utils.d.ts.map +1 -0
  32. package/build/lib/cli/utils.js +72 -51
  33. package/build/lib/cli/utils.js.map +1 -0
  34. package/build/lib/config-file.d.ts +100 -0
  35. package/build/lib/config-file.d.ts.map +1 -0
  36. package/build/lib/config-file.js +207 -0
  37. package/build/lib/config-file.js.map +1 -0
  38. package/build/lib/config.d.ts +49 -0
  39. package/build/lib/config.d.ts.map +1 -0
  40. package/build/lib/config.js +265 -201
  41. package/build/lib/config.js.map +1 -0
  42. package/build/lib/constants.d.ts +49 -0
  43. package/build/lib/constants.d.ts.map +1 -0
  44. package/build/lib/constants.js +66 -0
  45. package/build/lib/constants.js.map +1 -0
  46. package/build/lib/extension/driver-config.d.ts +82 -0
  47. package/build/lib/extension/driver-config.d.ts.map +1 -0
  48. package/build/lib/extension/driver-config.js +212 -0
  49. package/build/lib/extension/driver-config.js.map +1 -0
  50. package/build/lib/extension/extension-config.d.ts +249 -0
  51. package/build/lib/extension/extension-config.d.ts.map +1 -0
  52. package/build/lib/extension/extension-config.js +581 -0
  53. package/build/lib/extension/extension-config.js.map +1 -0
  54. package/build/lib/extension/index.d.ts +48 -0
  55. package/build/lib/extension/index.d.ts.map +1 -0
  56. package/build/lib/extension/index.js +105 -0
  57. package/build/lib/extension/index.js.map +1 -0
  58. package/build/lib/extension/manifest-migrations.d.ts +27 -0
  59. package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
  60. package/build/lib/extension/manifest-migrations.js +118 -0
  61. package/build/lib/extension/manifest-migrations.js.map +1 -0
  62. package/build/lib/extension/manifest.d.ts +145 -0
  63. package/build/lib/extension/manifest.d.ts.map +1 -0
  64. package/build/lib/extension/manifest.js +521 -0
  65. package/build/lib/extension/manifest.js.map +1 -0
  66. package/build/lib/extension/package-changed.d.ts +11 -0
  67. package/build/lib/extension/package-changed.d.ts.map +1 -0
  68. package/build/lib/extension/package-changed.js +62 -0
  69. package/build/lib/extension/package-changed.js.map +1 -0
  70. package/build/lib/extension/plugin-config.d.ts +56 -0
  71. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  72. package/build/lib/extension/plugin-config.js +102 -0
  73. package/build/lib/extension/plugin-config.js.map +1 -0
  74. package/build/lib/grid-register.d.ts +10 -0
  75. package/build/lib/grid-register.d.ts.map +1 -0
  76. package/build/lib/grid-register.js +122 -144
  77. package/build/lib/grid-register.js.map +1 -0
  78. package/build/lib/logger.d.ts +3 -0
  79. package/build/lib/logger.d.ts.map +1 -0
  80. package/build/lib/logger.js +5 -17
  81. package/build/lib/logger.js.map +1 -0
  82. package/build/lib/logsink.d.ts +4 -0
  83. package/build/lib/logsink.d.ts.map +1 -0
  84. package/build/lib/logsink.js +190 -187
  85. package/build/lib/logsink.js.map +1 -0
  86. package/build/lib/main.d.ts +62 -0
  87. package/build/lib/main.d.ts.map +1 -0
  88. package/build/lib/main.js +348 -228
  89. package/build/lib/main.js.map +1 -0
  90. package/build/lib/schema/arg-spec.d.ts +143 -0
  91. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  92. package/build/lib/schema/arg-spec.js +164 -0
  93. package/build/lib/schema/arg-spec.js.map +1 -0
  94. package/build/lib/schema/cli-args.d.ts +19 -0
  95. package/build/lib/schema/cli-args.d.ts.map +1 -0
  96. package/build/lib/schema/cli-args.js +217 -0
  97. package/build/lib/schema/cli-args.js.map +1 -0
  98. package/build/lib/schema/cli-transformers.d.ts +5 -0
  99. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  100. package/build/lib/schema/cli-transformers.js +124 -0
  101. package/build/lib/schema/cli-transformers.js.map +1 -0
  102. package/build/lib/schema/index.d.ts +3 -0
  103. package/build/lib/schema/index.d.ts.map +1 -0
  104. package/build/lib/schema/index.js +19 -0
  105. package/build/lib/schema/index.js.map +1 -0
  106. package/build/lib/schema/keywords.d.ts +24 -0
  107. package/build/lib/schema/keywords.d.ts.map +1 -0
  108. package/build/lib/schema/keywords.js +128 -0
  109. package/build/lib/schema/keywords.js.map +1 -0
  110. package/build/lib/schema/schema.d.ts +259 -0
  111. package/build/lib/schema/schema.d.ts.map +1 -0
  112. package/build/lib/schema/schema.js +615 -0
  113. package/build/lib/schema/schema.js.map +1 -0
  114. package/build/lib/utils.d.ts +121 -0
  115. package/build/lib/utils.d.ts.map +1 -0
  116. package/build/lib/utils.js +351 -273
  117. package/build/lib/utils.js.map +1 -0
  118. package/build/tsconfig.tsbuildinfo +1 -0
  119. package/build/types/cli.d.ts +134 -0
  120. package/build/types/cli.d.ts.map +1 -0
  121. package/build/types/cli.js +3 -0
  122. package/build/types/cli.js.map +1 -0
  123. package/build/types/index.d.ts +15 -0
  124. package/build/types/index.d.ts.map +1 -0
  125. package/build/types/index.js +19 -0
  126. package/build/types/index.js.map +1 -0
  127. package/build/types/manifest/base.d.ts +135 -0
  128. package/build/types/manifest/base.d.ts.map +1 -0
  129. package/build/types/manifest/base.js +3 -0
  130. package/build/types/manifest/base.js.map +1 -0
  131. package/build/types/manifest/index.d.ts +19 -0
  132. package/build/types/manifest/index.d.ts.map +1 -0
  133. package/build/types/manifest/index.js +40 -0
  134. package/build/types/manifest/index.js.map +1 -0
  135. package/build/types/manifest/v3.d.ts +139 -0
  136. package/build/types/manifest/v3.d.ts.map +1 -0
  137. package/build/types/manifest/v3.js +3 -0
  138. package/build/types/manifest/v3.js.map +1 -0
  139. package/driver.d.ts +1 -0
  140. package/driver.js +14 -0
  141. package/index.js +11 -0
  142. package/lib/appium.js +535 -186
  143. package/lib/cli/args.js +267 -422
  144. package/lib/cli/driver-command.js +126 -23
  145. package/lib/cli/extension-command.js +679 -271
  146. package/lib/cli/extension.js +48 -17
  147. package/lib/cli/parser.js +263 -83
  148. package/lib/cli/plugin-command.js +115 -20
  149. package/lib/cli/utils.js +24 -10
  150. package/lib/config-file.js +220 -0
  151. package/lib/config.js +244 -110
  152. package/lib/constants.js +71 -0
  153. package/lib/extension/driver-config.js +250 -0
  154. package/lib/extension/extension-config.js +682 -0
  155. package/lib/extension/index.js +116 -0
  156. package/lib/extension/manifest-migrations.js +120 -0
  157. package/lib/extension/manifest.js +573 -0
  158. package/lib/extension/package-changed.js +64 -0
  159. package/lib/extension/plugin-config.js +112 -0
  160. package/lib/grid-register.js +49 -35
  161. package/lib/logger.js +1 -2
  162. package/lib/logsink.js +64 -38
  163. package/lib/main.js +321 -101
  164. package/lib/schema/arg-spec.js +229 -0
  165. package/lib/schema/cli-args.js +238 -0
  166. package/lib/schema/cli-transformers.js +119 -0
  167. package/lib/schema/index.js +2 -0
  168. package/lib/schema/keywords.js +136 -0
  169. package/lib/schema/schema.js +722 -0
  170. package/lib/utils.js +291 -167
  171. package/package.json +83 -84
  172. package/plugin.d.ts +1 -0
  173. package/plugin.js +13 -0
  174. package/scripts/autoinstall-extensions.js +237 -0
  175. package/support.d.ts +1 -0
  176. package/support.js +13 -0
  177. package/tsconfig.json +25 -0
  178. package/types/cli.ts +189 -0
  179. package/types/index.ts +20 -0
  180. package/types/manifest/README.md +30 -0
  181. package/types/manifest/base.ts +158 -0
  182. package/types/manifest/index.ts +27 -0
  183. package/types/manifest/v3.ts +161 -0
  184. package/CHANGELOG.md +0 -3515
  185. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  186. package/build/lib/cli/npm.js +0 -208
  187. package/build/lib/cli/parser-helpers.js +0 -82
  188. package/build/lib/driver-config.js +0 -77
  189. package/build/lib/drivers.js +0 -96
  190. package/build/lib/extension-config.js +0 -253
  191. package/build/lib/plugin-config.js +0 -59
  192. package/build/lib/plugins.js +0 -14
  193. package/lib/cli/npm.js +0 -184
  194. package/lib/cli/parser-helpers.js +0 -79
  195. package/lib/driver-config.js +0 -46
  196. package/lib/drivers.js +0 -81
  197. package/lib/extension-config.js +0 -209
  198. package/lib/plugin-config.js +0 -34
  199. package/lib/plugins.js +0 -10
@@ -0,0 +1,521 @@
1
+ "use strict";
2
+ /**
3
+ * Module containing {@link Manifest} which handles reading & writing of extension config files.
4
+ */
5
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6
+ if (kind === "m") throw new TypeError("Private method is not writable");
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
9
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ var _Manifest_instances, _Manifest_data, _Manifest_appiumHome, _Manifest_manifestPath, _Manifest_writing, _Manifest_reading, _Manifest_setManifestPath;
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.Manifest = void 0;
22
+ const bluebird_1 = __importDefault(require("bluebird"));
23
+ const glob_1 = __importDefault(require("glob"));
24
+ const support_1 = require("@appium/support");
25
+ const lodash_1 = __importDefault(require("lodash"));
26
+ const path_1 = __importDefault(require("path"));
27
+ const yaml_1 = __importDefault(require("yaml"));
28
+ const constants_1 = require("../constants");
29
+ const logger_1 = __importDefault(require("../logger"));
30
+ const extension_config_1 = require("./extension-config");
31
+ const package_changed_1 = require("./package-changed");
32
+ const manifest_migrations_1 = require("./manifest-migrations");
33
+ /**
34
+ * The name of the prop (`drivers`) used in `extensions.yaml` for drivers.
35
+ * @type {`${typeof DRIVER_TYPE}s`}
36
+ */
37
+ const CONFIG_DATA_DRIVER_KEY = `${constants_1.DRIVER_TYPE}s`;
38
+ /**
39
+ * The name of the prop (`plugins`) used in `extensions.yaml` for plugins.
40
+ * @type {`${typeof PLUGIN_TYPE}s`}
41
+ */
42
+ const CONFIG_DATA_PLUGIN_KEY = `${constants_1.PLUGIN_TYPE}s`;
43
+ /**
44
+ * @type {Readonly<ManifestData>}
45
+ */
46
+ const INITIAL_MANIFEST_DATA = Object.freeze({
47
+ [CONFIG_DATA_DRIVER_KEY]: Object.freeze({}),
48
+ [CONFIG_DATA_PLUGIN_KEY]: Object.freeze({}),
49
+ schemaRev: constants_1.CURRENT_SCHEMA_REV,
50
+ });
51
+ /**
52
+ * Given a `package.json` return `true` if it represents an Appium Extension (either a driver or plugin).
53
+ *
54
+ * _This is a type guard; not a validator._
55
+ *
56
+ * The `package.json` must have an `appium` property which is an object.
57
+ * @param {any} value
58
+ * @returns {value is ExtPackageJson<ExtensionType>}
59
+ */
60
+ function isExtension(value) {
61
+ return (lodash_1.default.isPlainObject(value) &&
62
+ lodash_1.default.isPlainObject(value.appium) &&
63
+ lodash_1.default.isString(value.name) &&
64
+ lodash_1.default.isString(value.version));
65
+ }
66
+ /**
67
+ * Given a `package.json`, return `true` if it represents an Appium Driver.
68
+ *
69
+ * _This is a type guard; not a validator._
70
+ *
71
+ * To be considered a driver, a `package.json` must have an `appium.driverName` field.
72
+ *
73
+ * Further validation of the `appium` property happens elsewhere.
74
+ * @param {any} value - Value to test
75
+ * @returns {value is ExtPackageJson<DriverType>}
76
+ */
77
+ function isDriver(value) {
78
+ return isExtension(value) && 'driverName' in value.appium && lodash_1.default.isString(value.appium.driverName);
79
+ }
80
+ /**
81
+ * Given a `package.json`, return `true` if it represents an Appium Plugin.
82
+ *
83
+ * _This is a type guard; not a validator._
84
+ *
85
+ * To be considered a plugin, a `package.json` must have an `appium.pluginName` field.
86
+ *
87
+ * Further validation of the `appium` property happens elsewhere.
88
+ * @param {any} value - Value to test
89
+ * @returns {value is ExtPackageJson<PluginType>}
90
+ */
91
+ function isPlugin(value) {
92
+ return isExtension(value) && 'pluginName' in value.appium && lodash_1.default.isString(value.appium.pluginName);
93
+ }
94
+ /**
95
+ * Handles reading & writing of extension config files.
96
+ *
97
+ * Only one instance of this class exists per value of `APPIUM_HOME`.
98
+ */
99
+ class Manifest {
100
+ /**
101
+ * Sets internal data to a fresh clone of {@link INITIAL_MANIFEST_DATA}
102
+ *
103
+ * Use {@link Manifest.getInstance} instead.
104
+ * @param {string} appiumHome
105
+ * @private
106
+ */
107
+ constructor(appiumHome) {
108
+ _Manifest_instances.add(this);
109
+ /**
110
+ * The entire contents of a parsed YAML extension config file.
111
+ *
112
+ * Contains proxies for automatic persistence on disk
113
+ * @type {ManifestData}
114
+ */
115
+ _Manifest_data.set(this, void 0);
116
+ /**
117
+ * Path to `APPIUM_HOME`.
118
+ * @type {Readonly<string>}
119
+ */
120
+ _Manifest_appiumHome.set(this, void 0);
121
+ /**
122
+ * Path to `extensions.yaml`
123
+ * @type {string}
124
+ * Not set until {@link Manifest.read} is called.
125
+ */
126
+ _Manifest_manifestPath.set(this, void 0);
127
+ /**
128
+ * Helps avoid writing multiple times.
129
+ *
130
+ * If this is `undefined`, calling {@link Manifest.write} will cause it to be
131
+ * set to a `Promise`. When the call to `write()` is complete, the `Promise`
132
+ * will resolve and then this value will be set to `undefined`. Concurrent calls
133
+ * made while this value is a `Promise` will return the `Promise` itself.
134
+ * @type {Promise<boolean>|undefined}
135
+ */
136
+ _Manifest_writing.set(this, void 0);
137
+ /**
138
+ * Helps avoid reading multiple times.
139
+ *
140
+ * If this is `undefined`, calling {@link Manifest.read} will cause it to be
141
+ * set to a `Promise`. When the call to `read()` is complete, the `Promise`
142
+ * will resolve and then this value will be set to `undefined`. Concurrent calls
143
+ * made while this value is a `Promise` will return the `Promise` itself.
144
+ * @type {Promise<void>|undefined}
145
+ */
146
+ _Manifest_reading.set(this, void 0);
147
+ __classPrivateFieldSet(this, _Manifest_appiumHome, appiumHome, "f");
148
+ __classPrivateFieldSet(this, _Manifest_data, lodash_1.default.cloneDeep(INITIAL_MANIFEST_DATA), "f");
149
+ }
150
+ /**
151
+ * Searches `APPIUM_HOME` for installed extensions and adds them to the manifest.
152
+ * @returns {Promise<boolean>} `true` if any extensions were added, `false` otherwise.
153
+ */
154
+ async syncWithInstalledExtensions() {
155
+ // this could be parallelized, but we can't use fs.walk as an async iterator
156
+ let didChange = false;
157
+ /**
158
+ * Listener for the `match` event of a `glob` instance
159
+ * @param {string} filepath - Path to a `package.json`
160
+ * @returns {Promise<void>}
161
+ */
162
+ const onMatch = async (filepath) => {
163
+ try {
164
+ const pkg = JSON.parse(await support_1.fs.readFile(filepath, 'utf8'));
165
+ if (isExtension(pkg)) {
166
+ const extType = isDriver(pkg) ? constants_1.DRIVER_TYPE : constants_1.PLUGIN_TYPE;
167
+ /**
168
+ * this should only be 'unknown' if the extension's `package.json` is invalid
169
+ * @type {string}
170
+ */
171
+ const name = isDriver(pkg)
172
+ ? pkg.appium.driverName
173
+ : isPlugin(pkg)
174
+ ? pkg.appium.pluginName
175
+ : '(unknown)';
176
+ if ((isDriver(pkg) && !this.hasDriver(name)) ||
177
+ (isPlugin(pkg) && !this.hasPlugin(name))) {
178
+ logger_1.default.info(`Discovered installed ${extType} "${name}"`);
179
+ }
180
+ const changed = this.addExtensionFromPackage(pkg, filepath);
181
+ didChange = didChange || changed;
182
+ }
183
+ }
184
+ catch { }
185
+ };
186
+ /**
187
+ * A list of `Promise`s which read `package.json` files looking for Appium extensions.
188
+ * @type {Promise<void>[]}
189
+ */
190
+ const queue = [
191
+ // look at `package.json` in `APPIUM_HOME` only
192
+ onMatch(path_1.default.join(__classPrivateFieldGet(this, _Manifest_appiumHome, "f"), 'package.json')),
193
+ ];
194
+ // add dependencies to the queue
195
+ await new bluebird_1.default((resolve, reject) => {
196
+ (0, glob_1.default)('node_modules/{*,@*/*}/package.json', { cwd: __classPrivateFieldGet(this, _Manifest_appiumHome, "f"), silent: true, absolute: true },
197
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
198
+ (err) => {
199
+ if (err) {
200
+ reject(err);
201
+ }
202
+ resolve();
203
+ })
204
+ .on('error', reject)
205
+ .on('match', (filepath) => {
206
+ queue.push(onMatch(filepath));
207
+ });
208
+ });
209
+ // wait for everything to finish
210
+ await bluebird_1.default.all(queue);
211
+ return didChange;
212
+ }
213
+ /**
214
+ * Returns `true` if driver with name `name` is registered.
215
+ * @param {string} name - Driver name
216
+ * @returns {boolean}
217
+ */
218
+ hasDriver(name) {
219
+ return Boolean(__classPrivateFieldGet(this, _Manifest_data, "f").drivers[name]);
220
+ }
221
+ /**
222
+ * Returns `true` if plugin with name `name` is registered.
223
+ * @param {string} name - Plugin name
224
+ * @returns {boolean}
225
+ */
226
+ hasPlugin(name) {
227
+ return Boolean(__classPrivateFieldGet(this, _Manifest_data, "f").plugins[name]);
228
+ }
229
+ /**
230
+ * Given a path to a `package.json`, add it as either a driver or plugin to the manifest.
231
+ *
232
+ * @template {ExtensionType} ExtType
233
+ * @param {ExtPackageJson<ExtType>} pkgJson
234
+ * @param {string} pkgPath
235
+ * @returns {boolean} - `true` if this method did anything.
236
+ */
237
+ addExtensionFromPackage(pkgJson, pkgPath) {
238
+ const extensionPath = path_1.default.dirname(pkgPath);
239
+ /**
240
+ * @type {InternalMetadata}
241
+ */
242
+ const internal = {
243
+ pkgName: pkgJson.name,
244
+ version: pkgJson.version,
245
+ appiumVersion: pkgJson.peerDependencies?.appium,
246
+ installType: extension_config_1.INSTALL_TYPE_NPM,
247
+ installSpec: `${pkgJson.name}@${pkgJson.version}`,
248
+ installPath: extensionPath,
249
+ };
250
+ if (isDriver(pkgJson)) {
251
+ const value = {
252
+ ...lodash_1.default.omit(pkgJson.appium, 'driverName'),
253
+ ...internal,
254
+ };
255
+ if (!lodash_1.default.isEqual(value, __classPrivateFieldGet(this, _Manifest_data, "f").drivers[pkgJson.appium.driverName])) {
256
+ this.setExtension(constants_1.DRIVER_TYPE, pkgJson.appium.driverName, value);
257
+ return true;
258
+ }
259
+ return false;
260
+ }
261
+ else if (isPlugin(pkgJson)) {
262
+ const value = {
263
+ ...lodash_1.default.omit(pkgJson.appium, 'pluginName'),
264
+ ...internal,
265
+ };
266
+ if (!lodash_1.default.isEqual(value, __classPrivateFieldGet(this, _Manifest_data, "f").plugins[pkgJson.appium.pluginName])) {
267
+ this.setExtension(constants_1.PLUGIN_TYPE, pkgJson.appium.pluginName, value);
268
+ return true;
269
+ }
270
+ return false;
271
+ }
272
+ else {
273
+ throw new TypeError(`The extension in ${extensionPath} is neither a valid ${constants_1.DRIVER_TYPE} nor a valid ${constants_1.PLUGIN_TYPE}.`);
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 {ExtManifest<ExtType>} A clone of `extData`, potentially with a mutated `appiumVersion` field
286
+ */
287
+ setExtension(extType, extName, extData) {
288
+ const data = lodash_1.default.cloneDeep(extData);
289
+ __classPrivateFieldGet(this, _Manifest_data, "f")[`${extType}s`][extName] = data;
290
+ return data;
291
+ }
292
+ /**
293
+ * Sets the schema revision
294
+ * @param {keyof import('./manifest-migrations').ManifestDataVersions} rev
295
+ */
296
+ setSchemaRev(rev) {
297
+ __classPrivateFieldGet(this, _Manifest_data, "f").schemaRev = rev;
298
+ }
299
+ /**
300
+ * Remove an extension from the manifest.
301
+ * @param {ExtensionType} extType
302
+ * @param {string} extName
303
+ */
304
+ deleteExtension(extType, extName) {
305
+ delete __classPrivateFieldGet(this, _Manifest_data, "f")[`${extType}s`][extName];
306
+ }
307
+ /**
308
+ * Returns the `APPIUM_HOME` path
309
+ */
310
+ get appiumHome() {
311
+ return __classPrivateFieldGet(this, _Manifest_appiumHome, "f");
312
+ }
313
+ /**
314
+ * Returns the path to the manifest file (`extensions.yaml`)
315
+ */
316
+ get manifestPath() {
317
+ return __classPrivateFieldGet(this, _Manifest_manifestPath, "f");
318
+ }
319
+ /**
320
+ * Returns the schema rev of this manifest
321
+ */
322
+ get schemaRev() {
323
+ return __classPrivateFieldGet(this, _Manifest_data, "f").schemaRev;
324
+ }
325
+ /**
326
+ * Returns extension data for a particular type.
327
+ *
328
+ * @template {ExtensionType} ExtType
329
+ * @param {ExtType} extType
330
+ * @returns {Readonly<ExtRecord<ExtType>>}
331
+ */
332
+ getExtensionData(extType) {
333
+ return __classPrivateFieldGet(this, _Manifest_data, "f")[ /** @type {string} */(`${extType}s`)];
334
+ }
335
+ /**
336
+ * Reads manifest from disk and _overwrites_ the internal data.
337
+ *
338
+ * If the manifest does not exist on disk, an
339
+ * {@link INITIAL_MANIFEST_DATA "empty"} manifest file will be created, as
340
+ * well as its directory if needed.
341
+ *
342
+ * This will also, if necessary:
343
+ * 1. perform a migration of the manifest data
344
+ * 2. sync the manifest with extensions on-disk (kind of like "auto
345
+ * discovery")
346
+ * 3. write the manifest to disk.
347
+ *
348
+ * Only one read operation can happen at a time.
349
+ *
350
+ * @returns {Promise<ManifestData>} The data
351
+ */
352
+ async read() {
353
+ if (__classPrivateFieldGet(this, _Manifest_reading, "f")) {
354
+ await __classPrivateFieldGet(this, _Manifest_reading, "f");
355
+ return __classPrivateFieldGet(this, _Manifest_data, "f");
356
+ }
357
+ __classPrivateFieldSet(this, _Manifest_reading, (async () => {
358
+ /** @type {ManifestData} */
359
+ let data;
360
+ /**
361
+ * This will be `true` if, after reading, we need to update the manifest data
362
+ * and write it again to disk.
363
+ */
364
+ let shouldWrite = false;
365
+ await __classPrivateFieldGet(this, _Manifest_instances, "m", _Manifest_setManifestPath).call(this);
366
+ try {
367
+ const yaml = await support_1.fs.readFile(__classPrivateFieldGet(this, _Manifest_manifestPath, "f"), 'utf8');
368
+ data = yaml_1.default.parse(yaml);
369
+ logger_1.default.debug(`Parsed manifest file at ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}: ${JSON.stringify(data, null, 2)}`);
370
+ }
371
+ catch (err) {
372
+ if (err.code === 'ENOENT') {
373
+ logger_1.default.debug(`No manifest file found at ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}; creating`);
374
+ data = lodash_1.default.cloneDeep(INITIAL_MANIFEST_DATA);
375
+ shouldWrite = true;
376
+ }
377
+ else {
378
+ if (__classPrivateFieldGet(this, _Manifest_manifestPath, "f")) {
379
+ throw new Error(`Appium had trouble loading the extension installation ` +
380
+ `cache file (${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}). It may be invalid YAML. Specific error: ${err.message}`);
381
+ }
382
+ else {
383
+ throw new Error(`Appium encountered an unknown problem. Specific error: ${err.message}`);
384
+ }
385
+ }
386
+ }
387
+ __classPrivateFieldSet(this, _Manifest_data, data, "f");
388
+ /**
389
+ * the only way `shouldWrite` is `true` is if we have a new file. a new
390
+ * file will get the latest schema revision, so we can skip the migration.
391
+ */
392
+ if (!shouldWrite && (data.schemaRev ?? 0) < constants_1.CURRENT_SCHEMA_REV) {
393
+ logger_1.default.debug(`Updating manifest schema from rev ${data.schemaRev ?? '(none)'} to ${constants_1.CURRENT_SCHEMA_REV}`);
394
+ shouldWrite = await (0, manifest_migrations_1.migrate)(this);
395
+ }
396
+ /**
397
+ * we still may want to sync with installed extensions even if we have a
398
+ * new file. right now this is limited to the following cases:
399
+ * 1. we have a brand new manifest file
400
+ * 2. we have performed a migration on a manifest file
401
+ * 3. `appium` is a dependency within `package.json`, and `package.json`
402
+ * has changed since last time we checked.
403
+ *
404
+ * It may also make sense to sync with the extensions in an arbitrary
405
+ * `APPIUM_HOME`, but we don't do that here.
406
+ */
407
+ if (shouldWrite ||
408
+ ((await support_1.env.hasAppiumDependency(this.appiumHome)) &&
409
+ (await (0, package_changed_1.packageDidChange)(this.appiumHome)))) {
410
+ logger_1.default.debug('Discovering newly installed extensions...');
411
+ shouldWrite = (await this.syncWithInstalledExtensions()) || shouldWrite;
412
+ }
413
+ if (shouldWrite) {
414
+ await this.write();
415
+ }
416
+ })(), "f");
417
+ try {
418
+ await __classPrivateFieldGet(this, _Manifest_reading, "f");
419
+ return __classPrivateFieldGet(this, _Manifest_data, "f");
420
+ }
421
+ finally {
422
+ __classPrivateFieldSet(this, _Manifest_reading, undefined, "f");
423
+ }
424
+ }
425
+ /**
426
+ * Writes the data if it need s writing.
427
+ *
428
+ * If the `schemaRev` prop needs updating, the file will be written.
429
+ *
430
+ * @todo If this becomes too much of a bottleneck, throttle it.
431
+ * @returns {Promise<boolean>} Whether the data was written
432
+ */
433
+ async write() {
434
+ if (__classPrivateFieldGet(this, _Manifest_writing, "f")) {
435
+ return __classPrivateFieldGet(this, _Manifest_writing, "f");
436
+ }
437
+ __classPrivateFieldSet(this, _Manifest_writing, (async () => {
438
+ await __classPrivateFieldGet(this, _Manifest_instances, "m", _Manifest_setManifestPath).call(this);
439
+ try {
440
+ await support_1.fs.mkdirp(path_1.default.dirname(__classPrivateFieldGet(this, _Manifest_manifestPath, "f")));
441
+ }
442
+ catch (err) {
443
+ throw new Error(`Appium could not create the directory for the manifest file: ${path_1.default.dirname(__classPrivateFieldGet(this, _Manifest_manifestPath, "f"))}. Original error: ${err.message}`);
444
+ }
445
+ try {
446
+ await support_1.fs.writeFile(__classPrivateFieldGet(this, _Manifest_manifestPath, "f"), yaml_1.default.stringify(__classPrivateFieldGet(this, _Manifest_data, "f")), 'utf8');
447
+ return true;
448
+ }
449
+ catch (err) {
450
+ throw new Error(`Appium could not write to manifest at ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")} using APPIUM_HOME ${__classPrivateFieldGet(this, _Manifest_appiumHome, "f")}. Please ensure it is writable. Original error: ${err.message}`);
451
+ }
452
+ })(), "f");
453
+ try {
454
+ return await __classPrivateFieldGet(this, _Manifest_writing, "f");
455
+ }
456
+ finally {
457
+ __classPrivateFieldSet(this, _Manifest_writing, undefined, "f");
458
+ }
459
+ }
460
+ }
461
+ exports.Manifest = Manifest;
462
+ _Manifest_data = new WeakMap(), _Manifest_appiumHome = new WeakMap(), _Manifest_manifestPath = new WeakMap(), _Manifest_writing = new WeakMap(), _Manifest_reading = new WeakMap(), _Manifest_instances = new WeakSet(), _Manifest_setManifestPath =
463
+ /**
464
+ * Ensures the internal manifest path is set.
465
+ *
466
+ * Creates the directory if necessary.
467
+ * @returns {Promise<string>}
468
+ */
469
+ async function _Manifest_setManifestPath() {
470
+ if (!__classPrivateFieldGet(this, _Manifest_manifestPath, "f")) {
471
+ __classPrivateFieldSet(this, _Manifest_manifestPath, await support_1.env.resolveManifestPath(__classPrivateFieldGet(this, _Manifest_appiumHome, "f")), "f");
472
+ /* istanbul ignore if */
473
+ if (path_1.default.relative(__classPrivateFieldGet(this, _Manifest_appiumHome, "f"), __classPrivateFieldGet(this, _Manifest_manifestPath, "f")).startsWith('.')) {
474
+ throw new Error(`Mismatch between location of APPIUM_HOME and manifest file. APPIUM_HOME: ${this.appiumHome}, manifest file: ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}`);
475
+ }
476
+ }
477
+ return __classPrivateFieldGet(this, _Manifest_manifestPath, "f");
478
+ };
479
+ /**
480
+ * Returns a new or existing {@link Manifest} instance, based on the value of `appiumHome`.
481
+ *
482
+ * Maintains one instance per value of `appiumHome`.
483
+ * @param {string} appiumHome - Path to `APPIUM_HOME`
484
+ * @returns {Manifest}
485
+ */
486
+ Manifest.getInstance = lodash_1.default.memoize(function _getInstance(appiumHome) {
487
+ return new Manifest(appiumHome);
488
+ });
489
+ /**
490
+ * Type of the string referring to a driver (typically as a key or type string)
491
+ * @typedef {import('@appium/types').DriverType} DriverType
492
+ */
493
+ /**
494
+ * Type of the string referring to a plugin (typically as a key or type string)
495
+ * @typedef {import('@appium/types').PluginType} PluginType
496
+ */
497
+ /**
498
+ * @typedef SyncWithInstalledExtensionsOpts
499
+ * @property {number} [depthLimit] - Maximum depth to recurse into subdirectories
500
+ */
501
+ /**
502
+ * @typedef {import('appium/types').ManifestData} ManifestData
503
+ * @typedef {import('appium/types').InternalMetadata} InternalMetadata
504
+ */
505
+ /**
506
+ * @template {ExtensionType} ExtType
507
+ * @typedef {import('appium/types').ExtPackageJson<ExtType>} ExtPackageJson
508
+ */
509
+ /**
510
+ * @template {ExtensionType} ExtType
511
+ * @typedef {import('appium/types').ExtManifest<ExtType>} ExtManifest
512
+ */
513
+ /**
514
+ * @template {ExtensionType} ExtType
515
+ * @typedef {import('appium/types').ExtRecord<ExtType>} ExtRecord
516
+ */
517
+ /**
518
+ * Either `driver` or `plugin` rn
519
+ * @typedef {import('@appium/types').ExtensionType} ExtensionType
520
+ */
521
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../../../lib/extension/manifest.js"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;;AAEH,wDAAyB;AACzB,gDAAwB;AACxB,6CAAwC;AACxC,oDAAuB;AACvB,gDAAwB;AACxB,gDAAwB;AACxB,4CAA0E;AAC1E,uDAA4B;AAC5B,yDAAoD;AACpD,uDAAmD;AACnD,+DAA8C;AAE9C;;;GAGG;AACH,MAAM,sBAAsB,GAAG,GAAG,uBAAW,GAAG,CAAC;AAEjD;;;GAGG;AACH,MAAM,sBAAsB,GAAG,GAAG,uBAAW,GAAG,CAAC;AAEjD;;GAEG;AACH,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1C,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC3C,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC3C,SAAS,EAAE,8BAAkB;CAC9B,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,SAAS,WAAW,CAAC,KAAK;IACxB,OAAO,CACL,gBAAC,CAAC,aAAa,CAAC,KAAK,CAAC;QACtB,gBAAC,CAAC,aAAa,CAAC,KAAK,CAAC,MAAM,CAAC;QAC7B,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;QACtB,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAC1B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAS,QAAQ,CAAC,KAAK;IACrB,OAAO,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B,uBAAA,IAAI,0BAAiB,MAAM,aAAG,CAAC,mBAAmB,CAAC,uBAAA,IAAI,4BAAY,CAAC,MAAA,CAAC;QAErE,wBAAwB;QACxB,IAAI,cAAI,CAAC,QAAQ,CAAC,uBAAA,IAAI,4BAAY,EAAE,uBAAA,IAAI,8BAAc,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACvE,MAAM,IAAI,KAAK,CACb,4EACE,IAAI,CAAC,UACP,oBAAoB,uBAAA,IAAI,8BAAc,EAAE,CACzC,CAAC;SACH;KACF;IAED,OAAO,uBAAA,IAAI,8BAAc,CAAC;AAC5B,CAAC;AAxVD;;;;;;GAMG;AACI,oBAAW,GAAG,gBAAC,CAAC,OAAO,CAAC,SAAS,YAAY,CAAC,UAAU;IAC7D,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC;AA2XL;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG;AAEH;;;GAGG"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Determines if extensions have changed, and updates a hash the `package.json` in `appiumHome` if so.
3
+ *
4
+ * If they have, we need to sync them with the `extensions.yaml` manifest.
5
+ *
6
+ * _Warning: this makes a blocking call to `writeFileSync`._
7
+ * @param {string} appiumHome
8
+ * @returns {Promise<boolean>} `true` if `package.json` `appiumHome` changed
9
+ */
10
+ export function packageDidChange(appiumHome: string): Promise<boolean>;
11
+ //# sourceMappingURL=package-changed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-changed.d.ts","sourceRoot":"","sources":["../../../lib/extension/package-changed.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,6CAHW,MAAM,GACJ,QAAQ,OAAO,CAAC,CAkD5B"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.packageDidChange = void 0;
7
+ const support_1 = require("@appium/support");
8
+ const package_changed_1 = require("package-changed");
9
+ const path_1 = __importDefault(require("path"));
10
+ const constants_1 = require("../constants");
11
+ const logger_1 = __importDefault(require("../logger"));
12
+ /**
13
+ * Determines if extensions have changed, and updates a hash the `package.json` in `appiumHome` if so.
14
+ *
15
+ * If they have, we need to sync them with the `extensions.yaml` manifest.
16
+ *
17
+ * _Warning: this makes a blocking call to `writeFileSync`._
18
+ * @param {string} appiumHome
19
+ * @returns {Promise<boolean>} `true` if `package.json` `appiumHome` changed
20
+ */
21
+ async function packageDidChange(appiumHome) {
22
+ const hashFilename = path_1.default.join(appiumHome, constants_1.PKG_HASHFILE_RELATIVE_PATH);
23
+ // XXX: the types in `package-changed` seem to be wrong.
24
+ /** @type {boolean} */
25
+ let isChanged;
26
+ /** @type {() => void} */
27
+ let writeHash;
28
+ /** @type {string} */
29
+ let hash;
30
+ /** @type {string|undefined} */
31
+ let oldHash;
32
+ // first mkdirp the target dir.
33
+ const hashFilenameDir = path_1.default.dirname(hashFilename);
34
+ logger_1.default.debug(`Creating hash file directory: ${hashFilenameDir}`);
35
+ try {
36
+ await support_1.fs.mkdirp(hashFilenameDir);
37
+ }
38
+ catch (err) {
39
+ throw new Error(`Appium could not create the directory for hash file: ${hashFilenameDir}. Original error: ${err.message}`);
40
+ }
41
+ try {
42
+ ({ isChanged, writeHash, oldHash, hash } = await (0, package_changed_1.isPackageChanged)({
43
+ cwd: appiumHome,
44
+ hashFilename: constants_1.PKG_HASHFILE_RELATIVE_PATH,
45
+ }));
46
+ }
47
+ catch {
48
+ return true;
49
+ }
50
+ if (isChanged) {
51
+ try {
52
+ writeHash();
53
+ logger_1.default.debug(`Updated hash of ${appiumHome}/package.json from: ${oldHash ?? '(none)'} to: ${hash}`);
54
+ }
55
+ catch (err) {
56
+ throw new Error(`Appium could not write hash file: ${hashFilenameDir}. Original error: ${err.message}`);
57
+ }
58
+ }
59
+ return isChanged;
60
+ }
61
+ exports.packageDidChange = packageDidChange;
62
+ //# sourceMappingURL=package-changed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-changed.js","sourceRoot":"","sources":["../../../lib/extension/package-changed.js"],"names":[],"mappings":";;;;;;AAAA,6CAAmC;AACnC,qDAAiD;AACjD,gDAAwB;AACxB,4CAAwD;AACxD,uDAA4B;AAE5B;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CAAC,UAAU;IAC/C,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,sCAA0B,CAAC,CAAC;IAEvE,wDAAwD;IAExD,sBAAsB;IACtB,IAAI,SAAS,CAAC;IACd,yBAAyB;IACzB,IAAI,SAAS,CAAC;IACd,qBAAqB;IACrB,IAAI,IAAI,CAAC;IACT,+BAA+B;IAC/B,IAAI,OAAO,CAAC;IAEZ,+BAA+B;IAC/B,MAAM,eAAe,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACnD,gBAAG,CAAC,KAAK,CAAC,iCAAiC,eAAe,EAAE,CAAC,CAAC;IAC9D,IAAI;QACF,MAAM,YAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;KAClC;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,wDAAwD,eAAe,qBAAqB,GAAG,CAAC,OAAO,EAAE,CAC1G,CAAC;KACH;IAED,IAAI;QACF,CAAC,EAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAC,GAAG,MAAM,IAAA,kCAAgB,EAAC;YAC9D,GAAG,EAAE,UAAU;YACf,YAAY,EAAE,sCAA0B;SACzC,CAAC,CAAC,CAAC;KACL;IAAC,MAAM;QACN,OAAO,IAAI,CAAC;KACb;IAED,IAAI,SAAS,EAAE;QACb,IAAI;YACF,SAAS,EAAE,CAAC;YACZ,gBAAG,CAAC,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