chore: 更新学生档案数据
This commit is contained in:
177
node_modules/puppeteer/src/getConfiguration.ts
generated
vendored
Normal file
177
node_modules/puppeteer/src/getConfiguration.ts
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {homedir} from 'node:os';
|
||||
import {join} from 'node:path';
|
||||
|
||||
import {lilconfig} from 'lilconfig';
|
||||
import type {
|
||||
ChromeHeadlessShellSettings,
|
||||
ChromeSettings,
|
||||
Configuration,
|
||||
FirefoxSettings,
|
||||
SupportedBrowser,
|
||||
} from 'puppeteer-core';
|
||||
|
||||
function getBooleanEnvVar(name: string): boolean | undefined {
|
||||
const env = process.env[name];
|
||||
if (env === undefined) {
|
||||
return;
|
||||
}
|
||||
switch (env.toLowerCase()) {
|
||||
case '':
|
||||
case '0':
|
||||
case 'false':
|
||||
case 'off':
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function isSupportedBrowser(product: unknown): product is SupportedBrowser {
|
||||
switch (product) {
|
||||
case 'chrome':
|
||||
case 'firefox':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getDefaultBrowser(browser?: unknown): SupportedBrowser {
|
||||
if (!browser) {
|
||||
return 'chrome';
|
||||
}
|
||||
if (!isSupportedBrowser(browser)) {
|
||||
throw new Error(`Unsupported browser ${browser}`);
|
||||
}
|
||||
return browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function getLogLevel(logLevel: unknown): 'silent' | 'error' | 'warn' {
|
||||
switch (logLevel) {
|
||||
case 'silent':
|
||||
return 'silent';
|
||||
case 'error':
|
||||
return 'error';
|
||||
default:
|
||||
return 'warn';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export function getBrowserSetting(
|
||||
browser: 'chrome' | 'chrome-headless-shell' | 'firefox',
|
||||
configuration: Configuration,
|
||||
defaultConfig:
|
||||
| ChromeSettings
|
||||
| ChromeHeadlessShellSettings
|
||||
| FirefoxSettings = {},
|
||||
): ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings {
|
||||
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 ??
|
||||
configuration.skipDownload ??
|
||||
defaultConfig.skipDownload;
|
||||
|
||||
return browserSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export const getConfiguration = async (): Promise<Configuration> => {
|
||||
const result = await lilconfig('puppeteer', {
|
||||
searchPlaces: [
|
||||
'package.json',
|
||||
'.config/puppeteer.config.cjs',
|
||||
'.config/puppeteer.config.js',
|
||||
'.config/puppeteerrc.cjs',
|
||||
'.config/puppeteerrc.js',
|
||||
'.config/puppeteerrc.json',
|
||||
'.config/puppeteerrc',
|
||||
'.puppeteerrc.cjs',
|
||||
'.puppeteerrc.js',
|
||||
'.puppeteerrc.json',
|
||||
'.puppeteerrc',
|
||||
'puppeteer.config.cjs',
|
||||
'puppeteer.config.js',
|
||||
],
|
||||
}).search();
|
||||
const configuration: Configuration = result ? {...result.config} : {};
|
||||
|
||||
configuration.logLevel = getLogLevel(
|
||||
process.env['PUPPETEER_LOGLEVEL'] ?? configuration.logLevel,
|
||||
);
|
||||
|
||||
// Merging environment variables.
|
||||
configuration.defaultBrowser = getDefaultBrowser(
|
||||
process.env['PUPPETEER_BROWSER'] ?? configuration.defaultBrowser,
|
||||
);
|
||||
|
||||
configuration.executablePath =
|
||||
process.env['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 =
|
||||
getBooleanEnvVar('PUPPETEER_SKIP_DOWNLOAD') ?? configuration.skipDownload;
|
||||
|
||||
// Prepare variables used in browser downloading
|
||||
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'] ??
|
||||
configuration.cacheDirectory ??
|
||||
join(homedir(), '.cache', 'puppeteer');
|
||||
|
||||
configuration.temporaryDirectory =
|
||||
process.env['PUPPETEER_TMP_DIR'] ?? configuration.temporaryDirectory;
|
||||
|
||||
configuration.experiments ??= {};
|
||||
|
||||
return configuration;
|
||||
};
|
||||
46
node_modules/puppeteer/src/node/cli.ts
generated
vendored
Normal file
46
node_modules/puppeteer/src/node/cli.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2023 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import {CLI, Browser} from '@puppeteer/browsers';
|
||||
import type {PuppeteerNode} from 'puppeteer-core/internal/node/PuppeteerNode.js';
|
||||
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
|
||||
import {packageVersion} from 'puppeteer-core/internal/util/version.js';
|
||||
|
||||
import puppeteer from '../puppeteer.js';
|
||||
|
||||
const config = await (puppeteer as unknown as PuppeteerNode).configuration();
|
||||
|
||||
void new CLI({
|
||||
cachePath: config.cacheDirectory!,
|
||||
scriptName: 'puppeteer',
|
||||
version: packageVersion,
|
||||
prefixCommand: {
|
||||
cmd: 'browsers',
|
||||
description: 'Manage browsers of this Puppeteer installation',
|
||||
},
|
||||
allowCachePathOverride: false,
|
||||
pinnedBrowsers: {
|
||||
[Browser.CHROME]: {
|
||||
buildId:
|
||||
config.chrome?.version || PUPPETEER_REVISIONS['chrome'] || 'latest',
|
||||
skipDownload: config.chrome?.skipDownload ?? false,
|
||||
},
|
||||
[Browser.FIREFOX]: {
|
||||
buildId:
|
||||
config.firefox?.version || PUPPETEER_REVISIONS['firefox'] || 'latest',
|
||||
skipDownload: config.firefox?.skipDownload ?? true,
|
||||
},
|
||||
[Browser.CHROMEHEADLESSSHELL]: {
|
||||
buildId:
|
||||
config['chrome-headless-shell']?.version ||
|
||||
PUPPETEER_REVISIONS['chrome-headless-shell'] ||
|
||||
'latest',
|
||||
skipDownload: config['chrome-headless-shell']?.skipDownload ?? false,
|
||||
},
|
||||
},
|
||||
}).run(process.argv);
|
||||
180
node_modules/puppeteer/src/node/install.ts
generated
vendored
Normal file
180
node_modules/puppeteer/src/node/install.ts
generated
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import type {BrowserPlatform} from '@puppeteer/browsers';
|
||||
import {
|
||||
install,
|
||||
Browser,
|
||||
resolveBuildId,
|
||||
detectBrowserPlatform,
|
||||
} from '@puppeteer/browsers';
|
||||
import type {
|
||||
ChromeHeadlessShellSettings,
|
||||
ChromeSettings,
|
||||
FirefoxSettings,
|
||||
} from 'puppeteer-core';
|
||||
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
|
||||
|
||||
import {getConfiguration} from '../getConfiguration.js';
|
||||
|
||||
async function downloadBrowser({
|
||||
browser,
|
||||
configuration,
|
||||
cacheDir,
|
||||
platform,
|
||||
}: {
|
||||
browser: Extract<
|
||||
Browser,
|
||||
Browser.CHROME | Browser.CHROMEHEADLESSSHELL | Browser.FIREFOX
|
||||
>;
|
||||
configuration: ChromeSettings | ChromeHeadlessShellSettings | FirefoxSettings;
|
||||
platform: BrowserPlatform;
|
||||
cacheDir: string;
|
||||
}): Promise<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: 'default',
|
||||
baseUrl,
|
||||
buildIdAlias:
|
||||
buildId !== unresolvedBuildId ? unresolvedBuildId : undefined,
|
||||
});
|
||||
return `${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 downloadBrowsers(): Promise<void> {
|
||||
overrideProxy();
|
||||
|
||||
const configuration = await getConfiguration();
|
||||
if (configuration.skipDownload) {
|
||||
logPolitely('**INFO** Skipping downloading browsers as instructed.');
|
||||
return;
|
||||
}
|
||||
|
||||
const platform = detectBrowserPlatform();
|
||||
if (!platform) {
|
||||
throw new Error('The current platform is not supported.');
|
||||
}
|
||||
const cacheDir = configuration.cacheDirectory!;
|
||||
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (configuration['chrome-headless-shell']?.skipDownload) {
|
||||
logPolitely('**INFO** Skipping Chrome download as instructed.');
|
||||
} else {
|
||||
const browser = Browser.CHROMEHEADLESSSHELL;
|
||||
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const results = await Promise.allSettled(installationJobs);
|
||||
|
||||
// Log success messages only after all downloads+extraction complete so they
|
||||
// never land mid-progress-bar while the cursor is on a bar line.
|
||||
for (const result of results) {
|
||||
if (result.status === 'fulfilled') {
|
||||
logPolitely(result.value);
|
||||
}
|
||||
}
|
||||
|
||||
const failures = results.filter(r => {
|
||||
return r.status === 'rejected';
|
||||
});
|
||||
if (failures.length > 0) {
|
||||
for (const failure of failures) {
|
||||
console.error(failure.reason);
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function logPolitely(toBeLogged: unknown): void {
|
||||
const logLevel = process.env['npm_config_loglevel'] || '';
|
||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
||||
|
||||
if (!logLevelDisplay) {
|
||||
console.log(toBeLogged);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
function overrideProxy() {
|
||||
// Override current environment proxy settings with npm configuration, if any.
|
||||
const NPM_HTTPS_PROXY =
|
||||
process.env['npm_config_https_proxy'] || process.env['npm_config_proxy'];
|
||||
const NPM_HTTP_PROXY =
|
||||
process.env['npm_config_http_proxy'] || process.env['npm_config_proxy'];
|
||||
const NPM_NO_PROXY = process.env['npm_config_no_proxy'];
|
||||
|
||||
if (NPM_HTTPS_PROXY) {
|
||||
process.env['HTTPS_PROXY'] = NPM_HTTPS_PROXY;
|
||||
}
|
||||
if (NPM_HTTP_PROXY) {
|
||||
process.env['HTTP_PROXY'] = NPM_HTTP_PROXY;
|
||||
}
|
||||
if (NPM_NO_PROXY) {
|
||||
process.env['NO_PROXY'] = NPM_NO_PROXY;
|
||||
}
|
||||
}
|
||||
45
node_modules/puppeteer/src/puppeteer.ts
generated
vendored
Normal file
45
node_modules/puppeteer/src/puppeteer.ts
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2017 Google Inc.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
export * from 'puppeteer-core';
|
||||
|
||||
import {PuppeteerNode} from 'puppeteer-core';
|
||||
|
||||
import {getConfiguration} from './getConfiguration.js';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
// @ts-expect-error using internal API.
|
||||
const puppeteer = new PuppeteerNode({
|
||||
isPuppeteerCore: false,
|
||||
configuration: getConfiguration,
|
||||
});
|
||||
|
||||
export const {
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
connect,
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
defaultArgs,
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
executablePath,
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
launch,
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
trimCache,
|
||||
} = puppeteer;
|
||||
|
||||
export default puppeteer;
|
||||
Reference in New Issue
Block a user