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 { debugLogger } from '../../common/debugLogger';
|
||||||
import { extract } from '../../zipBundle';
|
import { extract } from '../../zipBundle';
|
||||||
import { ManualPromise } from '../../utils/manualPromise';
|
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> {
|
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise<boolean> {
|
||||||
if (await existsAsync(browserDirectory)) {
|
if (await existsAsync(browserDirectory)) {
|
||||||
@ -38,7 +39,8 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec
|
|||||||
for (let attempt = 1; attempt <= retryCount; ++attempt) {
|
for (let attempt = 1; attempt <= retryCount; ++attempt) {
|
||||||
debugLogger.log('install', `downloading ${title} - attempt #${attempt}`);
|
debugLogger.log('install', `downloading ${title} - attempt #${attempt}`);
|
||||||
const url = downloadURLs[(attempt - 1) % downloadURLs.length];
|
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) {
|
if (!error) {
|
||||||
debugLogger.log('install', `SUCCESS downloading ${title}`);
|
debugLogger.log('install', `SUCCESS downloading ${title}`);
|
||||||
break;
|
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.
|
* Thats why we execute it in a separate process and check manually if the destination file exists.
|
||||||
* https://github.com/microsoft/playwright/issues/17394
|
* https://github.com/microsoft/playwright/issues/17394
|
||||||
*/
|
*/
|
||||||
function downloadFileOutOfProcess(url: string, destinationPath: string, progressBarName: string, userAgent: string, downloadConnectionTimeout: number): Promise<{ error: Error | null }> {
|
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, progressBarName, userAgent, String(downloadConnectionTimeout)]);
|
const cp = childProcess.fork(path.join(__dirname, 'oopDownloadMain.js'), [url, destinationPath, userAgent, String(downloadConnectionTimeout)]);
|
||||||
const promise = new ManualPromise<{ error: Error | null }>();
|
const promise = new ManualPromise<{ error: Error | null }>();
|
||||||
cp.on('message', (message: any) => {
|
cp.on('message', (message: any) => {
|
||||||
if (message?.method === 'log')
|
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)
|
if (process.stdout.isTTY)
|
||||||
return getAnimatedDownloadProgress(progressBarName);
|
return getAnimatedDownloadProgress();
|
||||||
return getBasicDownloadProgress(progressBarName);
|
return getBasicDownloadProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallback {
|
function getAnimatedDownloadProgress(): OnProgressCallback {
|
||||||
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 ${progressBarName} - ${toMegabytes(
|
`${toMegabytes(
|
||||||
totalBytes
|
totalBytes
|
||||||
)} [:bar] :percent :etas `,
|
)} [:bar] :percent :etas`,
|
||||||
{
|
{
|
||||||
complete: '=',
|
complete: '=',
|
||||||
incomplete: ' ',
|
incomplete: ' ',
|
||||||
@ -109,9 +109,8 @@ function getAnimatedDownloadProgress(progressBarName: string): OnProgressCallbac
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBasicDownloadProgress(progressBarName: string): OnProgressCallback {
|
function getBasicDownloadProgress(): OnProgressCallback {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Downloading ${progressBarName}...`);
|
|
||||||
const totalRows = 10;
|
const totalRows = 10;
|
||||||
const stepWidth = 8;
|
const stepWidth = 8;
|
||||||
let lastRow = -1;
|
let lastRow = -1;
|
||||||
@ -133,9 +132,9 @@ function toMegabytes(bytes: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function main() {
|
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, {
|
await downloadFile(url, destination, {
|
||||||
progressCallback: getDownloadProgress(progressBarName),
|
progressCallback: getDownloadProgress(),
|
||||||
userAgent,
|
userAgent,
|
||||||
log: message => process.send?.({ method: 'log', params: { message } }),
|
log: message => process.send?.({ method: 'log', params: { message } }),
|
||||||
connectionTimeout: +downloadConnectionTimeout,
|
connectionTimeout: +downloadConnectionTimeout,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user