fix: consider downloadHost as baseUrl (#9973)

This commit is contained in:
Alex Rudenko 2023-04-05 09:58:53 +02:00 committed by GitHub
parent de0cc3245e
commit 05a44afe5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -63,6 +63,16 @@ export interface Options {
downloadedBytes: number,
totalBytes: number
) => void;
/**
* Determines the host that will be used for downloading.
*
* @defaultValue Either
*
* - https://storage.googleapis.com/chromium-browser-snapshots or
* - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
*
*/
baseUrl?: string;
}
export type InstalledBrowser = {
@ -82,7 +92,8 @@ export async function fetch(options: Options): Promise<InstalledBrowser> {
const url = getDownloadUrl(
options.browser,
options.platform,
options.buildId
options.buildId,
options.baseUrl
);
const fileName = url.toString().split('/').pop();
assert(fileName, `A malformed download URL was found: ${url}.`);
@ -131,14 +142,20 @@ export async function canFetch(options: Options): Promise<boolean> {
);
}
return await headHttpRequest(
getDownloadUrl(options.browser, options.platform, options.buildId)
getDownloadUrl(
options.browser,
options.platform,
options.buildId,
options.baseUrl
)
);
}
function getDownloadUrl(
browser: Browser,
platform: BrowserPlatform,
buildId: string
buildId: string,
baseUrl?: string
): URL {
return new URL(downloadUrls[browser](platform, buildId));
return new URL(downloadUrls[browser](platform, buildId, baseUrl));
}

View File

@ -48,6 +48,8 @@ export async function downloadBrowser(): Promise<void> {
return;
}
let downloadHost = configuration.downloadHost;
let platform = detectBrowserPlatform();
if (!platform) {
throw new Error('The current platform is not supported.');
@ -70,6 +72,19 @@ export async function downloadBrowser(): Promise<void> {
PUPPETEER_REVISIONS[product === 'chrome' ? 'chromium' : 'firefox'] ||
'latest';
if (product === 'chrome' && downloadHost) {
// TODO: remove downloadHost in favour of baseDownloadUrl. The "host" of
// Firefox is already a URL and not a host. This would be a breaking change.
if (
!downloadHost.endsWith('/chromium-browser-snapshots') &&
!downloadHost.endsWith('/chromium-browser-snapshots/')
) {
downloadHost += downloadHost.endsWith('/')
? 'chromium-browser-snapshots'
: '/chromium-browser-snapshots';
}
}
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
try {
@ -79,6 +94,7 @@ export async function downloadBrowser(): Promise<void> {
platform,
buildId,
downloadProgressCallback: makeProgressCallback(browser, buildId),
baseUrl: downloadHost,
});
logPolitely(