From 46e0eaa1e7cdd0a247cb086db3e86adeff4bcf73 Mon Sep 17 00:00:00 2001 From: Ryan Duffy Date: Wed, 8 Nov 2023 10:31:14 -0800 Subject: [PATCH] Add support for selecting the browser to update --- packages/replay/src/bin.ts | 9 +++++++-- packages/replay/src/install.ts | 10 ++++++++-- packages/replay/src/utils.ts | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/replay/src/bin.ts b/packages/replay/src/bin.ts index 39dcfcae..f7a4b56b 100644 --- a/packages/replay/src/bin.ts +++ b/packages/replay/src/bin.ts @@ -16,6 +16,7 @@ import { launchBrowser, } from "./main"; import { + BrowserName, FilterOptions, MetadataOptions, Options, @@ -110,6 +111,7 @@ commandWithGlobalOptions("rm-all") commandWithGlobalOptions("update-browsers") .description("Update browsers used in automation.") + .arguments("") .action(commandUpdateBrowsers); commandWithGlobalOptions("upload-sourcemaps") @@ -302,11 +304,14 @@ function commandRemoveAllRecordings(opts: Pick) { +async function commandUpdateBrowsers( + browsers: string[], + opts: Pick +) { 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"); diff --git a/packages/replay/src/install.ts b/packages/replay/src/install.ts index 46ccfe6a..6d35f732 100644 --- a/packages/replay/src/install.ts +++ b/packages/replay/src/install.ts @@ -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 { diff --git a/packages/replay/src/utils.ts b/packages/replay/src/utils.ts index 128dcd9e..c69288db 100644 --- a/packages/replay/src/utils.ts +++ b/packages/replay/src/utils.ts @@ -94,7 +94,7 @@ export async function exponentialBackoffRetry( throw Error("ShouldBeUnreachable"); } -function fuzzyBrowserName(browser?: string) { +function fuzzyBrowserName(browser?: string): BrowserName { browser = browser?.toLowerCase(); switch (browser) { @@ -104,7 +104,7 @@ function fuzzyBrowserName(browser?: string) { return "firefox"; } - return browser; + return browser as BrowserName; } function assertValidBrowserName(browser?: string): asserts browser is BrowserName {