Replace promisify(child_process.*)
Summary: Promisify leads to weird types and sometimes unexpected runtime behaviour. Replacing it with the dep we use everywhere. It's just really annoying that `stdout` is here explicitly `| null` which isn't the case in the default types. Reviewed By: timur-valiev Differential Revision: D31278303 fbshipit-source-id: eadbc49b287704e71a5ecba0d9a311eac91dc6f8
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7706b26d7a
commit
fe3eda024b
@@ -9,10 +9,9 @@
|
|||||||
|
|
||||||
import {ChildProcess} from 'child_process';
|
import {ChildProcess} from 'child_process';
|
||||||
import type {DeviceType} from 'flipper-plugin';
|
import type {DeviceType} from 'flipper-plugin';
|
||||||
import {promisify} from 'util';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import child_process from 'child_process';
|
import childProcess from 'child_process';
|
||||||
const execFile = child_process.execFile;
|
import {exec, execFile} from 'promisify-child-process';
|
||||||
import iosUtil from './iOSContainerUtility';
|
import iosUtil from './iOSContainerUtility';
|
||||||
import IOSDevice from './IOSDevice';
|
import IOSDevice from './IOSDevice';
|
||||||
import {getStaticPath} from '../../../utils/pathUtils';
|
import {getStaticPath} from '../../../utils/pathUtils';
|
||||||
@@ -40,8 +39,6 @@ export type IOSDeviceParams = {
|
|||||||
state?: string;
|
state?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const exec = promisify(child_process.exec);
|
|
||||||
|
|
||||||
function isAvailable(simulator: iOSSimulatorDevice): boolean {
|
function isAvailable(simulator: iOSSimulatorDevice): boolean {
|
||||||
// For some users "availability" is set, for others it's "isAvailable"
|
// For some users "availability" is set, for others it's "isAvailable"
|
||||||
// It's not clear which key is set, so we are checking both.
|
// It's not clear which key is set, so we are checking both.
|
||||||
@@ -77,7 +74,7 @@ export class IOSDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private forwardPort(port: number, multiplexChannelPort: number) {
|
private forwardPort(port: number, multiplexChannelPort: number) {
|
||||||
const childProcess = execFile(
|
const child = childProcess.execFile(
|
||||||
this.portforwardingClient,
|
this.portforwardingClient,
|
||||||
[`-portForward=${port}`, `-multiplexChannelPort=${multiplexChannelPort}`],
|
[`-portForward=${port}`, `-multiplexChannelPort=${multiplexChannelPort}`],
|
||||||
(err, stdout, stderr) => {
|
(err, stdout, stderr) => {
|
||||||
@@ -91,13 +88,13 @@ export class IOSDeviceManager {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
console.log('Port forwarding app started', childProcess);
|
console.log('Port forwarding app started', childProcess);
|
||||||
childProcess.addListener('error', (err) =>
|
child.addListener('error', (err) =>
|
||||||
console.warn('Port forwarding app error', err),
|
console.warn('Port forwarding app error', err),
|
||||||
);
|
);
|
||||||
childProcess.addListener('exit', (code) =>
|
child.addListener('exit', (code) =>
|
||||||
console.log(`Port forwarding app exited with code ${code}`),
|
console.log(`Port forwarding app exited with code ${code}`),
|
||||||
);
|
);
|
||||||
return childProcess;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
private startDevicePortForwarders(): void {
|
private startDevicePortForwarders(): void {
|
||||||
@@ -212,14 +209,14 @@ export class IOSDeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSimulators(bootedOnly: boolean): Promise<Array<IOSDeviceParams>> {
|
getSimulators(bootedOnly: boolean): Promise<Array<IOSDeviceParams>> {
|
||||||
return promisify(execFile)(
|
return execFile('xcrun', [
|
||||||
'xcrun',
|
'simctl',
|
||||||
['simctl', ...getDeviceSetPath(), 'list', 'devices', '--json'],
|
...getDeviceSetPath(),
|
||||||
{
|
'list',
|
||||||
encoding: 'utf8',
|
'devices',
|
||||||
},
|
'--json',
|
||||||
)
|
])
|
||||||
.then(({stdout}) => JSON.parse(stdout).devices)
|
.then(({stdout}) => JSON.parse(stdout!.toString()).devices)
|
||||||
.then((simulatorDevices: Array<iOSSimulatorDevice>) => {
|
.then((simulatorDevices: Array<iOSSimulatorDevice>) => {
|
||||||
const simulators = Object.values(simulatorDevices).flat();
|
const simulators = Object.values(simulatorDevices).flat();
|
||||||
return simulators
|
return simulators
|
||||||
@@ -267,9 +264,9 @@ export class IOSDeviceManager {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
let {stdout: xcodeCLIVersion} = await exec('xcode-select -p');
|
||||||
xcodeCLIVersion = xcodeCLIVersion.trim();
|
xcodeCLIVersion = xcodeCLIVersion!.toString().trim();
|
||||||
const {stdout} = await exec('ps aux | grep CoreSimulator');
|
const {stdout} = await exec('ps aux | grep CoreSimulator');
|
||||||
for (const line of stdout.split('\n')) {
|
for (const line of stdout!.toString().split('\n')) {
|
||||||
const match = parseXcodeFromCoreSimPath(line);
|
const match = parseXcodeFromCoreSimPath(line);
|
||||||
const runningVersion =
|
const runningVersion =
|
||||||
match && match.length > 0 ? match[0].trim() : null;
|
match && match.length > 0 ? match[0].trim() : null;
|
||||||
@@ -297,12 +294,8 @@ function getDeviceSetPath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function launchSimulator(udid: string): Promise<any> {
|
export async function launchSimulator(udid: string): Promise<any> {
|
||||||
await promisify(execFile)(
|
await execFile('xcrun', ['simctl', ...getDeviceSetPath(), 'boot', udid]);
|
||||||
'xcrun',
|
await execFile('open', ['-a', 'simulator']);
|
||||||
['simctl', ...getDeviceSetPath(), 'boot', udid],
|
|
||||||
{encoding: 'utf8'},
|
|
||||||
);
|
|
||||||
await promisify(execFile)('open', ['-a', 'simulator']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveDevices(
|
function getActiveDevices(
|
||||||
|
|||||||
Reference in New Issue
Block a user