appium 2.0.0-beta.8 → 2.0.0-rc.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/LICENSE +1 -1
- package/README.md +149 -58
- package/build/lib/appium.d.ts +229 -0
- package/build/lib/appium.d.ts.map +1 -0
- package/build/lib/appium.js +678 -441
- package/build/lib/appium.js.map +1 -0
- package/build/lib/cli/args.d.ts +17 -0
- package/build/lib/cli/args.d.ts.map +1 -0
- package/build/lib/cli/args.js +263 -300
- package/build/lib/cli/args.js.map +1 -0
- package/build/lib/cli/driver-command.d.ts +102 -0
- package/build/lib/cli/driver-command.d.ts.map +1 -0
- package/build/lib/cli/driver-command.js +131 -81
- package/build/lib/cli/driver-command.js.map +1 -0
- package/build/lib/cli/extension-command.d.ts +402 -0
- package/build/lib/cli/extension-command.d.ts.map +1 -0
- package/build/lib/cli/extension-command.js +799 -383
- package/build/lib/cli/extension-command.js.map +1 -0
- package/build/lib/cli/extension.d.ts +23 -0
- package/build/lib/cli/extension.d.ts.map +1 -0
- package/build/lib/cli/extension.js +71 -60
- package/build/lib/cli/extension.js.map +1 -0
- package/build/lib/cli/parser.d.ts +84 -0
- package/build/lib/cli/parser.d.ts.map +1 -0
- package/build/lib/cli/parser.js +252 -148
- package/build/lib/cli/parser.js.map +1 -0
- package/build/lib/cli/plugin-command.d.ts +99 -0
- package/build/lib/cli/plugin-command.d.ts.map +1 -0
- package/build/lib/cli/plugin-command.js +125 -81
- package/build/lib/cli/plugin-command.js.map +1 -0
- package/build/lib/cli/utils.d.ts +29 -0
- package/build/lib/cli/utils.d.ts.map +1 -0
- package/build/lib/cli/utils.js +72 -51
- package/build/lib/cli/utils.js.map +1 -0
- package/build/lib/config-file.d.ts +100 -0
- package/build/lib/config-file.d.ts.map +1 -0
- package/build/lib/config-file.js +207 -0
- package/build/lib/config-file.js.map +1 -0
- package/build/lib/config.d.ts +49 -0
- package/build/lib/config.d.ts.map +1 -0
- package/build/lib/config.js +262 -223
- package/build/lib/config.js.map +1 -0
- package/build/lib/constants.d.ts +56 -0
- package/build/lib/constants.d.ts.map +1 -0
- package/build/lib/constants.js +73 -0
- package/build/lib/constants.js.map +1 -0
- package/build/lib/extension/driver-config.d.ts +82 -0
- package/build/lib/extension/driver-config.d.ts.map +1 -0
- package/build/lib/extension/driver-config.js +210 -0
- package/build/lib/extension/driver-config.js.map +1 -0
- package/build/lib/extension/extension-config.d.ts +270 -0
- package/build/lib/extension/extension-config.d.ts.map +1 -0
- package/build/lib/extension/extension-config.js +601 -0
- package/build/lib/extension/extension-config.js.map +1 -0
- package/build/lib/extension/index.d.ts +48 -0
- package/build/lib/extension/index.d.ts.map +1 -0
- package/build/lib/extension/index.js +105 -0
- package/build/lib/extension/index.js.map +1 -0
- package/build/lib/extension/manifest-migrations.d.ts +27 -0
- package/build/lib/extension/manifest-migrations.d.ts.map +1 -0
- package/build/lib/extension/manifest-migrations.js +134 -0
- package/build/lib/extension/manifest-migrations.js.map +1 -0
- package/build/lib/extension/manifest.d.ts +145 -0
- package/build/lib/extension/manifest.d.ts.map +1 -0
- package/build/lib/extension/manifest.js +528 -0
- package/build/lib/extension/manifest.js.map +1 -0
- package/build/lib/extension/package-changed.d.ts +11 -0
- package/build/lib/extension/package-changed.d.ts.map +1 -0
- package/build/lib/extension/package-changed.js +62 -0
- package/build/lib/extension/package-changed.js.map +1 -0
- package/build/lib/extension/plugin-config.d.ts +56 -0
- package/build/lib/extension/plugin-config.d.ts.map +1 -0
- package/build/lib/extension/plugin-config.js +102 -0
- package/build/lib/extension/plugin-config.js.map +1 -0
- package/build/lib/grid-register.d.ts +10 -0
- package/build/lib/grid-register.d.ts.map +1 -0
- package/build/lib/grid-register.js +122 -144
- package/build/lib/grid-register.js.map +1 -0
- package/build/lib/logger.d.ts +3 -0
- package/build/lib/logger.d.ts.map +1 -0
- package/build/lib/logger.js +5 -17
- package/build/lib/logger.js.map +1 -0
- package/build/lib/logsink.d.ts +4 -0
- package/build/lib/logsink.d.ts.map +1 -0
- package/build/lib/logsink.js +189 -184
- package/build/lib/logsink.js.map +1 -0
- package/build/lib/main.d.ts +62 -0
- package/build/lib/main.d.ts.map +1 -0
- package/build/lib/main.js +406 -234
- package/build/lib/main.js.map +1 -0
- package/build/lib/schema/arg-spec.d.ts +143 -0
- package/build/lib/schema/arg-spec.d.ts.map +1 -0
- package/build/lib/schema/arg-spec.js +164 -0
- package/build/lib/schema/arg-spec.js.map +1 -0
- package/build/lib/schema/cli-args.d.ts +19 -0
- package/build/lib/schema/cli-args.d.ts.map +1 -0
- package/build/lib/schema/cli-args.js +220 -0
- package/build/lib/schema/cli-args.js.map +1 -0
- package/build/lib/schema/cli-transformers.d.ts +5 -0
- package/build/lib/schema/cli-transformers.d.ts.map +1 -0
- package/build/lib/schema/cli-transformers.js +124 -0
- package/build/lib/schema/cli-transformers.js.map +1 -0
- package/build/lib/schema/index.d.ts +3 -0
- package/build/lib/schema/index.d.ts.map +1 -0
- package/build/lib/schema/index.js +19 -0
- package/build/lib/schema/index.js.map +1 -0
- package/build/lib/schema/keywords.d.ts +24 -0
- package/build/lib/schema/keywords.d.ts.map +1 -0
- package/build/lib/schema/keywords.js +128 -0
- package/build/lib/schema/keywords.js.map +1 -0
- package/build/lib/schema/schema.d.ts +260 -0
- package/build/lib/schema/schema.d.ts.map +1 -0
- package/build/lib/schema/schema.js +640 -0
- package/build/lib/schema/schema.js.map +1 -0
- package/build/lib/utils.d.ts +276 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +373 -271
- package/build/lib/utils.js.map +1 -0
- package/build/types/cli.d.ts +134 -0
- package/build/types/cli.d.ts.map +1 -0
- package/build/types/cli.js +3 -0
- package/build/types/cli.js.map +1 -0
- package/build/types/index.d.ts +15 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +19 -0
- package/build/types/index.js.map +1 -0
- package/build/types/manifest/base.d.ts +135 -0
- package/build/types/manifest/base.d.ts.map +1 -0
- package/build/types/manifest/base.js +3 -0
- package/build/types/manifest/base.js.map +1 -0
- package/build/types/manifest/index.d.ts +21 -0
- package/build/types/manifest/index.d.ts.map +1 -0
- package/build/types/manifest/index.js +42 -0
- package/build/types/manifest/index.js.map +1 -0
- package/build/types/manifest/v3.d.ts +139 -0
- package/build/types/manifest/v3.d.ts.map +1 -0
- package/build/types/manifest/v3.js +3 -0
- package/build/types/manifest/v3.js.map +1 -0
- package/build/types/manifest/v4.d.ts +139 -0
- package/build/types/manifest/v4.d.ts.map +1 -0
- package/build/types/manifest/v4.js +3 -0
- package/build/types/manifest/v4.js.map +1 -0
- package/driver.d.ts +1 -0
- package/driver.js +14 -0
- package/index.js +11 -0
- package/lib/appium.js +555 -185
- package/lib/cli/args.js +275 -407
- package/lib/cli/driver-command.js +132 -24
- package/lib/cli/extension-command.js +751 -272
- package/lib/cli/extension.js +47 -20
- package/lib/cli/parser.js +267 -95
- package/lib/cli/plugin-command.js +122 -22
- package/lib/cli/utils.js +24 -10
- package/lib/config-file.js +220 -0
- package/lib/config.js +243 -132
- package/lib/constants.js +79 -0
- package/lib/extension/driver-config.js +247 -0
- package/lib/extension/extension-config.js +709 -0
- package/lib/extension/index.js +116 -0
- package/lib/extension/manifest-migrations.js +136 -0
- package/lib/extension/manifest.js +580 -0
- package/lib/extension/package-changed.js +64 -0
- package/lib/extension/plugin-config.js +112 -0
- package/lib/grid-register.js +49 -35
- package/lib/logger.js +1 -2
- package/lib/logsink.js +59 -36
- package/lib/main.js +392 -104
- package/lib/schema/arg-spec.js +229 -0
- package/lib/schema/cli-args.js +241 -0
- package/lib/schema/cli-transformers.js +119 -0
- package/lib/schema/index.js +2 -0
- package/lib/schema/keywords.js +136 -0
- package/lib/schema/schema.js +725 -0
- package/lib/utils.js +315 -167
- package/package.json +84 -82
- package/plugin.d.ts +1 -0
- package/plugin.js +13 -0
- package/scripts/autoinstall-extensions.js +243 -0
- package/support.d.ts +1 -0
- package/support.js +13 -0
- package/tsconfig.json +25 -0
- package/types/cli.ts +193 -0
- package/types/index.ts +20 -0
- package/types/manifest/README.md +30 -0
- package/types/manifest/base.ts +158 -0
- package/types/manifest/index.ts +28 -0
- package/types/manifest/v3.ts +161 -0
- package/types/manifest/v4.ts +161 -0
- package/CHANGELOG.md +0 -3669
- package/bin/ios-webkit-debug-proxy-launcher.js +0 -71
- package/build/lib/cli/argparse-actions.js +0 -104
- package/build/lib/cli/npm.js +0 -207
- package/build/lib/cli/parser-helpers.js +0 -93
- package/build/lib/driver-config.js +0 -77
- package/build/lib/drivers.js +0 -99
- package/build/lib/extension-config.js +0 -253
- package/build/lib/plugin-config.js +0 -59
- package/build/lib/plugins.js +0 -14
- package/lib/cli/argparse-actions.js +0 -77
- package/lib/cli/npm.js +0 -183
- package/lib/cli/parser-helpers.js +0 -91
- package/lib/driver-config.js +0 -46
- package/lib/drivers.js +0 -84
- package/lib/extension-config.js +0 -209
- package/lib/plugin-config.js +0 -34
- package/lib/plugins.js +0 -10
package/lib/config.js
CHANGED
|
@@ -1,54 +1,79 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
1
2
|
import _ from 'lodash';
|
|
2
|
-
import
|
|
3
|
-
import { mkdirp, fs, system } from 'appium-support';
|
|
3
|
+
import {system, fs} from '@appium/support';
|
|
4
4
|
import axios from 'axios';
|
|
5
|
-
import {
|
|
6
|
-
import { rootDir } from './utils';
|
|
7
|
-
import logger from './logger';
|
|
5
|
+
import {exec} from 'teen_process';
|
|
8
6
|
import semver from 'semver';
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
} from './cli/argparse-actions';
|
|
7
|
+
import findUp from 'find-up';
|
|
8
|
+
import {getDefaultsForSchema, getAllArgSpecs} from './schema/schema';
|
|
12
9
|
|
|
10
|
+
const npmPackage = fs.readPackageJsonFrom(__dirname);
|
|
13
11
|
|
|
14
|
-
const npmPackage = require(path.resolve(rootDir, 'package.json'));
|
|
15
12
|
const APPIUM_VER = npmPackage.version;
|
|
16
|
-
const
|
|
13
|
+
const ENGINES = /** @type {Record<string,string>} */ (npmPackage.engines);
|
|
14
|
+
const MIN_NODE_VERSION = ENGINES.node;
|
|
15
|
+
const MIN_NPM_VERSION = ENGINES.npm;
|
|
17
16
|
|
|
18
17
|
const GIT_META_ROOT = '.git';
|
|
19
18
|
const GIT_BINARY = `git${system.isWindows() ? '.exe' : ''}`;
|
|
20
19
|
const GITHUB_API = 'https://api.github.com/repos/appium/appium';
|
|
21
20
|
|
|
21
|
+
/**
|
|
22
|
+
* @type {import('appium/types').BuildInfo}
|
|
23
|
+
*/
|
|
22
24
|
const BUILD_INFO = {
|
|
23
25
|
version: APPIUM_VER,
|
|
24
26
|
};
|
|
25
27
|
|
|
26
|
-
function getNodeVersion
|
|
27
|
-
return semver.coerce(process.version);
|
|
28
|
+
function getNodeVersion() {
|
|
29
|
+
return /** @type {import('semver').SemVer} */ (semver.coerce(process.version));
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns version of `npm`
|
|
34
|
+
* @returns {Promise<string>}
|
|
35
|
+
*/
|
|
36
|
+
async function getNpmVersion() {
|
|
37
|
+
const {stdout} = await exec(system.isWindows() ? 'npm.cmd' : 'npm', ['--version']);
|
|
38
|
+
return stdout.trim();
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
/**
|
|
42
|
+
* @param {boolean} [useGithubApiFallback]
|
|
43
|
+
*/
|
|
44
|
+
async function updateBuildInfo(useGithubApiFallback = false) {
|
|
36
45
|
const sha = await getGitRev(useGithubApiFallback);
|
|
37
46
|
if (!sha) {
|
|
38
47
|
return;
|
|
39
48
|
}
|
|
40
49
|
BUILD_INFO['git-sha'] = sha;
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
BUILD_INFO.built =
|
|
50
|
+
const buildTimestamp = await getGitTimestamp(sha, useGithubApiFallback);
|
|
51
|
+
if (buildTimestamp) {
|
|
52
|
+
BUILD_INFO.built = buildTimestamp;
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Finds the Git metadata dir (see `GIT_META_ROOT`)
|
|
58
|
+
*
|
|
59
|
+
* This is needed because Appium cannot assume `package.json` and `.git` are in the same
|
|
60
|
+
* directory. Monorepos, see?
|
|
61
|
+
* @returns {Promise<string|undefined>} Path to dir or `undefined` if not found
|
|
62
|
+
*/
|
|
63
|
+
async function findGitRoot() {
|
|
64
|
+
return await findUp(GIT_META_ROOT, {cwd: rootDir, type: 'directory'});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {boolean} [useGithubApiFallback]
|
|
69
|
+
* @returns {Promise<string?>}
|
|
70
|
+
*/
|
|
71
|
+
async function getGitRev(useGithubApiFallback = false) {
|
|
72
|
+
const gitRoot = await findGitRoot();
|
|
73
|
+
if (gitRoot) {
|
|
49
74
|
try {
|
|
50
75
|
const {stdout} = await exec(GIT_BINARY, ['rev-parse', 'HEAD'], {
|
|
51
|
-
cwd:
|
|
76
|
+
cwd: gitRoot,
|
|
52
77
|
});
|
|
53
78
|
return stdout.trim();
|
|
54
79
|
} catch (ign) {}
|
|
@@ -58,28 +83,31 @@ async function getGitRev (useGithubApiFallback = false) {
|
|
|
58
83
|
return null;
|
|
59
84
|
}
|
|
60
85
|
|
|
86
|
+
// If the package folder is not a valid git repository
|
|
87
|
+
// then fetch the corresponding tag info from GitHub
|
|
61
88
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (name === `v${APPIUM_VER}` && commit && commit.sha) {
|
|
70
|
-
return commit.sha;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
89
|
+
return (
|
|
90
|
+
await axios.get(`${GITHUB_API}/git/refs/tags/appium@${APPIUM_VER}`, {
|
|
91
|
+
headers: {
|
|
92
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
).data?.object?.sha;
|
|
74
96
|
} catch (ign) {}
|
|
75
97
|
return null;
|
|
76
98
|
}
|
|
77
99
|
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} commitSha
|
|
102
|
+
* @param {boolean} [useGithubApiFallback]
|
|
103
|
+
* @returns {Promise<string?>}
|
|
104
|
+
*/
|
|
105
|
+
async function getGitTimestamp(commitSha, useGithubApiFallback = false) {
|
|
106
|
+
const gitRoot = await findGitRoot();
|
|
107
|
+
if (gitRoot) {
|
|
80
108
|
try {
|
|
81
109
|
const {stdout} = await exec(GIT_BINARY, ['show', '-s', '--format=%ci', commitSha], {
|
|
82
|
-
cwd:
|
|
110
|
+
cwd: gitRoot,
|
|
83
111
|
});
|
|
84
112
|
return stdout.trim();
|
|
85
113
|
} catch (ign) {}
|
|
@@ -90,46 +118,51 @@ async function getGitTimestamp (commitSha, useGithubApiFallback = false) {
|
|
|
90
118
|
}
|
|
91
119
|
|
|
92
120
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return resBodyObj.commit.committer.date;
|
|
101
|
-
}
|
|
102
|
-
if (resBodyObj.commit.author && resBodyObj.commit.author.date) {
|
|
103
|
-
return resBodyObj.commit.author.date;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
121
|
+
return (
|
|
122
|
+
await axios.get(`${GITHUB_API}/git/tags/${commitSha}`, {
|
|
123
|
+
headers: {
|
|
124
|
+
'User-Agent': `Appium ${APPIUM_VER}`,
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
).data?.tagger?.date;
|
|
106
128
|
} catch (ign) {}
|
|
107
129
|
return null;
|
|
108
130
|
}
|
|
109
131
|
|
|
110
132
|
/**
|
|
111
|
-
*
|
|
133
|
+
* Mutable object containing Appium build information. By default it
|
|
112
134
|
* only contains the Appium version, but is updated with the build timestamp
|
|
113
135
|
* and git commit hash asynchronously as soon as `updateBuildInfo` is called
|
|
114
136
|
* and succeeds.
|
|
137
|
+
* @returns {import('appium/types').BuildInfo}
|
|
115
138
|
*/
|
|
116
|
-
function getBuildInfo
|
|
139
|
+
function getBuildInfo() {
|
|
117
140
|
return BUILD_INFO;
|
|
118
141
|
}
|
|
119
142
|
|
|
120
|
-
function checkNodeOk
|
|
143
|
+
function checkNodeOk() {
|
|
121
144
|
const version = getNodeVersion();
|
|
122
145
|
if (!semver.satisfies(version, MIN_NODE_VERSION)) {
|
|
123
|
-
|
|
146
|
+
throw new Error(
|
|
147
|
+
`Node version must be at least ${MIN_NODE_VERSION}; current is ${version.version}`
|
|
148
|
+
);
|
|
124
149
|
}
|
|
125
150
|
}
|
|
126
151
|
|
|
127
|
-
function
|
|
152
|
+
export async function checkNpmOk() {
|
|
153
|
+
const npmVersion = await getNpmVersion();
|
|
154
|
+
if (!semver.satisfies(npmVersion, MIN_NPM_VERSION)) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
`npm version must be at least ${MIN_NPM_VERSION}; current is ${npmVersion}. Run "npm install -g npm" to upgrade.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function warnNodeDeprecations() {
|
|
128
162
|
/**
|
|
129
163
|
* Uncomment this section to get node version deprecation warnings
|
|
130
164
|
* Also add test cases to config-specs.js to cover the cases added
|
|
131
165
|
**/
|
|
132
|
-
|
|
133
166
|
// const version = getNodeVersion();
|
|
134
167
|
// if (version.major < 8) {
|
|
135
168
|
// logger.warn(`Appium support for versions of node < ${version.major} has been ` +
|
|
@@ -138,99 +171,177 @@ function warnNodeDeprecations () {
|
|
|
138
171
|
// }
|
|
139
172
|
}
|
|
140
173
|
|
|
141
|
-
async function
|
|
174
|
+
async function showBuildInfo() {
|
|
142
175
|
await updateBuildInfo(true);
|
|
143
176
|
console.log(JSON.stringify(getBuildInfo())); // eslint-disable-line no-console
|
|
144
177
|
}
|
|
145
178
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Returns k/v pairs of server arguments which are _not_ the defaults.
|
|
181
|
+
* @param {Args} parsedArgs
|
|
182
|
+
* @returns {Args}
|
|
183
|
+
*/
|
|
184
|
+
function getNonDefaultServerArgs(parsedArgs) {
|
|
185
|
+
/**
|
|
186
|
+
* Flattens parsed args into a single level object for comparison with
|
|
187
|
+
* flattened defaults across server args and extension args.
|
|
188
|
+
* @param {Args} args
|
|
189
|
+
* @returns {Record<string, { value: any, argSpec: ArgSpec }>}
|
|
190
|
+
*/
|
|
191
|
+
const flatten = (args) => {
|
|
192
|
+
const argSpecs = getAllArgSpecs();
|
|
193
|
+
const flattened = _.reduce(
|
|
194
|
+
[...argSpecs.values()],
|
|
195
|
+
(acc, argSpec) => {
|
|
196
|
+
if (_.has(args, argSpec.dest)) {
|
|
197
|
+
acc[argSpec.dest] = {value: _.get(args, argSpec.dest), argSpec};
|
|
198
|
+
}
|
|
199
|
+
return acc;
|
|
200
|
+
},
|
|
201
|
+
/** @type {Record<string, { value: any, argSpec: ArgSpec }>} */ ({})
|
|
202
|
+
);
|
|
154
203
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
// out which of the ones used are deprecated
|
|
158
|
-
return parser.rawArgs.reduce((acc, [[name], {dest, default: defaultValue, action}]) => {
|
|
159
|
-
if (!args[dest] || args[dest] === defaultValue) {
|
|
160
|
-
return acc;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (action?.deprecated_for) {
|
|
164
|
-
acc[name] = action.deprecated_for;
|
|
165
|
-
} else if (isSubClass(action, StoreDeprecatedDefaultCapabilityAction)) {
|
|
166
|
-
acc[name] = DEFAULT_CAPS_ARG;
|
|
167
|
-
}
|
|
168
|
-
return acc;
|
|
169
|
-
}, {});
|
|
170
|
-
}
|
|
204
|
+
return flattened;
|
|
205
|
+
};
|
|
171
206
|
|
|
172
|
-
|
|
173
|
-
if (port > 0 && port < 65536) return true; // eslint-disable-line curly
|
|
174
|
-
logger.error(`Port '${portName}' must be greater than 0 and less than 65536. Currently ${port}`);
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
207
|
+
const args = flatten(parsedArgs);
|
|
177
208
|
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
['noReset', 'fullReset'],
|
|
182
|
-
['ipa', 'safari'],
|
|
183
|
-
['app', 'safari'],
|
|
184
|
-
['forceIphone', 'forceIpad'],
|
|
185
|
-
['deviceName', 'defaultDevice']
|
|
186
|
-
];
|
|
187
|
-
|
|
188
|
-
for (let exSet of exclusives) {
|
|
189
|
-
let numFoundInArgs = 0;
|
|
190
|
-
for (let opt of exSet) {
|
|
191
|
-
if (_.has(args, opt) && args[opt]) {
|
|
192
|
-
numFoundInArgs++;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (numFoundInArgs > 1) {
|
|
196
|
-
throw new Error(`You can't pass in more than one argument from the ` +
|
|
197
|
-
`set ${JSON.stringify(exSet)}, since they are ` +
|
|
198
|
-
`mutually exclusive`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
209
|
+
// hopefully these function names are descriptive enough
|
|
210
|
+
const typesDiffer = /** @param {string} dest */ (dest) =>
|
|
211
|
+
typeof args[dest].value !== typeof defaultsFromSchema[dest];
|
|
201
212
|
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
213
|
+
const defaultValueIsArray = /** @param {string} dest */ (dest) =>
|
|
214
|
+
_.isArray(defaultsFromSchema[dest]);
|
|
215
|
+
|
|
216
|
+
const argsValueIsArray = /** @param {string} dest */ (dest) => _.isArray(args[dest].value);
|
|
217
|
+
|
|
218
|
+
const arraysDiffer = /** @param {string} dest */ (dest) =>
|
|
219
|
+
_.gt(_.size(_.difference(args[dest].value, defaultsFromSchema[dest])), 0);
|
|
220
|
+
|
|
221
|
+
const valuesDiffer = /** @param {string} dest */ (dest) =>
|
|
222
|
+
args[dest].value !== defaultsFromSchema[dest];
|
|
223
|
+
|
|
224
|
+
const defaultIsDefined = /** @param {string} dest */ (dest) =>
|
|
225
|
+
!_.isUndefined(defaultsFromSchema[dest]);
|
|
226
|
+
|
|
227
|
+
// note that `_.overEvery` is like an "AND", and `_.overSome` is like an "OR"
|
|
228
|
+
|
|
229
|
+
const argValueNotArrayOrArraysDiffer = _.overSome([_.negate(argsValueIsArray), arraysDiffer]);
|
|
230
|
+
|
|
231
|
+
const defaultValueNotArrayAndValuesDiffer = _.overEvery([
|
|
232
|
+
_.negate(defaultValueIsArray),
|
|
233
|
+
valuesDiffer,
|
|
234
|
+
]);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* This used to be a hideous conditional, but it's broken up into a hideous function instead.
|
|
238
|
+
* hopefully this makes things a little more understandable.
|
|
239
|
+
* - checks if the default value is defined
|
|
240
|
+
* - if so, and the default is not an array:
|
|
241
|
+
* - ensures the types are the same
|
|
242
|
+
* - ensures the values are equal
|
|
243
|
+
* - if so, and the default is an array:
|
|
244
|
+
* - ensures the args value is an array
|
|
245
|
+
* - ensures the args values do not differ from the default values
|
|
246
|
+
* @type {(dest: string) => boolean}
|
|
247
|
+
*/
|
|
248
|
+
const isNotDefault = _.overEvery([
|
|
249
|
+
defaultIsDefined,
|
|
250
|
+
_.overSome([
|
|
251
|
+
typesDiffer,
|
|
252
|
+
_.overEvery([defaultValueIsArray, argValueNotArrayOrArraysDiffer]),
|
|
253
|
+
defaultValueNotArrayAndValuesDiffer,
|
|
254
|
+
]),
|
|
255
|
+
]);
|
|
256
|
+
|
|
257
|
+
const defaultsFromSchema = getDefaultsForSchema(true);
|
|
210
258
|
|
|
211
|
-
|
|
259
|
+
return _.reduce(
|
|
260
|
+
_.pickBy(args, (__, key) => isNotDefault(key)),
|
|
261
|
+
// explodes the flattened object back into nested one
|
|
262
|
+
(acc, {value, argSpec}) => _.set(acc, argSpec.dest, value),
|
|
263
|
+
/** @type {Args} */ ({})
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Compacts an object for {@link showConfig}:
|
|
269
|
+
* 1. Removes `subcommand` key/value
|
|
270
|
+
* 2. Removes `undefined` values
|
|
271
|
+
* 3. Removes empty objects (but not `false` values)
|
|
272
|
+
* Does not operate recursively.
|
|
273
|
+
*/
|
|
274
|
+
const compactConfig = _.partial(
|
|
275
|
+
_.omitBy,
|
|
276
|
+
_,
|
|
277
|
+
(value, key) =>
|
|
278
|
+
key === 'subcommand' || _.isUndefined(value) || (_.isObject(value) && _.isEmpty(value))
|
|
279
|
+
);
|
|
212
280
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Shows a breakdown of the current config after CLI params, config file loaded & defaults applied.
|
|
283
|
+
*
|
|
284
|
+
* The actual shape of `preConfigParsedArgs` and `defaults` does not matter for the purposes of this function,
|
|
285
|
+
* but it's intended to be called with values of type {@link ParsedArgs} and `DefaultValues<true>`, respectively.
|
|
286
|
+
*
|
|
287
|
+
* @param {Partial<ParsedArgs>} nonDefaultPreConfigParsedArgs - Parsed CLI args (or param to `init()`) before config & defaults applied
|
|
288
|
+
* @param {import('./config-file').ReadConfigFileResult} configResult - Result of attempting to load a config file. _Must_ be normalized
|
|
289
|
+
* @param {Partial<ParsedArgs>} defaults - Configuration defaults from schemas
|
|
290
|
+
* @param {ParsedArgs} parsedArgs - Entire parsed args object
|
|
291
|
+
*/
|
|
292
|
+
function showConfig(nonDefaultPreConfigParsedArgs, configResult, defaults, parsedArgs) {
|
|
293
|
+
console.log('Appium Configuration\n');
|
|
294
|
+
console.log('from defaults:\n');
|
|
295
|
+
console.dir(compactConfig(defaults));
|
|
296
|
+
if (configResult.config) {
|
|
297
|
+
console.log(`\nfrom config file at ${configResult.filepath}:\n`);
|
|
298
|
+
console.dir(compactConfig(configResult.config));
|
|
299
|
+
} else {
|
|
300
|
+
console.log(`\n(no configuration file loaded)`);
|
|
301
|
+
}
|
|
302
|
+
const compactedNonDefaultPreConfigArgs = compactConfig(nonDefaultPreConfigParsedArgs);
|
|
303
|
+
if (_.isEmpty(compactedNonDefaultPreConfigArgs)) {
|
|
304
|
+
console.log(`\n(no CLI parameters provided)`);
|
|
305
|
+
} else {
|
|
306
|
+
console.log('\nvia CLI or function call:\n');
|
|
307
|
+
console.dir(compactedNonDefaultPreConfigArgs);
|
|
219
308
|
}
|
|
309
|
+
console.log('\nfinal configuration:\n');
|
|
310
|
+
console.dir(compactConfig(parsedArgs));
|
|
220
311
|
}
|
|
221
312
|
|
|
222
|
-
|
|
313
|
+
/**
|
|
314
|
+
* @param {string} tmpDir
|
|
315
|
+
*/
|
|
316
|
+
async function validateTmpDir(tmpDir) {
|
|
223
317
|
try {
|
|
224
|
-
await mkdirp(tmpDir);
|
|
318
|
+
await fs.mkdirp(tmpDir);
|
|
225
319
|
} catch (e) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
|
|
320
|
+
throw new Error(
|
|
321
|
+
`We could not ensure that the temp dir you specified ` +
|
|
322
|
+
`(${tmpDir}) exists. Please make sure it's writeable.`
|
|
323
|
+
);
|
|
228
324
|
}
|
|
229
325
|
}
|
|
230
326
|
|
|
327
|
+
const rootDir = fs.findRoot(__dirname);
|
|
328
|
+
|
|
231
329
|
export {
|
|
232
|
-
getBuildInfo,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
330
|
+
getBuildInfo,
|
|
331
|
+
checkNodeOk,
|
|
332
|
+
showBuildInfo,
|
|
333
|
+
warnNodeDeprecations,
|
|
334
|
+
validateTmpDir,
|
|
335
|
+
getNonDefaultServerArgs,
|
|
336
|
+
getGitRev,
|
|
337
|
+
APPIUM_VER,
|
|
338
|
+
updateBuildInfo,
|
|
339
|
+
showConfig,
|
|
340
|
+
rootDir,
|
|
236
341
|
};
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* @typedef {import('appium/types').ParsedArgs} ParsedArgs
|
|
345
|
+
* @typedef {import('appium/types').Args} Args
|
|
346
|
+
* @typedef {import('./schema/arg-spec').ArgSpec} ArgSpec
|
|
347
|
+
*/
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The name of the extension type for drivers
|
|
5
|
+
*/
|
|
6
|
+
export const DRIVER_TYPE = 'driver';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The name of the extension type for plugins
|
|
10
|
+
*/
|
|
11
|
+
export const PLUGIN_TYPE = 'plugin';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The `server` command of the `appium` CLI
|
|
15
|
+
*/
|
|
16
|
+
export const SERVER_SUBCOMMAND = 'server';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The value of `--use-plugins` if _all_ plugins should be loaded
|
|
20
|
+
*/
|
|
21
|
+
export const USE_ALL_PLUGINS = 'all';
|
|
22
|
+
|
|
23
|
+
// This is a map of plugin names to npm packages representing those plugins.
|
|
24
|
+
// The plugins in this list will be available to the CLI so users can just
|
|
25
|
+
// type 'appium plugin install 'name'', rather than having to specify the full
|
|
26
|
+
// npm package. I.e., these are the officially recognized plugins.
|
|
27
|
+
export const KNOWN_PLUGINS = Object.freeze(
|
|
28
|
+
/** @type {const} */ ({
|
|
29
|
+
images: '@appium/images-plugin',
|
|
30
|
+
'execute-driver': '@appium/execute-driver-plugin',
|
|
31
|
+
'relaxed-caps': '@appium/relaxed-caps-plugin',
|
|
32
|
+
'universal-xml': '@appium/universal-xml-plugin',
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// This is a map of driver names to npm packages representing those drivers.
|
|
37
|
+
// The drivers in this list will be available to the CLI so users can just
|
|
38
|
+
// type 'appium driver install 'name'', rather than having to specify the full
|
|
39
|
+
// npm package. I.e., these are the officially recognized drivers.
|
|
40
|
+
export const KNOWN_DRIVERS = Object.freeze(
|
|
41
|
+
/** @type {const} */ ({
|
|
42
|
+
uiautomator2: 'appium-uiautomator2-driver',
|
|
43
|
+
xcuitest: 'appium-xcuitest-driver',
|
|
44
|
+
mac2: 'appium-mac2-driver',
|
|
45
|
+
espresso: 'appium-espresso-driver',
|
|
46
|
+
safari: 'appium-safari-driver',
|
|
47
|
+
gecko: 'appium-geckodriver',
|
|
48
|
+
chromium: 'appium-chromium-driver',
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Relative path to directory containing any Appium internal files
|
|
54
|
+
*/
|
|
55
|
+
export const CACHE_DIR_RELATIVE_PATH = path.join('node_modules', '.cache', 'appium');
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Relative path to hashfile (from `APPIUM_HOME`) of consuming project's `package.json` (if it exists)
|
|
59
|
+
*/
|
|
60
|
+
export const PKG_HASHFILE_RELATIVE_PATH = path.join(CACHE_DIR_RELATIVE_PATH, 'package.hash');
|
|
61
|
+
|
|
62
|
+
export const EXT_SUBCOMMAND_LIST = 'list';
|
|
63
|
+
export const EXT_SUBCOMMAND_INSTALL = 'install';
|
|
64
|
+
export const EXT_SUBCOMMAND_UNINSTALL = 'uninstall';
|
|
65
|
+
export const EXT_SUBCOMMAND_UPDATE = 'update';
|
|
66
|
+
export const EXT_SUBCOMMAND_RUN = 'run';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Current revision of the manifest (`extensions.yaml`) schema
|
|
70
|
+
*/
|
|
71
|
+
export const CURRENT_SCHEMA_REV = 4;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The default number of stack frames to show in a "long" stack trace, when enabled via `--long-stacktrace`
|
|
75
|
+
* @remarks This value may be increased in the future.
|
|
76
|
+
* @privateRemarks A value like `Infinity` may provide to have deleterious effects on
|
|
77
|
+
* memory usage, perf, and/or log output, and higher limits may be difficult to scan.
|
|
78
|
+
*/
|
|
79
|
+
export const LONG_STACKTRACE_LIMIT = 100;
|