refactor: rename fetch->install, launcher->launch (#9985)
This commit is contained in:
parent
e7265c9aa9
commit
24bd05877d
@ -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,
|
||||
|
@ -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<string, [number, number]>();
|
||||
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<InstalledBrowser> {
|
||||
export async function install(options: Options): Promise<InstalledBrowser> {
|
||||
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<InstalledBrowser> {
|
||||
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<InstalledBrowser> {
|
||||
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<InstalledBrowser> {
|
||||
};
|
||||
}
|
||||
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<InstalledBrowser> {
|
||||
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<InstalledBrowser> {
|
||||
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<InstalledBrowser> {
|
||||
};
|
||||
}
|
||||
|
||||
export async function canFetch(options: Options): Promise<boolean> {
|
||||
export async function canDownload(options: Options): Promise<boolean> {
|
||||
options.platform ??= detectBrowserPlatform();
|
||||
if (!options.platform) {
|
||||
throw new Error(
|
@ -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;
|
||||
/**
|
@ -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,
|
||||
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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,
|
@ -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(
|
||||
|
@ -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), {
|
||||
|
@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
fetch,
|
||||
install,
|
||||
Browser,
|
||||
resolveBuildId,
|
||||
makeProgressCallback,
|
||||
@ -88,7 +88,7 @@ export async function downloadBrowser(): Promise<void> {
|
||||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
|
||||
|
||||
try {
|
||||
const result = await fetch({
|
||||
const result = await install({
|
||||
browser,
|
||||
cacheDir: configuration.cacheDirectory!,
|
||||
platform,
|
||||
|
Loading…
Reference in New Issue
Block a user