Skip to content

Commit

Permalink
fix: buggy behaviour when launching debugger on macOS (#771)
Browse files Browse the repository at this point in the history
* Fix launchDebugger.js behaviour on macOS

* log error to debug
  • Loading branch information
StasD authored and thymikee committed Oct 5, 2019
1 parent b9010e6 commit 743c466
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions packages/cli/src/commands/server/launchDebugger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -69,24 +47,21 @@ function getChromeAppName(): string {
}

function launchChrome(url: string) {
open(url, {app: [getChromeAppName()]}, err => {
if (err) {
logger.error('Google Chrome exited with error:', err);
}
});
return open(url, {app: [getChromeAppName()], wait: true});
}

function launchDebugger(url: string) {
if (!commandExists(getChromeAppName())) {
async function launchDebugger(url: string) {
try {
await launchChrome(url);
} catch (error) {
logger.debug(error);
logger.info(
`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;

0 comments on commit 743c466

Please sign in to comment.