Node updated. Some todos.
This commit is contained in:
180
Scripts/node_modules/puppeteer/src/getConfiguration.ts
generated
vendored
180
Scripts/node_modules/puppeteer/src/getConfiguration.ts
generated
vendored
@ -8,9 +8,15 @@ import {homedir} from 'os';
|
||||
import {join} from 'path';
|
||||
|
||||
import {cosmiconfigSync} from 'cosmiconfig';
|
||||
import type {Configuration, Product} from 'puppeteer-core';
|
||||
import type {
|
||||
ChromeHeadlessShellSettings,
|
||||
ChromeSettings,
|
||||
Configuration,
|
||||
FirefoxSettings,
|
||||
SupportedBrowser,
|
||||
} from 'puppeteer-core';
|
||||
|
||||
function getBooleanEnvVar(name: string) {
|
||||
function getBooleanEnvVar(name: string): boolean | undefined {
|
||||
const env = process.env[name];
|
||||
if (env === undefined) {
|
||||
return;
|
||||
@ -29,7 +35,7 @@ function getBooleanEnvVar(name: string) {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function isSupportedProduct(product: unknown): product is Product {
|
||||
function isSupportedBrowser(product: unknown): product is SupportedBrowser {
|
||||
switch (product) {
|
||||
case 'chrome':
|
||||
case 'firefox':
|
||||
@ -39,6 +45,73 @@ function isSupportedProduct(product: unknown): product is Product {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getDefaultBrowser(browser: unknown): SupportedBrowser {
|
||||
// Validate configuration.
|
||||
if (browser && !isSupportedBrowser(browser)) {
|
||||
throw new Error(`Unsupported browser ${browser}`);
|
||||
}
|
||||
switch (browser) {
|
||||
case 'firefox':
|
||||
return 'firefox';
|
||||
default:
|
||||
return 'chrome';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getLogLevel(logLevel: unknown): 'silent' | 'error' | 'warn' {
|
||||
switch (logLevel) {
|
||||
case 'silent':
|
||||
return 'silent';
|
||||
case 'error':
|
||||
return 'error';
|
||||
default:
|
||||
return 'warn';
|
||||
}
|
||||
}
|
||||
|
||||
function getBrowserSetting(
|
||||
browser: 'chrome' | 'chrome-headless-shell' | 'firefox',
|
||||
configuration: Configuration,
|
||||
defaultConfig:
|
||||
| ChromeSettings
|
||||
| ChromeHeadlessShellSettings
|
||||
| FirefoxSettings = {}
|
||||
): ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings {
|
||||
if (configuration.skipDownload) {
|
||||
return {
|
||||
skipDownload: true,
|
||||
};
|
||||
}
|
||||
const browserSetting:
|
||||
| ChromeSettings
|
||||
| ChromeHeadlessShellSettings
|
||||
| FirefoxSettings = {};
|
||||
const browserEnvName = browser.replaceAll('-', '_').toUpperCase();
|
||||
|
||||
browserSetting.version =
|
||||
process.env[`PUPPETEER_${browserEnvName}_VERSION`] ??
|
||||
configuration[browser]?.version ??
|
||||
defaultConfig.version;
|
||||
browserSetting.downloadBaseUrl =
|
||||
process.env[`PUPPETEER_${browserEnvName}_DOWNLOAD_BASE_URL`] ??
|
||||
configuration[browser]?.downloadBaseUrl ??
|
||||
defaultConfig.downloadBaseUrl;
|
||||
|
||||
browserSetting.skipDownload =
|
||||
getBooleanEnvVar(`PUPPETEER_${browserEnvName}_SKIP_DOWNLOAD`) ??
|
||||
getBooleanEnvVar(`PUPPETEER_SKIP_${browserEnvName}_DOWNLOAD`) ??
|
||||
configuration[browser]?.skipDownload ??
|
||||
defaultConfig.skipDownload;
|
||||
|
||||
return browserSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
@ -48,24 +121,17 @@ export const getConfiguration = (): Configuration => {
|
||||
}).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';
|
||||
configuration.logLevel = getLogLevel(
|
||||
process.env['PUPPETEER_LOGLEVEL'] ?? configuration.logLevel
|
||||
);
|
||||
|
||||
// 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.defaultBrowser = getDefaultBrowser(
|
||||
process.env['PUPPETEER_BROWSER'] ?? configuration.defaultBrowser
|
||||
);
|
||||
|
||||
configuration.executablePath =
|
||||
process.env['PUPPETEER_EXECUTABLE_PATH'] ??
|
||||
process.env['npm_config_puppeteer_executable_path'] ??
|
||||
process.env['npm_package_config_puppeteer_executable_path'] ??
|
||||
configuration.executablePath;
|
||||
process.env['PUPPETEER_EXECUTABLE_PATH'] ?? configuration.executablePath;
|
||||
|
||||
// Default to skipDownload if executablePath is set
|
||||
if (configuration.executablePath) {
|
||||
@ -73,84 +139,28 @@ export const getConfiguration = (): Configuration => {
|
||||
}
|
||||
|
||||
// Set skipDownload explicitly or from default
|
||||
configuration.skipDownload = Boolean(
|
||||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ??
|
||||
getBooleanEnvVar('npm_config_puppeteer_skip_download') ??
|
||||
getBooleanEnvVar('npm_package_config_puppeteer_skip_download') ??
|
||||
configuration.skipDownload
|
||||
);
|
||||
|
||||
// Set skipChromeDownload explicitly or from default
|
||||
configuration.skipChromeDownload = Boolean(
|
||||
getBooleanEnvVar('PUPPETEER_SKIP_CHROME_DOWNLOAD') ??
|
||||
getBooleanEnvVar('npm_config_puppeteer_skip_chrome_download') ??
|
||||
getBooleanEnvVar('npm_package_config_puppeteer_skip_chrome_download') ??
|
||||
configuration.skipChromeDownload
|
||||
);
|
||||
|
||||
// Set skipChromeDownload explicitly or from default
|
||||
configuration.skipChromeHeadlessShellDownload = Boolean(
|
||||
getBooleanEnvVar('PUPPETEER_SKIP_CHROME_HEADLESS_SHELL_DOWNLOAD') ??
|
||||
getBooleanEnvVar(
|
||||
'npm_config_puppeteer_skip_chrome_headless_shell_download'
|
||||
) ??
|
||||
getBooleanEnvVar(
|
||||
'npm_package_config_puppeteer_skip_chrome_headless_shell_download'
|
||||
) ??
|
||||
configuration.skipChromeHeadlessShellDownload
|
||||
);
|
||||
configuration.skipDownload =
|
||||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? configuration.skipDownload;
|
||||
|
||||
// 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.chrome = getBrowserSetting('chrome', configuration);
|
||||
configuration['chrome-headless-shell'] = getBrowserSetting(
|
||||
'chrome-headless-shell',
|
||||
configuration
|
||||
);
|
||||
configuration.firefox = getBrowserSetting('firefox', configuration, {
|
||||
skipDownload: true,
|
||||
});
|
||||
|
||||
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;
|
||||
process.env['PUPPETEER_TMP_DIR'] ?? configuration.temporaryDirectory;
|
||||
|
||||
configuration.experiments ??= {};
|
||||
|
||||
// Validate configuration.
|
||||
if (!isSupportedProduct(configuration.defaultProduct)) {
|
||||
throw new Error(`Unsupported product ${configuration.defaultProduct}`);
|
||||
}
|
||||
|
||||
return configuration;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user