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;
|
||||
};
|
||||
|
||||
30
Scripts/node_modules/puppeteer/src/node/cli.ts
generated
vendored
30
Scripts/node_modules/puppeteer/src/node/cli.ts
generated
vendored
@ -11,10 +11,7 @@ import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
|
||||
|
||||
import puppeteer from '../puppeteer.js';
|
||||
|
||||
// TODO: deprecate downloadPath in favour of cacheDirectory.
|
||||
const cacheDir =
|
||||
puppeteer.configuration.downloadPath ??
|
||||
puppeteer.configuration.cacheDirectory!;
|
||||
const cacheDir = puppeteer.configuration.cacheDirectory!;
|
||||
|
||||
void new CLI({
|
||||
cachePath: cacheDir,
|
||||
@ -25,8 +22,27 @@ void new CLI({
|
||||
},
|
||||
allowCachePathOverride: false,
|
||||
pinnedBrowsers: {
|
||||
[Browser.CHROME]: PUPPETEER_REVISIONS.chrome,
|
||||
[Browser.FIREFOX]: PUPPETEER_REVISIONS.firefox,
|
||||
[Browser.CHROMEHEADLESSSHELL]: PUPPETEER_REVISIONS['chrome-headless-shell'],
|
||||
[Browser.CHROME]: {
|
||||
buildId:
|
||||
puppeteer.configuration.chrome?.version ||
|
||||
PUPPETEER_REVISIONS['chrome'] ||
|
||||
'latest',
|
||||
skipDownload: puppeteer.configuration.chrome?.skipDownload ?? false,
|
||||
},
|
||||
[Browser.FIREFOX]: {
|
||||
buildId:
|
||||
puppeteer.configuration.firefox?.version ||
|
||||
PUPPETEER_REVISIONS['firefox'] ||
|
||||
'latest',
|
||||
skipDownload: puppeteer.configuration.firefox?.skipDownload ?? true,
|
||||
},
|
||||
[Browser.CHROMEHEADLESSSHELL]: {
|
||||
buildId:
|
||||
puppeteer.configuration['chrome-headless-shell']?.version ||
|
||||
PUPPETEER_REVISIONS['chrome-headless-shell'] ||
|
||||
'latest',
|
||||
skipDownload:
|
||||
puppeteer.configuration['chrome-headless-shell']?.skipDownload ?? false,
|
||||
},
|
||||
},
|
||||
}).run(process.argv);
|
||||
|
||||
197
Scripts/node_modules/puppeteer/src/node/install.ts
generated
vendored
197
Scripts/node_modules/puppeteer/src/node/install.ts
generated
vendored
@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {BrowserPlatform} from '@puppeteer/browsers';
|
||||
import {
|
||||
install,
|
||||
Browser,
|
||||
@ -11,126 +12,120 @@ import {
|
||||
makeProgressCallback,
|
||||
detectBrowserPlatform,
|
||||
} from '@puppeteer/browsers';
|
||||
import type {Product} from 'puppeteer-core';
|
||||
import type {
|
||||
ChromeHeadlessShellSettings,
|
||||
ChromeSettings,
|
||||
FirefoxSettings,
|
||||
} from 'puppeteer-core';
|
||||
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
|
||||
|
||||
import {getConfiguration} from '../getConfiguration.js';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
const supportedProducts = {
|
||||
chrome: 'Chrome',
|
||||
firefox: 'Firefox Nightly',
|
||||
} as const;
|
||||
async function downloadBrowser({
|
||||
browser,
|
||||
configuration,
|
||||
cacheDir,
|
||||
platform,
|
||||
}: {
|
||||
browser: Extract<
|
||||
Browser,
|
||||
Browser.CHROME | Browser.CHROMEHEADLESSSHELL | Browser.FIREFOX
|
||||
>;
|
||||
configuration: ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings;
|
||||
platform: BrowserPlatform;
|
||||
cacheDir: string;
|
||||
}) {
|
||||
const unresolvedBuildId =
|
||||
configuration?.version || PUPPETEER_REVISIONS[browser] || 'latest';
|
||||
const baseUrl = configuration?.downloadBaseUrl;
|
||||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
|
||||
|
||||
try {
|
||||
const result = await install({
|
||||
browser,
|
||||
cacheDir,
|
||||
platform,
|
||||
buildId,
|
||||
downloadProgressCallback: makeProgressCallback(browser, buildId),
|
||||
baseUrl,
|
||||
buildIdAlias:
|
||||
buildId !== unresolvedBuildId ? unresolvedBuildId : undefined,
|
||||
});
|
||||
logPolitely(`${browser} (${result.buildId}) downloaded to ${result.path}`);
|
||||
} catch (error) {
|
||||
throw new Error(
|
||||
`ERROR: Failed to set up ${browser} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`,
|
||||
{
|
||||
cause: error,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export async function downloadBrowser(): Promise<void> {
|
||||
export async function downloadBrowsers(): Promise<void> {
|
||||
overrideProxy();
|
||||
|
||||
const configuration = getConfiguration();
|
||||
if (configuration.skipDownload) {
|
||||
logPolitely('**INFO** Skipping browser download as instructed.');
|
||||
logPolitely('**INFO** Skipping downloading browsers as instructed.');
|
||||
return;
|
||||
}
|
||||
|
||||
const downloadBaseUrl = configuration.downloadBaseUrl;
|
||||
|
||||
const platform = detectBrowserPlatform();
|
||||
if (!platform) {
|
||||
throw new Error('The current platform is not supported.');
|
||||
}
|
||||
const cacheDir = configuration.cacheDirectory!;
|
||||
|
||||
const product = configuration.defaultProduct!;
|
||||
const browser = productToBrowser(product);
|
||||
const installationJobs = [];
|
||||
if (configuration.chrome?.skipDownload) {
|
||||
logPolitely('**INFO** Skipping Chrome download as instructed.');
|
||||
} else {
|
||||
const browser = Browser.CHROME;
|
||||
installationJobs.push(
|
||||
downloadBrowser({
|
||||
browser,
|
||||
configuration: configuration[browser] ?? {},
|
||||
cacheDir,
|
||||
platform,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const unresolvedBuildId =
|
||||
configuration.browserRevision || PUPPETEER_REVISIONS[product] || 'latest';
|
||||
const unresolvedShellBuildId =
|
||||
configuration.browserRevision ||
|
||||
PUPPETEER_REVISIONS['chrome-headless-shell'] ||
|
||||
'latest';
|
||||
if (configuration['chrome-headless-shell']?.skipDownload) {
|
||||
logPolitely('**INFO** Skipping Chrome download as instructed.');
|
||||
} else {
|
||||
const browser = Browser.CHROMEHEADLESSSHELL;
|
||||
|
||||
// TODO: deprecate downloadPath in favour of cacheDirectory.
|
||||
const cacheDir = configuration.downloadPath ?? configuration.cacheDirectory!;
|
||||
installationJobs.push(
|
||||
downloadBrowser({
|
||||
browser,
|
||||
configuration: configuration[browser] ?? {},
|
||||
cacheDir,
|
||||
platform,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (configuration.firefox?.skipDownload) {
|
||||
logPolitely('**INFO** Skipping Firefox download as instructed.');
|
||||
} else {
|
||||
const browser = Browser.FIREFOX;
|
||||
|
||||
installationJobs.push(
|
||||
downloadBrowser({
|
||||
browser,
|
||||
configuration: configuration[browser] ?? {},
|
||||
cacheDir,
|
||||
platform,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const installationJobs = [];
|
||||
|
||||
if (configuration.skipChromeDownload) {
|
||||
logPolitely('**INFO** Skipping Chrome download as instructed.');
|
||||
} else {
|
||||
const buildId = await resolveBuildId(
|
||||
browser,
|
||||
platform,
|
||||
unresolvedBuildId
|
||||
);
|
||||
installationJobs.push(
|
||||
install({
|
||||
browser,
|
||||
cacheDir,
|
||||
platform,
|
||||
buildId,
|
||||
downloadProgressCallback: makeProgressCallback(browser, buildId),
|
||||
baseUrl: downloadBaseUrl,
|
||||
})
|
||||
.then(result => {
|
||||
logPolitely(
|
||||
`${supportedProducts[product]} (${result.buildId}) downloaded to ${result.path}`
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
throw new Error(
|
||||
`ERROR: Failed to set up ${supportedProducts[product]} v${buildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`,
|
||||
{
|
||||
cause: error,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (browser === Browser.CHROME) {
|
||||
if (configuration.skipChromeHeadlessShellDownload) {
|
||||
logPolitely('**INFO** Skipping Chrome download as instructed.');
|
||||
} else {
|
||||
const shellBuildId = await resolveBuildId(
|
||||
browser,
|
||||
platform,
|
||||
unresolvedShellBuildId
|
||||
);
|
||||
|
||||
installationJobs.push(
|
||||
install({
|
||||
browser: Browser.CHROMEHEADLESSSHELL,
|
||||
cacheDir,
|
||||
platform,
|
||||
buildId: shellBuildId,
|
||||
downloadProgressCallback: makeProgressCallback(
|
||||
browser,
|
||||
shellBuildId
|
||||
),
|
||||
baseUrl: downloadBaseUrl,
|
||||
})
|
||||
.then(result => {
|
||||
logPolitely(
|
||||
`${Browser.CHROMEHEADLESSSHELL} (${result.buildId}) downloaded to ${result.path}`
|
||||
);
|
||||
})
|
||||
.catch(error => {
|
||||
throw new Error(
|
||||
`ERROR: Failed to set up ${Browser.CHROMEHEADLESSSHELL} v${shellBuildId}! Set "PUPPETEER_SKIP_DOWNLOAD" env variable to skip download.`,
|
||||
{
|
||||
cause: error,
|
||||
}
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(installationJobs);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -138,16 +133,6 @@ export async function downloadBrowser(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
function productToBrowser(product?: Product) {
|
||||
switch (product) {
|
||||
case 'chrome':
|
||||
return Browser.CHROME;
|
||||
case 'firefox':
|
||||
return Browser.FIREFOX;
|
||||
}
|
||||
return Browser.CHROME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user