appium-adb 14.3.4 → 14.4.0
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/CHANGELOG.md +12 -0
- package/build/lib/adb.d.ts +9 -4
- package/build/lib/adb.d.ts.map +1 -1
- package/build/lib/adb.js +8 -9
- package/build/lib/adb.js.map +1 -1
- package/build/lib/index.d.ts +1 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +2 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/logcat.d.ts.map +1 -1
- package/build/lib/logcat.js +6 -14
- package/build/lib/logcat.js.map +1 -1
- package/build/lib/tools/aab-utils.d.ts.map +1 -1
- package/build/lib/tools/aab-utils.js +2 -2
- package/build/lib/tools/aab-utils.js.map +1 -1
- package/build/lib/tools/android-manifest.d.ts.map +1 -1
- package/build/lib/tools/android-manifest.js +11 -12
- package/build/lib/tools/android-manifest.js.map +1 -1
- package/build/lib/tools/apk-signing.d.ts.map +1 -1
- package/build/lib/tools/apk-signing.js +18 -19
- package/build/lib/tools/apk-signing.js.map +1 -1
- package/build/lib/tools/apk-utils.d.ts.map +1 -1
- package/build/lib/tools/apk-utils.js +39 -40
- package/build/lib/tools/apk-utils.js.map +1 -1
- package/build/lib/tools/apks-utils.d.ts.map +1 -1
- package/build/lib/tools/apks-utils.js +8 -9
- package/build/lib/tools/apks-utils.js.map +1 -1
- package/build/lib/tools/app-commands.d.ts.map +1 -1
- package/build/lib/tools/app-commands.js +37 -36
- package/build/lib/tools/app-commands.js.map +1 -1
- package/build/lib/tools/device-settings.d.ts.map +1 -1
- package/build/lib/tools/device-settings.js +17 -18
- package/build/lib/tools/device-settings.js.map +1 -1
- package/build/lib/tools/emulator-commands.d.ts.map +1 -1
- package/build/lib/tools/emulator-commands.js +22 -23
- package/build/lib/tools/emulator-commands.js.map +1 -1
- package/build/lib/tools/fs-commands.d.ts.map +1 -1
- package/build/lib/tools/fs-commands.js +5 -4
- package/build/lib/tools/fs-commands.js.map +1 -1
- package/build/lib/tools/general-commands.d.ts.map +1 -1
- package/build/lib/tools/general-commands.js +29 -29
- package/build/lib/tools/general-commands.js.map +1 -1
- package/build/lib/tools/keyboard-commands.d.ts.map +1 -1
- package/build/lib/tools/keyboard-commands.js +6 -4
- package/build/lib/tools/keyboard-commands.js.map +1 -1
- package/build/lib/tools/lockmgmt.d.ts.map +1 -1
- package/build/lib/tools/lockmgmt.js +17 -20
- package/build/lib/tools/lockmgmt.js.map +1 -1
- package/build/lib/tools/logcat-commands.d.ts.map +1 -1
- package/build/lib/tools/logcat-commands.js +5 -9
- package/build/lib/tools/logcat-commands.js.map +1 -1
- package/build/lib/tools/network-commands.d.ts.map +1 -1
- package/build/lib/tools/network-commands.js +1 -5
- package/build/lib/tools/network-commands.js.map +1 -1
- package/build/lib/tools/process-commands.d.ts.map +1 -1
- package/build/lib/tools/process-commands.js +11 -12
- package/build/lib/tools/process-commands.js.map +1 -1
- package/build/lib/tools/system-calls.d.ts +12 -5
- package/build/lib/tools/system-calls.d.ts.map +1 -1
- package/build/lib/tools/system-calls.js +56 -50
- package/build/lib/tools/system-calls.js.map +1 -1
- package/build/lib/tools/types.d.ts +1 -1
- package/build/lib/tools/types.d.ts.map +1 -1
- package/build/lib/utils/helpers/constants.d.ts +6 -0
- package/build/lib/utils/helpers/constants.d.ts.map +1 -0
- package/build/lib/utils/helpers/constants.js +9 -0
- package/build/lib/utils/helpers/constants.js.map +1 -0
- package/build/lib/utils/helpers/index.d.ts +6 -0
- package/build/lib/utils/helpers/index.d.ts.map +1 -0
- package/build/lib/utils/helpers/index.js +21 -0
- package/build/lib/utils/helpers/index.js.map +1 -0
- package/build/lib/utils/helpers/install.d.ts +16 -0
- package/build/lib/utils/helpers/install.d.ts.map +1 -0
- package/build/lib/utils/helpers/install.js +39 -0
- package/build/lib/utils/helpers/install.js.map +1 -0
- package/build/lib/utils/helpers/manifest.d.ts +10 -0
- package/build/lib/utils/helpers/manifest.d.ts.map +1 -0
- package/build/lib/utils/helpers/manifest.js +124 -0
- package/build/lib/utils/helpers/manifest.js.map +1 -0
- package/build/lib/utils/helpers/resource.d.ts +11 -0
- package/build/lib/utils/helpers/resource.d.ts.map +1 -0
- package/build/lib/utils/helpers/resource.js +59 -0
- package/build/lib/utils/helpers/resource.js.map +1 -0
- package/build/lib/utils/helpers/sdk.d.ts +20 -0
- package/build/lib/utils/helpers/sdk.d.ts.map +1 -0
- package/build/lib/utils/helpers/sdk.js +80 -0
- package/build/lib/utils/helpers/sdk.js.map +1 -0
- package/build/lib/utils/index.d.ts +40 -0
- package/build/lib/utils/index.d.ts.map +1 -0
- package/build/lib/utils/index.js +58 -0
- package/build/lib/utils/index.js.map +1 -0
- package/build/lib/utils/lodash/core.d.ts +9 -0
- package/build/lib/utils/lodash/core.d.ts.map +1 -0
- package/build/lib/utils/lodash/core.js +60 -0
- package/build/lib/utils/lodash/core.js.map +1 -0
- package/build/lib/utils/lodash/index.d.ts +2 -0
- package/build/lib/utils/lodash/index.d.ts.map +1 -0
- package/build/lib/utils/lodash/index.js +18 -0
- package/build/lib/utils/lodash/index.js.map +1 -0
- package/lib/adb.ts +14 -6
- package/lib/index.ts +1 -1
- package/lib/logcat.ts +6 -11
- package/lib/tools/aab-utils.ts +1 -1
- package/lib/tools/android-manifest.ts +4 -4
- package/lib/tools/apk-signing.ts +11 -7
- package/lib/tools/apk-utils.ts +41 -42
- package/lib/tools/apks-utils.ts +4 -5
- package/lib/tools/app-commands.ts +40 -34
- package/lib/tools/device-settings.ts +17 -15
- package/lib/tools/emulator-commands.ts +22 -23
- package/lib/tools/fs-commands.ts +5 -4
- package/lib/tools/general-commands.ts +32 -27
- package/lib/tools/keyboard-commands.ts +6 -4
- package/lib/tools/lockmgmt.ts +17 -13
- package/lib/tools/logcat-commands.ts +5 -6
- package/lib/tools/network-commands.ts +1 -2
- package/lib/tools/process-commands.ts +11 -9
- package/lib/tools/system-calls.ts +54 -46
- package/lib/tools/types.ts +1 -1
- package/lib/utils/helpers/constants.ts +6 -0
- package/lib/utils/helpers/index.ts +10 -0
- package/lib/utils/helpers/install.ts +50 -0
- package/lib/utils/helpers/manifest.ts +127 -0
- package/lib/utils/helpers/resource.ts +63 -0
- package/lib/utils/helpers/sdk.ts +81 -0
- package/lib/utils/index.ts +25 -0
- package/lib/utils/lodash/core.ts +65 -0
- package/lib/utils/lodash/index.ts +1 -0
- package/package.json +3 -5
- package/build/lib/helpers.d.ts +0 -47
- package/build/lib/helpers.d.ts.map +0 -1
- package/build/lib/helpers.js +0 -283
- package/build/lib/helpers.js.map +0 -1
- package/lib/helpers.ts +0 -323
package/build/lib/helpers.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getJavaForOs = exports.getJavaHome = exports.getResourcePath = exports.DEFAULT_ADB_EXEC_TIMEOUT = exports.APK_INSTALL_TIMEOUT = exports.APK_EXTENSION = exports.APKS_EXTENSION = void 0;
|
|
7
|
-
exports.getSdkRootFromEnv = getSdkRootFromEnv;
|
|
8
|
-
exports.requireSdkRoot = requireSdkRoot;
|
|
9
|
-
exports.unzipFile = unzipFile;
|
|
10
|
-
exports.buildInstallArgs = buildInstallArgs;
|
|
11
|
-
exports.readPackageManifest = readPackageManifest;
|
|
12
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
-
const support_1 = require("@appium/support");
|
|
14
|
-
const logger_1 = require("./logger");
|
|
15
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
16
|
-
const teen_process_1 = require("teen_process");
|
|
17
|
-
// Constants
|
|
18
|
-
exports.APKS_EXTENSION = '.apks';
|
|
19
|
-
exports.APK_EXTENSION = '.apk';
|
|
20
|
-
exports.APK_INSTALL_TIMEOUT = 60000;
|
|
21
|
-
exports.DEFAULT_ADB_EXEC_TIMEOUT = 20000; // in milliseconds
|
|
22
|
-
const MODULE_NAME = 'appium-adb';
|
|
23
|
-
// Public methods
|
|
24
|
-
/**
|
|
25
|
-
* Calculates the absolute path to the given resource
|
|
26
|
-
*/
|
|
27
|
-
exports.getResourcePath = lodash_1.default.memoize(async function getResourcePath(relPath) {
|
|
28
|
-
const moduleRoot = await getModuleRoot();
|
|
29
|
-
const resultPath = node_path_1.default.resolve(moduleRoot, relPath);
|
|
30
|
-
if (!(await support_1.fs.exists(resultPath))) {
|
|
31
|
-
throw new Error(`Cannot find the resource '${relPath}' under the '${moduleRoot}' ` +
|
|
32
|
-
`folder of ${MODULE_NAME} Node.js module`);
|
|
33
|
-
}
|
|
34
|
-
return resultPath;
|
|
35
|
-
});
|
|
36
|
-
/**
|
|
37
|
-
* Retrieves the actual path to SDK root folder from the system environment
|
|
38
|
-
*/
|
|
39
|
-
function getSdkRootFromEnv() {
|
|
40
|
-
return process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves the actual path to SDK root folder
|
|
44
|
-
*/
|
|
45
|
-
async function requireSdkRoot(customRoot = null) {
|
|
46
|
-
const sdkRoot = customRoot || getSdkRootFromEnv();
|
|
47
|
-
const docMsg = 'Read https://developer.android.com/studio/command-line/variables for more details';
|
|
48
|
-
if (!sdkRoot || lodash_1.default.isEmpty(sdkRoot)) {
|
|
49
|
-
throw new Error(`Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. ${docMsg}`);
|
|
50
|
-
}
|
|
51
|
-
if (!(await support_1.fs.exists(sdkRoot))) {
|
|
52
|
-
throw new Error(`The Android SDK root folder '${sdkRoot}' does not exist on the local file system. ${docMsg}`);
|
|
53
|
-
}
|
|
54
|
-
const stats = await support_1.fs.stat(sdkRoot);
|
|
55
|
-
if (!stats.isDirectory()) {
|
|
56
|
-
throw new Error(`The Android SDK root '${sdkRoot}' must be a folder. ${docMsg}`);
|
|
57
|
-
}
|
|
58
|
-
return sdkRoot;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @param zipPath
|
|
62
|
-
* @param dstRoot
|
|
63
|
-
*/
|
|
64
|
-
async function unzipFile(zipPath, dstRoot = node_path_1.default.dirname(zipPath)) {
|
|
65
|
-
logger_1.log.debug(`Unzipping '${zipPath}' to '${dstRoot}'`);
|
|
66
|
-
await support_1.zip.assertValidZip(zipPath);
|
|
67
|
-
await support_1.zip.extractAllTo(zipPath, dstRoot);
|
|
68
|
-
logger_1.log.debug('Unzip successful');
|
|
69
|
-
}
|
|
70
|
-
exports.getJavaHome = lodash_1.default.memoize(async function getJavaHome() {
|
|
71
|
-
const result = process.env.JAVA_HOME;
|
|
72
|
-
if (!result) {
|
|
73
|
-
throw new Error('The JAVA_HOME environment variable is not set for the current process');
|
|
74
|
-
}
|
|
75
|
-
if (!(await support_1.fs.exists(result))) {
|
|
76
|
-
throw new Error(`The JAVA_HOME location '${result}' must exist`);
|
|
77
|
-
}
|
|
78
|
-
const stats = await support_1.fs.stat(result);
|
|
79
|
-
if (!stats.isDirectory()) {
|
|
80
|
-
throw new Error(`The JAVA_HOME location '${result}' must be a valid folder`);
|
|
81
|
-
}
|
|
82
|
-
return result;
|
|
83
|
-
});
|
|
84
|
-
exports.getJavaForOs = lodash_1.default.memoize(async function getJavaForOs() {
|
|
85
|
-
let javaHome;
|
|
86
|
-
let errMsg;
|
|
87
|
-
try {
|
|
88
|
-
javaHome = await (0, exports.getJavaHome)();
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
const error = err;
|
|
92
|
-
errMsg = error.message;
|
|
93
|
-
}
|
|
94
|
-
const executableName = `java${support_1.system.isWindows() ? '.exe' : ''}`;
|
|
95
|
-
if (javaHome) {
|
|
96
|
-
const resultPath = node_path_1.default.resolve(javaHome, 'bin', executableName);
|
|
97
|
-
if (await support_1.fs.exists(resultPath)) {
|
|
98
|
-
return resultPath;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
return await support_1.fs.which(executableName);
|
|
103
|
-
}
|
|
104
|
-
catch {
|
|
105
|
-
// Ignore and throw custom error below
|
|
106
|
-
}
|
|
107
|
-
throw new Error(`The '${executableName}' binary could not be found ` +
|
|
108
|
-
`neither in PATH nor under JAVA_HOME (${javaHome ? node_path_1.default.resolve(javaHome, 'bin') : errMsg})`);
|
|
109
|
-
});
|
|
110
|
-
/**
|
|
111
|
-
* Transforms given options into the list of `adb install.install-multiple` command arguments
|
|
112
|
-
*/
|
|
113
|
-
function buildInstallArgs(apiLevel, options = {}) {
|
|
114
|
-
const result = [];
|
|
115
|
-
if (!support_1.util.hasValue(options.replace) || options.replace) {
|
|
116
|
-
result.push('-r');
|
|
117
|
-
}
|
|
118
|
-
if (options.allowTestPackages) {
|
|
119
|
-
result.push('-t');
|
|
120
|
-
}
|
|
121
|
-
if (options.useSdcard) {
|
|
122
|
-
result.push('-s');
|
|
123
|
-
}
|
|
124
|
-
if (options.grantPermissions) {
|
|
125
|
-
if (apiLevel < 23) {
|
|
126
|
-
logger_1.log.debug(`Skipping permissions grant option, since ` +
|
|
127
|
-
`the current API level ${apiLevel} does not support applications ` +
|
|
128
|
-
`permissions customization`);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
result.push('-g');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// For multiple-install
|
|
135
|
-
if (options.partialInstall) {
|
|
136
|
-
result.push('-p');
|
|
137
|
-
}
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Extracts various package manifest details
|
|
142
|
-
* from the given application file.
|
|
143
|
-
*/
|
|
144
|
-
async function readPackageManifest(apkPath) {
|
|
145
|
-
await this.initAapt2();
|
|
146
|
-
const aapt2Binary = this.binaries?.aapt2;
|
|
147
|
-
if (!aapt2Binary) {
|
|
148
|
-
throw new Error('aapt2 binary is not available');
|
|
149
|
-
}
|
|
150
|
-
const args = ['dump', 'badging', apkPath];
|
|
151
|
-
logger_1.log.debug(`Reading package manifest: '${support_1.util.quote([aapt2Binary, ...args])}'`);
|
|
152
|
-
let stdout;
|
|
153
|
-
try {
|
|
154
|
-
({ stdout } = await (0, teen_process_1.exec)(aapt2Binary, args));
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
const error = e;
|
|
158
|
-
const prefix = `Cannot read the manifest from '${apkPath}'`;
|
|
159
|
-
const suffix = `Original error: ${error.stderr || error.message}`;
|
|
160
|
-
if (error.stderr && lodash_1.default.includes(error.stderr, `Unable to open 'badging'`)) {
|
|
161
|
-
throw new Error(`${prefix}. Update build tools to use a newer aapt2 version. ${suffix}`);
|
|
162
|
-
}
|
|
163
|
-
throw new Error(`${prefix}. ${suffix}`);
|
|
164
|
-
}
|
|
165
|
-
const extractValue = (line, propPattern, valueTransformer) => {
|
|
166
|
-
const match = propPattern.exec(line);
|
|
167
|
-
if (match) {
|
|
168
|
-
return valueTransformer ? valueTransformer(match[1]) : match[1];
|
|
169
|
-
}
|
|
170
|
-
return undefined;
|
|
171
|
-
};
|
|
172
|
-
const extractArray = (line, propPattern, valueTransformer) => {
|
|
173
|
-
let match;
|
|
174
|
-
const resultArray = [];
|
|
175
|
-
while ((match = propPattern.exec(line))) {
|
|
176
|
-
resultArray.push(valueTransformer ? valueTransformer(match[1]) : match[1]);
|
|
177
|
-
}
|
|
178
|
-
return resultArray;
|
|
179
|
-
};
|
|
180
|
-
const toInt = (x) => parseInt(x, 10);
|
|
181
|
-
const result = {
|
|
182
|
-
name: '',
|
|
183
|
-
versionCode: 0,
|
|
184
|
-
minSdkVersion: 0,
|
|
185
|
-
compileSdkVersion: 0,
|
|
186
|
-
usesPermissions: [],
|
|
187
|
-
launchableActivity: {
|
|
188
|
-
name: '',
|
|
189
|
-
},
|
|
190
|
-
architectures: [],
|
|
191
|
-
locales: [],
|
|
192
|
-
densities: [],
|
|
193
|
-
};
|
|
194
|
-
for (const line of stdout.split('\n')) {
|
|
195
|
-
if (line.startsWith('package:')) {
|
|
196
|
-
for (const [name, pattern, transformer] of [
|
|
197
|
-
['name', /name='([^']+)'/, null],
|
|
198
|
-
['versionCode', /versionCode='([^']+)'/, toInt],
|
|
199
|
-
['versionName', /versionName='([^']+)'/, null],
|
|
200
|
-
['platformBuildVersionName', /platformBuildVersionName='([^']+)'/, null],
|
|
201
|
-
['platformBuildVersionCode', /platformBuildVersionCode='([^']+)'/, toInt],
|
|
202
|
-
['compileSdkVersion', /compileSdkVersion='([^']+)'/, toInt],
|
|
203
|
-
['compileSdkVersionCodename', /compileSdkVersionCodename='([^']+)'/, null],
|
|
204
|
-
]) {
|
|
205
|
-
const value = extractValue(line, pattern, transformer);
|
|
206
|
-
if (!lodash_1.default.isUndefined(value)) {
|
|
207
|
-
result[name] = value;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else if (line.startsWith('sdkVersion:') || line.startsWith('minSdkVersion:')) {
|
|
212
|
-
const value = extractValue(line, /[sS]dkVersion:'([^']+)'/, toInt);
|
|
213
|
-
if (value) {
|
|
214
|
-
result.minSdkVersion = value;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
else if (line.startsWith('targetSdkVersion:')) {
|
|
218
|
-
const value = extractValue(line, /targetSdkVersion:'([^']+)'/, toInt);
|
|
219
|
-
if (value) {
|
|
220
|
-
result.targetSdkVersion = value;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else if (line.startsWith('uses-permission:')) {
|
|
224
|
-
const value = extractValue(line, /name='([^']+)'/, null);
|
|
225
|
-
if (value) {
|
|
226
|
-
result.usesPermissions.push(value);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
else if (line.startsWith('launchable-activity:')) {
|
|
230
|
-
for (const [name, pattern] of [
|
|
231
|
-
['name', /name='([^']+)'/],
|
|
232
|
-
['label', /label='([^']+)'/],
|
|
233
|
-
['icon', /icon='([^']+)'/],
|
|
234
|
-
]) {
|
|
235
|
-
const value = extractValue(line, pattern, null);
|
|
236
|
-
if (value) {
|
|
237
|
-
result.launchableActivity[name] = value;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
else if (line.startsWith('locales:')) {
|
|
242
|
-
result.locales = extractArray(line, /'([^']+)'/g, null);
|
|
243
|
-
}
|
|
244
|
-
else if (line.startsWith('native-code:')) {
|
|
245
|
-
result.architectures = extractArray(line, /'([^']+)'/g, null);
|
|
246
|
-
}
|
|
247
|
-
else if (line.startsWith('densities:')) {
|
|
248
|
-
result.densities = extractArray(line, /'([^']+)'/g, toInt);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
// Private methods
|
|
254
|
-
/**
|
|
255
|
-
* Calculates the absolute path to the current module's root folder
|
|
256
|
-
*/
|
|
257
|
-
const getModuleRoot = lodash_1.default.memoize(async function getModuleRoot() {
|
|
258
|
-
let moduleRoot = node_path_1.default.dirname(node_path_1.default.resolve(__filename));
|
|
259
|
-
let isAtFsRoot = false;
|
|
260
|
-
while (!isAtFsRoot) {
|
|
261
|
-
const manifestPath = node_path_1.default.join(moduleRoot, 'package.json');
|
|
262
|
-
try {
|
|
263
|
-
if (await support_1.fs.exists(manifestPath)) {
|
|
264
|
-
const manifestContent = await support_1.fs.readFile(manifestPath, 'utf8');
|
|
265
|
-
const manifest = JSON.parse(manifestContent);
|
|
266
|
-
if (manifest.name === MODULE_NAME) {
|
|
267
|
-
return moduleRoot;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
catch {
|
|
272
|
-
// Ignore errors and continue searching
|
|
273
|
-
}
|
|
274
|
-
const parentDir = node_path_1.default.dirname(moduleRoot);
|
|
275
|
-
isAtFsRoot = moduleRoot.length <= parentDir.length;
|
|
276
|
-
moduleRoot = parentDir;
|
|
277
|
-
}
|
|
278
|
-
if (isAtFsRoot) {
|
|
279
|
-
throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
|
|
280
|
-
}
|
|
281
|
-
return moduleRoot;
|
|
282
|
-
});
|
|
283
|
-
//# sourceMappingURL=helpers.js.map
|
package/build/lib/helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../lib/helpers.ts"],"names":[],"mappings":";;;;;;AAwCA,8CAEC;AAKD,wCAoBC;AAMD,8BAQC;AA+CD,4CAgCC;AAMD,kDAgHC;AAtRD,0DAA6B;AAC7B,6CAAsD;AACtD,qCAA6B;AAC7B,oDAAuB;AACvB,+CAAkD;AAOlD,YAAY;AACC,QAAA,cAAc,GAAG,OAAO,CAAC;AACzB,QAAA,aAAa,GAAG,MAAM,CAAC;AACvB,QAAA,mBAAmB,GAAG,KAAK,CAAC;AAC5B,QAAA,wBAAwB,GAAG,KAAK,CAAC,CAAC,kBAAkB;AACjE,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,iBAAiB;AAEjB;;GAEG;AACU,QAAA,eAAe,GAAG,gBAAC,CAAC,OAAO,CAAC,KAAK,UAAU,eAAe,CACrE,OAAe;IAEf,MAAM,UAAU,GAAG,MAAM,aAAa,EAAE,CAAC;IACzC,MAAM,UAAU,GAAG,mBAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACrD,IAAI,CAAC,CAAC,MAAM,YAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,6BAA6B,OAAO,gBAAgB,UAAU,IAAI;YAChE,aAAa,WAAW,iBAAiB,CAC5C,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,gBA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AO,CAAC,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACxD,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,UAAU,EAAE,CAAC;QACnB,MAAM,YAAY,GAAG,mBAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAC3D,IAAI,CAAC;YACH,IAAI,MAAM,YAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,MAAM,eAAe,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;gBAChE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,eAAe,CAAoB,CAAC;gBAChE,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;oBAClC,OAAO,UAAU,CAAC;gBACpB,CAAC;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,uCAAuC;QACzC,CAAC;QACD,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC3C,UAAU,GAAG,UAAU,CAAC,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC;QACnD,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,WAAW,iBAAiB,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
package/lib/helpers.ts
DELETED
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import {system, fs, zip, util} from '@appium/support';
|
|
3
|
-
import {log} from './logger';
|
|
4
|
-
import _ from 'lodash';
|
|
5
|
-
import {exec, type ExecError} from 'teen_process';
|
|
6
|
-
import type {ADB} from './adb';
|
|
7
|
-
import type {ApkManifest} from './tools/types';
|
|
8
|
-
|
|
9
|
-
// Declare __filename for CommonJS compatibility
|
|
10
|
-
declare const __filename: string;
|
|
11
|
-
|
|
12
|
-
// Constants
|
|
13
|
-
export const APKS_EXTENSION = '.apks';
|
|
14
|
-
export const APK_EXTENSION = '.apk';
|
|
15
|
-
export const APK_INSTALL_TIMEOUT = 60000;
|
|
16
|
-
export const DEFAULT_ADB_EXEC_TIMEOUT = 20000; // in milliseconds
|
|
17
|
-
const MODULE_NAME = 'appium-adb';
|
|
18
|
-
|
|
19
|
-
// Public methods
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Calculates the absolute path to the given resource
|
|
23
|
-
*/
|
|
24
|
-
export const getResourcePath = _.memoize(async function getResourcePath(
|
|
25
|
-
relPath: string,
|
|
26
|
-
): Promise<string> {
|
|
27
|
-
const moduleRoot = await getModuleRoot();
|
|
28
|
-
const resultPath = path.resolve(moduleRoot, relPath);
|
|
29
|
-
if (!(await fs.exists(resultPath))) {
|
|
30
|
-
throw new Error(
|
|
31
|
-
`Cannot find the resource '${relPath}' under the '${moduleRoot}' ` +
|
|
32
|
-
`folder of ${MODULE_NAME} Node.js module`,
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
return resultPath;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Retrieves the actual path to SDK root folder from the system environment
|
|
40
|
-
*/
|
|
41
|
-
export function getSdkRootFromEnv(): string | undefined {
|
|
42
|
-
return process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Retrieves the actual path to SDK root folder
|
|
47
|
-
*/
|
|
48
|
-
export async function requireSdkRoot(customRoot: string | null = null): Promise<string> {
|
|
49
|
-
const sdkRoot = customRoot || getSdkRootFromEnv();
|
|
50
|
-
const docMsg =
|
|
51
|
-
'Read https://developer.android.com/studio/command-line/variables for more details';
|
|
52
|
-
if (!sdkRoot || _.isEmpty(sdkRoot)) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. ${docMsg}`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (!(await fs.exists(sdkRoot))) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`The Android SDK root folder '${sdkRoot}' does not exist on the local file system. ${docMsg}`,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const stats = await fs.stat(sdkRoot);
|
|
64
|
-
if (!stats.isDirectory()) {
|
|
65
|
-
throw new Error(`The Android SDK root '${sdkRoot}' must be a folder. ${docMsg}`);
|
|
66
|
-
}
|
|
67
|
-
return sdkRoot;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @param zipPath
|
|
72
|
-
* @param dstRoot
|
|
73
|
-
*/
|
|
74
|
-
export async function unzipFile(
|
|
75
|
-
zipPath: string,
|
|
76
|
-
dstRoot: string = path.dirname(zipPath),
|
|
77
|
-
): Promise<void> {
|
|
78
|
-
log.debug(`Unzipping '${zipPath}' to '${dstRoot}'`);
|
|
79
|
-
await zip.assertValidZip(zipPath);
|
|
80
|
-
await zip.extractAllTo(zipPath, dstRoot);
|
|
81
|
-
log.debug('Unzip successful');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const getJavaHome = _.memoize(async function getJavaHome(): Promise<string> {
|
|
85
|
-
const result = process.env.JAVA_HOME;
|
|
86
|
-
if (!result) {
|
|
87
|
-
throw new Error('The JAVA_HOME environment variable is not set for the current process');
|
|
88
|
-
}
|
|
89
|
-
if (!(await fs.exists(result))) {
|
|
90
|
-
throw new Error(`The JAVA_HOME location '${result}' must exist`);
|
|
91
|
-
}
|
|
92
|
-
const stats = await fs.stat(result);
|
|
93
|
-
if (!stats.isDirectory()) {
|
|
94
|
-
throw new Error(`The JAVA_HOME location '${result}' must be a valid folder`);
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const getJavaForOs = _.memoize(async function getJavaForOs(): Promise<string> {
|
|
100
|
-
let javaHome: string | undefined;
|
|
101
|
-
let errMsg: string | undefined;
|
|
102
|
-
try {
|
|
103
|
-
javaHome = await getJavaHome();
|
|
104
|
-
} catch (err: unknown) {
|
|
105
|
-
const error = err as Error;
|
|
106
|
-
errMsg = error.message;
|
|
107
|
-
}
|
|
108
|
-
const executableName = `java${system.isWindows() ? '.exe' : ''}`;
|
|
109
|
-
if (javaHome) {
|
|
110
|
-
const resultPath = path.resolve(javaHome, 'bin', executableName);
|
|
111
|
-
if (await fs.exists(resultPath)) {
|
|
112
|
-
return resultPath;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
try {
|
|
116
|
-
return await fs.which(executableName);
|
|
117
|
-
} catch {
|
|
118
|
-
// Ignore and throw custom error below
|
|
119
|
-
}
|
|
120
|
-
throw new Error(
|
|
121
|
-
`The '${executableName}' binary could not be found ` +
|
|
122
|
-
`neither in PATH nor under JAVA_HOME (${javaHome ? path.resolve(javaHome, 'bin') : errMsg})`,
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Transforms given options into the list of `adb install.install-multiple` command arguments
|
|
128
|
-
*/
|
|
129
|
-
export function buildInstallArgs(
|
|
130
|
-
apiLevel: number,
|
|
131
|
-
options: BuildInstallArgsOptions = {},
|
|
132
|
-
): string[] {
|
|
133
|
-
const result: string[] = [];
|
|
134
|
-
|
|
135
|
-
if (!util.hasValue(options.replace) || options.replace) {
|
|
136
|
-
result.push('-r');
|
|
137
|
-
}
|
|
138
|
-
if (options.allowTestPackages) {
|
|
139
|
-
result.push('-t');
|
|
140
|
-
}
|
|
141
|
-
if (options.useSdcard) {
|
|
142
|
-
result.push('-s');
|
|
143
|
-
}
|
|
144
|
-
if (options.grantPermissions) {
|
|
145
|
-
if (apiLevel < 23) {
|
|
146
|
-
log.debug(
|
|
147
|
-
`Skipping permissions grant option, since ` +
|
|
148
|
-
`the current API level ${apiLevel} does not support applications ` +
|
|
149
|
-
`permissions customization`,
|
|
150
|
-
);
|
|
151
|
-
} else {
|
|
152
|
-
result.push('-g');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
// For multiple-install
|
|
156
|
-
if (options.partialInstall) {
|
|
157
|
-
result.push('-p');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Extracts various package manifest details
|
|
165
|
-
* from the given application file.
|
|
166
|
-
*/
|
|
167
|
-
export async function readPackageManifest(this: ADB, apkPath: string): Promise<ApkManifest> {
|
|
168
|
-
await this.initAapt2();
|
|
169
|
-
const aapt2Binary = this.binaries?.aapt2;
|
|
170
|
-
if (!aapt2Binary) {
|
|
171
|
-
throw new Error('aapt2 binary is not available');
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const args = ['dump', 'badging', apkPath];
|
|
175
|
-
log.debug(`Reading package manifest: '${util.quote([aapt2Binary, ...args])}'`);
|
|
176
|
-
let stdout: string;
|
|
177
|
-
try {
|
|
178
|
-
({stdout} = await exec(aapt2Binary, args));
|
|
179
|
-
} catch (e: unknown) {
|
|
180
|
-
const error = e as ExecError;
|
|
181
|
-
const prefix = `Cannot read the manifest from '${apkPath}'`;
|
|
182
|
-
const suffix = `Original error: ${error.stderr || error.message}`;
|
|
183
|
-
if (error.stderr && _.includes(error.stderr, `Unable to open 'badging'`)) {
|
|
184
|
-
throw new Error(`${prefix}. Update build tools to use a newer aapt2 version. ${suffix}`);
|
|
185
|
-
}
|
|
186
|
-
throw new Error(`${prefix}. ${suffix}`);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const extractValue = (
|
|
190
|
-
line: string,
|
|
191
|
-
propPattern: RegExp,
|
|
192
|
-
valueTransformer: ((x: string) => any) | null,
|
|
193
|
-
): any => {
|
|
194
|
-
const match = propPattern.exec(line);
|
|
195
|
-
if (match) {
|
|
196
|
-
return valueTransformer ? valueTransformer(match[1]) : match[1];
|
|
197
|
-
}
|
|
198
|
-
return undefined;
|
|
199
|
-
};
|
|
200
|
-
const extractArray = (
|
|
201
|
-
line: string,
|
|
202
|
-
propPattern: RegExp,
|
|
203
|
-
valueTransformer: ((x: string) => any) | null,
|
|
204
|
-
): any[] => {
|
|
205
|
-
let match: RegExpExecArray | null;
|
|
206
|
-
const resultArray: any[] = [];
|
|
207
|
-
while ((match = propPattern.exec(line))) {
|
|
208
|
-
resultArray.push(valueTransformer ? valueTransformer(match[1]) : match[1]);
|
|
209
|
-
}
|
|
210
|
-
return resultArray;
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const toInt = (x: string): number => parseInt(x, 10);
|
|
214
|
-
|
|
215
|
-
const result: ApkManifest = {
|
|
216
|
-
name: '',
|
|
217
|
-
versionCode: 0,
|
|
218
|
-
minSdkVersion: 0,
|
|
219
|
-
compileSdkVersion: 0,
|
|
220
|
-
usesPermissions: [],
|
|
221
|
-
launchableActivity: {
|
|
222
|
-
name: '',
|
|
223
|
-
},
|
|
224
|
-
architectures: [],
|
|
225
|
-
locales: [],
|
|
226
|
-
densities: [],
|
|
227
|
-
};
|
|
228
|
-
for (const line of stdout.split('\n')) {
|
|
229
|
-
if (line.startsWith('package:')) {
|
|
230
|
-
for (const [name, pattern, transformer] of [
|
|
231
|
-
['name', /name='([^']+)'/, null],
|
|
232
|
-
['versionCode', /versionCode='([^']+)'/, toInt],
|
|
233
|
-
['versionName', /versionName='([^']+)'/, null],
|
|
234
|
-
['platformBuildVersionName', /platformBuildVersionName='([^']+)'/, null],
|
|
235
|
-
['platformBuildVersionCode', /platformBuildVersionCode='([^']+)'/, toInt],
|
|
236
|
-
['compileSdkVersion', /compileSdkVersion='([^']+)'/, toInt],
|
|
237
|
-
['compileSdkVersionCodename', /compileSdkVersionCodename='([^']+)'/, null],
|
|
238
|
-
] as const) {
|
|
239
|
-
const value = extractValue(line, pattern, transformer);
|
|
240
|
-
if (!_.isUndefined(value)) {
|
|
241
|
-
(result as Record<string, any>)[name] = value;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
} else if (line.startsWith('sdkVersion:') || line.startsWith('minSdkVersion:')) {
|
|
245
|
-
const value = extractValue(line, /[sS]dkVersion:'([^']+)'/, toInt);
|
|
246
|
-
if (value) {
|
|
247
|
-
result.minSdkVersion = value;
|
|
248
|
-
}
|
|
249
|
-
} else if (line.startsWith('targetSdkVersion:')) {
|
|
250
|
-
const value = extractValue(line, /targetSdkVersion:'([^']+)'/, toInt);
|
|
251
|
-
if (value) {
|
|
252
|
-
result.targetSdkVersion = value;
|
|
253
|
-
}
|
|
254
|
-
} else if (line.startsWith('uses-permission:')) {
|
|
255
|
-
const value = extractValue(line, /name='([^']+)'/, null);
|
|
256
|
-
if (value) {
|
|
257
|
-
result.usesPermissions.push(value);
|
|
258
|
-
}
|
|
259
|
-
} else if (line.startsWith('launchable-activity:')) {
|
|
260
|
-
for (const [name, pattern] of [
|
|
261
|
-
['name', /name='([^']+)'/],
|
|
262
|
-
['label', /label='([^']+)'/],
|
|
263
|
-
['icon', /icon='([^']+)'/],
|
|
264
|
-
] as const) {
|
|
265
|
-
const value = extractValue(line, pattern, null);
|
|
266
|
-
if (value) {
|
|
267
|
-
(result.launchableActivity as Record<string, any>)[name] = value;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
} else if (line.startsWith('locales:')) {
|
|
271
|
-
result.locales = extractArray(line, /'([^']+)'/g, null) as string[];
|
|
272
|
-
} else if (line.startsWith('native-code:')) {
|
|
273
|
-
result.architectures = extractArray(line, /'([^']+)'/g, null) as string[];
|
|
274
|
-
} else if (line.startsWith('densities:')) {
|
|
275
|
-
result.densities = extractArray(line, /'([^']+)'/g, toInt) as number[];
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return result;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Private methods
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Calculates the absolute path to the current module's root folder
|
|
285
|
-
*/
|
|
286
|
-
const getModuleRoot = _.memoize(async function getModuleRoot(): Promise<string> {
|
|
287
|
-
let moduleRoot = path.dirname(path.resolve(__filename));
|
|
288
|
-
let isAtFsRoot = false;
|
|
289
|
-
while (!isAtFsRoot) {
|
|
290
|
-
const manifestPath = path.join(moduleRoot, 'package.json');
|
|
291
|
-
try {
|
|
292
|
-
if (await fs.exists(manifestPath)) {
|
|
293
|
-
const manifestContent = await fs.readFile(manifestPath, 'utf8');
|
|
294
|
-
const manifest = JSON.parse(manifestContent) as {name?: string};
|
|
295
|
-
if (manifest.name === MODULE_NAME) {
|
|
296
|
-
return moduleRoot;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
} catch {
|
|
300
|
-
// Ignore errors and continue searching
|
|
301
|
-
}
|
|
302
|
-
const parentDir = path.dirname(moduleRoot);
|
|
303
|
-
isAtFsRoot = moduleRoot.length <= parentDir.length;
|
|
304
|
-
moduleRoot = parentDir;
|
|
305
|
-
}
|
|
306
|
-
if (isAtFsRoot) {
|
|
307
|
-
throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
|
|
308
|
-
}
|
|
309
|
-
return moduleRoot;
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
// Type definitions
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Options for building install arguments
|
|
316
|
-
*/
|
|
317
|
-
interface BuildInstallArgsOptions {
|
|
318
|
-
replace?: boolean;
|
|
319
|
-
allowTestPackages?: boolean;
|
|
320
|
-
useSdcard?: boolean;
|
|
321
|
-
grantPermissions?: boolean;
|
|
322
|
-
partialInstall?: boolean;
|
|
323
|
-
}
|