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,
|
buildId: args.browser.buildId,
|
||||||
platform: args.platform,
|
platform: args.platform,
|
||||||
cacheDir: args.path ?? this.#cachePath,
|
cacheDir: args.path ?? this.#cachePath,
|
||||||
downloadProgressCallback: this.#makeProgressCallback(
|
downloadProgressCallback: makeProgressCallback(
|
||||||
args.browser.name,
|
args.browser.name,
|
||||||
args.browser.buildId
|
args.browser.buildId
|
||||||
),
|
),
|
||||||
@ -265,32 +265,35 @@ export class CLI {
|
|||||||
#parseBuildId(version: string): string {
|
#parseBuildId(version: string): string {
|
||||||
return version.split('@').pop() ?? 'latest';
|
return version.split('@').pop() ?? 'latest';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#toMegabytes(bytes: number) {
|
|
||||||
const mb = bytes / 1000 / 1000;
|
export function makeProgressCallback(
|
||||||
return `${Math.round(mb * 10) / 10} MB`;
|
browser: Browser,
|
||||||
}
|
buildId: string
|
||||||
|
): (downloadedBytes: number, totalBytes: number) => void {
|
||||||
#makeProgressCallback(browser: Browser, buildId: string) {
|
let progressBar: ProgressBar;
|
||||||
let progressBar: ProgressBar;
|
let lastDownloadedBytes = 0;
|
||||||
let lastDownloadedBytes = 0;
|
return (downloadedBytes: number, totalBytes: number) => {
|
||||||
return (downloadedBytes: number, totalBytes: number) => {
|
if (!progressBar) {
|
||||||
if (!progressBar) {
|
progressBar = new ProgressBar(
|
||||||
progressBar = new ProgressBar(
|
`Downloading ${browser} r${buildId} - ${toMegabytes(
|
||||||
`Downloading ${browser} r${buildId} - ${this.#toMegabytes(
|
totalBytes
|
||||||
totalBytes
|
)} [:bar] :percent :etas `,
|
||||||
)} [:bar] :percent :etas `,
|
{
|
||||||
{
|
complete: '=',
|
||||||
complete: '=',
|
incomplete: ' ',
|
||||||
incomplete: ' ',
|
width: 20,
|
||||||
width: 20,
|
total: totalBytes,
|
||||||
total: totalBytes,
|
}
|
||||||
}
|
);
|
||||||
);
|
}
|
||||||
}
|
const delta = downloadedBytes - lastDownloadedBytes;
|
||||||
const delta = downloadedBytes - lastDownloadedBytes;
|
lastDownloadedBytes = downloadedBytes;
|
||||||
lastDownloadedBytes = downloadedBytes;
|
progressBar.tick(delta);
|
||||||
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 {fetch, canFetch} from './fetch.js';
|
||||||
export {detectBrowserPlatform} from './detectPlatform.js';
|
export {detectBrowserPlatform} from './detectPlatform.js';
|
||||||
export {
|
export {
|
||||||
|
resolveBuildId,
|
||||||
Browser,
|
Browser,
|
||||||
BrowserPlatform,
|
BrowserPlatform,
|
||||||
ChromeReleaseChannel,
|
ChromeReleaseChannel,
|
||||||
} from './browser-data/browser-data.js';
|
} from './browser-data/browser-data.js';
|
||||||
export {CLI} from './CLI.js';
|
export {CLI, makeProgressCallback} from './CLI.js';
|
||||||
export {Cache} from './Cache.js';
|
export {Cache} from './Cache.js';
|
||||||
|
Loading…
Reference in New Issue
Block a user