mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: print where the browsers are downloaded from (#18360)
Fixes https://github.com/microsoft/playwright/issues/16926
This commit is contained in:
parent
12fdd3336e
commit
041a98928b
@ -24,6 +24,7 @@ import { existsAsync } from '../../utils/fileUtils';
|
||||
import { debugLogger } from '../../common/debugLogger';
|
||||
import { extract } from '../../zipBundle';
|
||||
import { ManualPromise } from '../../utils/manualPromise';
|
||||
import { colors } from '../../utilsBundle';
|
||||
|
||||
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise<boolean> {
|
||||
if (await existsAsync(browserDirectory)) {
|
||||
@ -38,7 +39,8 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec
|
||||
for (let attempt = 1; attempt <= retryCount; ++attempt) {
|
||||
debugLogger.log('install', `downloading ${title} - attempt #${attempt}`);
|
||||
const url = downloadURLs[(attempt - 1) % downloadURLs.length];
|
||||
const { error } = await downloadFileOutOfProcess(url, zipPath, title, getUserAgent(), downloadConnectionTimeout);
|
||||
logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`));
|
||||
const { error } = await downloadFileOutOfProcess(url, zipPath, getUserAgent(), downloadConnectionTimeout);
|
||||
if (!error) {
|
||||
debugLogger.log('install', `SUCCESS downloading ${title}`);
|
||||
break;
|
||||
@ -71,8 +73,8 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec
|
||||
* Thats why we execute it in a separate process and check manually if the destination file exists.
|
||||
* https://github.com/microsoft/playwright/issues/17394
|
||||
*/
|
||||
function downloadFileOutOfProcess(url: string, destinationPath: string, progressBarName: string, userAgent: string, downloadConnectionTimeout: number): Promise<{ error: Error | null }> {
|
||||
const cp = childProcess.fork(path.join(__dirname, 'oopDownloadMain.js'), [url, destinationPath, progressBarName, userAgent, String(downloadConnectionTimeout)]);
|
||||
function downloadFileOutOfProcess(url: string, destinationPath: string, userAgent: string, downloadConnectionTimeout: number): Promise<{ error: Error | null }> {
|
||||
const cp = childProcess.fork(path.join(__dirname, 'oopDownloadMain.js'), [url, destinationPath, userAgent, String(downloadConnectionTimeout)]);
|
||||
const promise = new ManualPromise<{ error: Error | null }>();
|
||||
cp.on('message', (message: any) => {
|
||||
if (message?.method === 'log')
|
||||
|
||||
@ -79,22 +79,22 @@ function downloadFile(url: string, destinationPath: string, options: DownloadFil
|
||||
}
|
||||
}
|
||||
|
||||
function getDownloadProgress(progressBarName: string): OnProgressCallback {
|
||||
function getDownloadProgress(): OnProgressCallback {
|
||||
if (process.stdout.isTTY)
|
||||
return getAnimatedDownloadProgress(progressBarName);
|
||||
return getBasicDownloadProgress(progressBarName);
|
||||
return getAnimatedDownloadProgress();
|
||||
return getBasicDownloadProgress();
|
||||
}
|
||||
|
||||
function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallback {
|
||||
function getAnimatedDownloadProgress(): OnProgressCallback {
|
||||
let progressBar: ProgressBar;
|
||||
let lastDownloadedBytes = 0;
|
||||
|
||||
return (downloadedBytes: number, totalBytes: number) => {
|
||||
if (!progressBar) {
|
||||
progressBar = new ProgressBar(
|
||||
`Downloading ${progressBarName} - ${toMegabytes(
|
||||
`${toMegabytes(
|
||||
totalBytes
|
||||
)} [:bar] :percent :etas `,
|
||||
)} [:bar] :percent :etas`,
|
||||
{
|
||||
complete: '=',
|
||||
incomplete: ' ',
|
||||
@ -109,9 +109,8 @@ function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallbac
|
||||
};
|
||||
}
|
||||
|
||||
function getBasicDownloadProgress(progressBarName: string): OnProgressCallback {
|
||||
function getBasicDownloadProgress(): OnProgressCallback {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`Downloading ${progressBarName}...`);
|
||||
const totalRows = 10;
|
||||
const stepWidth = 8;
|
||||
let lastRow = -1;
|
||||
@ -133,9 +132,9 @@ function toMegabytes(bytes: number) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const [url, destination, progressBarName, userAgent, downloadConnectionTimeout] = process.argv.slice(2);
|
||||
const [url, destination, userAgent, downloadConnectionTimeout] = process.argv.slice(2);
|
||||
await downloadFile(url, destination, {
|
||||
progressCallback: getDownloadProgress(progressBarName),
|
||||
progressCallback: getDownloadProgress(),
|
||||
userAgent,
|
||||
log: message => process.send?.({ method: 'log', params: { message } }),
|
||||
connectionTimeout: +downloadConnectionTimeout,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user