Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix buggy behaviour in launchDebugger on macOS #770

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 12 additions & 36 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 @@ -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;