From 5ac8f7a16f1047bc6f2cae8da6d833d90f7e54ca Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Fri, 29 Jan 2021 05:08:30 -0800 Subject: [PATCH] Small refactors Summary: Going to make more changes here soon and wanted to apply some small changes first. Reviewed By: jknoxville Differential Revision: D26078645 fbshipit-source-id: 3a2bcd593b893160b5a332c858a514ebe89d3f4d --- desktop/app/src/utils/iOSContainerUtility.tsx | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/desktop/app/src/utils/iOSContainerUtility.tsx b/desktop/app/src/utils/iOSContainerUtility.tsx index ede7d6720..c08b56906 100644 --- a/desktop/app/src/utils/iOSContainerUtility.tsx +++ b/desktop/app/src/utils/iOSContainerUtility.tsx @@ -7,10 +7,8 @@ * @format */ -import child_process from 'child_process'; -import {promisify} from 'util'; import {Mutex} from 'async-mutex'; -const unsafeExec = promisify(child_process.exec); +import {exec as unsafeExec, Output} from 'promisify-child-process'; import {killOrphanedInstrumentsProcesses} from './processCleanup'; import {reportPlatformFailures} from './metrics'; import {promises, constants} from 'fs'; @@ -48,10 +46,12 @@ function isAvailable(idbPath: string): Promise { .catch((_) => false); } -function safeExec(command: string): Promise<{stdout: string; stderr: string}> { - return mutex.acquire().then((release) => { - return unsafeExec(command).finally(release); - }); +function safeExec( + command: string, +): Promise<{stdout: string; stderr: string} | Output> { + return mutex + .acquire() + .then((release) => unsafeExec(command).finally(release)); } async function targets(idbPath: string): Promise> { @@ -65,7 +65,10 @@ async function targets(idbPath: string): Promise> { // when installed, use it. if (await memoize(isAvailable)(idbPath)) { return safeExec(`${idbPath} list-targets --json`).then(({stdout}) => - stdout + // It is safe to assume this to be non-null as it only turns null + // if the output redirection is misconfigured: + // https://stackoverflow.com/questions/27786228/node-child-process-spawn-stdout-returning-as-null + stdout! .toString() .trim() .split('\n') @@ -80,7 +83,7 @@ async function targets(idbPath: string): Promise> { } else { await killOrphanedInstrumentsProcesses(); return safeExec('instruments -s devices').then(({stdout}) => - stdout + stdout! .toString() .split('\n') .map((line) => line.trim()) @@ -173,8 +176,8 @@ function wrapWithErrorMessage(p: Promise): Promise { } export default { - isAvailable: isAvailable, - targets: targets, - push: push, - pull: pull, + isAvailable, + targets, + push, + pull, };