From a29f2c3b10abb69f654f1412506fc1f65bac05a3 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 9 Sep 2019 08:37:52 -0700 Subject: [PATCH] Make iOSContainerUtility strict Summary: _typescript_ Reviewed By: jknoxville Differential Revision: D17259181 fbshipit-source-id: 5167be6cbf23b42d0f79246dae22f4e4a9417339 --- src/fb-stubs/iOSContainerUtility.tsx | 54 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/fb-stubs/iOSContainerUtility.tsx b/src/fb-stubs/iOSContainerUtility.tsx index 1078e33f5..786a9eead 100644 --- a/src/fb-stubs/iOSContainerUtility.tsx +++ b/src/fb-stubs/iOSContainerUtility.tsx @@ -4,9 +4,9 @@ * LICENSE file in the root directory of this source tree. * @format */ -import {promisify} from 'util'; import {DeviceType} from '../devices/BaseDevice'; -const exec = promisify(require('child_process').exec); +import promisify_child_process from 'promisify-child-process'; +import {notNull} from '../utils/typeUtils'; const errorMessage = 'Physical iOS devices not yet supported'; @@ -20,38 +20,40 @@ function isAvailable(): boolean { return false; } -function targets(): Promise> { - return exec('instruments -s devices').then(({stdout}) => - stdout - .toString() - .split('\n') - .map(line => line.trim()) - .map(line => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) - .filter(Boolean) - .filter( - ([match, name, udid, isSim]) => - !isSim && (name.includes('iPhone') || name.includes('iPad')), - ) - .map(([match, name, udid]) => { - return {udid: udid, type: 'physical', name: name}; - }), - ); +async function targets(): Promise> { + const {stdout} = await promisify_child_process.exec('instruments -s devices'); + if (!stdout) { + return []; + } + return stdout + .toString() + .split('\n') + .map(line => line.trim()) + .map(line => /(.+) \([^(]+\) \[(.*)\]( \(Simulator\))?/.exec(line)) + .filter(notNull) + .filter( + ([_match, name, _udid, isSim]) => + !isSim && (name.includes('iPhone') || name.includes('iPad')), + ) + .map(([_match, name, udid]) => { + return {udid: udid, type: 'physical', name: name}; + }); } function push( - udid: string, - src: string, - bundleId: string, - dst: string, + _udid: string, + _src: string, + _bundleId: string, + _dst: string, ): Promise { return Promise.reject(errorMessage); } function pull( - udid: string, - src: string, - bundleId: string, - dst: string, + _udid: string, + _src: string, + _bundleId: string, + _dst: string, ): Promise { return Promise.reject(errorMessage); }