appium 3.4.2 → 3.5.1

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 (196) hide show
  1. package/build/lib/appium.d.ts +3 -0
  2. package/build/lib/appium.d.ts.map +1 -1
  3. package/build/lib/appium.js +73 -51
  4. package/build/lib/appium.js.map +1 -1
  5. package/build/lib/bidi-commands.d.ts.map +1 -1
  6. package/build/lib/bidi-commands.js +36 -31
  7. package/build/lib/bidi-commands.js.map +1 -1
  8. package/build/lib/bootstrap/appium-initializer.d.ts.map +1 -1
  9. package/build/lib/bootstrap/appium-initializer.js +13 -13
  10. package/build/lib/bootstrap/appium-initializer.js.map +1 -1
  11. package/build/lib/bootstrap/appium-main-runner.d.ts.map +1 -1
  12. package/build/lib/bootstrap/appium-main-runner.js +2 -2
  13. package/build/lib/bootstrap/appium-main-runner.js.map +1 -1
  14. package/build/lib/bootstrap/config-file.d.ts.map +1 -1
  15. package/build/lib/bootstrap/config-file.js +11 -11
  16. package/build/lib/bootstrap/config-file.js.map +1 -1
  17. package/build/lib/bootstrap/grid-v3-register.d.ts.map +1 -1
  18. package/build/lib/bootstrap/grid-v3-register.js +9 -6
  19. package/build/lib/bootstrap/grid-v3-register.js.map +1 -1
  20. package/build/lib/bootstrap/main-helpers.d.ts +1 -1
  21. package/build/lib/bootstrap/main-helpers.d.ts.map +1 -1
  22. package/build/lib/bootstrap/main-helpers.js +19 -20
  23. package/build/lib/bootstrap/main-helpers.js.map +1 -1
  24. package/build/lib/bootstrap/node-helpers.d.ts +1 -1
  25. package/build/lib/bootstrap/node-helpers.d.ts.map +1 -1
  26. package/build/lib/bootstrap/node-helpers.js +8 -16
  27. package/build/lib/bootstrap/node-helpers.js.map +1 -1
  28. package/build/lib/bootstrap/startup-config.d.ts.map +1 -1
  29. package/build/lib/bootstrap/startup-config.js +32 -30
  30. package/build/lib/bootstrap/startup-config.js.map +1 -1
  31. package/build/lib/cli/args.d.ts +3 -2
  32. package/build/lib/cli/args.d.ts.map +1 -1
  33. package/build/lib/cli/args.js +2 -5
  34. package/build/lib/cli/args.js.map +1 -1
  35. package/build/lib/cli/driver-command.d.ts +1 -2
  36. package/build/lib/cli/driver-command.d.ts.map +1 -1
  37. package/build/lib/cli/driver-command.js +7 -8
  38. package/build/lib/cli/driver-command.js.map +1 -1
  39. package/build/lib/cli/extension-command.d.ts +2 -2
  40. package/build/lib/cli/extension-command.d.ts.map +1 -1
  41. package/build/lib/cli/extension-command.js +105 -71
  42. package/build/lib/cli/extension-command.js.map +1 -1
  43. package/build/lib/cli/extension.d.ts.map +1 -1
  44. package/build/lib/cli/extension.js.map +1 -1
  45. package/build/lib/cli/parser.d.ts.map +1 -1
  46. package/build/lib/cli/parser.js +21 -14
  47. package/build/lib/cli/parser.js.map +1 -1
  48. package/build/lib/cli/plugin-command.d.ts +1 -1
  49. package/build/lib/cli/plugin-command.d.ts.map +1 -1
  50. package/build/lib/cli/plugin-command.js +5 -5
  51. package/build/lib/cli/plugin-command.js.map +1 -1
  52. package/build/lib/cli/setup-command.d.ts +1 -1
  53. package/build/lib/cli/setup-command.d.ts.map +1 -1
  54. package/build/lib/cli/setup-command.js +14 -19
  55. package/build/lib/cli/setup-command.js.map +1 -1
  56. package/build/lib/cli/utils.d.ts.map +1 -1
  57. package/build/lib/cli/utils.js +3 -2
  58. package/build/lib/cli/utils.js.map +1 -1
  59. package/build/lib/doctor/doctor.d.ts +0 -1
  60. package/build/lib/doctor/doctor.d.ts.map +1 -1
  61. package/build/lib/doctor/doctor.js +12 -17
  62. package/build/lib/doctor/doctor.js.map +1 -1
  63. package/build/lib/extension/driver-config.d.ts.map +1 -1
  64. package/build/lib/extension/driver-config.js +11 -12
  65. package/build/lib/extension/driver-config.js.map +1 -1
  66. package/build/lib/extension/extension-config.d.ts.map +1 -1
  67. package/build/lib/extension/extension-config.js +30 -30
  68. package/build/lib/extension/extension-config.js.map +1 -1
  69. package/build/lib/extension/index.d.ts.map +1 -1
  70. package/build/lib/extension/index.js +28 -41
  71. package/build/lib/extension/index.js.map +1 -1
  72. package/build/lib/extension/manifest.d.ts +3 -2
  73. package/build/lib/extension/manifest.d.ts.map +1 -1
  74. package/build/lib/extension/manifest.js +20 -24
  75. package/build/lib/extension/manifest.js.map +1 -1
  76. package/build/lib/extension/plugin-config.d.ts.map +1 -1
  77. package/build/lib/extension/plugin-config.js +7 -9
  78. package/build/lib/extension/plugin-config.js.map +1 -1
  79. package/build/lib/helpers/build.d.ts +0 -1
  80. package/build/lib/helpers/build.d.ts.map +1 -1
  81. package/build/lib/helpers/build.js +2 -4
  82. package/build/lib/helpers/build.js.map +1 -1
  83. package/build/lib/helpers/capability.d.ts.map +1 -1
  84. package/build/lib/helpers/capability.js +27 -22
  85. package/build/lib/helpers/capability.js.map +1 -1
  86. package/build/lib/helpers/network.d.ts.map +1 -1
  87. package/build/lib/helpers/network.js +4 -3
  88. package/build/lib/helpers/network.js.map +1 -1
  89. package/build/lib/insecure-features.d.ts.map +1 -1
  90. package/build/lib/insecure-features.js +9 -13
  91. package/build/lib/insecure-features.js.map +1 -1
  92. package/build/lib/inspector-commands.d.ts.map +1 -1
  93. package/build/lib/inspector-commands.js +29 -28
  94. package/build/lib/inspector-commands.js.map +1 -1
  95. package/build/lib/logsink.d.ts.map +1 -1
  96. package/build/lib/logsink.js +8 -7
  97. package/build/lib/logsink.js.map +1 -1
  98. package/build/lib/schema/arg-spec.d.ts.map +1 -1
  99. package/build/lib/schema/arg-spec.js +5 -8
  100. package/build/lib/schema/arg-spec.js.map +1 -1
  101. package/build/lib/schema/cli-args.d.ts.map +1 -1
  102. package/build/lib/schema/cli-args.js +20 -19
  103. package/build/lib/schema/cli-args.js.map +1 -1
  104. package/build/lib/schema/cli-transformers.d.ts.map +1 -1
  105. package/build/lib/schema/cli-transformers.js.map +1 -1
  106. package/build/lib/schema/schema.d.ts.map +1 -1
  107. package/build/lib/schema/schema.js +28 -21
  108. package/build/lib/schema/schema.js.map +1 -1
  109. package/build/lib/utils/hash.d.ts +5 -0
  110. package/build/lib/utils/hash.d.ts.map +1 -0
  111. package/build/lib/{utils.js → utils/hash.js} +3 -21
  112. package/build/lib/utils/hash.js.map +1 -0
  113. package/build/lib/utils/index.d.ts +8 -0
  114. package/build/lib/utils/index.d.ts.map +1 -0
  115. package/build/lib/utils/index.js +31 -0
  116. package/build/lib/utils/index.js.map +1 -0
  117. package/build/lib/utils/is-package-changed.d.ts +16 -0
  118. package/build/lib/utils/is-package-changed.d.ts.map +1 -0
  119. package/build/lib/utils/is-package-changed.js +62 -0
  120. package/build/lib/utils/is-package-changed.js.map +1 -0
  121. package/build/lib/utils/object.d.ts +120 -0
  122. package/build/lib/utils/object.d.ts.map +1 -0
  123. package/build/lib/utils/object.js +288 -0
  124. package/build/lib/utils/object.js.map +1 -0
  125. package/build/lib/{extension → utils}/package-changed.d.ts +0 -1
  126. package/build/lib/utils/package-changed.d.ts.map +1 -0
  127. package/build/lib/{extension → utils}/package-changed.js +3 -4
  128. package/build/lib/utils/package-changed.js.map +1 -0
  129. package/build/lib/utils/package-json.d.ts +9 -0
  130. package/build/lib/utils/package-json.d.ts.map +1 -0
  131. package/build/lib/utils/package-json.js +32 -0
  132. package/build/lib/utils/package-json.js.map +1 -0
  133. package/build/lib/utils/resolve-from.d.ts +11 -0
  134. package/build/lib/utils/resolve-from.d.ts.map +1 -0
  135. package/build/lib/utils/resolve-from.js +41 -0
  136. package/build/lib/utils/resolve-from.js.map +1 -0
  137. package/build/types/cli.d.ts.map +1 -1
  138. package/build/types/index.d.ts.map +1 -1
  139. package/build/types/manifest/base.d.ts.map +1 -1
  140. package/build/types/manifest/v3.d.ts.map +1 -1
  141. package/build/types/manifest/v4.d.ts.map +1 -1
  142. package/lib/appium.ts +96 -61
  143. package/lib/bidi-commands.ts +107 -61
  144. package/lib/bootstrap/appium-initializer.ts +27 -19
  145. package/lib/bootstrap/appium-main-runner.ts +8 -4
  146. package/lib/bootstrap/config-file.ts +33 -16
  147. package/lib/bootstrap/grid-v3-register.ts +26 -19
  148. package/lib/bootstrap/main-helpers.ts +25 -19
  149. package/lib/bootstrap/node-helpers.ts +20 -24
  150. package/lib/bootstrap/startup-config.ts +42 -39
  151. package/lib/cli/args.ts +3 -4
  152. package/lib/cli/driver-command.ts +19 -13
  153. package/lib/cli/extension-command.ts +214 -149
  154. package/lib/cli/extension.ts +4 -6
  155. package/lib/cli/parser.ts +32 -30
  156. package/lib/cli/plugin-command.ts +20 -9
  157. package/lib/cli/setup-command.ts +54 -39
  158. package/lib/cli/utils.ts +4 -3
  159. package/lib/doctor/doctor.ts +15 -17
  160. package/lib/extension/driver-config.ts +22 -17
  161. package/lib/extension/extension-config.ts +76 -69
  162. package/lib/extension/index.ts +60 -51
  163. package/lib/extension/manifest.ts +35 -33
  164. package/lib/extension/plugin-config.ts +15 -10
  165. package/lib/helpers/build.ts +6 -5
  166. package/lib/helpers/capability.ts +40 -35
  167. package/lib/helpers/network.ts +6 -5
  168. package/lib/insecure-features.ts +16 -14
  169. package/lib/inspector-commands.ts +72 -40
  170. package/lib/logsink.ts +22 -26
  171. package/lib/schema/arg-spec.ts +9 -8
  172. package/lib/schema/cli-args-guards.ts +4 -4
  173. package/lib/schema/cli-args.ts +25 -21
  174. package/lib/schema/cli-transformers.ts +6 -2
  175. package/lib/schema/format-errors.ts +1 -1
  176. package/lib/schema/schema.ts +52 -38
  177. package/lib/{utils.ts → utils/hash.ts} +2 -19
  178. package/lib/utils/index.ts +23 -0
  179. package/lib/utils/is-package-changed.ts +78 -0
  180. package/lib/utils/object.ts +312 -0
  181. package/lib/{extension → utils}/package-changed.ts +6 -7
  182. package/lib/utils/package-json.ts +36 -0
  183. package/lib/utils/resolve-from.ts +40 -0
  184. package/package.json +16 -19
  185. package/scripts/autoinstall-extensions.js +8 -13
  186. package/tsconfig.json +8 -2
  187. package/types/cli.ts +18 -18
  188. package/types/index.ts +2 -2
  189. package/types/manifest/base.ts +2 -2
  190. package/types/manifest/v3.ts +2 -2
  191. package/types/manifest/v4.ts +2 -2
  192. package/build/lib/extension/package-changed.d.ts.map +0 -1
  193. package/build/lib/extension/package-changed.js.map +0 -1
  194. package/build/lib/utils.d.ts +0 -13
  195. package/build/lib/utils.d.ts.map +0 -1
  196. package/build/lib/utils.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import _ from 'lodash';
1
+ import {mapValues} from './utils';
2
2
  import {
3
3
  METHOD_MAP as BASE_METHOD_MAP,
4
4
  BIDI_COMMANDS as BASE_BIDI_COMMANDS,
@@ -24,25 +24,35 @@ import type {AppiumDriver} from './appium';
24
24
  /**
25
25
  * Returns available REST and BiDi commands for base, driver and plugins.
26
26
  */
27
- export async function listCommands(this: AppiumDriver, sessionId?: string): Promise<ListCommandsResponse> {
27
+ export async function listCommands(
28
+ this: AppiumDriver,
29
+ sessionId?: string,
30
+ ): Promise<ListCommandsResponse> {
28
31
  let driverRestMethodMap: MethodMap<any> = {};
29
32
  let driverBiDiCommands: BidiModuleMap = {};
30
33
  let pluginRestMethodMaps: Record<string, MethodMap<any>> = {};
31
34
  let pluginBiDiCommands: Record<string, BidiModuleMap> = {};
32
35
  if (sessionId) {
33
- const driverClass = this.driverForSession(sessionId)?.constructor as (DriverClass | undefined);
36
+ const driverClass = this.driverForSession(sessionId)?.constructor as DriverClass | undefined;
34
37
  driverRestMethodMap = driverClass?.newMethodMap ?? {};
35
38
  driverBiDiCommands = driverClass?.newBidiCommands ?? {};
36
- const pluginClasses = this.pluginsForSession(sessionId)
37
- .map((p) => p.constructor as PluginClass);
38
- pluginRestMethodMaps = _.fromPairs(pluginClasses.map((c) => [c.name, c.newMethodMap ?? {}]));
39
- pluginBiDiCommands = _.fromPairs(pluginClasses.map((c) => [c.name, c.newBidiCommands ?? {}]));
39
+ const pluginClasses = this.pluginsForSession(sessionId).map(
40
+ (p) => p.constructor as PluginClass,
41
+ );
42
+ pluginRestMethodMaps = Object.fromEntries(
43
+ pluginClasses.map((c) => [c.name, c.newMethodMap ?? {}]),
44
+ );
45
+ pluginBiDiCommands = Object.fromEntries(
46
+ pluginClasses.map((c) => [c.name, c.newBidiCommands ?? {}]),
47
+ );
40
48
  }
41
49
  return {
42
50
  rest: {
43
51
  base: methodMapToRestCommandsInfo(BASE_METHOD_MAP),
44
52
  driver: methodMapToRestCommandsInfo(driverRestMethodMap),
45
- plugins: pluginRestMethodMaps ? _.mapValues(pluginRestMethodMaps, methodMapToRestCommandsInfo) : undefined,
53
+ plugins: pluginRestMethodMaps
54
+ ? mapValues(pluginRestMethodMaps, methodMapToRestCommandsInfo)
55
+ : undefined,
46
56
  },
47
57
  bidi: toBiDiCommandsMap(BASE_BIDI_COMMANDS, driverBiDiCommands, pluginBiDiCommands),
48
58
  };
@@ -51,33 +61,46 @@ export async function listCommands(this: AppiumDriver, sessionId?: string): Prom
51
61
  /**
52
62
  * Returns available execute methods exposed by driver and plugins.
53
63
  */
54
- export async function listExtensions(this: AppiumDriver, sessionId?: string): Promise<ListExtensionsResponse> {
64
+ export async function listExtensions(
65
+ this: AppiumDriver,
66
+ sessionId?: string,
67
+ ): Promise<ListExtensionsResponse> {
55
68
  let driverExecuteMethodMap: ExecuteMethodMap<any> = {};
56
69
  let pluginExecuteMethodMaps: Record<string, ExecuteMethodMap<any>> = {};
57
70
  if (sessionId) {
58
- const driverClass = this.driverForSession(sessionId)?.constructor as (DriverClass | undefined);
71
+ const driverClass = this.driverForSession(sessionId)?.constructor as DriverClass | undefined;
59
72
  driverExecuteMethodMap = driverClass?.executeMethodMap ?? {};
60
- const pluginClasses = this.pluginsForSession(sessionId)
61
- .map((p) => p.constructor as PluginClass);
62
- pluginExecuteMethodMaps = _.fromPairs(pluginClasses.map((c) => [c.name, c.executeMethodMap ?? {}]));
73
+ const pluginClasses = this.pluginsForSession(sessionId).map(
74
+ (p) => p.constructor as PluginClass,
75
+ );
76
+ pluginExecuteMethodMaps = Object.fromEntries(
77
+ pluginClasses.map((c) => [c.name, c.executeMethodMap ?? {}]),
78
+ );
63
79
  }
64
80
  return {
65
81
  rest: {
66
82
  driver: executeMethodMapToCommandsInfo(driverExecuteMethodMap),
67
- plugins: pluginExecuteMethodMaps ? _.mapValues(pluginExecuteMethodMaps, executeMethodMapToCommandsInfo) : undefined,
83
+ plugins: pluginExecuteMethodMaps
84
+ ? mapValues(pluginExecuteMethodMaps, executeMethodMapToCommandsInfo)
85
+ : undefined,
68
86
  },
69
87
  };
70
88
  }
71
89
 
72
- function toRestCommandParams(params: PayloadParams | undefined): RestCommandItemParam[] | undefined {
90
+ function toRestCommandParams(
91
+ params: PayloadParams | undefined,
92
+ ): RestCommandItemParam[] | undefined {
73
93
  if (!params) {
74
94
  return;
75
95
  }
76
96
 
77
- const toRestCommandItemParam = (x: any, isRequired: boolean): RestCommandItemParam | undefined => {
78
- const isNameAnArray = _.isArray(x);
97
+ const toRestCommandItemParam = (
98
+ x: any,
99
+ isRequired: boolean,
100
+ ): RestCommandItemParam | undefined => {
101
+ const isNameAnArray = Array.isArray(x);
79
102
  const name = isNameAnArray ? x[0] : x;
80
- if (!_.isString(name)) {
103
+ if (typeof name !== 'string') {
81
104
  return;
82
105
  }
83
106
 
@@ -93,22 +116,22 @@ function toRestCommandParams(params: PayloadParams | undefined): RestCommandItem
93
116
 
94
117
  const requiredParams: RestCommandItemParam[] = (params.required ?? [])
95
118
  .map((name: any) => toRestCommandItemParam(name, true))
96
- .filter((x) => !_.isUndefined(x));
119
+ .filter((x): x is RestCommandItemParam => x !== undefined);
97
120
  const optionalParams: RestCommandItemParam[] = (params.optional ?? [])
98
121
  .map((name: any) => toRestCommandItemParam(name, false))
99
- .filter((x) => !_.isUndefined(x));
122
+ .filter((x): x is RestCommandItemParam => x !== undefined);
100
123
  return requiredParams.length || optionalParams.length
101
124
  ? [...requiredParams, ...optionalParams]
102
125
  : undefined;
103
126
  }
104
127
 
105
- function methodMapToRestCommandsInfo (mm: MethodMap<any>): Record<string, RestMethodsToCommandsMap> {
128
+ function methodMapToRestCommandsInfo(mm: MethodMap<any>): Record<string, RestMethodsToCommandsMap> {
106
129
  const res: Record<string, RestMethodsToCommandsMap> = {};
107
- for (const [uriPath, methods] of _.toPairs(mm)) {
108
- const methodsMap = {};
109
- for (const [method, spec] of _.toPairs(methods)) {
110
- methodsMap[method] = {
111
- command: spec.command,
130
+ for (const [uriPath, methods] of Object.entries(mm)) {
131
+ const methodsMap: RestMethodsToCommandsMap = {};
132
+ for (const [method, spec] of Object.entries(methods)) {
133
+ methodsMap[String(method)] = {
134
+ command: spec.command as string,
112
135
  deprecated: spec.deprecated,
113
136
  info: spec.info,
114
137
  params: toRestCommandParams(spec.payloadParams),
@@ -121,7 +144,7 @@ function methodMapToRestCommandsInfo (mm: MethodMap<any>): Record<string, RestMe
121
144
 
122
145
  function executeMethodMapToCommandsInfo(emm: ExecuteMethodMap<any>): RestMethodsToCommandsMap {
123
146
  const result: RestMethodsToCommandsMap = {};
124
- for (const [name, info] of _.toPairs(emm)) {
147
+ for (const [name, info] of Object.entries(emm)) {
125
148
  result[name] = {
126
149
  command: info.command as string,
127
150
  deprecated: info.deprecated,
@@ -135,17 +158,22 @@ function executeMethodMapToCommandsInfo(emm: ExecuteMethodMap<any>): RestMethods
135
158
  function toBiDiCommandsMap(
136
159
  baseModuleMap: BidiModuleMap,
137
160
  driverModuleMap: BidiModuleMap,
138
- pluginModuleMaps: Record<string, BidiModuleMap>
161
+ pluginModuleMaps: Record<string, BidiModuleMap>,
139
162
  ): BiDiCommandsMap {
140
- const toBiDiCommandParams = (params: BidiMethodParams | undefined): BiDiCommandItemParam[] | undefined => {
163
+ const toBiDiCommandParams = (
164
+ params: BidiMethodParams | undefined,
165
+ ): BiDiCommandItemParam[] | undefined => {
141
166
  if (!params) {
142
167
  return;
143
168
  }
144
169
 
145
- const toBiDiCommandItemParam = (x: any, isRequired: boolean): BiDiCommandItemParam | undefined => {
146
- const isNameAnArray = _.isArray(x);
170
+ const toBiDiCommandItemParam = (
171
+ x: any,
172
+ isRequired: boolean,
173
+ ): BiDiCommandItemParam | undefined => {
174
+ const isNameAnArray = Array.isArray(x);
147
175
  const name = isNameAnArray ? x[0] : x;
148
- if (!_.isString(name)) {
176
+ if (typeof name !== 'string') {
149
177
  return;
150
178
  }
151
179
 
@@ -161,20 +189,22 @@ function toBiDiCommandsMap(
161
189
 
162
190
  const requiredParams: BiDiCommandItemParam[] = (params.required ?? [])
163
191
  .map((name) => toBiDiCommandItemParam(name, true))
164
- .filter((x) => !_.isUndefined(x));
192
+ .filter((x): x is BiDiCommandItemParam => x !== undefined);
165
193
  const optionalParams: BiDiCommandItemParam[] = (params.optional ?? [])
166
194
  .map((name) => toBiDiCommandItemParam(name, false))
167
- .filter((x) => !_.isUndefined(x));
195
+ .filter((x): x is BiDiCommandItemParam => x !== undefined);
168
196
  return requiredParams.length || optionalParams.length
169
197
  ? [...requiredParams, ...optionalParams]
170
198
  : undefined;
171
199
  };
172
200
 
173
- const moduleMapToBiDiCommandsInfo = (mm: BidiModuleMap): Record<string, BiDiCommandNamesToInfosMap> => {
201
+ const moduleMapToBiDiCommandsInfo = (
202
+ mm: BidiModuleMap,
203
+ ): Record<string, BiDiCommandNamesToInfosMap> => {
174
204
  const res: Record<string, BiDiCommandNamesToInfosMap> = {};
175
- for (const [domain, commands] of _.toPairs(mm)) {
176
- const commandsMap = {};
177
- for (const [name, spec] of _.toPairs(commands)) {
205
+ for (const [domain, commands] of Object.entries(mm)) {
206
+ const commandsMap: BiDiCommandNamesToInfosMap = {};
207
+ for (const [name, spec] of Object.entries(commands)) {
178
208
  commandsMap[name] = {
179
209
  command: spec.command,
180
210
  deprecated: spec.deprecated,
@@ -190,6 +220,8 @@ function toBiDiCommandsMap(
190
220
  return {
191
221
  base: moduleMapToBiDiCommandsInfo(baseModuleMap),
192
222
  driver: moduleMapToBiDiCommandsInfo(driverModuleMap),
193
- plugins: pluginModuleMaps ? _.mapValues(pluginModuleMaps, moduleMapToBiDiCommandsInfo) : undefined,
223
+ plugins: pluginModuleMaps
224
+ ? mapValues(pluginModuleMaps, moduleMapToBiDiCommandsInfo)
225
+ : undefined,
194
226
  };
195
- }
227
+ }
package/lib/logsink.ts CHANGED
@@ -4,8 +4,7 @@ import type {Logger, Logform} from 'winston';
4
4
  import type Transport from 'winston-transport';
5
5
  import globalLog from '@appium/logger';
6
6
  import {createLogger, format, transports} from 'winston';
7
- import {fs} from '@appium/support';
8
- import _ from 'lodash';
7
+ import {fs, util} from '@appium/support';
9
8
  import {adler32} from './utils';
10
9
  import {LRUCache} from 'lru-cache';
11
10
 
@@ -78,17 +77,20 @@ export async function init(args: ParsedArgs): Promise<void> {
78
77
  prefixes.push(prefix);
79
78
  }
80
79
  let msg = message;
81
- if (!_.isEmpty(prefixes)) {
80
+ if (!util.isEmpty(prefixes)) {
82
81
  const finalPrefix = prefixes
83
82
  .map(toDecoratedPrefix)
84
83
  .map((pfx) => (isLogColorEnabled(args) ? colorizePrefix(pfx) : pfx))
85
84
  .join('');
86
85
  msg = `${finalPrefix} ${msg}`;
87
86
  }
88
- const winstonLevel = TO_WINSTON_LEVELS_MAP[level] || 'info';
87
+ const winstonLevel =
88
+ level in TO_WINSTON_LEVELS_MAP
89
+ ? TO_WINSTON_LEVELS_MAP[level as keyof typeof TO_WINSTON_LEVELS_MAP]
90
+ : 'info';
89
91
  try {
90
92
  (log as Logger)[winstonLevel as keyof Logger](msg);
91
- if (_.isFunction(args.logHandler)) {
93
+ if (typeof args.logHandler === 'function') {
92
94
  args.logHandler(level, msg);
93
95
  }
94
96
  } catch (e) {
@@ -96,9 +98,9 @@ export async function init(args: ParsedArgs): Promise<void> {
96
98
  if (!reportedLoggerErrors.has(err.message) && process.stderr.writable) {
97
99
  // eslint-disable-next-line no-console
98
100
  console.error(
99
- `The log message '${_.truncate(msg, {length: 30})}' cannot be written into ` +
101
+ `The log message '${util.truncateString(msg, {length: 30})}' cannot be written into ` +
100
102
  `one or more requested destinations: ${[...transportNames].join(', ')}. ` +
101
- `Original error: ${err.message}`
103
+ `Original error: ${err.message}`,
102
104
  );
103
105
  reportedLoggerErrors.add(err.message);
104
106
  }
@@ -121,7 +123,7 @@ export function clear(): void {
121
123
 
122
124
  function createConsoleTransport(
123
125
  args: ParsedArgs,
124
- logLvl: string
126
+ logLvl: string,
125
127
  ): transports.ConsoleTransportInstance {
126
128
  const opt: transports.ConsoleTransportOptions = {
127
129
  level: logLvl,
@@ -135,27 +137,17 @@ function createConsoleTransport(
135
137
  return new transports.Console(opt);
136
138
  }
137
139
 
138
- function createFileTransport(
139
- args: ParsedArgs,
140
- logLvl: string
141
- ): transports.FileTransportInstance {
140
+ function createFileTransport(args: ParsedArgs, logLvl: string): transports.FileTransportInstance {
142
141
  const opt: transports.FileTransportOptions = {
143
142
  filename: args.logFile,
144
143
  maxFiles: 1,
145
144
  level: logLvl,
146
- format: format.combine(
147
- stripColorFormat,
148
- formatTimestamp(args),
149
- formatLog(args, false),
150
- ),
145
+ format: format.combine(stripColorFormat, formatTimestamp(args), formatLog(args, false)),
151
146
  };
152
147
  return new transports.File(opt);
153
148
  }
154
149
 
155
- function createHttpTransport(
156
- args: ParsedArgs,
157
- logLvl: string
158
- ): transports.HttpTransportInstance {
150
+ function createHttpTransport(args: ParsedArgs, logLvl: string): transports.HttpTransportInstance {
159
151
  let host = '127.0.0.1';
160
152
  let port = 9003;
161
153
 
@@ -209,7 +201,7 @@ async function createTransports(args: ParsedArgs): Promise<Transport[]> {
209
201
  // eslint-disable-next-line no-console
210
202
  console.log(
211
203
  `Tried to attach logging to file '${args.logFile}' but an error ` +
212
- `occurred: ${err.message}`
204
+ `occurred: ${err.message}`,
213
205
  );
214
206
  }
215
207
  }
@@ -222,7 +214,7 @@ async function createTransports(args: ParsedArgs): Promise<Transport[]> {
222
214
  // eslint-disable-next-line no-console
223
215
  console.log(
224
216
  `Tried to attach logging to Http at ${args.webhook} but ` +
225
- `an error occurred: ${err.message}`
217
+ `an error occurred: ${err.message}`,
226
218
  );
227
219
  }
228
220
  }
@@ -260,7 +252,7 @@ function formatLog(args: ParsedArgs, targetConsole: boolean): Logform.Format {
260
252
  delete infoCopy.timestamp;
261
253
  }
262
254
 
263
- if (!_.isEmpty(contextInfo)) {
255
+ if (!util.isEmpty(contextInfo)) {
264
256
  infoCopy.context = {...contextInfo};
265
257
  }
266
258
 
@@ -308,11 +300,15 @@ export function stripColorCodes(text: string): string {
308
300
  }
309
301
 
310
302
  // Strip the color marking within messages (depends on stripColorCodes)
311
- const stripColorFormat = format(function stripColor(info: {level: string; message: unknown; [key: string]: unknown}) {
303
+ const stripColorFormat = format(function stripColor(info: {
304
+ level: string;
305
+ message: unknown;
306
+ [key: string]: unknown;
307
+ }) {
312
308
  return {
313
309
  ...info,
314
310
  level: stripColorCodes(info.level),
315
- message: _.isString(info.message) ? stripColorCodes(info.message) : info.message,
311
+ message: typeof info.message === 'string' ? stripColorCodes(info.message) : info.message,
316
312
  };
317
313
  })();
318
314
 
@@ -1,5 +1,5 @@
1
- import _ from 'lodash';
2
1
  import type {ExtensionType} from '@appium/types';
2
+ import {camelCase, kebabCase} from '../utils';
3
3
 
4
4
  /**
5
5
  * The original ID of the Appium config schema.
@@ -45,7 +45,7 @@ export class ArgSpec<D = unknown> {
45
45
  constructor(name: string, {extType, extName, dest, defaultValue}: ArgSpecOptions<D> = {}) {
46
46
  const arg = ArgSpec.toArg(name, extType, extName);
47
47
  const ref = ArgSpec.toSchemaRef(name, extType, extName);
48
- const rawDest = _.camelCase(dest ?? name);
48
+ const rawDest = camelCase(dest ?? name);
49
49
  const destKeypath = extType && extName ? [extType, extName, rawDest].join('.') : rawDest;
50
50
 
51
51
  this.defaultValue = defaultValue;
@@ -83,9 +83,9 @@ export class ArgSpec<D = unknown> {
83
83
  * Return the unique CLI argument key for the argument.
84
84
  */
85
85
  static toArg(name: string, extType?: ExtensionType, extName?: string): string {
86
- const properName = _.kebabCase(name.replace(/^--?/, ''));
86
+ const properName = kebabCase(name.replace(/^--?/, ''));
87
87
  if (extType && extName) {
88
- return [extType, _.kebabCase(extName), properName].join('-');
88
+ return [extType, kebabCase(extName), properName].join('-');
89
89
  }
90
90
  return properName;
91
91
  }
@@ -94,15 +94,16 @@ export class ArgSpec<D = unknown> {
94
94
  * Normalizes a raw extension name (not including type).
95
95
  */
96
96
  static toNormalizedExtName(extName: string): string {
97
- return _.kebabCase(extName);
97
+ return kebabCase(extName);
98
98
  }
99
99
 
100
100
  /**
101
101
  * Parse root schema ID (`<extType>-<normalizedExtName>.json`) to extension info.
102
102
  */
103
- static extensionInfoFromRootSchemaId(
104
- schemaId: string
105
- ): {extType?: ExtensionType; normalizedExtName?: string} {
103
+ static extensionInfoFromRootSchemaId(schemaId: string): {
104
+ extType?: ExtensionType;
105
+ normalizedExtName?: string;
106
+ } {
106
107
  const matches = schemaId.match(SCHEMA_ID_REGEXP);
107
108
  if (matches?.groups) {
108
109
  const {extType, normalizedExtName} = matches.groups as {
@@ -28,7 +28,7 @@ export function isServerCommandArgs(args: AnyArgs): args is Args<CliCommandServe
28
28
  * @param args - Parsed args before full subcommand-specific narrowing
29
29
  */
30
30
  export function isSetupCommandArgs(
31
- args: AnyArgs
31
+ args: AnyArgs,
32
32
  ): args is Args<CliCommandSetup, CliCommandSetupSubcommand> {
33
33
  return args.subcommand === SETUP_SUBCOMMAND;
34
34
  }
@@ -39,7 +39,7 @@ export function isSetupCommandArgs(
39
39
  * @param args - Parsed args before full subcommand-specific narrowing
40
40
  */
41
41
  export function isExtensionCommandArgs(
42
- args: AnyArgs
42
+ args: AnyArgs,
43
43
  ): args is Args<CliExtensionCommand, CliExtensionSubcommand> {
44
44
  return args.subcommand === DRIVER_TYPE || args.subcommand === PLUGIN_TYPE;
45
45
  }
@@ -50,7 +50,7 @@ export function isExtensionCommandArgs(
50
50
  * @param args - Parsed args before full subcommand-specific narrowing
51
51
  */
52
52
  export function isDriverCommandArgs(
53
- args: AnyArgs
53
+ args: AnyArgs,
54
54
  ): args is Args<CliCommandDriver, CliExtensionSubcommand> {
55
55
  return args.subcommand === DRIVER_TYPE;
56
56
  }
@@ -61,7 +61,7 @@ export function isDriverCommandArgs(
61
61
  * @param args - Parsed args before full subcommand-specific narrowing
62
62
  */
63
63
  export function isPluginCommandArgs(
64
- args: AnyArgs
64
+ args: AnyArgs,
65
65
  ): args is Args<CliCommandPlugin, CliExtensionSubcommand> {
66
66
  return args.subcommand === PLUGIN_TYPE;
67
67
  }
@@ -1,6 +1,7 @@
1
1
  import {ArgumentTypeError, type ArgumentOptions} from 'argparse';
2
- import _ from 'lodash';
2
+ import {util} from '@appium/support';
3
3
  import type {JSONSchema7, JSONSchema7TypeName} from 'json-schema';
4
+ import {kebabCase} from '../utils';
4
5
  import {formatErrors} from './format-errors';
5
6
  import {flattenSchema, validate} from './schema';
6
7
  import {transformers, parseCsvLine} from './cli-transformers';
@@ -30,7 +31,7 @@ const SHORT_ARG_CUTOFF = 3;
30
31
  export function toParserArgs(): ArgumentDefinitions {
31
32
  const flattened = flattenSchema().filter(({schema}) => !schema.appiumCliIgnored);
32
33
  return new Map(
33
- _.map(flattened, ({schema, argSpec}) => subSchemaToArgDef(schema as AppiumJSONSchema, argSpec))
34
+ flattened.map(({schema, argSpec}) => subSchemaToArgDef(schema as AppiumJSONSchema, argSpec)),
34
35
  );
35
36
  }
36
37
 
@@ -43,25 +44,25 @@ function aliasToFlag(argSpec: ArgSpec, alias?: string): string {
43
44
  const isShort = arg.length < SHORT_ARG_CUTOFF;
44
45
  if (extType && extName) {
45
46
  return isShort
46
- ? `--${extType}-${_.kebabCase(extName)}-${arg}`
47
- : `--${extType}-${_.kebabCase(extName)}-${_.kebabCase(arg)}`;
47
+ ? `--${extType}-${kebabCase(extName)}-${arg}`
48
+ : `--${extType}-${kebabCase(extName)}-${kebabCase(arg)}`;
48
49
  }
49
- return isShort ? `-${arg}` : `--${_.kebabCase(arg)}`;
50
+ return isShort ? `-${arg}` : `--${kebabCase(arg)}`;
50
51
  }
51
52
 
52
- const screamingSnakeCase = _.flow(_.snakeCase, _.toUpper);
53
+ const screamingSnakeCase = (s: string) => kebabCase(s).replace(/-/g, '_').toUpperCase();
53
54
 
54
55
  /**
55
56
  * Given an argument spec, return a validator/coercer function backed by schema validation.
56
57
  */
57
58
  function getSchemaValidator<Coerced>(
58
59
  {ref: schemaId}: ArgSpec,
59
- coerce: (value: string) => Coerced = _.identity as (value: string) => Coerced
60
+ coerce: (value: string) => Coerced = (value) => value as Coerced,
60
61
  ): (value: string) => Coerced {
61
62
  return (value) => {
62
63
  const coerced = coerce(value);
63
64
  const errors = validate(coerced, schemaId);
64
- if (_.isEmpty(errors)) {
65
+ if (util.isEmpty(errors)) {
65
66
  return coerced;
66
67
  }
67
68
  throw new ArgumentTypeError('\n\n' + formatErrors(errors, value, {schemaId}));
@@ -104,12 +105,15 @@ function subSchemaToArgDef(subSchema: AppiumJSONSchema, argSpec: ArgSpec): ArgDe
104
105
  break;
105
106
  }
106
107
  case TYPENAMES.OBJECT: {
107
- argTypeFunction = _.flow(transformers.json, (o) => {
108
- if (!_.isPlainObject(o)) {
109
- throw new ArgumentTypeError(`'${_.truncate(String(o), {length: 100})}' must be a plain object`);
108
+ argTypeFunction = (value: string) => {
109
+ const o = transformers.json(value);
110
+ if (!util.isPlainObject(o)) {
111
+ throw new ArgumentTypeError(
112
+ `'${util.truncateString(String(o), {length: 100})}' must be a plain object`,
113
+ );
110
114
  }
111
115
  return o;
112
- });
116
+ };
113
117
  break;
114
118
  }
115
119
  case TYPENAMES.ARRAY: {
@@ -121,7 +125,7 @@ function subSchemaToArgDef(subSchema: AppiumJSONSchema, argSpec: ArgSpec): ArgDe
121
125
  break;
122
126
  }
123
127
  case TYPENAMES.INTEGER: {
124
- argTypeFunction = getSchemaValidator(argSpec, _.parseInt);
128
+ argTypeFunction = getSchemaValidator(argSpec, (v) => parseInt(v, 10));
125
129
  break;
126
130
  }
127
131
  case TYPENAMES.STRING: {
@@ -142,12 +146,13 @@ function subSchemaToArgDef(subSchema: AppiumJSONSchema, argSpec: ArgSpec): ArgDe
142
146
  if (type === TYPENAMES.ARRAY) {
143
147
  const csvTransformer = argTypeFunction as (x: string) => string[];
144
148
  argTypeFunction = (val) =>
145
- _.flatMap(csvTransformer(val).map(transformers[appiumCliTransformer as AppiumCliTransformerName]));
149
+ csvTransformer(val).flatMap((item) =>
150
+ transformers[appiumCliTransformer as AppiumCliTransformerName](item),
151
+ );
146
152
  } else {
147
- argTypeFunction = _.flow(
148
- argTypeFunction ?? _.identity,
149
- transformers[appiumCliTransformer as AppiumCliTransformerName]
150
- ) as (value: string) => unknown;
153
+ const baseFn = argTypeFunction ?? ((value: string) => value);
154
+ const transformer = transformers[appiumCliTransformer as AppiumCliTransformerName];
155
+ argTypeFunction = (value: string) => transformer(baseFn(value) as string);
151
156
  }
152
157
  }
153
158
 
@@ -155,12 +160,12 @@ function subSchemaToArgDef(subSchema: AppiumJSONSchema, argSpec: ArgSpec): ArgDe
155
160
  argOpts.type = argTypeFunction;
156
161
  }
157
162
 
158
- if (enumValues && !_.isEmpty(enumValues)) {
163
+ if (enumValues && !util.isEmpty(enumValues)) {
159
164
  if (type === TYPENAMES.STRING) {
160
165
  argOpts.choices = enumValues.map(String);
161
166
  } else {
162
167
  throw new TypeError(
163
- `Problem with schema for ${arg}; \`enum\` is only supported for \`type: 'string'\``
168
+ `Problem with schema for ${arg}; \`enum\` is only supported for \`type: 'string'\``,
164
169
  );
165
170
  }
166
171
  }
@@ -168,4 +173,3 @@ function subSchemaToArgDef(subSchema: AppiumJSONSchema, argSpec: ArgSpec): ArgDe
168
173
  const finalAliases = aliases as [string] | [string, string];
169
174
  return [finalAliases, argOpts];
170
175
  }
171
-
@@ -31,7 +31,9 @@ export const transformers = {
31
31
  try {
32
32
  csv = readFileSync(csvOrPath, 'utf8');
33
33
  } catch (err) {
34
- throw new ArgumentTypeError(`Could not read file '${csvOrPath}': ${(err as Error).message}`);
34
+ throw new ArgumentTypeError(
35
+ `Could not read file '${csvOrPath}': ${(err as Error).message}`,
36
+ );
35
37
  }
36
38
  loadedFromFile = true;
37
39
  }
@@ -56,7 +58,9 @@ export const transformers = {
56
58
  // Intentionally sync: argparse type hooks are synchronous.
57
59
  json = readFileSync(jsonOrPath, 'utf8');
58
60
  } catch (err) {
59
- throw new ArgumentTypeError(`Could not read file '${jsonOrPath}': ${(err as Error).message}`);
61
+ throw new ArgumentTypeError(
62
+ `Could not read file '${jsonOrPath}': ${(err as Error).message}`,
63
+ );
60
64
  }
61
65
  loadedFromFile = true;
62
66
  }
@@ -31,7 +31,7 @@ export interface FormatConfigErrorsOptions {
31
31
  export function formatErrors(
32
32
  errors: ErrorObject[] = [],
33
33
  config: NormalizedAppiumConfig | Record<string, unknown> | string | undefined = {},
34
- opts: FormatConfigErrorsOptions = {}
34
+ opts: FormatConfigErrorsOptions = {},
35
35
  ): string | IOutputError[] {
36
36
  if (errors && !errors.length) {
37
37
  throw new TypeError('Array of errors must be non-empty');