summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts')
-rw-r--r--remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts138
1 files changed, 138 insertions, 0 deletions
diff --git a/remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts b/remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts
new file mode 100644
index 0000000000..28cf026eb7
--- /dev/null
+++ b/remote/test/puppeteer/packages/puppeteer/src/getConfiguration.ts
@@ -0,0 +1,138 @@
+/**
+ * @license
+ * Copyright 2023 Google Inc.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import {homedir} from 'os';
+import {join} from 'path';
+
+import {cosmiconfigSync} from 'cosmiconfig';
+import type {Configuration, Product} from 'puppeteer-core';
+
+/**
+ * @internal
+ */
+function isSupportedProduct(product: unknown): product is Product {
+ switch (product) {
+ case 'chrome':
+ case 'firefox':
+ return true;
+ default:
+ return false;
+ }
+}
+
+/**
+ * @internal
+ */
+export const getConfiguration = (): Configuration => {
+ const result = cosmiconfigSync('puppeteer', {
+ searchStrategy: 'global',
+ }).search();
+ 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.
+ configuration.defaultProduct = (process.env['PUPPETEER_PRODUCT'] ??
+ process.env['npm_config_puppeteer_product'] ??
+ process.env['npm_package_config_puppeteer_product'] ??
+ configuration.defaultProduct ??
+ 'chrome') as Product;
+
+ configuration.executablePath =
+ process.env['PUPPETEER_EXECUTABLE_PATH'] ??
+ process.env['npm_config_puppeteer_executable_path'] ??
+ process.env['npm_package_config_puppeteer_executable_path'] ??
+ configuration.executablePath;
+
+ // Default to skipDownload if executablePath is set
+ if (configuration.executablePath) {
+ configuration.skipDownload = true;
+ }
+
+ // Set skipDownload explicitly or from default
+ configuration.skipDownload = Boolean(
+ process.env['PUPPETEER_SKIP_DOWNLOAD'] ??
+ process.env['npm_config_puppeteer_skip_download'] ??
+ process.env['npm_package_config_puppeteer_skip_download'] ??
+ configuration.skipDownload
+ );
+
+ // Set skipChromeDownload explicitly or from default
+ configuration.skipChromeDownload = Boolean(
+ process.env['PUPPETEER_SKIP_CHROME_DOWNLOAD'] ??
+ process.env['npm_config_puppeteer_skip_chrome_download'] ??
+ process.env['npm_package_config_puppeteer_skip_chrome_download'] ??
+ configuration.skipChromeDownload
+ );
+
+ // Set skipChromeDownload explicitly or from default
+ configuration.skipChromeHeadlessShellDownload = Boolean(
+ process.env['PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD'] ??
+ process.env['npm_config_puppeteer_skip_chrome_headless_shell_download'] ??
+ process.env[
+ 'npm_package_config_puppeteer_skip_chrome_headless_shell_download'
+ ] ??
+ configuration.skipChromeHeadlessShellDownload
+ );
+
+ // Prepare variables used in browser downloading
+ if (!configuration.skipDownload) {
+ configuration.browserRevision =
+ process.env['PUPPETEER_BROWSER_REVISION'] ??
+ process.env['npm_config_puppeteer_browser_revision'] ??
+ process.env['npm_package_config_puppeteer_browser_revision'] ??
+ configuration.browserRevision;
+
+ const downloadHost =
+ process.env['PUPPETEER_DOWNLOAD_HOST'] ??
+ process.env['npm_config_puppeteer_download_host'] ??
+ process.env['npm_package_config_puppeteer_download_host'];
+
+ 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 =
+ process.env['PUPPETEER_DOWNLOAD_PATH'] ??
+ process.env['npm_config_puppeteer_download_path'] ??
+ process.env['npm_package_config_puppeteer_download_path'] ??
+ configuration.downloadPath;
+ }
+
+ configuration.cacheDirectory =
+ process.env['PUPPETEER_CACHE_DIR'] ??
+ process.env['npm_config_puppeteer_cache_dir'] ??
+ process.env['npm_package_config_puppeteer_cache_dir'] ??
+ configuration.cacheDirectory ??
+ join(homedir(), '.cache', 'puppeteer');
+ configuration.temporaryDirectory =
+ process.env['PUPPETEER_TMP_DIR'] ??
+ process.env['npm_config_puppeteer_tmp_dir'] ??
+ process.env['npm_package_config_puppeteer_tmp_dir'] ??
+ configuration.temporaryDirectory;
+
+ configuration.experiments ??= {};
+
+ // Validate configuration.
+ if (!isSupportedProduct(configuration.defaultProduct)) {
+ throw new Error(`Unsupported product ${configuration.defaultProduct}`);
+ }
+
+ return configuration;
+};