fix: rename PUPPETEER_DOWNLOAD_HOST to PUPPETEER_DOWNLOAD_BASE_URL (#10130)

This commit is contained in:
Alex Rudenko 2023-05-05 10:32:58 +02:00 committed by GitHub
parent 9e21d30f75
commit 9758cae029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 32 deletions

View File

@ -21,10 +21,10 @@ export interface Configuration
| browserRevision | <code>optional</code> | string | <p>Specifies a certain version of the browser you'd like Puppeteer to use.</p><p>Can be overridden by <code>PUPPETEER_BROWSER_REVISION</code>.</p><p>See [puppeteer.launch](./puppeteer.puppeteernode.launch.md) on how executable path is inferred.</p> | A compatible-revision of the browser. | | browserRevision | <code>optional</code> | string | <p>Specifies a certain version of the browser you'd like Puppeteer to use.</p><p>Can be overridden by <code>PUPPETEER_BROWSER_REVISION</code>.</p><p>See [puppeteer.launch](./puppeteer.puppeteernode.launch.md) on how executable path is inferred.</p> | A compatible-revision of the browser. |
| cacheDirectory | <code>optional</code> | string | <p>Defines the directory to be used by Puppeteer for caching.</p><p>Can be overridden by <code>PUPPETEER_CACHE_DIR</code>.</p> | <code>path.join(os.homedir(), '.cache', 'puppeteer')</code> | | cacheDirectory | <code>optional</code> | string | <p>Defines the directory to be used by Puppeteer for caching.</p><p>Can be overridden by <code>PUPPETEER_CACHE_DIR</code>.</p> | <code>path.join(os.homedir(), '.cache', 'puppeteer')</code> |
| defaultProduct | <code>optional</code> | [Product](./puppeteer.product.md) | <p>Specifies which browser you'd like Puppeteer to use.</p><p>Can be overridden by <code>PUPPETEER_PRODUCT</code>.</p> | <code>chrome</code> | | defaultProduct | <code>optional</code> | [Product](./puppeteer.product.md) | <p>Specifies which browser you'd like Puppeteer to use.</p><p>Can be overridden by <code>PUPPETEER_PRODUCT</code>.</p> | <code>chrome</code> |
| downloadHost | <code>optional</code> | string | <p>Specifies the URL prefix that is used to download the browser.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_HOST</code>.</p> | Either https://storage.googleapis.com or https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, depending on the product. | | downloadBaseUrl | <code>optional</code> | string | <p>Specifies the URL prefix that is used to download the browser.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_BASE_URL</code>.</p> | Either https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, depending on the product. |
| downloadPath | <code>optional</code> | string | <p>Specifies the path for the downloads folder.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_PATH</code>.</p> | <code>&lt;cache&gt;/&lt;product&gt;</code> where <code>&lt;cache&gt;</code> is Puppeteer's cache directory and <code>&lt;product&gt;</code> is the name of the browser. | | downloadPath | <code>optional</code> | string | <p>Specifies the path for the downloads folder.</p><p>Can be overridden by <code>PUPPETEER_DOWNLOAD_PATH</code>.</p> | <code>&lt;cache&gt;/&lt;product&gt;</code> where <code>&lt;cache&gt;</code> is Puppeteer's cache directory and <code>&lt;product&gt;</code> is the name of the browser. |
| executablePath | <code>optional</code> | string | <p>Specifies an executable path to be used in [puppeteer.launch](./puppeteer.puppeteernode.launch.md).</p><p>Can be overridden by <code>PUPPETEER_EXECUTABLE_PATH</code>.</p> | **Auto-computed.** | | executablePath | <code>optional</code> | string | <p>Specifies an executable path to be used in [puppeteer.launch](./puppeteer.puppeteernode.launch.md).</p><p>Can be overridden by <code>PUPPETEER_EXECUTABLE_PATH</code>.</p> | **Auto-computed.** |
| experiments | <code>optional</code> | [ExperimentsConfiguration](./puppeteer.experimentsconfiguration.md) | Defines experimental options for Puppeteer. | | | experiments | <code>optional</code> | [ExperimentsConfiguration](./puppeteer.experimentsconfiguration.md) | Defines experimental options for Puppeteer. | |
| logLevel | <code>optional</code> | 'silent' \| 'error' \| 'warn' | <p>Tells Puppeteer to log at the given level.</p><p>At the moment, any option silences logging.</p> | <code>undefined</code> | | logLevel | <code>optional</code> | 'silent' \| 'error' \| 'warn' | Tells Puppeteer to log at the given level. | <code>warn</code> |
| skipDownload | <code>optional</code> | boolean | <p>Tells Puppeteer to not download during installation.</p><p>Can be overridden by <code>PUPPETEER_SKIP_DOWNLOAD</code>.</p> | | | skipDownload | <code>optional</code> | boolean | <p>Tells Puppeteer to not download during installation.</p><p>Can be overridden by <code>PUPPETEER_SKIP_DOWNLOAD</code>.</p> | |
| temporaryDirectory | <code>optional</code> | string | <p>Defines the directory to be used by Puppeteer for creating temporary files.</p><p>Can be overridden by <code>PUPPETEER_TMP_DIR</code>.</p> | <code>os.tmpdir()</code> | | temporaryDirectory | <code>optional</code> | string | <p>Defines the directory to be used by Puppeteer for creating temporary files.</p><p>Can be overridden by <code>PUPPETEER_TMP_DIR</code>.</p> | <code>os.tmpdir()</code> |

View File

@ -12,12 +12,12 @@ export interface InstallOptions
## Properties ## Properties
| Property | Modifiers | Type | Description | Default | | Property | Modifiers | Type | Description | Default |
| ------------------------ | --------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------------ | --------------------- | -------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| baseUrl | <code>optional</code> | string | Determines the host that will be used for downloading. | <p>Either</p><p>- https://storage.googleapis.com/chromium-browser-snapshots or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central</p> | | baseUrl | <code>optional</code> | string | Determines the host that will be used for downloading. | <p>Either</p><p>- https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central</p> |
| browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | | | browser | | [Browser](./browsers.browser.md) | Determines which browser to install. | |
| buildId | | string | Determines which buildId to dowloand. BuildId should uniquely identify binaries and they are used for caching. | | | buildId | | string | Determines which buildId to dowloand. BuildId should uniquely identify binaries and they are used for caching. | |
| cacheDir | | string | Determines the path to download browsers to. | | | cacheDir | | string | Determines the path to download browsers to. | |
| downloadProgressCallback | <code>optional</code> | (downloadedBytes: number, totalBytes: number) =&gt; void | Provides information about the progress of the download. | | | downloadProgressCallback | <code>optional</code> | (downloadedBytes: number, totalBytes: number) =&gt; void | Provides information about the progress of the download. | |
| platform | <code>optional</code> | [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** | | platform | <code>optional</code> | [BrowserPlatform](./browsers.browserplatform.md) | Determines which platform the browser will be suited for. | **Auto-detected.** |
| unpack | <code>optional</code> | boolean | Whether to unpack and install browser archives. | <code>true</code> | | unpack | <code>optional</code> | boolean | Whether to unpack and install browser archives. | <code>true</code> |

View File

@ -84,7 +84,7 @@ export interface InstallOptions {
* *
* @defaultValue Either * @defaultValue Either
* *
* - https://storage.googleapis.com/chromium-browser-snapshots or * - https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or
* - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central * - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
* *
*/ */

View File

@ -56,16 +56,16 @@ export interface Configuration {
/** /**
* Specifies the URL prefix that is used to download the browser. * Specifies the URL prefix that is used to download the browser.
* *
* Can be overridden by `PUPPETEER_DOWNLOAD_HOST`. * Can be overridden by `PUPPETEER_DOWNLOAD_BASE_URL`.
* *
* @remarks * @remarks
* This must include the protocol and may even need a path prefix. * This must include the protocol and may even need a path prefix.
* *
* @defaultValue Either https://storage.googleapis.com or * @defaultValue Either https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or
* https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central, * https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central,
* depending on the product. * depending on the product.
*/ */
downloadHost?: string; downloadBaseUrl?: string;
/** /**
* Specifies the path for the downloads folder. * Specifies the path for the downloads folder.
* *
@ -109,9 +109,7 @@ export interface Configuration {
/** /**
* Tells Puppeteer to log at the given level. * Tells Puppeteer to log at the given level.
* *
* At the moment, any option silences logging. * @defaultValue `warn`
*
* @defaultValue `undefined`
*/ */
logLevel?: 'silent' | 'error' | 'warn'; logLevel?: 'silent' | 'error' | 'warn';
/** /**

View File

@ -48,8 +48,7 @@ export class ChromeLauncher extends ProductLauncher {
const headless = options.headless ?? true; const headless = options.headless ?? true;
if ( if (
headless === true && headless === true &&
(!this.puppeteer.configuration.logLevel || this.puppeteer.configuration.logLevel === 'warn' &&
this.puppeteer.configuration.logLevel === 'warn') &&
!Boolean(process.env['PUPPETEER_DISABLE_HEADLESS_WARNING']) !Boolean(process.env['PUPPETEER_DISABLE_HEADLESS_WARNING'])
) { ) {
console.warn( console.warn(

View File

@ -24,6 +24,12 @@ export const getConfiguration = (): Configuration => {
const result = cosmiconfigSync('puppeteer').search(); const result = cosmiconfigSync('puppeteer').search();
const configuration: Configuration = result ? result.config : {}; const configuration: Configuration = result ? result.config : {};
configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ??
process.env['npm_config_LOGLEVEL'] ??
process.env['npm_package_config_LOGLEVEL'] ??
configuration.logLevel ??
'warn') as 'silent' | 'error' | 'warn';
// Merging environment variables. // Merging environment variables.
configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ?? configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ??
process.env['npm_config_puppeteer_product'] ?? process.env['npm_config_puppeteer_product'] ??
@ -57,11 +63,25 @@ export const getConfiguration = (): Configuration => {
process.env['npm_config_puppeteer_browser_revision'] ?? process.env['npm_config_puppeteer_browser_revision'] ??
process.env['npm_package_config_puppeteer_browser_revision'] ?? process.env['npm_package_config_puppeteer_browser_revision'] ??
configuration.browserRevision; configuration.browserRevision;
configuration.downloadHost =
const downloadHost =
process.env['PUPPETEER_DOWNLOAD_HOST'] ?? process.env['PUPPETEER_DOWNLOAD_HOST'] ??
process.env['npm_config_puppeteer_download_host'] ?? process.env['npm_config_puppeteer_download_host'] ??
process.env['npm_package_config_puppeteer_download_host'] ?? process.env['npm_package_config_puppeteer_download_host'];
configuration.downloadHost;
if (downloadHost && configuration.logLevel === 'warn') {
console.warn(
`PUPPETEER_DOWNLOAD_HOST is deprecated. Use PUPPETEER_DOWNLOAD_BASE_URL instead.`
);
}
configuration.downloadBaseUrl =
process.env['PUPPETEER_DOWNLOAD_BASE_URL'] ??
process.env['npm_config_puppeteer_download_base_url'] ??
process.env['npm_package_config_puppeteer_download_base_url'] ??
configuration.downloadBaseUrl ??
downloadHost;
configuration.downloadPath = configuration.downloadPath =
process.env['PUPPETEER_DOWNLOAD_PATH'] ?? process.env['PUPPETEER_DOWNLOAD_PATH'] ??
process.env['npm_config_puppeteer_download_path'] ?? process.env['npm_config_puppeteer_download_path'] ??
@ -83,11 +103,6 @@ export const getConfiguration = (): Configuration => {
configuration.experiments ??= {}; configuration.experiments ??= {};
configuration.logLevel = (process.env['PUPPETEER_LOGLEVEL'] ??
process.env['npm_config_LOGLEVEL'] ??
process.env['npm_package_config_LOGLEVEL'] ??
configuration.logLevel) as 'silent' | 'error' | 'warn';
// Validate configuration. // Validate configuration.
if (!isSupportedProduct(configuration.defaultProduct)) { if (!isSupportedProduct(configuration.defaultProduct)) {
throw new Error(`Unsupported product ${configuration.defaultProduct}`); throw new Error(`Unsupported product ${configuration.defaultProduct}`);

View File

@ -46,7 +46,7 @@ export async function downloadBrowser(): Promise<void> {
return; return;
} }
const downloadHost = configuration.downloadHost; const downloadBaseUrl = configuration.downloadBaseUrl;
const platform = detectBrowserPlatform(); const platform = detectBrowserPlatform();
if (!platform) { if (!platform) {
@ -68,9 +68,7 @@ export async function downloadBrowser(): Promise<void> {
platform, platform,
buildId, buildId,
downloadProgressCallback: makeProgressCallback(browser, buildId), downloadProgressCallback: makeProgressCallback(browser, buildId),
// TODO: remove downloadHost in favour of baseDownloadUrl. The "host" of baseUrl: downloadBaseUrl,
// Firefox is already a URL and not a host. This would be a breaking change.
baseUrl: downloadHost,
}); });
logPolitely( logPolitely(