feat(install/download-hosts): allow multiple per browser (#2452)

In addition to `PLAYWRIGHT_DOWNLOAD_HOST` env variable, this patch adds a per-browser 
configuration:

- `PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST`
- `PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST`
- `PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST`
This commit is contained in:
Mike Tobia 2020-06-18 14:20:43 -04:00 committed by GitHub
parent 971bd88922
commit 63924d9a26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,13 @@ const DEFAULT_DOWNLOAD_HOSTS: { [key: string]: string } = {
webkit: 'https://playwright.azureedge.net',
};
const ENV_DOWNLOAD_HOSTS: { [key: string]: string } = {
default: 'PLAYWRIGHT_DOWNLOAD_HOST',
chromium: 'PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST',
firefox: 'PLAYWRIGHT_FIREFOX_DOWNLOAD_HOST',
webkit: 'PLAYWRIGHT_WEBKIT_DOWNLOAD_HOST',
};
function getDownloadUrl(browserName: BrowserName, platform: BrowserPlatform): string | undefined {
if (browserName === 'chromium') {
return new Map<BrowserPlatform, string>([
@ -76,7 +83,7 @@ function getDownloadUrl(browserName: BrowserName, platform: BrowserPlatform): st
}
function revisionURL(browser: BrowserDescriptor, platform = browserPaths.hostPlatform): string {
const serverHost = getFromENV('PLAYWRIGHT_DOWNLOAD_HOST') || DEFAULT_DOWNLOAD_HOSTS[browser.name];
const serverHost = getFromENV(ENV_DOWNLOAD_HOSTS[browser.name]) || getFromENV(ENV_DOWNLOAD_HOSTS.default) || DEFAULT_DOWNLOAD_HOSTS[browser.name];
const urlTemplate = getDownloadUrl(browser.name, platform);
assert(urlTemplate, `ERROR: Playwright does not support ${browser.name} on ${platform}`);
return util.format(urlTemplate, serverHost, browser.revision);