Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/devicectl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {exec, SubProcess} from 'teen_process';
import _ from 'lodash';
import logger from '@appium/logger';
import type {DevicectlOptions, ExecuteOptions, ExecuteResult} from './types';
import * as processMixins from './mixins/process';
Expand All @@ -21,6 +20,19 @@ type SudoUser = {uid: number; gid: number};
export class Devicectl {
/** The unique device identifier */
public readonly udid: string;

sendMemoryWarning = processMixins.sendMemoryWarning;
sendSignalToProcess = processMixins.sendSignalToProcess;
launchApp = processMixins.launchApp;

listProcesses = infoMixins.listProcesses;
listApps = infoMixins.listApps;

listFiles = copyMixins.listFiles;
pullFile = copyMixins.pullFile;

listDevices = listMixins.listDevices;

private readonly preferNonRootWhenSudo: boolean;
private readonly sudoUser: SudoUser | null;

Expand Down Expand Up @@ -58,7 +70,7 @@ export class Devicectl {

const finalArgs = ['devicectl', ...subcommand, ...(noDevice ? [] : ['--device', this.udid])];

if (subcommandOptions && !_.isEmpty(subcommandOptions)) {
if (subcommandOptions && subcommandOptions.length > 0) {
finalArgs.push(
...(Array.isArray(subcommandOptions) ? subcommandOptions : [subcommandOptions]),
);
Expand All @@ -81,7 +93,7 @@ export class Devicectl {

const execOpts = {
...userOpts,
...(_.isNumber(timeout) ? {timeout} : {}),
...(typeof timeout === 'number' ? {timeout} : {}),
};
const result = await exec(XCRUN, finalArgs, execOpts);

Expand All @@ -95,18 +107,6 @@ export class Devicectl {
}
}

sendMemoryWarning = processMixins.sendMemoryWarning;
sendSignalToProcess = processMixins.sendSignalToProcess;
launchApp = processMixins.launchApp;

listProcesses = infoMixins.listProcesses;
listApps = infoMixins.listApps;

listFiles = copyMixins.listFiles;
pullFile = copyMixins.pullFile;

listDevices = listMixins.listDevices;

private resolveSudoUser(): SudoUser | null {
if (!process.geteuid || process.geteuid() !== 0) {
return null;
Expand Down
7 changes: 4 additions & 3 deletions lib/mixins/process.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from 'lodash';
import type {LaunchAppOptions} from '../types';
import type {Devicectl} from '../devicectl';

Expand Down Expand Up @@ -42,10 +41,12 @@ export async function launchApp(
subcommandOptions.push('--terminate-existing');
}

if (!_.isEmpty(env)) {
if (env && Object.keys(env).length > 0) {
subcommandOptions.push(
'--environment-variables',
JSON.stringify(_.mapValues(env, (v) => _.toString(v))),
JSON.stringify(
Object.fromEntries(Object.entries(env).map(([key, value]) => [key, String(value)])),
),
);
}

Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
],
"dependencies": {
"@appium/logger": "^2.0.0-rc.1",
"lodash": "^4.2.1",
"teen_process": "^4.1.0"
},
"scripts": {
Expand Down Expand Up @@ -63,7 +62,6 @@
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/chai": "^5.2.3",
"@types/lodash": "^4.14.196",
"@types/mocha": "^10.0.1",
"@types/node": "^25.0.3",
"chai": "^6.0.0",
Expand Down
Loading