Node updated. Some todos.
This commit is contained in:
136
Scripts/node_modules/@puppeteer/browsers/lib/cjs/install.js
generated
vendored
136
Scripts/node_modules/@puppeteer/browsers/lib/cjs/install.js
generated
vendored
@ -10,6 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.canDownload = exports.getInstalledBrowsers = exports.uninstall = exports.install = void 0;
|
||||
const assert_1 = __importDefault(require("assert"));
|
||||
const child_process_1 = require("child_process");
|
||||
const fs_1 = require("fs");
|
||||
const promises_1 = require("fs/promises");
|
||||
const os_1 = __importDefault(require("os"));
|
||||
@ -41,6 +42,90 @@ async function install(options) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
const url = getDownloadUrl(options.browser, options.platform, options.buildId, options.baseUrl);
|
||||
try {
|
||||
return await installUrl(url, options);
|
||||
}
|
||||
catch (err) {
|
||||
// If custom baseUrl is provided, do not fall back to CfT dashboard.
|
||||
if (options.baseUrl && !options.forceFallbackForTesting) {
|
||||
throw err;
|
||||
}
|
||||
debugInstall(`Error downloading from ${url}.`);
|
||||
switch (options.browser) {
|
||||
case browser_data_js_1.Browser.CHROME:
|
||||
case browser_data_js_1.Browser.CHROMEDRIVER:
|
||||
case browser_data_js_1.Browser.CHROMEHEADLESSSHELL: {
|
||||
debugInstall(`Trying to find download URL via https://googlechromelabs.github.io/chrome-for-testing.`);
|
||||
const version = (await (0, httpUtil_js_1.getJSON)(new URL(`https://googlechromelabs.github.io/chrome-for-testing/${options.buildId}.json`)));
|
||||
let platform = '';
|
||||
switch (options.platform) {
|
||||
case browser_data_js_1.BrowserPlatform.LINUX:
|
||||
platform = 'linux64';
|
||||
break;
|
||||
case browser_data_js_1.BrowserPlatform.MAC_ARM:
|
||||
platform = 'mac-arm64';
|
||||
break;
|
||||
case browser_data_js_1.BrowserPlatform.MAC:
|
||||
platform = 'mac-x64';
|
||||
break;
|
||||
case browser_data_js_1.BrowserPlatform.WIN32:
|
||||
platform = 'win32';
|
||||
break;
|
||||
case browser_data_js_1.BrowserPlatform.WIN64:
|
||||
platform = 'win64';
|
||||
break;
|
||||
}
|
||||
const url = version.downloads[options.browser]?.find(link => {
|
||||
return link['platform'] === platform;
|
||||
})?.url;
|
||||
if (url) {
|
||||
debugInstall(`Falling back to downloading from ${url}.`);
|
||||
return await installUrl(new URL(url), options);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
default:
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.install = install;
|
||||
async function installDeps(installedBrowser) {
|
||||
if (process.platform !== 'linux' ||
|
||||
installedBrowser.platform !== browser_data_js_1.BrowserPlatform.LINUX) {
|
||||
return;
|
||||
}
|
||||
// Currently, only Debian-like deps are supported.
|
||||
const depsPath = path_1.default.join(path_1.default.dirname(installedBrowser.executablePath), 'deb.deps');
|
||||
if (!(0, fs_1.existsSync)(depsPath)) {
|
||||
debugInstall(`deb.deps file was not found at ${depsPath}`);
|
||||
return;
|
||||
}
|
||||
const data = (0, fs_1.readFileSync)(depsPath, 'utf-8').split('\n').join(',');
|
||||
if (process.getuid?.() !== 0) {
|
||||
throw new Error('Installing system dependencies requires root privileges');
|
||||
}
|
||||
let result = (0, child_process_1.spawnSync)('apt-get', ['-v']);
|
||||
if (result.status !== 0) {
|
||||
throw new Error('Failed to install system dependencies: apt-get does not seem to be available');
|
||||
}
|
||||
debugInstall(`Trying to install dependencies: ${data}`);
|
||||
result = (0, child_process_1.spawnSync)('apt-get', [
|
||||
'satisfy',
|
||||
'-y',
|
||||
data,
|
||||
'--no-install-recommends',
|
||||
]);
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`Failed to install system dependencies: status=${result.status},error=${result.error},stdout=${result.stdout.toString('utf8')},stderr=${result.stderr.toString('utf8')}`);
|
||||
}
|
||||
debugInstall(`Installed system dependencies ${data}`);
|
||||
}
|
||||
async function installUrl(url, options) {
|
||||
options.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)();
|
||||
if (!options.platform) {
|
||||
throw new Error(`Cannot download a binary for the provided platform: ${os_1.default.platform()} (${os_1.default.arch()})`);
|
||||
}
|
||||
const fileName = url.toString().split('/').pop();
|
||||
(0, assert_1.default)(fileName, `A malformed download URL was found: ${url}.`);
|
||||
const cache = new Cache_js_1.Cache(options.cacheDir);
|
||||
@ -60,10 +145,18 @@ async function install(options) {
|
||||
return archivePath;
|
||||
}
|
||||
const outputPath = cache.installationDir(options.browser, options.platform, options.buildId);
|
||||
if ((0, fs_1.existsSync)(outputPath)) {
|
||||
return new Cache_js_1.InstalledBrowser(cache, options.browser, options.buildId, options.platform);
|
||||
}
|
||||
try {
|
||||
if ((0, fs_1.existsSync)(outputPath)) {
|
||||
const installedBrowser = new Cache_js_1.InstalledBrowser(cache, options.browser, options.buildId, options.platform);
|
||||
if (!(0, fs_1.existsSync)(installedBrowser.executablePath)) {
|
||||
throw new Error(`The browser folder (${outputPath}) exists but the executable (${installedBrowser.executablePath}) is missing`);
|
||||
}
|
||||
await runSetup(installedBrowser);
|
||||
if (options.installDeps) {
|
||||
await installDeps(installedBrowser);
|
||||
}
|
||||
return installedBrowser;
|
||||
}
|
||||
debugInstall(`Downloading binary from ${url}`);
|
||||
try {
|
||||
debugTime('download');
|
||||
@ -80,15 +173,48 @@ async function install(options) {
|
||||
finally {
|
||||
debugTimeEnd('extract');
|
||||
}
|
||||
const installedBrowser = new Cache_js_1.InstalledBrowser(cache, options.browser, options.buildId, options.platform);
|
||||
if (options.buildIdAlias) {
|
||||
const metadata = installedBrowser.readMetadata();
|
||||
metadata.aliases[options.buildIdAlias] = options.buildId;
|
||||
installedBrowser.writeMetadata(metadata);
|
||||
}
|
||||
await runSetup(installedBrowser);
|
||||
if (options.installDeps) {
|
||||
await installDeps(installedBrowser);
|
||||
}
|
||||
return installedBrowser;
|
||||
}
|
||||
finally {
|
||||
if ((0, fs_1.existsSync)(archivePath)) {
|
||||
await (0, promises_1.unlink)(archivePath);
|
||||
}
|
||||
}
|
||||
return new Cache_js_1.InstalledBrowser(cache, options.browser, options.buildId, options.platform);
|
||||
}
|
||||
exports.install = install;
|
||||
async function runSetup(installedBrowser) {
|
||||
// On Windows for Chrome invoke setup.exe to configure sandboxes.
|
||||
if ((installedBrowser.platform === browser_data_js_1.BrowserPlatform.WIN32 ||
|
||||
installedBrowser.platform === browser_data_js_1.BrowserPlatform.WIN64) &&
|
||||
installedBrowser.browser === browser_data_js_1.Browser.CHROME &&
|
||||
installedBrowser.platform === (0, detectPlatform_js_1.detectBrowserPlatform)()) {
|
||||
try {
|
||||
debugTime('permissions');
|
||||
const browserDir = path_1.default.dirname(installedBrowser.executablePath);
|
||||
const setupExePath = path_1.default.join(browserDir, 'setup.exe');
|
||||
if (!(0, fs_1.existsSync)(setupExePath)) {
|
||||
return;
|
||||
}
|
||||
(0, child_process_1.spawnSync)(path_1.default.join(browserDir, 'setup.exe'), [`--configure-browser-in-directory=` + browserDir], {
|
||||
shell: true,
|
||||
});
|
||||
// TODO: Handle error here. Currently the setup.exe sometimes
|
||||
// errors although it sets the permissions correctly.
|
||||
}
|
||||
finally {
|
||||
debugTimeEnd('permissions');
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @public
|
||||
|
||||
Reference in New Issue
Block a user