11import * as path from 'path' ;
2- import { promisify } from 'util' ;
32
43import { delay , isErrorLike } from '@httptoolkit/util' ;
5- import getBrowserLauncherCb from '@httptoolkit/browser-launcher' ;
64import {
7- LaunchOptions ,
8- Launch ,
9- BrowserInstance ,
5+ getLauncher ,
6+ updateBrowsers ,
107 Browser ,
11- update as updateBrowserCacheCb
8+ BrowserInstance ,
9+ LaunchOptions ,
10+ LaunchFunction
1211} from '@httptoolkit/browser-launcher' ;
1312
1413import { logError } from './error-tracking' ;
1514import { readFile , deleteFile } from './util/fs' ;
1615
17- const getBrowserLauncher = promisify ( getBrowserLauncherCb ) ;
18- const updateBrowserCache : ( configPath : string ) => Promise < unknown > = promisify ( updateBrowserCacheCb ) ;
19-
2016const browserConfigPath = ( configPath : string ) => path . join ( configPath , 'browsers.json' ) ;
2117
2218export { BrowserInstance , Browser } ;
@@ -44,23 +40,23 @@ export async function checkBrowserConfig(configPath: string) {
4440 }
4541}
4642
47- let launcher : Promise < Launch > | undefined ;
43+ let launcher : Promise < LaunchFunction > | undefined ;
4844
49- function getLauncher ( configPath : string ) {
45+ function getBrowserLauncher ( configPath : string ) {
5046 if ( ! launcher ) {
5147 const browserConfig = browserConfigPath ( configPath ) ;
52- launcher = getBrowserLauncher ( browserConfig ) ;
48+ launcher = getLauncher ( browserConfig ) ;
5349
5450 launcher . then ( async ( ) => {
5551 // Async after first creating the launcher, we trigger a background cache update.
5652 // This can be *synchronously* expensive (spawns 10s of procs, 10+ms sync per
5753 // spawn on unix-based OSs) so defer briefly.
5854 await delay ( 2000 ) ;
5955 try {
60- await updateBrowserCache ( browserConfig ) ;
56+ await updateBrowsers ( browserConfig ) ;
6157 console . log ( 'Browser cache updated' ) ;
6258 // Need to reload the launcher after updating the cache:
63- launcher = getBrowserLauncher ( browserConfig ) ;
59+ launcher = getLauncher ( browserConfig ) ;
6460 } catch ( e ) {
6561 logError ( e )
6662 }
@@ -77,7 +73,7 @@ function getLauncher(configPath: string) {
7773}
7874
7975export const getAvailableBrowsers = async ( configPath : string ) => {
80- return ( await getLauncher ( configPath ) ) . browsers ;
76+ return ( await getBrowserLauncher ( configPath ) ) . browsers ;
8177} ;
8278
8379export const getBrowserDetails = async ( configPath : string , variant : string ) : Promise < Browser | undefined > => {
@@ -90,8 +86,8 @@ export const getBrowserDetails = async (configPath: string, variant: string): Pr
9086export { LaunchOptions } ;
9187
9288export const launchBrowser = async ( url : string , options : LaunchOptions , configPath : string ) => {
93- const launcher = await getLauncher ( configPath ) ;
94- const browserInstance = await promisify ( launcher ) ( url , options ) ;
89+ const launcher = await getBrowserLauncher ( configPath ) ;
90+ const browserInstance = await launcher ( url , options ) ;
9591
9692 browserInstance . process . on ( 'error' , ( e ) => {
9793 // If nothing else is listening for this error, this acts as default
0 commit comments