appium 2.0.0-beta.7 → 2.0.0-beta.71

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 (206) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +149 -58
  3. package/build/lib/appium.d.ts +229 -0
  4. package/build/lib/appium.d.ts.map +1 -0
  5. package/build/lib/appium.js +678 -439
  6. package/build/lib/appium.js.map +1 -0
  7. package/build/lib/cli/args.d.ts +17 -0
  8. package/build/lib/cli/args.d.ts.map +1 -0
  9. package/build/lib/cli/args.js +263 -300
  10. package/build/lib/cli/args.js.map +1 -0
  11. package/build/lib/cli/driver-command.d.ts +102 -0
  12. package/build/lib/cli/driver-command.d.ts.map +1 -0
  13. package/build/lib/cli/driver-command.js +131 -81
  14. package/build/lib/cli/driver-command.js.map +1 -0
  15. package/build/lib/cli/extension-command.d.ts +402 -0
  16. package/build/lib/cli/extension-command.d.ts.map +1 -0
  17. package/build/lib/cli/extension-command.js +799 -383
  18. package/build/lib/cli/extension-command.js.map +1 -0
  19. package/build/lib/cli/extension.d.ts +23 -0
  20. package/build/lib/cli/extension.d.ts.map +1 -0
  21. package/build/lib/cli/extension.js +71 -60
  22. package/build/lib/cli/extension.js.map +1 -0
  23. package/build/lib/cli/parser.d.ts +84 -0
  24. package/build/lib/cli/parser.d.ts.map +1 -0
  25. package/build/lib/cli/parser.js +252 -148
  26. package/build/lib/cli/parser.js.map +1 -0
  27. package/build/lib/cli/plugin-command.d.ts +99 -0
  28. package/build/lib/cli/plugin-command.d.ts.map +1 -0
  29. package/build/lib/cli/plugin-command.js +125 -81
  30. package/build/lib/cli/plugin-command.js.map +1 -0
  31. package/build/lib/cli/utils.d.ts +29 -0
  32. package/build/lib/cli/utils.d.ts.map +1 -0
  33. package/build/lib/cli/utils.js +72 -51
  34. package/build/lib/cli/utils.js.map +1 -0
  35. package/build/lib/config-file.d.ts +100 -0
  36. package/build/lib/config-file.d.ts.map +1 -0
  37. package/build/lib/config-file.js +207 -0
  38. package/build/lib/config-file.js.map +1 -0
  39. package/build/lib/config.d.ts +49 -0
  40. package/build/lib/config.d.ts.map +1 -0
  41. package/build/lib/config.js +262 -223
  42. package/build/lib/config.js.map +1 -0
  43. package/build/lib/constants.d.ts +56 -0
  44. package/build/lib/constants.d.ts.map +1 -0
  45. package/build/lib/constants.js +73 -0
  46. package/build/lib/constants.js.map +1 -0
  47. package/build/lib/extension/driver-config.d.ts +82 -0
  48. package/build/lib/extension/driver-config.d.ts.map +1 -0
  49. package/build/lib/extension/driver-config.js +210 -0
  50. package/build/lib/extension/driver-config.js.map +1 -0
  51. package/build/lib/extension/extension-config.d.ts +270 -0
  52. package/build/lib/extension/extension-config.d.ts.map +1 -0
  53. package/build/lib/extension/extension-config.js +601 -0
  54. package/build/lib/extension/extension-config.js.map +1 -0
  55. package/build/lib/extension/index.d.ts +48 -0
  56. package/build/lib/extension/index.d.ts.map +1 -0
  57. package/build/lib/extension/index.js +105 -0
  58. package/build/lib/extension/index.js.map +1 -0
  59. package/build/lib/extension/manifest-migrations.d.ts +27 -0
  60. package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
  61. package/build/lib/extension/manifest-migrations.js +134 -0
  62. package/build/lib/extension/manifest-migrations.js.map +1 -0
  63. package/build/lib/extension/manifest.d.ts +145 -0
  64. package/build/lib/extension/manifest.d.ts.map +1 -0
  65. package/build/lib/extension/manifest.js +528 -0
  66. package/build/lib/extension/manifest.js.map +1 -0
  67. package/build/lib/extension/package-changed.d.ts +11 -0
  68. package/build/lib/extension/package-changed.d.ts.map +1 -0
  69. package/build/lib/extension/package-changed.js +62 -0
  70. package/build/lib/extension/package-changed.js.map +1 -0
  71. package/build/lib/extension/plugin-config.d.ts +56 -0
  72. package/build/lib/extension/plugin-config.d.ts.map +1 -0
  73. package/build/lib/extension/plugin-config.js +102 -0
  74. package/build/lib/extension/plugin-config.js.map +1 -0
  75. package/build/lib/grid-register.d.ts +10 -0
  76. package/build/lib/grid-register.d.ts.map +1 -0
  77. package/build/lib/grid-register.js +122 -144
  78. package/build/lib/grid-register.js.map +1 -0
  79. package/build/lib/logger.d.ts +3 -0
  80. package/build/lib/logger.d.ts.map +1 -0
  81. package/build/lib/logger.js +5 -17
  82. package/build/lib/logger.js.map +1 -0
  83. package/build/lib/logsink.d.ts +4 -0
  84. package/build/lib/logsink.d.ts.map +1 -0
  85. package/build/lib/logsink.js +189 -184
  86. package/build/lib/logsink.js.map +1 -0
  87. package/build/lib/main.d.ts +62 -0
  88. package/build/lib/main.d.ts.map +1 -0
  89. package/build/lib/main.js +388 -234
  90. package/build/lib/main.js.map +1 -0
  91. package/build/lib/schema/arg-spec.d.ts +143 -0
  92. package/build/lib/schema/arg-spec.d.ts.map +1 -0
  93. package/build/lib/schema/arg-spec.js +164 -0
  94. package/build/lib/schema/arg-spec.js.map +1 -0
  95. package/build/lib/schema/cli-args.d.ts +19 -0
  96. package/build/lib/schema/cli-args.d.ts.map +1 -0
  97. package/build/lib/schema/cli-args.js +220 -0
  98. package/build/lib/schema/cli-args.js.map +1 -0
  99. package/build/lib/schema/cli-transformers.d.ts +5 -0
  100. package/build/lib/schema/cli-transformers.d.ts.map +1 -0
  101. package/build/lib/schema/cli-transformers.js +124 -0
  102. package/build/lib/schema/cli-transformers.js.map +1 -0
  103. package/build/lib/schema/index.d.ts +3 -0
  104. package/build/lib/schema/index.d.ts.map +1 -0
  105. package/build/lib/schema/index.js +19 -0
  106. package/build/lib/schema/index.js.map +1 -0
  107. package/build/lib/schema/keywords.d.ts +24 -0
  108. package/build/lib/schema/keywords.d.ts.map +1 -0
  109. package/build/lib/schema/keywords.js +128 -0
  110. package/build/lib/schema/keywords.js.map +1 -0
  111. package/build/lib/schema/schema.d.ts +260 -0
  112. package/build/lib/schema/schema.d.ts.map +1 -0
  113. package/build/lib/schema/schema.js +640 -0
  114. package/build/lib/schema/schema.js.map +1 -0
  115. package/build/lib/utils.d.ts +266 -0
  116. package/build/lib/utils.d.ts.map +1 -0
  117. package/build/lib/utils.js +349 -273
  118. package/build/lib/utils.js.map +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 +21 -0
  132. package/build/types/manifest/index.d.ts.map +1 -0
  133. package/build/types/manifest/index.js +42 -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/build/types/manifest/v4.d.ts +139 -0
  140. package/build/types/manifest/v4.d.ts.map +1 -0
  141. package/build/types/manifest/v4.js +3 -0
  142. package/build/types/manifest/v4.js.map +1 -0
  143. package/driver.d.ts +1 -0
  144. package/driver.js +14 -0
  145. package/index.js +11 -0
  146. package/lib/appium.js +558 -186
  147. package/lib/cli/args.js +275 -407
  148. package/lib/cli/driver-command.js +132 -24
  149. package/lib/cli/extension-command.js +751 -272
  150. package/lib/cli/extension.js +47 -20
  151. package/lib/cli/parser.js +267 -95
  152. package/lib/cli/plugin-command.js +122 -22
  153. package/lib/cli/utils.js +24 -10
  154. package/lib/config-file.js +220 -0
  155. package/lib/config.js +243 -132
  156. package/lib/constants.js +79 -0
  157. package/lib/extension/driver-config.js +247 -0
  158. package/lib/extension/extension-config.js +709 -0
  159. package/lib/extension/index.js +116 -0
  160. package/lib/extension/manifest-migrations.js +136 -0
  161. package/lib/extension/manifest.js +580 -0
  162. package/lib/extension/package-changed.js +64 -0
  163. package/lib/extension/plugin-config.js +112 -0
  164. package/lib/grid-register.js +49 -35
  165. package/lib/logger.js +1 -2
  166. package/lib/logsink.js +59 -36
  167. package/lib/main.js +369 -104
  168. package/lib/schema/arg-spec.js +229 -0
  169. package/lib/schema/cli-args.js +241 -0
  170. package/lib/schema/cli-transformers.js +119 -0
  171. package/lib/schema/index.js +2 -0
  172. package/lib/schema/keywords.js +136 -0
  173. package/lib/schema/schema.js +725 -0
  174. package/lib/utils.js +289 -167
  175. package/package.json +84 -83
  176. package/plugin.d.ts +1 -0
  177. package/plugin.js +13 -0
  178. package/scripts/autoinstall-extensions.js +243 -0
  179. package/support.d.ts +1 -0
  180. package/support.js +13 -0
  181. package/tsconfig.json +25 -0
  182. package/types/cli.ts +193 -0
  183. package/types/index.ts +20 -0
  184. package/types/manifest/README.md +30 -0
  185. package/types/manifest/base.ts +158 -0
  186. package/types/manifest/index.ts +28 -0
  187. package/types/manifest/v3.ts +161 -0
  188. package/types/manifest/v4.ts +161 -0
  189. package/CHANGELOG.md +0 -3594
  190. package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
  191. package/build/lib/cli/argparse-actions.js +0 -104
  192. package/build/lib/cli/npm.js +0 -200
  193. package/build/lib/cli/parser-helpers.js +0 -93
  194. package/build/lib/driver-config.js +0 -77
  195. package/build/lib/drivers.js +0 -99
  196. package/build/lib/extension-config.js +0 -253
  197. package/build/lib/plugin-config.js +0 -59
  198. package/build/lib/plugins.js +0 -14
  199. package/lib/cli/argparse-actions.js +0 -77
  200. package/lib/cli/npm.js +0 -175
  201. package/lib/cli/parser-helpers.js +0 -91
  202. package/lib/driver-config.js +0 -46
  203. package/lib/drivers.js +0 -84
  204. package/lib/extension-config.js +0 -209
  205. package/lib/plugin-config.js +0 -34
  206. package/lib/plugins.js +0 -10
@@ -0,0 +1,528 @@
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
+ * @param {boolean} hasAppiumDependency - This affects whether or not the "dev" `InstallType` is used
153
+ * @returns {Promise<boolean>} `true` if any extensions were added, `false` otherwise.
154
+ */
155
+ async syncWithInstalledExtensions(hasAppiumDependency = false) {
156
+ // this could be parallelized, but we can't use fs.walk as an async iterator
157
+ let didChange = false;
158
+ /**
159
+ * Listener for the `match` event of a `glob` instance
160
+ * @param {string} filepath - Path to a `package.json`
161
+ * @param {boolean} [devType] - If `true`, this is an extension in "dev mode"
162
+ * @returns {Promise<void>}
163
+ */
164
+ const onMatch = async (filepath, devType = false) => {
165
+ try {
166
+ const pkg = JSON.parse(await support_1.fs.readFile(filepath, 'utf8'));
167
+ if (isExtension(pkg)) {
168
+ const extType = isDriver(pkg) ? constants_1.DRIVER_TYPE : constants_1.PLUGIN_TYPE;
169
+ /**
170
+ * this should only be 'unknown' if the extension's `package.json` is invalid
171
+ * @type {string}
172
+ */
173
+ const name = isDriver(pkg)
174
+ ? pkg.appium.driverName
175
+ : isPlugin(pkg)
176
+ ? pkg.appium.pluginName
177
+ : '(unknown)';
178
+ if ((isDriver(pkg) && !this.hasDriver(name)) ||
179
+ (isPlugin(pkg) && !this.hasPlugin(name))) {
180
+ logger_1.default.info(`Discovered installed ${extType} "${name}"`);
181
+ }
182
+ const installType = devType && hasAppiumDependency ? extension_config_1.INSTALL_TYPE_DEV : extension_config_1.INSTALL_TYPE_NPM;
183
+ const changed = this.addExtensionFromPackage(pkg, filepath, installType);
184
+ didChange = didChange || changed;
185
+ }
186
+ }
187
+ catch { }
188
+ };
189
+ /**
190
+ * A list of `Promise`s which read `package.json` files looking for Appium extensions.
191
+ * @type {Promise<void>[]}
192
+ */
193
+ const queue = [
194
+ // look at `package.json` in `APPIUM_HOME` only.
195
+ // this causes extensions in "dev mode" to be automatically found
196
+ onMatch(path_1.default.join(__classPrivateFieldGet(this, _Manifest_appiumHome, "f"), 'package.json'), true),
197
+ ];
198
+ // add dependencies to the queue
199
+ await new bluebird_1.default((resolve, reject) => {
200
+ (0, glob_1.default)('node_modules/{*,@*/*}/package.json', { cwd: __classPrivateFieldGet(this, _Manifest_appiumHome, "f"), silent: true, absolute: true },
201
+ // eslint-disable-next-line promise/prefer-await-to-callbacks
202
+ (err) => {
203
+ if (err) {
204
+ reject(err);
205
+ }
206
+ resolve();
207
+ })
208
+ .on('error', reject)
209
+ .on('match', (filepath) => {
210
+ queue.push(onMatch(filepath));
211
+ });
212
+ });
213
+ // wait for everything to finish
214
+ await bluebird_1.default.all(queue);
215
+ return didChange;
216
+ }
217
+ /**
218
+ * Returns `true` if driver with name `name` is registered.
219
+ * @param {string} name - Driver name
220
+ * @returns {boolean}
221
+ */
222
+ hasDriver(name) {
223
+ return Boolean(__classPrivateFieldGet(this, _Manifest_data, "f").drivers[name]);
224
+ }
225
+ /**
226
+ * Returns `true` if plugin with name `name` is registered.
227
+ * @param {string} name - Plugin name
228
+ * @returns {boolean}
229
+ */
230
+ hasPlugin(name) {
231
+ return Boolean(__classPrivateFieldGet(this, _Manifest_data, "f").plugins[name]);
232
+ }
233
+ /**
234
+ * Given a path to a `package.json`, add it as either a driver or plugin to the manifest.
235
+ *
236
+ * @template {ExtensionType} ExtType
237
+ * @param {ExtPackageJson<ExtType>} pkgJson
238
+ * @param {string} pkgPath
239
+ * @param {typeof INSTALL_TYPE_NPM | typeof INSTALL_TYPE_DEV} [installType]
240
+ * @returns {boolean} - `true` if this method did anything.
241
+ */
242
+ addExtensionFromPackage(pkgJson, pkgPath, installType = extension_config_1.INSTALL_TYPE_NPM) {
243
+ const extensionPath = path_1.default.dirname(pkgPath);
244
+ /**
245
+ * @type {InternalMetadata}
246
+ */
247
+ const internal = {
248
+ pkgName: pkgJson.name,
249
+ version: pkgJson.version,
250
+ appiumVersion: pkgJson.peerDependencies?.appium,
251
+ installType,
252
+ installSpec: `${pkgJson.name}@${pkgJson.version}`,
253
+ installPath: extensionPath,
254
+ };
255
+ if (isDriver(pkgJson)) {
256
+ const value = {
257
+ ...lodash_1.default.omit(pkgJson.appium, 'driverName'),
258
+ ...internal,
259
+ };
260
+ if (!lodash_1.default.isEqual(value, __classPrivateFieldGet(this, _Manifest_data, "f").drivers[pkgJson.appium.driverName])) {
261
+ this.setExtension(constants_1.DRIVER_TYPE, pkgJson.appium.driverName, value);
262
+ return true;
263
+ }
264
+ return false;
265
+ }
266
+ else if (isPlugin(pkgJson)) {
267
+ const value = {
268
+ ...lodash_1.default.omit(pkgJson.appium, 'pluginName'),
269
+ ...internal,
270
+ };
271
+ if (!lodash_1.default.isEqual(value, __classPrivateFieldGet(this, _Manifest_data, "f").plugins[pkgJson.appium.pluginName])) {
272
+ this.setExtension(constants_1.PLUGIN_TYPE, pkgJson.appium.pluginName, value);
273
+ return true;
274
+ }
275
+ return false;
276
+ }
277
+ else {
278
+ throw new TypeError(`The extension in ${extensionPath} is neither a valid ${constants_1.DRIVER_TYPE} nor a valid ${constants_1.PLUGIN_TYPE}.`);
279
+ }
280
+ }
281
+ /**
282
+ * Adds an extension to the manifest as was installed by the `appium` CLI. The
283
+ * `extData`, `extType`, and `extName` have already been determined.
284
+ *
285
+ * See {@link Manifest.addExtensionFromPackage} for adding an extension from an on-disk package.
286
+ * @template {ExtensionType} ExtType
287
+ * @param {ExtType} extType - `driver` or `plugin`
288
+ * @param {string} extName - Name of extension
289
+ * @param {ExtManifest<ExtType>} extData - Extension metadata
290
+ * @returns {ExtManifest<ExtType>} A clone of `extData`, potentially with a mutated `appiumVersion` field
291
+ */
292
+ setExtension(extType, extName, extData) {
293
+ const data = lodash_1.default.cloneDeep(extData);
294
+ __classPrivateFieldGet(this, _Manifest_data, "f")[`${extType}s`][extName] = data;
295
+ return data;
296
+ }
297
+ /**
298
+ * Sets the schema revision
299
+ * @param {keyof import('./manifest-migrations').ManifestDataVersions} rev
300
+ */
301
+ setSchemaRev(rev) {
302
+ __classPrivateFieldGet(this, _Manifest_data, "f").schemaRev = rev;
303
+ }
304
+ /**
305
+ * Remove an extension from the manifest.
306
+ * @param {ExtensionType} extType
307
+ * @param {string} extName
308
+ */
309
+ deleteExtension(extType, extName) {
310
+ delete __classPrivateFieldGet(this, _Manifest_data, "f")[`${extType}s`][extName];
311
+ }
312
+ /**
313
+ * Returns the `APPIUM_HOME` path
314
+ */
315
+ get appiumHome() {
316
+ return __classPrivateFieldGet(this, _Manifest_appiumHome, "f");
317
+ }
318
+ /**
319
+ * Returns the path to the manifest file (`extensions.yaml`)
320
+ */
321
+ get manifestPath() {
322
+ return __classPrivateFieldGet(this, _Manifest_manifestPath, "f");
323
+ }
324
+ /**
325
+ * Returns the schema rev of this manifest
326
+ */
327
+ get schemaRev() {
328
+ return __classPrivateFieldGet(this, _Manifest_data, "f").schemaRev;
329
+ }
330
+ /**
331
+ * Returns extension data for a particular type.
332
+ *
333
+ * @template {ExtensionType} ExtType
334
+ * @param {ExtType} extType
335
+ * @returns {Readonly<ExtRecord<ExtType>>}
336
+ */
337
+ getExtensionData(extType) {
338
+ return __classPrivateFieldGet(this, _Manifest_data, "f")[ /** @type {string} */(`${extType}s`)];
339
+ }
340
+ /**
341
+ * Reads manifest from disk and _overwrites_ the internal data.
342
+ *
343
+ * If the manifest does not exist on disk, an
344
+ * {@link INITIAL_MANIFEST_DATA "empty"} manifest file will be created, as
345
+ * well as its directory if needed.
346
+ *
347
+ * This will also, if necessary:
348
+ * 1. perform a migration of the manifest data
349
+ * 2. sync the manifest with extensions on-disk (kind of like "auto
350
+ * discovery")
351
+ * 3. write the manifest to disk.
352
+ *
353
+ * Only one read operation can happen at a time.
354
+ *
355
+ * @returns {Promise<ManifestData>} The data
356
+ */
357
+ async read() {
358
+ if (__classPrivateFieldGet(this, _Manifest_reading, "f")) {
359
+ await __classPrivateFieldGet(this, _Manifest_reading, "f");
360
+ return __classPrivateFieldGet(this, _Manifest_data, "f");
361
+ }
362
+ __classPrivateFieldSet(this, _Manifest_reading, (async () => {
363
+ /** @type {ManifestData} */
364
+ let data;
365
+ /**
366
+ * This will be `true` if, after reading, we need to update the manifest data
367
+ * and write it again to disk.
368
+ */
369
+ let shouldWrite = false;
370
+ await __classPrivateFieldGet(this, _Manifest_instances, "m", _Manifest_setManifestPath).call(this);
371
+ try {
372
+ const yaml = await support_1.fs.readFile(__classPrivateFieldGet(this, _Manifest_manifestPath, "f"), 'utf8');
373
+ data = yaml_1.default.parse(yaml);
374
+ logger_1.default.debug(`Parsed manifest file at ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}: ${JSON.stringify(data, null, 2)}`);
375
+ }
376
+ catch (err) {
377
+ if (err.code === 'ENOENT') {
378
+ logger_1.default.debug(`No manifest file found at ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}; creating`);
379
+ data = lodash_1.default.cloneDeep(INITIAL_MANIFEST_DATA);
380
+ shouldWrite = true;
381
+ }
382
+ else {
383
+ if (__classPrivateFieldGet(this, _Manifest_manifestPath, "f")) {
384
+ throw new Error(`Appium had trouble loading the extension installation ` +
385
+ `cache file (${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}). It may be invalid YAML. Specific error: ${err.message}`);
386
+ }
387
+ else {
388
+ throw new Error(`Appium encountered an unknown problem. Specific error: ${err.message}`);
389
+ }
390
+ }
391
+ }
392
+ __classPrivateFieldSet(this, _Manifest_data, data, "f");
393
+ /**
394
+ * the only way `shouldWrite` is `true` is if we have a new file. a new
395
+ * file will get the latest schema revision, so we can skip the migration.
396
+ */
397
+ if (!shouldWrite && (data.schemaRev ?? 0) < constants_1.CURRENT_SCHEMA_REV) {
398
+ logger_1.default.debug(`Updating manifest schema from rev ${data.schemaRev ?? '(none)'} to ${constants_1.CURRENT_SCHEMA_REV}`);
399
+ shouldWrite = await (0, manifest_migrations_1.migrate)(this);
400
+ }
401
+ const hasAppiumDependency = await support_1.env.hasAppiumDependency(this.appiumHome);
402
+ /**
403
+ * we still may want to sync with installed extensions even if we have a
404
+ * new file. right now this is limited to the following cases:
405
+ * 1. we have a brand new manifest file
406
+ * 2. we have performed a migration on a manifest file
407
+ * 3. `appium` is a dependency within `package.json`, and `package.json`
408
+ * has changed since last time we checked.
409
+ *
410
+ * It may also make sense to sync with the extensions in an arbitrary
411
+ * `APPIUM_HOME`, but we don't do that here.
412
+ */
413
+ if (shouldWrite || (hasAppiumDependency && (await (0, package_changed_1.packageDidChange)(this.appiumHome)))) {
414
+ logger_1.default.debug('Discovering newly installed extensions...');
415
+ shouldWrite = (await this.syncWithInstalledExtensions(hasAppiumDependency)) || shouldWrite;
416
+ }
417
+ if (shouldWrite) {
418
+ await this.write();
419
+ }
420
+ })(), "f");
421
+ try {
422
+ await __classPrivateFieldGet(this, _Manifest_reading, "f");
423
+ return __classPrivateFieldGet(this, _Manifest_data, "f");
424
+ }
425
+ finally {
426
+ __classPrivateFieldSet(this, _Manifest_reading, undefined, "f");
427
+ }
428
+ }
429
+ /**
430
+ * Writes the data if it need s writing.
431
+ *
432
+ * If the `schemaRev` prop needs updating, the file will be written.
433
+ *
434
+ * @todo If this becomes too much of a bottleneck, throttle it.
435
+ * @returns {Promise<boolean>} Whether the data was written
436
+ */
437
+ async write() {
438
+ if (__classPrivateFieldGet(this, _Manifest_writing, "f")) {
439
+ return __classPrivateFieldGet(this, _Manifest_writing, "f");
440
+ }
441
+ __classPrivateFieldSet(this, _Manifest_writing, (async () => {
442
+ await __classPrivateFieldGet(this, _Manifest_instances, "m", _Manifest_setManifestPath).call(this);
443
+ try {
444
+ await support_1.fs.mkdirp(path_1.default.dirname(__classPrivateFieldGet(this, _Manifest_manifestPath, "f")));
445
+ }
446
+ catch (err) {
447
+ 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}`);
448
+ }
449
+ try {
450
+ await support_1.fs.writeFile(__classPrivateFieldGet(this, _Manifest_manifestPath, "f"), yaml_1.default.stringify(__classPrivateFieldGet(this, _Manifest_data, "f")), 'utf8');
451
+ return true;
452
+ }
453
+ catch (err) {
454
+ 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}`);
455
+ }
456
+ })(), "f");
457
+ try {
458
+ return await __classPrivateFieldGet(this, _Manifest_writing, "f");
459
+ }
460
+ finally {
461
+ __classPrivateFieldSet(this, _Manifest_writing, undefined, "f");
462
+ }
463
+ }
464
+ }
465
+ exports.Manifest = Manifest;
466
+ _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 =
467
+ /**
468
+ * Ensures the internal manifest path is set.
469
+ *
470
+ * Creates the directory if necessary.
471
+ * @returns {Promise<string>}
472
+ */
473
+ async function _Manifest_setManifestPath() {
474
+ if (!__classPrivateFieldGet(this, _Manifest_manifestPath, "f")) {
475
+ __classPrivateFieldSet(this, _Manifest_manifestPath, await support_1.env.resolveManifestPath(__classPrivateFieldGet(this, _Manifest_appiumHome, "f")), "f");
476
+ /* istanbul ignore if */
477
+ if (path_1.default.relative(__classPrivateFieldGet(this, _Manifest_appiumHome, "f"), __classPrivateFieldGet(this, _Manifest_manifestPath, "f")).startsWith('.')) {
478
+ throw new Error(`Mismatch between location of APPIUM_HOME and manifest file. APPIUM_HOME: ${this.appiumHome}, manifest file: ${__classPrivateFieldGet(this, _Manifest_manifestPath, "f")}`);
479
+ }
480
+ }
481
+ return __classPrivateFieldGet(this, _Manifest_manifestPath, "f");
482
+ };
483
+ /**
484
+ * Returns a new or existing {@link Manifest} instance, based on the value of `appiumHome`.
485
+ *
486
+ * Maintains one instance per value of `appiumHome`.
487
+ */
488
+ Manifest.getInstance = lodash_1.default.memoize(
489
+ /**
490
+ * @param {string} appiumHome - Path to `APPIUM_HOME`
491
+ * @returns {Manifest}
492
+ */
493
+ function _getInstance(appiumHome) {
494
+ return new Manifest(appiumHome);
495
+ });
496
+ /**
497
+ * Type of the string referring to a driver (typically as a key or type string)
498
+ * @typedef {import('@appium/types').DriverType} DriverType
499
+ */
500
+ /**
501
+ * Type of the string referring to a plugin (typically as a key or type string)
502
+ * @typedef {import('@appium/types').PluginType} PluginType
503
+ */
504
+ /**
505
+ * @typedef SyncWithInstalledExtensionsOpts
506
+ * @property {number} [depthLimit] - Maximum depth to recurse into subdirectories
507
+ */
508
+ /**
509
+ * @typedef {import('appium/types').ManifestData} ManifestData
510
+ * @typedef {import('appium/types').InternalMetadata} InternalMetadata
511
+ */
512
+ /**
513
+ * @template {ExtensionType} ExtType
514
+ * @typedef {import('appium/types').ExtPackageJson<ExtType>} ExtPackageJson
515
+ */
516
+ /**
517
+ * @template {ExtensionType} ExtType
518
+ * @typedef {import('appium/types').ExtManifest<ExtType>} ExtManifest
519
+ */
520
+ /**
521
+ * @template {ExtensionType} ExtType
522
+ * @typedef {import('appium/types').ExtRecord<ExtType>} ExtRecord
523
+ */
524
+ /**
525
+ * Either `driver` or `plugin` rn
526
+ * @typedef {import('@appium/types').ExtensionType} ExtensionType
527
+ */
528
+ //# 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,yDAAsE;AACtE,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,C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,OAAO;AAC5B;;;GAGG;AACH,SAAS,YAAY,CAAC,UAAU;IAC9B,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC,CACF,CAAC;AA8XJ;;;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;IAEv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