diff --git a/packages/browsers/src/CLI.ts b/packages/browsers/src/CLI.ts index d6431c7f..1d694073 100644 --- a/packages/browsers/src/CLI.ts +++ b/packages/browsers/src/CLI.ts @@ -155,7 +155,7 @@ export class CLI { buildId: args.browser.buildId, platform: args.platform, cacheDir: args.path ?? this.#cachePath, - downloadProgressCallback: this.#makeProgressCallback( + downloadProgressCallback: makeProgressCallback( args.browser.name, args.browser.buildId ), @@ -265,32 +265,35 @@ export class CLI { #parseBuildId(version: string): string { return version.split('@').pop() ?? 'latest'; } - - #toMegabytes(bytes: number) { - const mb = bytes / 1000 / 1000; - return `${Math.round(mb * 10) / 10} MB`; - } - - #makeProgressCallback(browser: Browser, buildId: string) { - let progressBar: ProgressBar; - let lastDownloadedBytes = 0; - return (downloadedBytes: number, totalBytes: number) => { - if (!progressBar) { - progressBar = new ProgressBar( - `Downloading ${browser} r${buildId} - ${this.#toMegabytes( - totalBytes - )} [:bar] :percent :etas `, - { - complete: '=', - incomplete: ' ', - width: 20, - total: totalBytes, - } - ); - } - const delta = downloadedBytes - lastDownloadedBytes; - lastDownloadedBytes = downloadedBytes; - progressBar.tick(delta); - }; - } +} + +export function makeProgressCallback( + browser: Browser, + buildId: string +): (downloadedBytes: number, totalBytes: number) => void { + let progressBar: ProgressBar; + let lastDownloadedBytes = 0; + return (downloadedBytes: number, totalBytes: number) => { + if (!progressBar) { + progressBar = new ProgressBar( + `Downloading ${browser} r${buildId} - ${toMegabytes( + totalBytes + )} [:bar] :percent :etas `, + { + complete: '=', + incomplete: ' ', + width: 20, + total: totalBytes, + } + ); + } + const delta = downloadedBytes - lastDownloadedBytes; + lastDownloadedBytes = downloadedBytes; + progressBar.tick(delta); + }; +} + +function toMegabytes(bytes: number) { + const mb = bytes / 1000 / 1000; + return `${Math.round(mb * 10) / 10} MB`; } diff --git a/packages/browsers/src/main.ts b/packages/browsers/src/main.ts index fa24f7b9..157e7c11 100644 --- a/packages/browsers/src/main.ts +++ b/packages/browsers/src/main.ts @@ -24,9 +24,10 @@ export { export {fetch, canFetch} from './fetch.js'; export {detectBrowserPlatform} from './detectPlatform.js'; export { + resolveBuildId, Browser, BrowserPlatform, ChromeReleaseChannel, } from './browser-data/browser-data.js'; -export {CLI} from './CLI.js'; +export {CLI, makeProgressCallback} from './CLI.js'; export {Cache} from './Cache.js';