From 22a86747d4f4655bd7037ba9f7dcdcef45792c94 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 12 Nov 2019 06:53:57 -0800 Subject: [PATCH] Wrap command execution in util Summary: Take the low level execution details out of the healthchecks. The xcode-select change is sound because `xcode-select -p` returns status code > 0 when not set, so exec will throw, so no need to inspect stdout. Reviewed By: passy Differential Revision: D18449564 fbshipit-source-id: b2e2797a51aca45cfd78e707e99341798401897c --- doctor/src/index.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/doctor/src/index.ts b/doctor/src/index.ts index ea06347fa..51eacd43f 100644 --- a/doctor/src/index.ts +++ b/doctor/src/index.ts @@ -44,9 +44,7 @@ export function getHealthchecks(): Healthchecks { label: 'OpenSSL Installed', isRequired: true, run: async (_: EnvironmentInfo) => { - const isAvailable = await promisify(exec)('openssl version') - .then(() => true) - .catch(() => false); + const isAvailable = await commandSucceeds('openssl version'); return { hasProblem: !isAvailable, }; @@ -91,20 +89,16 @@ export function getHealthchecks(): Healthchecks { label: 'xcode-select set', isRequired: true, run: async (_: EnvironmentInfo) => ({ - hasProblem: - (await promisify(exec)('xcode-select -p')).stdout.trim() - .length < 1, + hasProblem: !(await commandSucceeds('xcode-select -p')), }), }, { label: 'Instruments exists', isRequired: true, run: async (_: EnvironmentInfo) => { - const hasInstruments = await promisify(exec)( + const hasInstruments = await commandSucceeds( 'which instruments', - ) - .then(_ => true) - .catch(_ => false); + ); return { hasProblem: !hasInstruments, @@ -146,3 +140,9 @@ export async function runHealthchecks() { ); return results; } + +async function commandSucceeds(command: string): Promise { + return await promisify(exec)(command) + .then(() => true) + .catch(() => false); +}