Skip to content
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;