Revert "add --quiet option to npx playwright install command"

This reverts commit 2a66d70b1c.
This commit is contained in:
JacksonLei123 2024-12-18 21:13:12 -05:00
parent 7004464433
commit 90da45e5d3
3 changed files with 27 additions and 33 deletions

View file

@ -130,8 +130,7 @@ program
.option('--force', 'force reinstall of stable browser channels')
.option('--only-shell', 'only install headless shell when installing chromium')
.option('--no-shell', 'do not install chromium headless shell')
.option('--quiet', 'do not print logs while installing')
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean, quiet?: boolean }) {
.action(async function(args: string[], options: { withDeps?: boolean, force?: boolean, dryRun?: boolean, shell?: boolean, noShell?: boolean, onlyShell?: boolean }) {
// For '--no-shell' option, commander sets `shell: false` instead.
if (options.shell === false)
options.noShell = true;
@ -175,8 +174,7 @@ program
}
} else {
const forceReinstall = hasNoArguments ? false : !!options.force;
const suppressLogs = options.quiet;
await registry.install(executables, forceReinstall, suppressLogs);
await registry.install(executables, forceReinstall);
await registry.validateHostRequirementsForExecutablesIfNeeded(executables, process.env.PW_LANG_NAME || 'javascript').catch((e: Error) => {
e.name = 'Playwright Host validation warning';
console.error(e);

View file

@ -27,7 +27,7 @@ import { browserDirectoryToMarkerFilePath } from '.';
import { getUserAgent } from '../../utils/userAgent';
import type { DownloadParams } from './oopDownloadBrowserMain';
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string | undefined, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number, quiet?: boolean): Promise<boolean> {
export async function downloadBrowserWithProgressBar(title: string, browserDirectory: string, executablePath: string | undefined, downloadURLs: string[], downloadFileName: string, downloadConnectionTimeout: number): Promise<boolean> {
if (await existsAsync(browserDirectoryToMarkerFilePath(browserDirectory))) {
// Already downloaded.
debugLogger.log('install', `${title} is already downloaded.`);
@ -40,9 +40,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];
if (!quiet)
logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`));
const { error } = await downloadBrowserWithProgressBarOutOfProcess(title, browserDirectory, url, zipPath, executablePath, downloadConnectionTimeout, quiet);
logPolitely(`Downloading ${title}` + colors.dim(` from ${url}`));
const { error } = await downloadBrowserWithProgressBarOutOfProcess(title, browserDirectory, url, zipPath, executablePath, downloadConnectionTimeout);
if (!error) {
debugLogger.log('install', `SUCCESS installing ${title}`);
break;
@ -64,8 +63,7 @@ export async function downloadBrowserWithProgressBar(title: string, browserDirec
if (await existsAsync(zipPath))
await fs.promises.unlink(zipPath);
}
if (!quiet)
logPolitely(`${title} downloaded to ${browserDirectory}`);
logPolitely(`${title} downloaded to ${browserDirectory}`);
return true;
}
@ -74,18 +72,16 @@ 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 downloadBrowserWithProgressBarOutOfProcess(title: string, browserDirectory: string, url: string, zipPath: string, executablePath: string | undefined, connectionTimeout: number, quiet?: boolean): Promise<{ error: Error | null }> {
function downloadBrowserWithProgressBarOutOfProcess(title: string, browserDirectory: string, url: string, zipPath: string, executablePath: string | undefined, connectionTimeout: number): Promise<{ error: Error | null }> {
const cp = childProcess.fork(path.join(__dirname, 'oopDownloadBrowserMain.js'));
const promise = new ManualPromise<{ error: Error | null }>();
if (!quiet) {
const progress = getDownloadProgress();
cp.on('message', (message: any) => {
if (message?.method === 'log')
debugLogger.log('install', message.params.message);
if (message?.method === 'progress')
progress(message.params.done, message.params.total);
});
}
const progress = getDownloadProgress();
cp.on('message', (message: any) => {
if (message?.method === 'log')
debugLogger.log('install', message.params.message);
if (message?.method === 'progress')
progress(message.params.done, message.params.total);
});
cp.on('exit', code => {
if (code !== 0) {
promise.resolve({ error: new Error(`Download failure, code=${code}`) });

View file

@ -465,7 +465,7 @@ export interface Executable {
}
interface ExecutableImpl extends Executable {
_install?: (quiet?: boolean) => Promise<void>;
_install?: () => Promise<void>;
_dependencyGroup?: DependencyGroup;
_isHermeticInstallation?: boolean;
}
@ -527,7 +527,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromium.dir, ['chrome-linux'], [], ['chrome-win']),
downloadURLs: this._downloadURLs(chromium),
browserVersion: chromium.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(chromium, chromiumExecutable, quiet),
_install: () => this._downloadExecutable(chromium, chromiumExecutable),
_dependencyGroup: 'chromium',
_isHermeticInstallation: true,
});
@ -545,7 +545,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumHeadlessShell.dir, ['chrome-linux'], [], ['chrome-win']),
downloadURLs: this._downloadURLs(chromiumHeadlessShell),
browserVersion: chromium.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(chromiumHeadlessShell, chromiumHeadlessShellExecutable, quiet),
_install: () => this._downloadExecutable(chromiumHeadlessShell, chromiumHeadlessShellExecutable),
_dependencyGroup: 'chromium',
_isHermeticInstallation: true,
});
@ -581,7 +581,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromiumTipOfTree.dir, ['chrome-linux'], [], ['chrome-win']),
downloadURLs: this._downloadURLs(chromiumTipOfTree),
browserVersion: chromiumTipOfTree.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(chromiumTipOfTree, chromiumTipOfTreeExecutable, quiet),
_install: () => this._downloadExecutable(chromiumTipOfTree, chromiumTipOfTreeExecutable),
_dependencyGroup: 'chromium',
_isHermeticInstallation: true,
});
@ -691,7 +691,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, chromium.dir, ['chrome-linux'], [], ['chrome-win']),
downloadURLs: this._downloadURLs(chromium),
browserVersion: chromium.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(chromium, chromiumExecutable, quiet),
_install: () => this._downloadExecutable(chromium, chromiumExecutable),
_dependencyGroup: 'chromium',
_isHermeticInstallation: true,
});
@ -709,7 +709,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, firefox.dir, ['firefox'], [], ['firefox']),
downloadURLs: this._downloadURLs(firefox),
browserVersion: firefox.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(firefox, firefoxExecutable, quiet),
_install: () => this._downloadExecutable(firefox, firefoxExecutable),
_dependencyGroup: 'firefox',
_isHermeticInstallation: true,
});
@ -727,7 +727,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, firefoxBeta.dir, ['firefox'], [], ['firefox']),
downloadURLs: this._downloadURLs(firefoxBeta),
browserVersion: firefoxBeta.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable, quiet),
_install: () => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable),
_dependencyGroup: 'firefox',
_isHermeticInstallation: true,
});
@ -755,7 +755,7 @@ export class Registry {
_validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']),
downloadURLs: this._downloadURLs(webkit),
browserVersion: webkit.browserVersion,
_install: (quiet?: boolean) => this._downloadExecutable(webkit, webkitExecutable, quiet),
_install: () => this._downloadExecutable(webkit, webkitExecutable),
_dependencyGroup: 'webkit',
_isHermeticInstallation: true,
});
@ -772,7 +772,7 @@ export class Registry {
installType: ffmpeg.installByDefault ? 'download-by-default' : 'download-on-demand',
_validateHostRequirements: () => Promise.resolve(),
downloadURLs: this._downloadURLs(ffmpeg),
_install: (quiet?: boolean) => this._downloadExecutable(ffmpeg, ffmpegExecutable, quiet),
_install: () => this._downloadExecutable(ffmpeg, ffmpegExecutable),
_dependencyGroup: 'tools',
_isHermeticInstallation: true,
});
@ -965,7 +965,7 @@ export class Registry {
return await installDependenciesLinux(targets, dryRun);
}
async install(executablesToInstall: Executable[], forceReinstall: boolean, quiet?: boolean) {
async install(executablesToInstall: Executable[], forceReinstall: boolean) {
const executables = this._dedupe(executablesToInstall);
await fs.promises.mkdir(registryDirectory, { recursive: true });
const lockfilePath = path.join(registryDirectory, '__dirlock');
@ -1017,7 +1017,7 @@ export class Registry {
`<3 Playwright Team`,
].join('\n'), 1));
}
await executable._install(quiet);
await executable._install();
}
} catch (e) {
if (e.code === 'ELOCKED') {
@ -1114,7 +1114,7 @@ export class Registry {
return downloadURLs;
}
private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string, quiet?: boolean) {
private async _downloadExecutable(descriptor: BrowsersJSONDescriptor, executablePath?: string) {
const downloadURLs = this._downloadURLs(descriptor);
if (!downloadURLs.length)
throw new Error(`ERROR: Playwright does not support ${descriptor.name} on ${hostPlatform}`);
@ -1138,7 +1138,7 @@ export class Registry {
const downloadFileName = `playwright-download-${descriptor.name}-${hostPlatform}-${descriptor.revision}.zip`;
const downloadConnectionTimeoutEnv = getFromENV('PLAYWRIGHT_DOWNLOAD_CONNECTION_TIMEOUT');
const downloadConnectionTimeout = +(downloadConnectionTimeoutEnv || '0') || 30_000;
await downloadBrowserWithProgressBar(title, descriptor.dir, executablePath, downloadURLs, downloadFileName, downloadConnectionTimeout, quiet).catch(e => {
await downloadBrowserWithProgressBar(title, descriptor.dir, executablePath, downloadURLs, downloadFileName, downloadConnectionTimeout).catch(e => {
throw new Error(`Failed to download ${title}, caused by\n${e.stack}`);
});
}