Node updated. Some todos.

This commit is contained in:
Norm Rasmussen
2024-09-23 20:52:09 -04:00
parent 8bfaca8375
commit f25622067f
2041 changed files with 124145 additions and 110445 deletions

View File

@ -121,8 +121,10 @@ class CLI {
}
#build(yargs) {
const latestOrPinned = this.#pinnedBrowsers ? 'pinned' : 'latest';
// If there are pinned browsers allow the positional arg to be optional
const browserArgType = this.#pinnedBrowsers ? '[browser]' : '<browser>';
return yargs
.command('install <browser>', 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => {
.command(`install ${browserArgType}`, 'Download and install the specified browser. If successful, the command outputs the actual browser buildId that was installed and the absolute path to the browser executable (format: <browser>@<buildID> <path>).', yargs => {
this.#defineBrowserParameter(yargs);
this.#definePlatformParameter(yargs);
this.#definePathParameter(yargs);
@ -130,8 +132,19 @@ class CLI {
type: 'string',
desc: 'Base URL to download from',
});
if (this.#pinnedBrowsers) {
yargs.example('$0 install', 'Install all pinned browsers');
}
yargs.option('install-deps', {
type: 'boolean',
desc: 'Whether to attempt installing system dependencies (only supported on Linux, requires root privileges).',
default: false,
});
yargs.example('$0 install chrome', `Install the ${latestOrPinned} available build of the Chrome browser.`);
yargs.example('$0 install chrome@latest', 'Install the latest available build for the Chrome browser.');
yargs.example('$0 install chrome@stable', 'Install the latest available build for the Chrome browser from the stable channel.');
yargs.example('$0 install chrome@beta', 'Install the latest available build for the Chrome browser from the beta channel.');
yargs.example('$0 install chrome@dev', 'Install the latest available build for the Chrome browser from the dev channel.');
yargs.example('$0 install chrome@canary', 'Install the latest available build for the Chrome Canary browser.');
yargs.example('$0 install chrome@115', 'Install the latest available build for Chrome 115.');
yargs.example('$0 install chromedriver@canary', 'Install the latest available build for ChromeDriver Canary.');
@ -141,39 +154,44 @@ class CLI {
yargs.example('$0 install chrome-headless-shell@beta', 'Install the latest available chrome-headless-shell build corresponding to the Beta channel.');
yargs.example('$0 install chrome-headless-shell@118', 'Install the latest available chrome-headless-shell 118 build.');
yargs.example('$0 install chromium@1083080', 'Install the revision 1083080 of the Chromium browser.');
yargs.example('$0 install firefox', 'Install the latest available build of the Firefox browser.');
yargs.example('$0 install firefox', 'Install the latest nightly available build of the Firefox browser.');
yargs.example('$0 install firefox@stable', 'Install the latest stable build of the Firefox browser.');
yargs.example('$0 install firefox@beta', 'Install the latest beta build of the Firefox browser.');
yargs.example('$0 install firefox@devedition', 'Install the latest devedition build of the Firefox browser.');
yargs.example('$0 install firefox@esr', 'Install the latest ESR build of the Firefox browser.');
yargs.example('$0 install firefox@nightly', 'Install the latest nightly build of the Firefox browser.');
yargs.example('$0 install firefox@stable_111.0.1', 'Install a specific version of the Firefox browser.');
yargs.example('$0 install firefox --platform mac', 'Install the latest Mac (Intel) build of the Firefox browser.');
if (this.#allowCachePathOverride) {
yargs.example('$0 install firefox --path /tmp/my-browser-cache', 'Install to the specified cache directory.');
}
}, async (argv) => {
const args = argv;
args.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)();
if (!args.platform) {
throw new Error(`Could not resolve the current platform`);
}
if (args.browser.buildId === 'pinned') {
const pinnedVersion = this.#pinnedBrowsers?.[args.browser.name];
if (!pinnedVersion) {
throw new Error(`No pinned version found for ${args.browser.name}`);
if (this.#pinnedBrowsers && !args.browser) {
// Use allSettled to avoid scenarios that
// a browser may fail early and leave the other
// installation in a faulty state
const result = await Promise.allSettled(Object.entries(this.#pinnedBrowsers).map(async ([browser, options]) => {
if (options.skipDownload) {
return;
}
await this.#install({
...argv,
browser: {
name: browser,
buildId: options.buildId,
},
});
}));
for (const install of result) {
if (install.status === 'rejected') {
throw install.reason;
}
}
args.browser.buildId = pinnedVersion;
}
args.browser.buildId = await (0, browser_data_js_1.resolveBuildId)(args.browser.name, args.platform, args.browser.buildId);
await (0, install_js_1.install)({
browser: args.browser.name,
buildId: args.browser.buildId,
platform: args.platform,
cacheDir: args.path ?? this.#cachePath,
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId),
baseUrl: args.baseUrl,
});
console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({
browser: args.browser.name,
buildId: args.browser.buildId,
cacheDir: args.path ?? this.#cachePath,
platform: args.platform,
})}`);
else {
await this.#install(args);
}
})
.command('launch <browser>', 'Launch the specified browser', yargs => {
this.#defineBrowserParameter(yargs);
@ -246,6 +264,40 @@ class CLI {
? 'pinned'
: 'latest';
}
async #install(args) {
args.platform ??= (0, detectPlatform_js_1.detectBrowserPlatform)();
if (!args.browser) {
throw new Error(`No browser arg proveded`);
}
if (!args.platform) {
throw new Error(`Could not resolve the current platform`);
}
if (args.browser.buildId === 'pinned') {
const options = this.#pinnedBrowsers?.[args.browser.name];
if (!options || !options.buildId) {
throw new Error(`No pinned version found for ${args.browser.name}`);
}
args.browser.buildId = options.buildId;
}
const originalBuildId = args.browser.buildId;
args.browser.buildId = await (0, browser_data_js_1.resolveBuildId)(args.browser.name, args.platform, args.browser.buildId);
await (0, install_js_1.install)({
browser: args.browser.name,
buildId: args.browser.buildId,
platform: args.platform,
cacheDir: args.path ?? this.#cachePath,
downloadProgressCallback: makeProgressCallback(args.browser.name, args.browser.buildId),
baseUrl: args.baseUrl,
buildIdAlias: originalBuildId !== args.browser.buildId ? originalBuildId : undefined,
installDeps: args.installDeps,
});
console.log(`${args.browser.name}@${args.browser.buildId} ${(0, launch_js_1.computeExecutablePath)({
browser: args.browser.name,
buildId: args.browser.buildId,
cacheDir: args.path ?? this.#cachePath,
platform: args.platform,
})}`);
}
}
exports.CLI = CLI;
/**
@ -256,7 +308,7 @@ function makeProgressCallback(browser, buildId) {
let lastDownloadedBytes = 0;
return (downloadedBytes, totalBytes) => {
if (!progressBar) {
progressBar = new progress_1.default(`Downloading ${browser} r${buildId} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
progressBar = new progress_1.default(`Downloading ${browser} ${buildId} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
complete: '=',
incomplete: ' ',
width: 20,