chore: print where the browsers are downloaded from (#18360)

Fixes https://github.com/microsoft/playwright/issues/16926
This commit is contained in:
Pavel Feldman 2022-10-27 09:19:09 -07:00 committed by GitHub
parent 12fdd3336e
commit 041a98928b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -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')

View File

@ -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,