( protocol: string, hostname: string, port: number, browser: string, openUrl?: string, )
| 298 | } |
| 299 | } |
| 300 | export async function openInBrowser( |
| 301 | protocol: string, |
| 302 | hostname: string, |
| 303 | port: number, |
| 304 | browser: string, |
| 305 | openUrl?: string, |
| 306 | ): Promise<void> { |
| 307 | const url = new URL(openUrl || '', `${protocol}//${hostname}:${port}`).toString(); |
| 308 | if (/chrome/i.test(browser)) { |
| 309 | browser = open.apps.chrome as string; |
| 310 | } |
| 311 | if (/brave/i.test(browser)) { |
| 312 | browser = appNames[process.platform]['brave']; |
| 313 | } |
| 314 | const isMacChrome = |
| 315 | process.platform === 'darwin' && |
| 316 | (/chrome/i.test(browser) || |
| 317 | (/default/i.test(browser) && /chrome/i.test(await getDefaultBrowserId()))); |
| 318 | if (!isMacChrome) { |
| 319 | await (browser === 'default' ? open(url) : open(url, {app: {name: browser}})); |
| 320 | return; |
| 321 | } |
| 322 | try { |
| 323 | // If we're on macOS, and we haven't requested a specific browser, |
| 324 | // we can try opening Chrome with AppleScript. This lets us reuse an |
| 325 | // existing tab when possible instead of creating a new one. |
| 326 | await openInExistingChromeBrowser(url); |
| 327 | } catch (err) { |
| 328 | // if no open Chrome process, just go ahead and open default browser. |
| 329 | await open(url); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | export async function checkLockfileHash(dir: string) { |
| 334 | const lockfileLoc = await findUp(['package-lock.json', 'yarn.lock']); |
no test coverage detected