diff --git a/packages/cli/src/commands/server/launchDebugger.js b/packages/cli/src/commands/server/launchDebugger.js index 1865e4462..ae0331c1c 100644 --- a/packages/cli/src/commands/server/launchDebugger.js +++ b/packages/cli/src/commands/server/launchDebugger.js @@ -26,28 +26,6 @@ function commandExistsUnixSync(commandName) { } } -function commandExistsWindowsSync(commandName) { - try { - const stdout = execSync('where ' + commandName, {stdio: []}); - return !!stdout; - } catch (error) { - return false; - } -} - -function commandExists(commandName) { - switch (process.platform) { - case 'win32': - return commandExistsWindowsSync(commandName); - case 'linux': - case 'darwin': - return commandExistsUnixSync(commandName); - default: - // assume it doesn't exist, just to be safe. - return false; - } -} - function getChromeAppName(): string { switch (process.platform) { case 'darwin': @@ -68,25 +46,23 @@ function getChromeAppName(): string { } } -function launchChrome(url: string) { - open(url, {app: [getChromeAppName()]}, err => { - if (err) { - logger.error('Google Chrome exited with error:', err); - } - }); +async function launchChrome(url: string) { + const {err} = await open(url, {app: getChromeAppName()}); + if (err) { + logger.error('Google Chrome exited with error:', err); + } } -function launchDebugger(url: string) { - if (!commandExists(getChromeAppName())) { +async function launchDebugger(url: string) { + try { + await launchChrome(url); + } catch (error) { + launchDefaultBrowser(url); logger.info( - `For a better debugging experience please install Google Chrome from: ${chalk.underline.dim( - 'https://www.google.com/chrome/', - )}`, + `For a better debugging experience please install Google Chrome from: + ${chalk.underline.dim('https://www.google.com/chrome/')}`, ); - launchDefaultBrowser(url); - return; } - launchChrome(url); } export default launchDebugger;