Skip to content

Commit 91b15b9

Browse files
committed
WIP: bump browser launcher
1 parent 4eb87e7 commit 91b15b9

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/browsers.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import * as path from 'path';
2-
import { promisify } from 'util';
32

43
import { delay, isErrorLike } from '@httptoolkit/util';
5-
import getBrowserLauncherCb from '@httptoolkit/browser-launcher';
64
import {
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

1413
import { logError } from './error-tracking';
1514
import { readFile, deleteFile } from './util/fs';
1615

17-
const getBrowserLauncher = promisify(getBrowserLauncherCb);
18-
const updateBrowserCache: (configPath: string) => Promise<unknown> = promisify(updateBrowserCacheCb);
19-
2016
const browserConfigPath = (configPath: string) => path.join(configPath, 'browsers.json');
2117

2218
export { 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

7975
export const getAvailableBrowsers = async (configPath: string) => {
80-
return (await getLauncher(configPath)).browsers;
76+
return (await getBrowserLauncher(configPath)).browsers;
8177
};
8278

8379
export const getBrowserDetails = async (configPath: string, variant: string): Promise<Browser | undefined> => {
@@ -90,8 +86,8 @@ export const getBrowserDetails = async (configPath: string, variant: string): Pr
9086
export { LaunchOptions };
9187

9288
export 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

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
{
4848
// Some browser launchers (Opera) use resource files from within the browser-launcher
4949
// module. We need to reroute that to point to the unbundled files:
50-
test: /node_modules\/@httptoolkit\/browser-launcher\/lib\/run.js$/,
50+
test: /node_modules\/@httptoolkit\/browser-launcher\/dist\/run.js$/,
5151
loader: 'string-replace-loader',
5252
options: {
5353
search: '../res/',
@@ -93,7 +93,7 @@ module.exports = {
9393
resourceRegExp: /^\.\/protocol.json$/,
9494
contextRegExp: /chrome-remote-interface/
9595
}),
96-
// Copy Mockttp's schema (read with readFile) into the output directory
96+
// Copy browser launcher's static resources into the output directory
9797
new CopyWebpackPlugin({
9898
patterns: [{
9999
from: path.join('node_modules', '@httptoolkit', 'browser-launcher', 'res'),

0 commit comments

Comments
 (0)