appium 3.5.0 → 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.
- package/build/lib/appium.d.ts.map +1 -1
- package/build/lib/appium.js +43 -45
- package/build/lib/appium.js.map +1 -1
- package/build/lib/bidi-commands.d.ts.map +1 -1
- package/build/lib/bidi-commands.js +34 -29
- package/build/lib/bidi-commands.js.map +1 -1
- package/build/lib/bootstrap/appium-initializer.d.ts.map +1 -1
- package/build/lib/bootstrap/appium-initializer.js +13 -13
- package/build/lib/bootstrap/appium-initializer.js.map +1 -1
- package/build/lib/bootstrap/appium-main-runner.d.ts.map +1 -1
- package/build/lib/bootstrap/appium-main-runner.js +2 -2
- package/build/lib/bootstrap/appium-main-runner.js.map +1 -1
- package/build/lib/bootstrap/config-file.d.ts.map +1 -1
- package/build/lib/bootstrap/config-file.js +11 -11
- package/build/lib/bootstrap/config-file.js.map +1 -1
- package/build/lib/bootstrap/grid-v3-register.d.ts.map +1 -1
- package/build/lib/bootstrap/grid-v3-register.js +9 -6
- package/build/lib/bootstrap/grid-v3-register.js.map +1 -1
- package/build/lib/bootstrap/main-helpers.d.ts +1 -1
- package/build/lib/bootstrap/main-helpers.d.ts.map +1 -1
- package/build/lib/bootstrap/main-helpers.js +19 -20
- package/build/lib/bootstrap/main-helpers.js.map +1 -1
- package/build/lib/bootstrap/node-helpers.d.ts +1 -1
- package/build/lib/bootstrap/node-helpers.d.ts.map +1 -1
- package/build/lib/bootstrap/node-helpers.js +7 -14
- package/build/lib/bootstrap/node-helpers.js.map +1 -1
- package/build/lib/bootstrap/startup-config.d.ts.map +1 -1
- package/build/lib/bootstrap/startup-config.js +32 -30
- package/build/lib/bootstrap/startup-config.js.map +1 -1
- package/build/lib/cli/args.d.ts +3 -2
- package/build/lib/cli/args.d.ts.map +1 -1
- package/build/lib/cli/args.js +2 -5
- package/build/lib/cli/args.js.map +1 -1
- package/build/lib/cli/driver-command.d.ts +1 -2
- package/build/lib/cli/driver-command.d.ts.map +1 -1
- package/build/lib/cli/driver-command.js +7 -8
- package/build/lib/cli/driver-command.js.map +1 -1
- package/build/lib/cli/extension-command.d.ts +2 -2
- package/build/lib/cli/extension-command.d.ts.map +1 -1
- package/build/lib/cli/extension-command.js +100 -66
- package/build/lib/cli/extension-command.js.map +1 -1
- package/build/lib/cli/extension.d.ts.map +1 -1
- package/build/lib/cli/extension.js.map +1 -1
- package/build/lib/cli/parser.d.ts.map +1 -1
- package/build/lib/cli/parser.js +21 -14
- package/build/lib/cli/parser.js.map +1 -1
- package/build/lib/cli/plugin-command.d.ts +1 -1
- package/build/lib/cli/plugin-command.d.ts.map +1 -1
- package/build/lib/cli/plugin-command.js +5 -5
- package/build/lib/cli/plugin-command.js.map +1 -1
- package/build/lib/cli/setup-command.d.ts +1 -1
- package/build/lib/cli/setup-command.d.ts.map +1 -1
- package/build/lib/cli/setup-command.js +14 -19
- package/build/lib/cli/setup-command.js.map +1 -1
- package/build/lib/cli/utils.d.ts.map +1 -1
- package/build/lib/cli/utils.js +3 -2
- package/build/lib/cli/utils.js.map +1 -1
- package/build/lib/doctor/doctor.d.ts +0 -1
- package/build/lib/doctor/doctor.d.ts.map +1 -1
- package/build/lib/doctor/doctor.js +12 -17
- package/build/lib/doctor/doctor.js.map +1 -1
- package/build/lib/extension/driver-config.d.ts.map +1 -1
- package/build/lib/extension/driver-config.js +11 -12
- package/build/lib/extension/driver-config.js.map +1 -1
- package/build/lib/extension/extension-config.d.ts.map +1 -1
- package/build/lib/extension/extension-config.js +28 -27
- package/build/lib/extension/extension-config.js.map +1 -1
- package/build/lib/extension/index.d.ts.map +1 -1
- package/build/lib/extension/index.js +13 -16
- package/build/lib/extension/index.js.map +1 -1
- package/build/lib/extension/manifest.d.ts +3 -2
- package/build/lib/extension/manifest.d.ts.map +1 -1
- package/build/lib/extension/manifest.js +19 -22
- package/build/lib/extension/manifest.js.map +1 -1
- package/build/lib/extension/plugin-config.d.ts.map +1 -1
- package/build/lib/extension/plugin-config.js +7 -9
- package/build/lib/extension/plugin-config.js.map +1 -1
- package/build/lib/helpers/build.d.ts +0 -1
- package/build/lib/helpers/build.d.ts.map +1 -1
- package/build/lib/helpers/build.js +2 -4
- package/build/lib/helpers/build.js.map +1 -1
- package/build/lib/helpers/capability.d.ts.map +1 -1
- package/build/lib/helpers/capability.js +27 -22
- package/build/lib/helpers/capability.js.map +1 -1
- package/build/lib/helpers/network.d.ts.map +1 -1
- package/build/lib/helpers/network.js +4 -3
- package/build/lib/helpers/network.js.map +1 -1
- package/build/lib/insecure-features.d.ts.map +1 -1
- package/build/lib/insecure-features.js +9 -13
- package/build/lib/insecure-features.js.map +1 -1
- package/build/lib/inspector-commands.d.ts.map +1 -1
- package/build/lib/inspector-commands.js +29 -28
- package/build/lib/inspector-commands.js.map +1 -1
- package/build/lib/logsink.d.ts.map +1 -1
- package/build/lib/logsink.js +8 -7
- package/build/lib/logsink.js.map +1 -1
- package/build/lib/schema/arg-spec.d.ts.map +1 -1
- package/build/lib/schema/arg-spec.js +5 -8
- package/build/lib/schema/arg-spec.js.map +1 -1
- package/build/lib/schema/cli-args.d.ts.map +1 -1
- package/build/lib/schema/cli-args.js +20 -19
- package/build/lib/schema/cli-args.js.map +1 -1
- package/build/lib/schema/cli-transformers.d.ts.map +1 -1
- package/build/lib/schema/cli-transformers.js.map +1 -1
- package/build/lib/schema/schema.d.ts.map +1 -1
- package/build/lib/schema/schema.js +28 -21
- package/build/lib/schema/schema.js.map +1 -1
- package/build/lib/utils/hash.d.ts +5 -0
- package/build/lib/utils/hash.d.ts.map +1 -0
- package/build/lib/{utils.js → utils/hash.js} +3 -21
- package/build/lib/utils/hash.js.map +1 -0
- package/build/lib/utils/index.d.ts +8 -0
- package/build/lib/utils/index.d.ts.map +1 -0
- package/build/lib/utils/index.js +31 -0
- package/build/lib/utils/index.js.map +1 -0
- package/build/lib/utils/is-package-changed.d.ts +16 -0
- package/build/lib/utils/is-package-changed.d.ts.map +1 -0
- package/build/lib/utils/is-package-changed.js +62 -0
- package/build/lib/utils/is-package-changed.js.map +1 -0
- package/build/lib/utils/object.d.ts +120 -0
- package/build/lib/utils/object.d.ts.map +1 -0
- package/build/lib/utils/object.js +288 -0
- package/build/lib/utils/object.js.map +1 -0
- package/build/lib/{extension → utils}/package-changed.d.ts +0 -1
- package/build/lib/utils/package-changed.d.ts.map +1 -0
- package/build/lib/{extension → utils}/package-changed.js +3 -4
- package/build/lib/utils/package-changed.js.map +1 -0
- package/build/lib/utils/package-json.d.ts +9 -0
- package/build/lib/utils/package-json.d.ts.map +1 -0
- package/build/lib/utils/package-json.js +32 -0
- package/build/lib/utils/package-json.js.map +1 -0
- package/build/lib/utils/resolve-from.d.ts +11 -0
- package/build/lib/utils/resolve-from.d.ts.map +1 -0
- package/build/lib/utils/resolve-from.js +41 -0
- package/build/lib/utils/resolve-from.js.map +1 -0
- package/build/types/cli.d.ts.map +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/manifest/base.d.ts.map +1 -1
- package/build/types/manifest/v3.d.ts.map +1 -1
- package/build/types/manifest/v4.d.ts.map +1 -1
- package/lib/appium.ts +59 -55
- package/lib/bidi-commands.ts +106 -60
- package/lib/bootstrap/appium-initializer.ts +27 -19
- package/lib/bootstrap/appium-main-runner.ts +8 -4
- package/lib/bootstrap/config-file.ts +33 -16
- package/lib/bootstrap/grid-v3-register.ts +26 -19
- package/lib/bootstrap/main-helpers.ts +25 -19
- package/lib/bootstrap/node-helpers.ts +19 -22
- package/lib/bootstrap/startup-config.ts +42 -39
- package/lib/cli/args.ts +3 -4
- package/lib/cli/driver-command.ts +19 -13
- package/lib/cli/extension-command.ts +208 -143
- package/lib/cli/extension.ts +4 -6
- package/lib/cli/parser.ts +32 -30
- package/lib/cli/plugin-command.ts +20 -9
- package/lib/cli/setup-command.ts +54 -39
- package/lib/cli/utils.ts +4 -3
- package/lib/doctor/doctor.ts +15 -17
- package/lib/extension/driver-config.ts +22 -17
- package/lib/extension/extension-config.ts +74 -66
- package/lib/extension/index.ts +42 -25
- package/lib/extension/manifest.ts +34 -31
- package/lib/extension/plugin-config.ts +15 -10
- package/lib/helpers/build.ts +6 -5
- package/lib/helpers/capability.ts +40 -35
- package/lib/helpers/network.ts +6 -5
- package/lib/insecure-features.ts +16 -14
- package/lib/inspector-commands.ts +72 -40
- package/lib/logsink.ts +22 -26
- package/lib/schema/arg-spec.ts +9 -8
- package/lib/schema/cli-args-guards.ts +4 -4
- package/lib/schema/cli-args.ts +25 -21
- package/lib/schema/cli-transformers.ts +6 -2
- package/lib/schema/format-errors.ts +1 -1
- package/lib/schema/schema.ts +52 -38
- package/lib/{utils.ts → utils/hash.ts} +2 -19
- package/lib/utils/index.ts +23 -0
- package/lib/utils/is-package-changed.ts +78 -0
- package/lib/utils/object.ts +312 -0
- package/lib/{extension → utils}/package-changed.ts +6 -7
- package/lib/utils/package-json.ts +36 -0
- package/lib/utils/resolve-from.ts +40 -0
- package/package.json +13 -16
- package/scripts/autoinstall-extensions.js +8 -8
- package/tsconfig.json +8 -2
- package/types/cli.ts +18 -18
- package/types/index.ts +2 -2
- package/types/manifest/base.ts +2 -2
- package/types/manifest/v3.ts +2 -2
- package/types/manifest/v4.ts +2 -2
- package/build/lib/extension/package-changed.d.ts.map +0 -1
- package/build/lib/extension/package-changed.js.map +0 -1
- package/build/lib/utils.d.ts +0 -13
- package/build/lib/utils.d.ts.map +0 -1
- package/build/lib/utils.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
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(
|
|
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
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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(
|
|
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
|
|
71
|
+
const driverClass = this.driverForSession(sessionId)?.constructor as DriverClass | undefined;
|
|
59
72
|
driverExecuteMethodMap = driverClass?.executeMethodMap ?? {};
|
|
60
|
-
const pluginClasses = this.pluginsForSession(sessionId)
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
83
|
+
plugins: pluginExecuteMethodMaps
|
|
84
|
+
? mapValues(pluginExecuteMethodMaps, executeMethodMapToCommandsInfo)
|
|
85
|
+
: undefined,
|
|
68
86
|
},
|
|
69
87
|
};
|
|
70
88
|
}
|
|
71
89
|
|
|
72
|
-
function toRestCommandParams(
|
|
90
|
+
function toRestCommandParams(
|
|
91
|
+
params: PayloadParams | undefined,
|
|
92
|
+
): RestCommandItemParam[] | undefined {
|
|
73
93
|
if (!params) {
|
|
74
94
|
return;
|
|
75
95
|
}
|
|
76
96
|
|
|
77
|
-
const toRestCommandItemParam = (
|
|
78
|
-
|
|
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 (
|
|
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) =>
|
|
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) =>
|
|
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
|
|
128
|
+
function methodMapToRestCommandsInfo(mm: MethodMap<any>): Record<string, RestMethodsToCommandsMap> {
|
|
106
129
|
const res: Record<string, RestMethodsToCommandsMap> = {};
|
|
107
|
-
for (const [uriPath, methods] of
|
|
108
|
-
const methodsMap = {};
|
|
109
|
-
for (const [method, spec] of
|
|
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
|
|
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 = (
|
|
163
|
+
const toBiDiCommandParams = (
|
|
164
|
+
params: BidiMethodParams | undefined,
|
|
165
|
+
): BiDiCommandItemParam[] | undefined => {
|
|
141
166
|
if (!params) {
|
|
142
167
|
return;
|
|
143
168
|
}
|
|
144
169
|
|
|
145
|
-
const toBiDiCommandItemParam = (
|
|
146
|
-
|
|
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 (
|
|
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) =>
|
|
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) =>
|
|
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 = (
|
|
201
|
+
const moduleMapToBiDiCommandsInfo = (
|
|
202
|
+
mm: BidiModuleMap,
|
|
203
|
+
): Record<string, BiDiCommandNamesToInfosMap> => {
|
|
174
204
|
const res: Record<string, BiDiCommandNamesToInfosMap> = {};
|
|
175
|
-
for (const [domain, commands] of
|
|
176
|
-
const commandsMap = {};
|
|
177
|
-
for (const [name, spec] of
|
|
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
|
|
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 (!
|
|
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 =
|
|
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 (
|
|
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 '${
|
|
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 (!
|
|
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: {
|
|
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:
|
|
311
|
+
message: typeof info.message === 'string' ? stripColorCodes(info.message) : info.message,
|
|
316
312
|
};
|
|
317
313
|
})();
|
|
318
314
|
|
package/lib/schema/arg-spec.ts
CHANGED
|
@@ -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 =
|
|
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 =
|
|
86
|
+
const properName = kebabCase(name.replace(/^--?/, ''));
|
|
87
87
|
if (extType && extName) {
|
|
88
|
-
return [extType,
|
|
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
|
|
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
|
-
|
|
105
|
-
|
|
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
|
}
|
package/lib/schema/cli-args.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {ArgumentTypeError, type ArgumentOptions} from 'argparse';
|
|
2
|
-
import
|
|
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
|
-
|
|
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}-${
|
|
47
|
-
: `--${extType}-${
|
|
47
|
+
? `--${extType}-${kebabCase(extName)}-${arg}`
|
|
48
|
+
: `--${extType}-${kebabCase(extName)}-${kebabCase(arg)}`;
|
|
48
49
|
}
|
|
49
|
-
return isShort ? `-${arg}` : `--${
|
|
50
|
+
return isShort ? `-${arg}` : `--${kebabCase(arg)}`;
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
const screamingSnakeCase =
|
|
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 =
|
|
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 (
|
|
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 =
|
|
108
|
-
|
|
109
|
-
|
|
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,
|
|
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
|
-
|
|
149
|
+
csvTransformer(val).flatMap((item) =>
|
|
150
|
+
transformers[appiumCliTransformer as AppiumCliTransformerName](item),
|
|
151
|
+
);
|
|
146
152
|
} else {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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 && !
|
|
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(
|
|
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(
|
|
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');
|