From 24bd05877de9c8b310a150976668743f73c94f10 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 6 Apr 2023 13:23:28 +0200 Subject: [PATCH] refactor: rename fetch->install, launcher->launch (#9985) --- packages/browsers/src/CLI.ts | 6 ++--- .../browsers/src/{fetch.ts => install.ts} | 24 +++++++++---------- .../browsers/src/{launcher.ts => launch.ts} | 4 ++-- packages/browsers/src/main.ts | 4 ++-- .../chrome/{fetch.spec.ts => install.spec.ts} | 22 ++++++++--------- .../{launcher.spec.ts => launch.spec.ts} | 4 ++-- .../{launcher.spec.ts => launch.spec.ts} | 4 ++-- .../{fetch.spec.ts => install.spec.ts} | 10 ++++---- .../firefox/{launcher.spec.ts => launch.ts} | 4 ++-- packages/browsers/test/src/utils.ts | 2 +- .../browsers/tools/downloadTestBrowsers.mjs | 6 ++--- packages/puppeteer/src/node/install.ts | 4 ++-- 12 files changed, 47 insertions(+), 47 deletions(-) rename packages/browsers/src/{fetch.ts => install.ts} (89%) rename packages/browsers/src/{launcher.ts => launch.ts} (99%) rename packages/browsers/test/src/chrome/{fetch.spec.ts => install.spec.ts} (93%) rename packages/browsers/test/src/chrome/{launcher.spec.ts => launch.spec.ts} (99%) rename packages/browsers/test/src/chromium/{launcher.spec.ts => launch.spec.ts} (99%) rename packages/browsers/test/src/firefox/{fetch.spec.ts => install.spec.ts} (91%) rename packages/browsers/test/src/firefox/{launcher.spec.ts => launch.ts} (98%) diff --git a/packages/browsers/src/CLI.ts b/packages/browsers/src/CLI.ts index 1d4947324e1..4a7818a687e 100644 --- a/packages/browsers/src/CLI.ts +++ b/packages/browsers/src/CLI.ts @@ -30,12 +30,12 @@ import { } from './browser-data/browser-data.js'; import {Cache} from './Cache.js'; import {detectBrowserPlatform} from './detectPlatform.js'; -import {fetch} from './fetch.js'; +import {install} from './install.js'; import { computeExecutablePath, computeSystemExecutablePath, launch, -} from './launcher.js'; +} from './launch.js'; type InstallArgs = { browser: { @@ -157,7 +157,7 @@ export class CLI { args.platform, args.browser.buildId ); - await fetch({ + await install({ browser: args.browser.name, buildId: args.browser.buildId, platform: args.platform, diff --git a/packages/browsers/src/fetch.ts b/packages/browsers/src/install.ts similarity index 89% rename from packages/browsers/src/fetch.ts rename to packages/browsers/src/install.ts index 970a042fe73..8afe6e530d4 100644 --- a/packages/browsers/src/fetch.ts +++ b/packages/browsers/src/install.ts @@ -31,7 +31,7 @@ import {detectBrowserPlatform} from './detectPlatform.js'; import {unpackArchive} from './fileUtil.js'; import {downloadFile, headHttpRequest} from './httpUtil.js'; -const debugFetch = debug('puppeteer:browsers:fetcher'); +const debugInstall = debug('puppeteer:browsers:install'); const times = new Map(); function debugTime(label: string) { @@ -46,7 +46,7 @@ function debugTimeEnd(label: string) { } const duration = end[0] * 1000 + end[1] / 1e6 - (start[0] * 1000 + start[1] / 1e6); // calculate duration in milliseconds - debugFetch(`Duration for ${label}: ${duration}ms`); + debugInstall(`Duration for ${label}: ${duration}ms`); } /** @@ -64,7 +64,7 @@ export interface Options { */ platform?: BrowserPlatform; /** - * Determines which browser to fetch. + * Determines which browser to install. */ browser: Browser; /** @@ -94,7 +94,7 @@ export interface Options { * * @defaultValue `true` */ - install?: boolean; + unpack?: boolean; } export type InstalledBrowser = { @@ -104,9 +104,9 @@ export type InstalledBrowser = { platform: BrowserPlatform; }; -export async function fetch(options: Options): Promise { +export async function install(options: Options): Promise { options.platform ??= detectBrowserPlatform(); - options.install ??= true; + options.unpack ??= true; if (!options.platform) { throw new Error( `Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})` @@ -127,7 +127,7 @@ export async function fetch(options: Options): Promise { await mkdir(browserRoot, {recursive: true}); } - if (!options.install) { + if (!options.unpack) { if (existsSync(archivePath)) { return { path: archivePath, @@ -136,7 +136,7 @@ export async function fetch(options: Options): Promise { buildId: options.buildId, }; } - debugFetch(`Downloading binary from ${url}`); + debugInstall(`Downloading binary from ${url}`); debugTime('download'); await downloadFile(url, archivePath, options.downloadProgressCallback); debugTimeEnd('download'); @@ -162,7 +162,7 @@ export async function fetch(options: Options): Promise { }; } try { - debugFetch(`Downloading binary from ${url}`); + debugInstall(`Downloading binary from ${url}`); try { debugTime('download'); await downloadFile(url, archivePath, options.downloadProgressCallback); @@ -170,7 +170,7 @@ export async function fetch(options: Options): Promise { debugTimeEnd('download'); } - debugFetch(`Installing ${archivePath} to ${outputPath}`); + debugInstall(`Installing ${archivePath} to ${outputPath}`); try { debugTime('extract'); await unpackArchive(archivePath, outputPath); @@ -178,7 +178,7 @@ export async function fetch(options: Options): Promise { debugTimeEnd('extract'); } } catch (err) { - debugFetch(`Error during installation`, err); + debugInstall(`Error during installation`, err); } finally { if (existsSync(archivePath)) { await unlink(archivePath); @@ -192,7 +192,7 @@ export async function fetch(options: Options): Promise { }; } -export async function canFetch(options: Options): Promise { +export async function canDownload(options: Options): Promise { options.platform ??= detectBrowserPlatform(); if (!options.platform) { throw new Error( diff --git a/packages/browsers/src/launcher.ts b/packages/browsers/src/launch.ts similarity index 99% rename from packages/browsers/src/launcher.ts rename to packages/browsers/src/launch.ts index c41168c231c..45fcf72070b 100644 --- a/packages/browsers/src/launcher.ts +++ b/packages/browsers/src/launch.ts @@ -48,7 +48,7 @@ export interface Options { */ platform?: BrowserPlatform; /** - * Determines which browser to fetch. + * Determines which browser to launch. */ browser: Browser; /** @@ -87,7 +87,7 @@ export interface SystemOptions { */ platform?: BrowserPlatform; /** - * Determines which browser to fetch. + * Determines which browser to launch. */ browser: Browser; /** diff --git a/packages/browsers/src/main.ts b/packages/browsers/src/main.ts index 0c3deca60be..ab169f19c31 100644 --- a/packages/browsers/src/main.ts +++ b/packages/browsers/src/main.ts @@ -21,8 +21,8 @@ export { TimeoutError, CDP_WEBSOCKET_ENDPOINT_REGEX, WEBDRIVER_BIDI_WEBSOCKET_ENDPOINT_REGEX, -} from './launcher.js'; -export {fetch, canFetch} from './fetch.js'; +} from './launch.js'; +export {install, canDownload} from './install.js'; export {detectBrowserPlatform} from './detectPlatform.js'; export { resolveBuildId, diff --git a/packages/browsers/test/src/chrome/fetch.spec.ts b/packages/browsers/test/src/chrome/install.spec.ts similarity index 93% rename from packages/browsers/test/src/chrome/fetch.spec.ts rename to packages/browsers/test/src/chrome/install.spec.ts index 3a2db243d27..402306d5da5 100644 --- a/packages/browsers/test/src/chrome/fetch.spec.ts +++ b/packages/browsers/test/src/chrome/install.spec.ts @@ -22,8 +22,8 @@ import os from 'os'; import path from 'path'; import { - fetch, - canFetch, + install, + canDownload, Browser, BrowserPlatform, Cache, @@ -35,7 +35,7 @@ import {testChromeBuildId} from '../versions.js'; * Tests in this spec use real download URLs and unpack live browser archives * so it requires the network access. */ -describe('Chrome fetch', () => { +describe('Chrome install', () => { setupTestServer(); let tmpDir = '/tmp/puppeteer-browsers-test'; @@ -50,7 +50,7 @@ describe('Chrome fetch', () => { it('should check if a buildId can be downloaded', async () => { assert.ok( - await canFetch({ + await canDownload({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, @@ -62,7 +62,7 @@ describe('Chrome fetch', () => { it('should report if a buildId is not downloadable', async () => { assert.strictEqual( - await canFetch({ + await canDownload({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, @@ -81,7 +81,7 @@ describe('Chrome fetch', () => { `${BrowserPlatform.LINUX}-${testChromeBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); - let browser = await fetch({ + let browser = await install({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, @@ -91,7 +91,7 @@ describe('Chrome fetch', () => { assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); // Second iteration should be no-op. - browser = await fetch({ + browser = await install({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, @@ -159,9 +159,9 @@ describe('Chrome fetch', () => { delete process.env['HTTPS_PROXY']; }); - it('can send canFetch requests via a proxy', async () => { + it('can send canDownload requests via a proxy', async () => { assert.strictEqual( - await canFetch({ + await canDownload({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, @@ -175,7 +175,7 @@ describe('Chrome fetch', () => { ]); }); - it('can fetch via a proxy', async function () { + it('can download via a proxy', async function () { this.timeout(120000); const expectedOutputPath = path.join( tmpDir, @@ -183,7 +183,7 @@ describe('Chrome fetch', () => { `${BrowserPlatform.LINUX}-${testChromeBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); - const browser = await fetch({ + const browser = await install({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, diff --git a/packages/browsers/test/src/chrome/launcher.spec.ts b/packages/browsers/test/src/chrome/launch.spec.ts similarity index 99% rename from packages/browsers/test/src/chrome/launcher.spec.ts rename to packages/browsers/test/src/chrome/launch.spec.ts index 9aef9079a7f..cef690a6bba 100644 --- a/packages/browsers/test/src/chrome/launcher.spec.ts +++ b/packages/browsers/test/src/chrome/launch.spec.ts @@ -23,7 +23,7 @@ import { CDP_WEBSOCKET_ENDPOINT_REGEX, computeExecutablePath, launch, - fetch, + install, Browser, BrowserPlatform, } from '../../../lib/cjs/main.js'; @@ -54,7 +54,7 @@ describe('Chrome', () => { tmpDir = fs.mkdtempSync( path.join(os.tmpdir(), 'puppeteer-browsers-test') ); - await fetch({ + await install({ cacheDir: tmpDir, browser: Browser.CHROME, buildId: testChromeBuildId, diff --git a/packages/browsers/test/src/chromium/launcher.spec.ts b/packages/browsers/test/src/chromium/launch.spec.ts similarity index 99% rename from packages/browsers/test/src/chromium/launcher.spec.ts rename to packages/browsers/test/src/chromium/launch.spec.ts index cd9c2ac817c..2d5d704887c 100644 --- a/packages/browsers/test/src/chromium/launcher.spec.ts +++ b/packages/browsers/test/src/chromium/launch.spec.ts @@ -23,7 +23,7 @@ import { CDP_WEBSOCKET_ENDPOINT_REGEX, computeExecutablePath, launch, - fetch, + install, Browser, BrowserPlatform, } from '../../../lib/cjs/main.js'; @@ -54,7 +54,7 @@ describe('Chromium', () => { tmpDir = fs.mkdtempSync( path.join(os.tmpdir(), 'puppeteer-browsers-test') ); - await fetch({ + await install({ cacheDir: tmpDir, browser: Browser.CHROMIUM, buildId: testChromiumBuildId, diff --git a/packages/browsers/test/src/firefox/fetch.spec.ts b/packages/browsers/test/src/firefox/install.spec.ts similarity index 91% rename from packages/browsers/test/src/firefox/fetch.spec.ts rename to packages/browsers/test/src/firefox/install.spec.ts index 97548b757f5..29d5974c73b 100644 --- a/packages/browsers/test/src/firefox/fetch.spec.ts +++ b/packages/browsers/test/src/firefox/install.spec.ts @@ -19,7 +19,7 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; -import {fetch, Browser, BrowserPlatform} from '../../../lib/cjs/main.js'; +import {install, Browser, BrowserPlatform} from '../../../lib/cjs/main.js'; import {setupTestServer, getServerUrl, clearCache} from '../utils.js'; import {testFirefoxBuildId} from '../versions.js'; @@ -27,7 +27,7 @@ import {testFirefoxBuildId} from '../versions.js'; * Tests in this spec use real download URLs and unpack live browser archives * so it requires the network access. */ -describe('Firefox fetch', () => { +describe('Firefox install', () => { setupTestServer(); let tmpDir = '/tmp/puppeteer-browsers-test'; @@ -48,7 +48,7 @@ describe('Firefox fetch', () => { `${BrowserPlatform.LINUX}-${testFirefoxBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); - const browser = await fetch({ + const browser = await install({ cacheDir: tmpDir, browser: Browser.FIREFOX, platform: BrowserPlatform.LINUX, @@ -59,7 +59,7 @@ describe('Firefox fetch', () => { assert.ok(fs.existsSync(expectedOutputPath)); }); - // Fetch relies on the `hdiutil` utility on MacOS. + // install relies on the `hdiutil` utility on MacOS. // The utility is not available on other platforms. (os.platform() === 'darwin' ? it : it.skip)( 'should download a buildId that is a dmg archive', @@ -71,7 +71,7 @@ describe('Firefox fetch', () => { `${BrowserPlatform.MAC}-${testFirefoxBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); - const browser = await fetch({ + const browser = await install({ cacheDir: tmpDir, browser: Browser.FIREFOX, platform: BrowserPlatform.MAC, diff --git a/packages/browsers/test/src/firefox/launcher.spec.ts b/packages/browsers/test/src/firefox/launch.ts similarity index 98% rename from packages/browsers/test/src/firefox/launcher.spec.ts rename to packages/browsers/test/src/firefox/launch.ts index 83c6151c891..88388d8d6d8 100644 --- a/packages/browsers/test/src/firefox/launcher.spec.ts +++ b/packages/browsers/test/src/firefox/launch.ts @@ -22,7 +22,7 @@ import path from 'path'; import { computeExecutablePath, launch, - fetch, + install, Browser, BrowserPlatform, createProfile, @@ -54,7 +54,7 @@ describe('Firefox', () => { tmpDir = fs.mkdtempSync( path.join(os.tmpdir(), 'puppeteer-browsers-test') ); - await fetch({ + await install({ cacheDir: tmpDir, browser: Browser.FIREFOX, buildId: testFirefoxBuildId, diff --git a/packages/browsers/test/src/utils.ts b/packages/browsers/test/src/utils.ts index ee77f5dbc12..9afb1bb7631 100644 --- a/packages/browsers/test/src/utils.ts +++ b/packages/browsers/test/src/utils.ts @@ -22,7 +22,7 @@ import {Writable, Readable} from 'stream'; import {TestServer} from '@pptr/testserver'; -import {isErrorLike} from '../../lib/cjs/launcher.js'; +import {isErrorLike} from '../../lib/cjs/launch.js'; import {Cache} from '../../lib/cjs/main.js'; export function createMockedReadlineInterface( diff --git a/packages/browsers/tools/downloadTestBrowsers.mjs b/packages/browsers/tools/downloadTestBrowsers.mjs index 1af9906e554..9ee861f878f 100644 --- a/packages/browsers/tools/downloadTestBrowsers.mjs +++ b/packages/browsers/tools/downloadTestBrowsers.mjs @@ -19,7 +19,7 @@ * mirrors the structure of the download server. */ -import {BrowserPlatform, fetch} from '@puppeteer/browsers'; +import {BrowserPlatform, install} from '@puppeteer/browsers'; import path from 'path'; import fs from 'fs'; @@ -59,12 +59,12 @@ for (const version of Object.keys(versions)) { continue; } - const result = await fetch({ + const result = await install({ browser, buildId, platform, cacheDir: path.join(cacheDir, 'tmp'), - install: false, + unpack: false, }); fs.mkdirSync(path.dirname(targetPath), { diff --git a/packages/puppeteer/src/node/install.ts b/packages/puppeteer/src/node/install.ts index e0261c6f2f1..9ee970ae260 100644 --- a/packages/puppeteer/src/node/install.ts +++ b/packages/puppeteer/src/node/install.ts @@ -15,7 +15,7 @@ */ import { - fetch, + install, Browser, resolveBuildId, makeProgressCallback, @@ -88,7 +88,7 @@ export async function downloadBrowser(): Promise { const buildId = await resolveBuildId(browser, platform, unresolvedBuildId); try { - const result = await fetch({ + const result = await install({ browser, cacheDir: configuration.cacheDirectory!, platform,