chore: expose additional methods for Puppeteer (#9900)
This commit is contained in:
parent
69b77ded4d
commit
00abcdca7f
@ -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,19 +265,18 @@ 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) {
|
||||
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} - ${this.#toMegabytes(
|
||||
`Downloading ${browser} r${buildId} - ${toMegabytes(
|
||||
totalBytes
|
||||
)} [:bar] :percent :etas `,
|
||||
{
|
||||
@ -293,4 +292,8 @@ export class CLI {
|
||||
progressBar.tick(delta);
|
||||
};
|
||||
}
|
||||
|
||||
function toMegabytes(bytes: number) {
|
||||
const mb = bytes / 1000 / 1000;
|
||||
return `${Math.round(mb * 10) / 10} MB`;
|
||||
}
|
||||
|
@ -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';
|
||||
|
Loading…
Reference in New Issue
Block a user