Skip to content

Commit

Permalink
Add support for selecting the browser to update (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy authored Nov 9, 2023
1 parent 7517229 commit aeabea9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions packages/replay/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
launchBrowser,
} from "./main";
import {
BrowserName,
FilterOptions,
MetadataOptions,
Options,
Expand Down Expand Up @@ -110,6 +111,7 @@ commandWithGlobalOptions("rm-all")

commandWithGlobalOptions("update-browsers")
.description("Update browsers used in automation.")
.arguments("<browsers...>")
.action(commandUpdateBrowsers);

commandWithGlobalOptions("upload-sourcemaps")
Expand Down Expand Up @@ -302,11 +304,14 @@ function commandRemoveAllRecordings(opts: Pick<CommandLineOptions, "directory" |
}
}

async function commandUpdateBrowsers(opts: Pick<CommandLineOptions, "directory" | "warn">) {
async function commandUpdateBrowsers(
browsers: string[],
opts: Pick<CommandLineOptions, "directory" | "warn">
) {
try {
debug("Options", opts);

await updateBrowsers({ ...opts, verbose: true });
await updateBrowsers({ ...opts, browsers: browsers.map(fuzzyBrowserName), verbose: true });
process.exit(0);
} catch (e) {
console.error("Failed to updated browsers");
Expand Down
10 changes: 8 additions & 2 deletions packages/replay/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ function ensurePuppeteerBrowsersInstalled(kind: BrowserName | "all" = "all", opt
return ensureBrowsersInstalled("chromium", false, opts);
}

function updateBrowsers(opts: Options) {
return ensureBrowsersInstalled("all", true, opts);
async function updateBrowsers(opts: Options & { browsers?: BrowserName[] }) {
if (opts.browsers) {
for (const browserName of opts.browsers) {
await ensureBrowsersInstalled(browserName, true, opts);
}
} else {
return ensureBrowsersInstalled("all", true, opts);
}
}

function getPlatformKey(browserName: BrowserName): PlatformKeys | undefined {
Expand Down
4 changes: 2 additions & 2 deletions packages/replay/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function exponentialBackoffRetry<T>(
throw Error("ShouldBeUnreachable");
}

function fuzzyBrowserName(browser?: string) {
function fuzzyBrowserName(browser?: string): BrowserName {
browser = browser?.toLowerCase();

switch (browser) {
Expand All @@ -104,7 +104,7 @@ function fuzzyBrowserName(browser?: string) {
return "firefox";
}

return browser;
return browser as BrowserName;
}

function assertValidBrowserName(browser?: string): asserts browser is BrowserName {
Expand Down

0 comments on commit aeabea9

Please sign in to comment.