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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export {
|
|
2
|
+
APKS_EXTENSION,
|
|
3
|
+
APK_EXTENSION,
|
|
4
|
+
APK_INSTALL_TIMEOUT,
|
|
5
|
+
DEFAULT_ADB_EXEC_TIMEOUT,
|
|
6
|
+
} from './constants';
|
|
7
|
+
export {buildInstallArgs, type BuildInstallArgsOptions} from './install';
|
|
8
|
+
export {readPackageManifest} from './manifest';
|
|
9
|
+
export {getResourcePath, unzipFile} from './resource';
|
|
10
|
+
export {getSdkRootFromEnv, requireSdkRoot, getJavaHome, getJavaForOs} from './sdk';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {util} from '@appium/support';
|
|
2
|
+
import {log} from '../../logger';
|
|
3
|
+
|
|
4
|
+
export interface BuildInstallArgsOptions {
|
|
5
|
+
replace?: boolean;
|
|
6
|
+
allowTestPackages?: boolean;
|
|
7
|
+
useSdcard?: boolean;
|
|
8
|
+
grantPermissions?: boolean;
|
|
9
|
+
partialInstall?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds command-line arguments for `adb install`.
|
|
14
|
+
*
|
|
15
|
+
* @param apiLevel - Android API level of the target device
|
|
16
|
+
* @param options - Install options mapped to adb flags
|
|
17
|
+
* @returns A list of install flags
|
|
18
|
+
*/
|
|
19
|
+
export function buildInstallArgs(
|
|
20
|
+
apiLevel: number,
|
|
21
|
+
options: BuildInstallArgsOptions = {},
|
|
22
|
+
): string[] {
|
|
23
|
+
const result: string[] = [];
|
|
24
|
+
|
|
25
|
+
if (!util.hasValue(options.replace) || options.replace) {
|
|
26
|
+
result.push('-r');
|
|
27
|
+
}
|
|
28
|
+
if (options.allowTestPackages) {
|
|
29
|
+
result.push('-t');
|
|
30
|
+
}
|
|
31
|
+
if (options.useSdcard) {
|
|
32
|
+
result.push('-s');
|
|
33
|
+
}
|
|
34
|
+
if (options.grantPermissions) {
|
|
35
|
+
if (apiLevel < 23) {
|
|
36
|
+
log.debug(
|
|
37
|
+
`Skipping permissions grant option, since ` +
|
|
38
|
+
`the current API level ${apiLevel} does not support applications ` +
|
|
39
|
+
`permissions customization`,
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
result.push('-g');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (options.partialInstall) {
|
|
46
|
+
result.push('-p');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import {util} from '@appium/support';
|
|
2
|
+
import {exec, type ExecError} from 'teen_process';
|
|
3
|
+
import {log} from '../../logger';
|
|
4
|
+
import type {ADB} from '../../adb';
|
|
5
|
+
import type {ApkManifest} from '../../tools/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Reads and parses Android manifest metadata from an APK via `aapt2`.
|
|
9
|
+
*
|
|
10
|
+
* @param apkPath - Local path to the APK file
|
|
11
|
+
* @returns Parsed manifest data
|
|
12
|
+
*/
|
|
13
|
+
export async function readPackageManifest(this: ADB, apkPath: string): Promise<ApkManifest> {
|
|
14
|
+
await this.initAapt2();
|
|
15
|
+
const aapt2Binary = this.binaries?.aapt2;
|
|
16
|
+
if (!aapt2Binary) {
|
|
17
|
+
throw new Error('aapt2 binary is not available');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const args = ['dump', 'badging', apkPath];
|
|
21
|
+
log.debug(`Reading package manifest: '${util.quote([aapt2Binary, ...args])}'`);
|
|
22
|
+
let stdout: string;
|
|
23
|
+
try {
|
|
24
|
+
({stdout} = await exec(aapt2Binary, args));
|
|
25
|
+
} catch (e: unknown) {
|
|
26
|
+
const error = e as ExecError;
|
|
27
|
+
const prefix = `Cannot read the manifest from '${apkPath}'`;
|
|
28
|
+
const suffix = `Original error: ${error.stderr || error.message}`;
|
|
29
|
+
if (error.stderr && error.stderr.includes(`Unable to open 'badging'`)) {
|
|
30
|
+
throw new Error(`${prefix}. Update build tools to use a newer aapt2 version. ${suffix}`, {
|
|
31
|
+
cause: e,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
throw new Error(`${prefix}. ${suffix}`, {cause: e});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const extractValue = (
|
|
38
|
+
line: string,
|
|
39
|
+
propPattern: RegExp,
|
|
40
|
+
valueTransformer: ((x: string) => any) | null,
|
|
41
|
+
): any => {
|
|
42
|
+
const match = propPattern.exec(line);
|
|
43
|
+
if (match) {
|
|
44
|
+
return valueTransformer ? valueTransformer(match[1]) : match[1];
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
const extractArray = (
|
|
49
|
+
line: string,
|
|
50
|
+
propPattern: RegExp,
|
|
51
|
+
valueTransformer: ((x: string) => any) | null,
|
|
52
|
+
): any[] => {
|
|
53
|
+
let match: RegExpExecArray | null;
|
|
54
|
+
const resultArray: any[] = [];
|
|
55
|
+
while ((match = propPattern.exec(line))) {
|
|
56
|
+
resultArray.push(valueTransformer ? valueTransformer(match[1]) : match[1]);
|
|
57
|
+
}
|
|
58
|
+
return resultArray;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const toInt = (x: string): number => parseInt(x, 10);
|
|
62
|
+
|
|
63
|
+
const result: ApkManifest = {
|
|
64
|
+
name: '',
|
|
65
|
+
versionCode: 0,
|
|
66
|
+
minSdkVersion: 0,
|
|
67
|
+
compileSdkVersion: 0,
|
|
68
|
+
usesPermissions: [],
|
|
69
|
+
launchableActivity: {
|
|
70
|
+
name: '',
|
|
71
|
+
},
|
|
72
|
+
architectures: [],
|
|
73
|
+
locales: [],
|
|
74
|
+
densities: [],
|
|
75
|
+
};
|
|
76
|
+
for (const line of stdout.split('\n')) {
|
|
77
|
+
if (line.startsWith('package:')) {
|
|
78
|
+
for (const [name, pattern, transformer] of [
|
|
79
|
+
['name', /name='([^']+)'/, null],
|
|
80
|
+
['versionCode', /versionCode='([^']+)'/, toInt],
|
|
81
|
+
['versionName', /versionName='([^']+)'/, null],
|
|
82
|
+
['platformBuildVersionName', /platformBuildVersionName='([^']+)'/, null],
|
|
83
|
+
['platformBuildVersionCode', /platformBuildVersionCode='([^']+)'/, toInt],
|
|
84
|
+
['compileSdkVersion', /compileSdkVersion='([^']+)'/, toInt],
|
|
85
|
+
['compileSdkVersionCodename', /compileSdkVersionCodename='([^']+)'/, null],
|
|
86
|
+
] as const) {
|
|
87
|
+
const value = extractValue(line, pattern, transformer);
|
|
88
|
+
if (value !== undefined) {
|
|
89
|
+
(result as Record<string, any>)[name] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else if (line.startsWith('sdkVersion:') || line.startsWith('minSdkVersion:')) {
|
|
93
|
+
const value = extractValue(line, /[sS]dkVersion:'([^']+)'/, toInt);
|
|
94
|
+
if (value) {
|
|
95
|
+
result.minSdkVersion = value;
|
|
96
|
+
}
|
|
97
|
+
} else if (line.startsWith('targetSdkVersion:')) {
|
|
98
|
+
const value = extractValue(line, /targetSdkVersion:'([^']+)'/, toInt);
|
|
99
|
+
if (value) {
|
|
100
|
+
result.targetSdkVersion = value;
|
|
101
|
+
}
|
|
102
|
+
} else if (line.startsWith('uses-permission:')) {
|
|
103
|
+
const value = extractValue(line, /name='([^']+)'/, null);
|
|
104
|
+
if (value) {
|
|
105
|
+
result.usesPermissions.push(value);
|
|
106
|
+
}
|
|
107
|
+
} else if (line.startsWith('launchable-activity:')) {
|
|
108
|
+
for (const [name, pattern] of [
|
|
109
|
+
['name', /name='([^']+)'/],
|
|
110
|
+
['label', /label='([^']+)'/],
|
|
111
|
+
['icon', /icon='([^']+)'/],
|
|
112
|
+
] as const) {
|
|
113
|
+
const value = extractValue(line, pattern, null);
|
|
114
|
+
if (value) {
|
|
115
|
+
(result.launchableActivity as Record<string, any>)[name] = value;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
} else if (line.startsWith('locales:')) {
|
|
119
|
+
result.locales = extractArray(line, /'([^']+)'/g, null) as string[];
|
|
120
|
+
} else if (line.startsWith('native-code:')) {
|
|
121
|
+
result.architectures = extractArray(line, /'([^']+)'/g, null) as string[];
|
|
122
|
+
} else if (line.startsWith('densities:')) {
|
|
123
|
+
result.densities = extractArray(line, /'([^']+)'/g, toInt) as number[];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {fs, zip, util} from '@appium/support';
|
|
3
|
+
import {log} from '../../logger';
|
|
4
|
+
import {MODULE_NAME} from './constants';
|
|
5
|
+
|
|
6
|
+
// Declare __filename for CommonJS compatibility
|
|
7
|
+
declare const __filename: string;
|
|
8
|
+
|
|
9
|
+
export const getResourcePath = util.memoize(async function getResourcePath(
|
|
10
|
+
relPath: string,
|
|
11
|
+
): Promise<string> {
|
|
12
|
+
const moduleRoot = await getModuleRoot();
|
|
13
|
+
const resultPath = path.resolve(moduleRoot, relPath);
|
|
14
|
+
if (!(await fs.exists(resultPath))) {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Cannot find the resource '${relPath}' under the '${moduleRoot}' ` +
|
|
17
|
+
`folder of ${MODULE_NAME} Node.js module`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return resultPath;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Unzips an archive into the target destination directory.
|
|
25
|
+
*
|
|
26
|
+
* @param zipPath - Source zip file path
|
|
27
|
+
* @param dstRoot - Destination directory. Defaults to zip parent directory
|
|
28
|
+
*/
|
|
29
|
+
export async function unzipFile(
|
|
30
|
+
zipPath: string,
|
|
31
|
+
dstRoot: string = path.dirname(zipPath),
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
log.debug(`Unzipping '${zipPath}' to '${dstRoot}'`);
|
|
34
|
+
await zip.assertValidZip(zipPath);
|
|
35
|
+
await zip.extractAllTo(zipPath, dstRoot);
|
|
36
|
+
log.debug('Unzip successful');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getModuleRoot = util.memoize(async function getModuleRoot(): Promise<string> {
|
|
40
|
+
let moduleRoot = path.dirname(path.resolve(__filename));
|
|
41
|
+
let isAtFsRoot = false;
|
|
42
|
+
while (!isAtFsRoot) {
|
|
43
|
+
const manifestPath = path.join(moduleRoot, 'package.json');
|
|
44
|
+
try {
|
|
45
|
+
if (await fs.exists(manifestPath)) {
|
|
46
|
+
const manifestContent = await fs.readFile(manifestPath, 'utf8');
|
|
47
|
+
const manifest = JSON.parse(manifestContent) as {name?: string};
|
|
48
|
+
if (manifest.name === MODULE_NAME) {
|
|
49
|
+
return moduleRoot;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
// Ignore errors and continue searching
|
|
54
|
+
}
|
|
55
|
+
const parentDir = path.dirname(moduleRoot);
|
|
56
|
+
isAtFsRoot = moduleRoot.length <= parentDir.length;
|
|
57
|
+
moduleRoot = parentDir;
|
|
58
|
+
}
|
|
59
|
+
if (isAtFsRoot) {
|
|
60
|
+
throw new Error(`Cannot find the root folder of the ${MODULE_NAME} Node.js module`);
|
|
61
|
+
}
|
|
62
|
+
return moduleRoot;
|
|
63
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {fs, system, util} from '@appium/support';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Gets Android SDK root from environment variables.
|
|
6
|
+
*
|
|
7
|
+
* @returns SDK root path if present
|
|
8
|
+
*/
|
|
9
|
+
export function getSdkRootFromEnv(): string | undefined {
|
|
10
|
+
return process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Resolves and validates Android SDK root path.
|
|
15
|
+
*
|
|
16
|
+
* @param customRoot - Optional explicit SDK root path override
|
|
17
|
+
* @returns Absolute path to a valid SDK root directory
|
|
18
|
+
*/
|
|
19
|
+
export async function requireSdkRoot(customRoot: string | null = null): Promise<string> {
|
|
20
|
+
const sdkRoot = customRoot || getSdkRootFromEnv();
|
|
21
|
+
const docMsg =
|
|
22
|
+
'Read https://developer.android.com/studio/command-line/variables for more details';
|
|
23
|
+
if (!sdkRoot || util.isEmpty(sdkRoot)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. ${docMsg}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
if (!(await fs.exists(sdkRoot))) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
`The Android SDK root folder '${sdkRoot}' does not exist on the local file system. ${docMsg}`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const stats = await fs.stat(sdkRoot);
|
|
35
|
+
if (!stats.isDirectory()) {
|
|
36
|
+
throw new Error(`The Android SDK root '${sdkRoot}' must be a folder. ${docMsg}`);
|
|
37
|
+
}
|
|
38
|
+
return sdkRoot;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const getJavaHome = util.memoize(async function getJavaHome(): Promise<string> {
|
|
42
|
+
const result = process.env.JAVA_HOME;
|
|
43
|
+
if (!result) {
|
|
44
|
+
throw new Error('The JAVA_HOME environment variable is not set for the current process');
|
|
45
|
+
}
|
|
46
|
+
if (!(await fs.exists(result))) {
|
|
47
|
+
throw new Error(`The JAVA_HOME location '${result}' must exist`);
|
|
48
|
+
}
|
|
49
|
+
const stats = await fs.stat(result);
|
|
50
|
+
if (!stats.isDirectory()) {
|
|
51
|
+
throw new Error(`The JAVA_HOME location '${result}' must be a valid folder`);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export const getJavaForOs = util.memoize(async function getJavaForOs(): Promise<string> {
|
|
57
|
+
let javaHome: string | undefined;
|
|
58
|
+
let errMsg: string | undefined;
|
|
59
|
+
try {
|
|
60
|
+
javaHome = await getJavaHome();
|
|
61
|
+
} catch (err: unknown) {
|
|
62
|
+
const error = err as Error;
|
|
63
|
+
errMsg = error.message;
|
|
64
|
+
}
|
|
65
|
+
const executableName = `java${system.isWindows() ? '.exe' : ''}`;
|
|
66
|
+
if (javaHome) {
|
|
67
|
+
const resultPath = path.resolve(javaHome, 'bin', executableName);
|
|
68
|
+
if (await fs.exists(resultPath)) {
|
|
69
|
+
return resultPath;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return await fs.which(executableName);
|
|
74
|
+
} catch {
|
|
75
|
+
// Ignore and throw custom error below
|
|
76
|
+
}
|
|
77
|
+
throw new Error(
|
|
78
|
+
`The '${executableName}' binary could not be found ` +
|
|
79
|
+
`neither in PATH nor under JAVA_HOME (${javaHome ? path.resolve(javaHome, 'bin') : errMsg})`,
|
|
80
|
+
);
|
|
81
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as helpers from './helpers';
|
|
2
|
+
import * as lodash from './lodash';
|
|
3
|
+
import {util} from '@appium/support';
|
|
4
|
+
|
|
5
|
+
export const APKS_EXTENSION = helpers.APKS_EXTENSION;
|
|
6
|
+
export const APK_INSTALL_TIMEOUT = helpers.APK_INSTALL_TIMEOUT;
|
|
7
|
+
export const DEFAULT_ADB_EXEC_TIMEOUT = helpers.DEFAULT_ADB_EXEC_TIMEOUT;
|
|
8
|
+
export const buildInstallArgs = helpers.buildInstallArgs;
|
|
9
|
+
export const readPackageManifest = helpers.readPackageManifest;
|
|
10
|
+
export const getResourcePath = helpers.getResourcePath;
|
|
11
|
+
export const unzipFile = helpers.unzipFile;
|
|
12
|
+
export const getSdkRootFromEnv = helpers.getSdkRootFromEnv;
|
|
13
|
+
export const requireSdkRoot = helpers.requireSdkRoot;
|
|
14
|
+
export const getJavaHome = helpers.getJavaHome;
|
|
15
|
+
export const getJavaForOs = helpers.getJavaForOs;
|
|
16
|
+
|
|
17
|
+
export const memoize = util.memoize;
|
|
18
|
+
export const cloneDeep = lodash.cloneDeep;
|
|
19
|
+
export const defaults = lodash.defaults;
|
|
20
|
+
export const intersectionWith = lodash.intersectionWith;
|
|
21
|
+
export const zip = lodash.zip;
|
|
22
|
+
export const pick = lodash.pick;
|
|
23
|
+
export const defaultsDeep = lodash.defaultsDeep;
|
|
24
|
+
|
|
25
|
+
export type {BuildInstallArgsOptions} from './helpers';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {util} from '@appium/support';
|
|
2
|
+
|
|
3
|
+
type AnyObject = Record<string, any>;
|
|
4
|
+
|
|
5
|
+
export const cloneDeep = <T>(value: T): T => {
|
|
6
|
+
if (typeof globalThis.structuredClone === 'function') {
|
|
7
|
+
return globalThis.structuredClone(value);
|
|
8
|
+
}
|
|
9
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const defaults = (target: AnyObject, ...sources: AnyObject[]): AnyObject => {
|
|
13
|
+
for (const source of sources) {
|
|
14
|
+
if (!source) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
for (const [key, value] of Object.entries(source)) {
|
|
18
|
+
if (target[key] === undefined) {
|
|
19
|
+
target[key] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const _defaultsDeep = (target: AnyObject, ...sources: AnyObject[]): AnyObject => {
|
|
27
|
+
for (const source of sources) {
|
|
28
|
+
if (!source) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of Object.entries(source)) {
|
|
32
|
+
const current = target[key];
|
|
33
|
+
if (current === undefined) {
|
|
34
|
+
target[key] = util.isPlainObject(value) || Array.isArray(value) ? cloneDeep(value) : value;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (util.isPlainObject(current) && util.isPlainObject(value)) {
|
|
38
|
+
_defaultsDeep(current, value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return target;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const intersectionWith = <T>(
|
|
46
|
+
first: T[],
|
|
47
|
+
second: T[],
|
|
48
|
+
comparator: (left: T, right: T) => boolean,
|
|
49
|
+
): T[] => first.filter((item) => second.some((other) => comparator(item, other)));
|
|
50
|
+
export const zip = <A, B>(
|
|
51
|
+
arrA: readonly A[],
|
|
52
|
+
arrB: readonly B[],
|
|
53
|
+
): Array<[A | undefined, B | undefined]> => {
|
|
54
|
+
const length = Math.max(arrA.length, arrB.length);
|
|
55
|
+
return Array.from({length}, (_, idx) => [arrA[idx], arrB[idx]]);
|
|
56
|
+
};
|
|
57
|
+
export const pick = <T extends AnyObject>(obj: T, keysArg: string[]) =>
|
|
58
|
+
keysArg.reduce((acc, key) => {
|
|
59
|
+
if (key in obj) {
|
|
60
|
+
acc[key] = obj[key];
|
|
61
|
+
}
|
|
62
|
+
return acc;
|
|
63
|
+
}, {} as AnyObject) as Partial<T>;
|
|
64
|
+
export const defaultsDeep = <T extends AnyObject>(target: T, ...sources: AnyObject[]): T =>
|
|
65
|
+
_defaultsDeep(target, ...sources) as T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-adb",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.4.0",
|
|
4
4
|
"description": "Android Debug Bridge interface",
|
|
5
5
|
"main": "./build/lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -46,11 +46,10 @@
|
|
|
46
46
|
],
|
|
47
47
|
"homepage": "https://github.com/appium/appium-adb",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@appium/support": "^7.
|
|
49
|
+
"@appium/support": "^7.2.2",
|
|
50
50
|
"async-lock": "^1.0.0",
|
|
51
51
|
"asyncbox": "^6.0.1",
|
|
52
52
|
"ini": "^6.0.0",
|
|
53
|
-
"lodash": "^4.0.0",
|
|
54
53
|
"lru-cache": "^11.1.0",
|
|
55
54
|
"semver": "^7.0.0",
|
|
56
55
|
"teen_process": "^4.0.4"
|
|
@@ -63,7 +62,6 @@
|
|
|
63
62
|
"@semantic-release/git": "^10.0.1",
|
|
64
63
|
"@types/async-lock": "^1.4.0",
|
|
65
64
|
"@types/ini": "^4.1.0",
|
|
66
|
-
"@types/lodash": "^4.14.195",
|
|
67
65
|
"@types/mocha": "^10.0.1",
|
|
68
66
|
"@types/node": "^25.0.0",
|
|
69
67
|
"@types/semver": "^7.5.0",
|
|
@@ -74,7 +72,7 @@
|
|
|
74
72
|
"mocha": "^11.0.1",
|
|
75
73
|
"prettier": "^3.0.0",
|
|
76
74
|
"semantic-release": "^25.0.2",
|
|
77
|
-
"sinon": "^
|
|
75
|
+
"sinon": "^22.0.0",
|
|
78
76
|
"ts-node": "^10.9.1",
|
|
79
77
|
"typescript": "^6.0.2"
|
|
80
78
|
},
|
package/build/lib/helpers.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import type { ADB } from './adb';
|
|
3
|
-
import type { ApkManifest } from './tools/types';
|
|
4
|
-
export declare const APKS_EXTENSION = ".apks";
|
|
5
|
-
export declare const APK_EXTENSION = ".apk";
|
|
6
|
-
export declare const APK_INSTALL_TIMEOUT = 60000;
|
|
7
|
-
export declare const DEFAULT_ADB_EXEC_TIMEOUT = 20000;
|
|
8
|
-
/**
|
|
9
|
-
* Calculates the absolute path to the given resource
|
|
10
|
-
*/
|
|
11
|
-
export declare const getResourcePath: ((relPath: string) => Promise<string>) & _.MemoizedFunction;
|
|
12
|
-
/**
|
|
13
|
-
* Retrieves the actual path to SDK root folder from the system environment
|
|
14
|
-
*/
|
|
15
|
-
export declare function getSdkRootFromEnv(): string | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves the actual path to SDK root folder
|
|
18
|
-
*/
|
|
19
|
-
export declare function requireSdkRoot(customRoot?: string | null): Promise<string>;
|
|
20
|
-
/**
|
|
21
|
-
* @param zipPath
|
|
22
|
-
* @param dstRoot
|
|
23
|
-
*/
|
|
24
|
-
export declare function unzipFile(zipPath: string, dstRoot?: string): Promise<void>;
|
|
25
|
-
export declare const getJavaHome: (() => Promise<string>) & _.MemoizedFunction;
|
|
26
|
-
export declare const getJavaForOs: (() => Promise<string>) & _.MemoizedFunction;
|
|
27
|
-
/**
|
|
28
|
-
* Transforms given options into the list of `adb install.install-multiple` command arguments
|
|
29
|
-
*/
|
|
30
|
-
export declare function buildInstallArgs(apiLevel: number, options?: BuildInstallArgsOptions): string[];
|
|
31
|
-
/**
|
|
32
|
-
* Extracts various package manifest details
|
|
33
|
-
* from the given application file.
|
|
34
|
-
*/
|
|
35
|
-
export declare function readPackageManifest(this: ADB, apkPath: string): Promise<ApkManifest>;
|
|
36
|
-
/**
|
|
37
|
-
* Options for building install arguments
|
|
38
|
-
*/
|
|
39
|
-
interface BuildInstallArgsOptions {
|
|
40
|
-
replace?: boolean;
|
|
41
|
-
allowTestPackages?: boolean;
|
|
42
|
-
useSdcard?: boolean;
|
|
43
|
-
grantPermissions?: boolean;
|
|
44
|
-
partialInstall?: boolean;
|
|
45
|
-
}
|
|
46
|
-
export {};
|
|
47
|
-
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../lib/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAM/C,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,aAAa,SAAS,CAAC;AACpC,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AACzC,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAK9C;;GAEG;AACH,eAAO,MAAM,eAAe,aACjB,MAAM,KACd,OAAO,CAAC,MAAM,CAAC,sBAUhB,CAAC;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAEtD;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,UAAU,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAoBtF;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,MAA8B,GACtC,OAAO,CAAC,IAAI,CAAC,CAKf;AAED,eAAO,MAAM,WAAW,SAA2C,OAAO,CAAC,MAAM,CAAC,sBAahF,CAAC;AAEH,eAAO,MAAM,YAAY,SAA4C,OAAO,CAAC,MAAM,CAAC,sBAyBlF,CAAC;AAEH;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,uBAA4B,GACpC,MAAM,EAAE,CA6BV;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAgH1F;AAmCD;;GAEG;AACH,UAAU,uBAAuB;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B"}
|