chore: add missing dynamic sdkLanguage based CLI invocations (#9817)

This commit is contained in:
Max Schmitt 2021-10-27 18:58:13 +02:00 committed by GitHub
parent 56b0823269
commit be64b5f6e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 19 deletions

View file

@ -45,7 +45,7 @@ export abstract class BrowserType extends SdkObject {
} }
executablePath(): string { executablePath(): string {
return registry.findExecutable(this._name).executablePath() || ''; return registry.findExecutable(this._name).executablePath(this._playwrightOptions.sdkLanguage) || '';
} }
name(): string { name(): string {
@ -173,7 +173,7 @@ export abstract class BrowserType extends SdkObject {
if (!registryExecutable || registryExecutable.browserName !== this._name) if (!registryExecutable || registryExecutable.browserName !== this._name)
throw new Error(`Unsupported ${this._name} channel "${options.channel}"`); throw new Error(`Unsupported ${this._name} channel "${options.channel}"`);
executable = registryExecutable.executablePathOrDie(this._playwrightOptions.sdkLanguage); executable = registryExecutable.executablePathOrDie(this._playwrightOptions.sdkLanguage);
await registryExecutable.validateHostRequirements(); await registryExecutable.validateHostRequirements(this._playwrightOptions.sdkLanguage);
} }
let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined; let wsEndpointCallback: ((wsEndpoint: string) => void) | undefined;

View file

@ -20,6 +20,7 @@ import * as os from 'os';
import childProcess from 'child_process'; import childProcess from 'child_process';
import { getUbuntuVersion } from './ubuntuVersion'; import { getUbuntuVersion } from './ubuntuVersion';
import * as utils from './utils'; import * as utils from './utils';
import { buildPlaywrightCLICommand } from './registry';
const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin'); const BIN_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
@ -148,7 +149,7 @@ export async function validateDependenciesWindows(windowsExeAndDllDirectories: s
} }
} }
export async function validateDependenciesLinux(linuxLddDirectories: string[], dlOpenLibraries: string[]) { export async function validateDependenciesLinux(sdkLanguage: string, linuxLddDirectories: string[], dlOpenLibraries: string[]) {
const directoryPaths = linuxLddDirectories; const directoryPaths = linuxLddDirectories;
const lddPaths: string[] = []; const lddPaths: string[] = [];
for (const directoryPath of directoryPaths) for (const directoryPath of directoryPaths)
@ -194,7 +195,7 @@ export async function validateDependenciesLinux(linuxLddDirectories: string[], d
`Host system is missing a few dependencies to run browsers.`, `Host system is missing a few dependencies to run browsers.`,
`Please install them with the following command:`, `Please install them with the following command:`,
``, ``,
` ${maybeSudo}npx playwright install-deps`, ` ${maybeSudo}${buildPlaywrightCLICommand(sdkLanguage, 'install-deps')}`,
``, ``,
`<3 Playwright Team`, `<3 Playwright Team`,
].join('\n'), 1)); ].join('\n'), 1));

View file

@ -235,8 +235,8 @@ export interface Executable {
installType: 'download-by-default' | 'download-on-demand' | 'install-script' | 'none'; installType: 'download-by-default' | 'download-on-demand' | 'install-script' | 'none';
directory: string | undefined; directory: string | undefined;
executablePathOrDie(sdkLanguage: string): string; executablePathOrDie(sdkLanguage: string): string;
executablePath(): string | undefined; executablePath(sdkLanguage: string): string | undefined;
validateHostRequirements(): Promise<void>; validateHostRequirements(sdkLanguage: string): Promise<void>;
} }
interface ExecutableImpl extends Executable { interface ExecutableImpl extends Executable {
@ -282,7 +282,7 @@ export class Registry {
executablePath: () => chromiumExecutable, executablePath: () => chromiumExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium', chromiumExecutable, chromium.installByDefault, sdkLanguage), executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium', chromiumExecutable, chromium.installByDefault, sdkLanguage),
installType: chromium.installByDefault ? 'download-by-default' : 'download-on-demand', installType: chromium.installByDefault ? 'download-by-default' : 'download-on-demand',
validateHostRequirements: () => this._validateHostRequirements('chromium', chromium.dir, ['chrome-linux'], [], ['chrome-win']), validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'chromium', chromium.dir, ['chrome-linux'], [], ['chrome-win']),
_install: () => this._downloadExecutable(chromium, chromiumExecutable, DOWNLOAD_URLS['chromium'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'), _install: () => this._downloadExecutable(chromium, chromiumExecutable, DOWNLOAD_URLS['chromium'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'),
_dependencyGroup: 'chromium', _dependencyGroup: 'chromium',
}); });
@ -297,7 +297,7 @@ export class Registry {
executablePath: () => chromiumWithSymbolsExecutable, executablePath: () => chromiumWithSymbolsExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium-with-symbols', chromiumWithSymbolsExecutable, chromiumWithSymbols.installByDefault, sdkLanguage), executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('chromium-with-symbols', chromiumWithSymbolsExecutable, chromiumWithSymbols.installByDefault, sdkLanguage),
installType: chromiumWithSymbols.installByDefault ? 'download-by-default' : 'download-on-demand', installType: chromiumWithSymbols.installByDefault ? 'download-by-default' : 'download-on-demand',
validateHostRequirements: () => this._validateHostRequirements('chromium', chromiumWithSymbols.dir, ['chrome-linux'], [], ['chrome-win']), validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'chromium', chromiumWithSymbols.dir, ['chrome-linux'], [], ['chrome-win']),
_install: () => this._downloadExecutable(chromiumWithSymbols, chromiumWithSymbolsExecutable, DOWNLOAD_URLS['chromium-with-symbols'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'), _install: () => this._downloadExecutable(chromiumWithSymbols, chromiumWithSymbolsExecutable, DOWNLOAD_URLS['chromium-with-symbols'][hostPlatform], 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST'),
_dependencyGroup: 'chromium', _dependencyGroup: 'chromium',
}); });
@ -380,7 +380,7 @@ export class Registry {
executablePath: () => firefoxExecutable, executablePath: () => firefoxExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox', firefoxExecutable, firefox.installByDefault, sdkLanguage), executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox', firefoxExecutable, firefox.installByDefault, sdkLanguage),
installType: firefox.installByDefault ? 'download-by-default' : 'download-on-demand', installType: firefox.installByDefault ? 'download-by-default' : 'download-on-demand',
validateHostRequirements: () => this._validateHostRequirements('firefox', firefox.dir, ['firefox'], [], ['firefox']), validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'firefox', firefox.dir, ['firefox'], [], ['firefox']),
_install: () => this._downloadExecutable(firefox, firefoxExecutable, DOWNLOAD_URLS['firefox'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'), _install: () => this._downloadExecutable(firefox, firefoxExecutable, DOWNLOAD_URLS['firefox'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'),
_dependencyGroup: 'firefox', _dependencyGroup: 'firefox',
}); });
@ -395,7 +395,7 @@ export class Registry {
executablePath: () => firefoxBetaExecutable, executablePath: () => firefoxBetaExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox-beta', firefoxBetaExecutable, firefoxBeta.installByDefault, sdkLanguage), executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('firefox-beta', firefoxBetaExecutable, firefoxBeta.installByDefault, sdkLanguage),
installType: firefoxBeta.installByDefault ? 'download-by-default' : 'download-on-demand', installType: firefoxBeta.installByDefault ? 'download-by-default' : 'download-on-demand',
validateHostRequirements: () => this._validateHostRequirements('firefox', firefoxBeta.dir, ['firefox'], [], ['firefox']), validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'firefox', firefoxBeta.dir, ['firefox'], [], ['firefox']),
_install: () => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable, DOWNLOAD_URLS['firefox-beta'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'), _install: () => this._downloadExecutable(firefoxBeta, firefoxBetaExecutable, DOWNLOAD_URLS['firefox-beta'][hostPlatform], 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST'),
_dependencyGroup: 'firefox', _dependencyGroup: 'firefox',
}); });
@ -418,7 +418,7 @@ export class Registry {
executablePath: () => webkitExecutable, executablePath: () => webkitExecutable,
executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('webkit', webkitExecutable, webkit.installByDefault, sdkLanguage), executablePathOrDie: (sdkLanguage: string) => executablePathOrDie('webkit', webkitExecutable, webkit.installByDefault, sdkLanguage),
installType: webkit.installByDefault ? 'download-by-default' : 'download-on-demand', installType: webkit.installByDefault ? 'download-by-default' : 'download-on-demand',
validateHostRequirements: () => this._validateHostRequirements('webkit', webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']), validateHostRequirements: (sdkLanguage: string) => this._validateHostRequirements(sdkLanguage, 'webkit', webkit.dir, webkitLinuxLddDirectories, ['libGLESv2.so.2', 'libx264.so'], ['']),
_install: () => this._downloadExecutable(webkit, webkitExecutable, DOWNLOAD_URLS['webkit'][hostPlatform], 'PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST'), _install: () => this._downloadExecutable(webkit, webkitExecutable, DOWNLOAD_URLS['webkit'][hostPlatform], 'PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST'),
_dependencyGroup: 'webkit', _dependencyGroup: 'webkit',
}); });
@ -440,7 +440,7 @@ export class Registry {
} }
private _createChromiumChannel(name: ChromiumChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl { private _createChromiumChannel(name: ChromiumChannel, lookAt: Record<'linux' | 'darwin' | 'win32', string>, install?: () => Promise<void>): ExecutableImpl {
const executablePath = (shouldThrow: boolean) => { const executablePath = (sdkLanguage: string, shouldThrow: boolean) => {
const suffix = lookAt[process.platform as 'linux' | 'darwin' | 'win32']; const suffix = lookAt[process.platform as 'linux' | 'darwin' | 'win32'];
if (!suffix) { if (!suffix) {
if (shouldThrow) if (shouldThrow)
@ -461,7 +461,7 @@ export class Registry {
const location = prefixes.length ? ` at ${path.join(prefixes[0], suffix)}` : ``; const location = prefixes.length ? ` at ${path.join(prefixes[0], suffix)}` : ``;
// TODO: language-specific error message // TODO: language-specific error message
const installation = install ? `\nRun "npx playwright install ${name}"` : ''; const installation = install ? `\nRun "${buildPlaywrightCLICommand(sdkLanguage, 'install ' + name)}"` : '';
throw new Error(`Chromium distribution '${name}' is not found${location}${installation}`); throw new Error(`Chromium distribution '${name}' is not found${location}${installation}`);
}; };
return { return {
@ -469,8 +469,8 @@ export class Registry {
name, name,
browserName: 'chromium', browserName: 'chromium',
directory: undefined, directory: undefined,
executablePath: () => executablePath(false), executablePath: (sdkLanguage: string) => executablePath(sdkLanguage, false),
executablePathOrDie: (sdkLanguage: string) => executablePath(true)!, executablePathOrDie: (sdkLanguage: string) => executablePath(sdkLanguage, true)!,
installType: install ? 'install-script' : 'none', installType: install ? 'install-script' : 'none',
validateHostRequirements: () => Promise.resolve(), validateHostRequirements: () => Promise.resolve(),
_install: install, _install: install,
@ -501,7 +501,7 @@ export class Registry {
return Array.from(set); return Array.from(set);
} }
private async _validateHostRequirements(browserName: BrowserName, browserDirectory: string, linuxLddDirectories: string[], dlOpenLibraries: string[], windowsExeAndDllDirectories: string[]) { private async _validateHostRequirements(sdkLanguage: string, browserName: BrowserName, browserDirectory: string, linuxLddDirectories: string[], dlOpenLibraries: string[], windowsExeAndDllDirectories: string[]) {
if (getAsBooleanFromENV('PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS')) { if (getAsBooleanFromENV('PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS')) {
process.stdout.write('Skipping host requirements validation logic because `PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS` env variable is set.\n'); process.stdout.write('Skipping host requirements validation logic because `PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS` env variable is set.\n');
return; return;
@ -511,7 +511,7 @@ export class Registry {
throw new Error(`Cannot launch Firefox on Ubuntu 16.04! Minimum required Ubuntu version for Firefox browser is 18.04`); throw new Error(`Cannot launch Firefox on Ubuntu 16.04! Minimum required Ubuntu version for Firefox browser is 18.04`);
if (os.platform() === 'linux') if (os.platform() === 'linux')
return await validateDependenciesLinux(linuxLddDirectories.map(d => path.join(browserDirectory, d)), dlOpenLibraries); return await validateDependenciesLinux(sdkLanguage, linuxLddDirectories.map(d => path.join(browserDirectory, d)), dlOpenLibraries);
if (os.platform() === 'win32' && os.arch() === 'x64') if (os.platform() === 'win32' && os.arch() === 'x64')
return await validateDependenciesWindows(windowsExeAndDllDirectories.map(d => path.join(browserDirectory, d))); return await validateDependenciesWindows(windowsExeAndDllDirectories.map(d => path.join(browserDirectory, d)));
} }
@ -697,7 +697,7 @@ function markerFilePath(browserDirectory: string): string {
return path.join(browserDirectory, 'INSTALLATION_COMPLETE'); return path.join(browserDirectory, 'INSTALLATION_COMPLETE');
} }
function buildPlaywrightCLICommand(sdkLanguage: string, parameters: string): string { export function buildPlaywrightCLICommand(sdkLanguage: string, parameters: string): string {
switch (sdkLanguage) { switch (sdkLanguage) {
case 'python': case 'python':
return `playwright ${parameters}`; return `playwright ${parameters}`;

View file

@ -21,7 +21,7 @@ import { spawnSync } from 'child_process';
import { PNG } from 'pngjs'; import { PNG } from 'pngjs';
import { registry } from 'playwright-core/lib/utils/registry'; import { registry } from 'playwright-core/lib/utils/registry';
const ffmpeg = registry.findExecutable('ffmpeg')!.executablePath(); const ffmpeg = registry.findExecutable('ffmpeg')!.executablePath('javascript');
export class VideoPlayer { export class VideoPlayer {
fileName: string; fileName: string;