From dcd6a3e1daaf9b68035edf5381a97809ad7a8841 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Tue, 21 Feb 2023 17:15:49 +0100 Subject: [PATCH] chore: rename revision to buildId (#9721) --- packages/browsers/src/CLI.ts | 28 +++++++-------- packages/browsers/src/CacheStructure.ts | 12 +++---- packages/browsers/src/browsers/browsers.ts | 8 ++--- packages/browsers/src/browsers/chrome.ts | 14 ++++---- packages/browsers/src/browsers/firefox.ts | 16 ++++----- packages/browsers/src/fetch.ts | 20 +++++------ packages/browsers/src/launcher.ts | 8 ++--- packages/browsers/test/src/cli.spec.ts | 12 +++---- packages/browsers/test/src/fetch.spec.ts | 38 ++++++++++----------- packages/browsers/test/src/launcher.spec.ts | 16 ++++----- 10 files changed, 86 insertions(+), 86 deletions(-) diff --git a/packages/browsers/src/CLI.ts b/packages/browsers/src/CLI.ts index bf1848f92bb..6f6f2dcda51 100644 --- a/packages/browsers/src/CLI.ts +++ b/packages/browsers/src/CLI.ts @@ -18,7 +18,7 @@ import ProgressBar from 'progress'; import yargs from 'yargs'; import {hideBin} from 'yargs/helpers'; -import {resolveRevision} from './browsers/browsers.js'; +import {resolveBuildId} from './browsers/browsers.js'; import {Browser, BrowserPlatform} from './browsers/types.js'; import {detectBrowserPlatform} from './detectPlatform.js'; import {fetch} from './fetch.js'; @@ -27,7 +27,7 @@ import {computeExecutablePath, launch} from './launcher.js'; type InstallArgs = { browser: { name: Browser; - revision: string; + buildId: string; }; path?: string; platform?: BrowserPlatform; @@ -36,7 +36,7 @@ type InstallArgs = { type LaunchArgs = { browser: { name: Browser; - revision: string; + buildId: string; }; path?: string; platform?: BrowserPlatform; @@ -62,7 +62,7 @@ export class CLI { coerce: (opt): InstallArgs['browser'] => { return { name: this.#parseBrowser(opt), - revision: this.#parseRevision(opt), + buildId: this.#parseBuildId(opt), }; }, }); @@ -73,23 +73,23 @@ export class CLI { if (!args.platform) { throw new Error(`Could not resolve the current platform`); } - args.browser.revision = await resolveRevision( + args.browser.buildId = await resolveBuildId( args.browser.name, args.platform, - args.browser.revision + args.browser.buildId ); await fetch({ browser: args.browser.name, - revision: args.browser.revision, + buildId: args.browser.buildId, platform: args.platform, cacheDir: args.path ?? this.#cachePath, downloadProgressCallback: this.#makeProgressCallback( args.browser.name, - args.browser.revision + args.browser.buildId ), }); console.log( - `${args.browser.name}@${args.browser.revision} downloaded successfully.` + `${args.browser.name}@${args.browser.buildId} downloaded successfully.` ); } ) @@ -114,7 +114,7 @@ export class CLI { coerce: (opt): LaunchArgs['browser'] => { return { name: this.#parseBrowser(opt), - revision: this.#parseRevision(opt), + buildId: this.#parseBuildId(opt), }; }, }); @@ -123,7 +123,7 @@ export class CLI { const args = argv as unknown as LaunchArgs; const executablePath = computeExecutablePath({ browser: args.browser.name, - revision: args.browser.revision, + buildId: args.browser.buildId, cacheDir: args.path ?? this.#cachePath, platform: args.platform, }); @@ -156,7 +156,7 @@ export class CLI { return version.split('@').shift() as Browser; } - #parseRevision(version: string): string { + #parseBuildId(version: string): string { return version.split('@').pop() ?? 'latest'; } @@ -165,13 +165,13 @@ export class CLI { return `${Math.round(mb * 10) / 10} Mb`; } - #makeProgressCallback(browser: Browser, revision: string) { + #makeProgressCallback(browser: Browser, buildId: string) { let progressBar: ProgressBar; let lastDownloadedBytes = 0; return (downloadedBytes: number, totalBytes: number) => { if (!progressBar) { progressBar = new ProgressBar( - `Downloading ${browser} r${revision} - ${this.#toMegabytes( + `Downloading ${browser} r${buildId} - ${this.#toMegabytes( totalBytes )} [:bar] :percent :etas `, { diff --git a/packages/browsers/src/CacheStructure.ts b/packages/browsers/src/CacheStructure.ts index 077d794b171..9120f7d9be4 100644 --- a/packages/browsers/src/CacheStructure.ts +++ b/packages/browsers/src/CacheStructure.ts @@ -23,12 +23,12 @@ import {Browser, BrowserPlatform} from './browsers/types.js'; * * - rootDir * -- | browserRoot(browser1) - * ---- - | installationDir() - * ------ the browser-platform-revision + * ---- - | installationDir() + * ------ the browser-platform-buildId * ------ specific structure. * -- | browserRoot(browser2) - * ---- - | installationDir() - * ------ the browser-platform-revision + * ---- - | installationDir() + * ------ the browser-platform-buildId * ------ specific structure. * @internal */ @@ -46,8 +46,8 @@ export class CacheStructure { installationDir( browser: Browser, platform: BrowserPlatform, - revision: string + buildId: string ): string { - return path.join(this.browserRoot(browser), `${platform}-${revision}`); + return path.join(this.browserRoot(browser), `${platform}-${buildId}`); } } diff --git a/packages/browsers/src/browsers/browsers.ts b/packages/browsers/src/browsers/browsers.ts index 77cb1d5cef5..54d9beecc69 100644 --- a/packages/browsers/src/browsers/browsers.ts +++ b/packages/browsers/src/browsers/browsers.ts @@ -30,7 +30,7 @@ export const executablePathByBrowser = { export {Browser, BrowserPlatform}; -export async function resolveRevision( +export async function resolveBuildId( browser: Browser, platform: BrowserPlatform, tag: string @@ -39,14 +39,14 @@ export async function resolveRevision( case Browser.FIREFOX: switch (tag as BrowserTag) { case BrowserTag.LATEST: - return await firefox.resolveRevision('FIREFOX_NIGHTLY'); + return await firefox.resolveBuildId('FIREFOX_NIGHTLY'); } case Browser.CHROME: switch (tag as BrowserTag) { case BrowserTag.LATEST: - return await chrome.resolveRevision(platform, 'latest'); + return await chrome.resolveBuildId(platform, 'latest'); } } - // We assume the tag is the revision if it didn't match any keywords. + // We assume the tag is the buildId if it didn't match any keywords. return tag; } diff --git a/packages/browsers/src/browsers/chrome.ts b/packages/browsers/src/browsers/chrome.ts index d9192d4d34b..af880ce7133 100644 --- a/packages/browsers/src/browsers/chrome.ts +++ b/packages/browsers/src/browsers/chrome.ts @@ -20,7 +20,7 @@ import {httpRequest} from '../httpUtil.js'; import {BrowserPlatform} from './types.js'; -function archive(platform: BrowserPlatform, revision: string): string { +function archive(platform: BrowserPlatform, buildId: string): string { switch (platform) { case BrowserPlatform.LINUX: return 'chrome-linux'; @@ -30,7 +30,7 @@ function archive(platform: BrowserPlatform, revision: string): string { case BrowserPlatform.WIN32: case BrowserPlatform.WIN64: // Windows archive name changed at r591479. - return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32'; + return parseInt(buildId, 10) > 591479 ? 'chrome-win' : 'chrome-win32'; } } @@ -51,18 +51,18 @@ function folder(platform: BrowserPlatform): string { export function resolveDownloadUrl( platform: BrowserPlatform, - revision: string, + buildId: string, baseUrl = 'https://storage.googleapis.com/chromium-browser-snapshots' ): string { - return `${baseUrl}/${folder(platform)}/${revision}/${archive( + return `${baseUrl}/${folder(platform)}/${buildId}/${archive( platform, - revision + buildId )}.zip`; } export function relativeExecutablePath( platform: BrowserPlatform, - _revision: string + _buildId: string ): string { switch (platform) { case BrowserPlatform.MAC: @@ -82,7 +82,7 @@ export function relativeExecutablePath( } } -export async function resolveRevision( +export async function resolveBuildId( platform: BrowserPlatform, // We will need it for other channels/keywords. _channel: 'latest' = 'latest' diff --git a/packages/browsers/src/browsers/firefox.ts b/packages/browsers/src/browsers/firefox.ts index 530da121250..2894e5c0e34 100644 --- a/packages/browsers/src/browsers/firefox.ts +++ b/packages/browsers/src/browsers/firefox.ts @@ -20,30 +20,30 @@ import {httpRequest} from '../httpUtil.js'; import {BrowserPlatform} from './types.js'; -function archive(platform: BrowserPlatform, revision: string): string { +function archive(platform: BrowserPlatform, buildId: string): string { switch (platform) { case BrowserPlatform.LINUX: - return `firefox-${revision}.en-US.${platform}-x86_64.tar.bz2`; + return `firefox-${buildId}.en-US.${platform}-x86_64.tar.bz2`; case BrowserPlatform.MAC_ARM: case BrowserPlatform.MAC: - return `firefox-${revision}.en-US.mac.dmg`; + return `firefox-${buildId}.en-US.mac.dmg`; case BrowserPlatform.WIN32: case BrowserPlatform.WIN64: - return `firefox-${revision}.en-US.${platform}.zip`; + return `firefox-${buildId}.en-US.${platform}.zip`; } } export function resolveDownloadUrl( platform: BrowserPlatform, - revision: string, + buildId: string, baseUrl = 'https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central' ): string { - return `${baseUrl}/${archive(platform, revision)}`; + return `${baseUrl}/${archive(platform, buildId)}`; } export function relativeExecutablePath( platform: BrowserPlatform, - _revision: string + _buildId: string ): string { switch (platform) { case BrowserPlatform.MAC_ARM: @@ -57,7 +57,7 @@ export function relativeExecutablePath( } } -export async function resolveRevision( +export async function resolveBuildId( channel: 'FIREFOX_NIGHTLY' = 'FIREFOX_NIGHTLY' ): Promise { return new Promise((resolve, reject) => { diff --git a/packages/browsers/src/fetch.ts b/packages/browsers/src/fetch.ts index 65877fe9100..b1bfea4b173 100644 --- a/packages/browsers/src/fetch.ts +++ b/packages/browsers/src/fetch.ts @@ -48,10 +48,10 @@ export interface Options { */ browser: Browser; /** - * Determines which revision to dowloand. Revision should uniquely identify + * Determines which buildId to dowloand. BuildId should uniquely identify * binaries and they are used for caching. */ - revision: string; + buildId: string; /** * Provides information about the progress of the download. */ @@ -64,7 +64,7 @@ export interface Options { export type InstalledBrowser = { path: string; browser: Browser; - revision: string; + buildId: string; platform: BrowserPlatform; }; @@ -78,7 +78,7 @@ export async function fetch(options: Options): Promise { const url = getDownloadUrl( options.browser, options.platform, - options.revision + options.buildId ); const fileName = url.toString().split('/').pop(); assert(fileName, `A malformed download URL was found: ${url}.`); @@ -91,14 +91,14 @@ export async function fetch(options: Options): Promise { const outputPath = structure.installationDir( options.browser, options.platform, - options.revision + options.buildId ); if (existsSync(outputPath)) { return { path: outputPath, browser: options.browser, platform: options.platform, - revision: options.revision, + buildId: options.buildId, }; } try { @@ -115,7 +115,7 @@ export async function fetch(options: Options): Promise { path: outputPath, browser: options.browser, platform: options.platform, - revision: options.revision, + buildId: options.buildId, }; } @@ -127,14 +127,14 @@ export async function canFetch(options: Options): Promise { ); } return await headHttpRequest( - getDownloadUrl(options.browser, options.platform, options.revision) + getDownloadUrl(options.browser, options.platform, options.buildId) ); } function getDownloadUrl( browser: Browser, platform: BrowserPlatform, - revision: string + buildId: string ): URL { - return new URL(downloadUrls[browser](platform, revision)); + return new URL(downloadUrls[browser](platform, buildId)); } diff --git a/packages/browsers/src/launcher.ts b/packages/browsers/src/launcher.ts index 05cfa58edc0..6915fab962c 100644 --- a/packages/browsers/src/launcher.ts +++ b/packages/browsers/src/launcher.ts @@ -48,10 +48,10 @@ export interface Options { */ browser: Browser; /** - * Determines which revision to dowloand. Revision should uniquely identify + * Determines which buildId to dowloand. BuildId should uniquely identify * binaries and they are used for caching. */ - revision: string; + buildId: string; } export function computeExecutablePath(options: Options): string { @@ -64,11 +64,11 @@ export function computeExecutablePath(options: Options): string { const installationDir = new CacheStructure(options.cacheDir).installationDir( options.browser, options.platform, - options.revision + options.buildId ); return path.join( installationDir, - executablePathByBrowser[options.browser](options.platform, options.revision) + executablePathByBrowser[options.browser](options.platform, options.buildId) ); } diff --git a/packages/browsers/test/src/cli.spec.ts b/packages/browsers/test/src/cli.spec.ts index ee7f8b31cf2..a36c258b499 100644 --- a/packages/browsers/test/src/cli.spec.ts +++ b/packages/browsers/test/src/cli.spec.ts @@ -25,8 +25,8 @@ describe('CLI', function () { this.timeout(90000); let tmpDir = '/tmp/puppeteer-browsers-test'; - const testChromeRevision = '1083080'; - const testFirefoxRevision = '111.0a1'; + const testChromeBuildId = '1083080'; + const testFirefoxBuildId = '111.0a1'; beforeEach(() => { tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'puppeteer-browsers-test')); @@ -41,7 +41,7 @@ describe('CLI', function () { 'npx', '@puppeteer/browsers', 'install', - `chrome@${testChromeRevision}`, + `chrome@${testChromeBuildId}`, `--path=${tmpDir}`, '--platform=linux', ]); @@ -50,7 +50,7 @@ describe('CLI', function () { path.join( tmpDir, 'chrome', - `linux-${testChromeRevision}`, + `linux-${testChromeBuildId}`, 'chrome-linux' ) ) @@ -62,13 +62,13 @@ describe('CLI', function () { 'npx', '@puppeteer/browsers', 'install', - `firefox@${testFirefoxRevision}`, + `firefox@${testFirefoxBuildId}`, `--path=${tmpDir}`, '--platform=linux', ]); assert.ok( fs.existsSync( - path.join(tmpDir, 'firefox', `linux-${testFirefoxRevision}`, 'firefox') + path.join(tmpDir, 'firefox', `linux-${testFirefoxBuildId}`, 'firefox') ) ); }); diff --git a/packages/browsers/test/src/fetch.spec.ts b/packages/browsers/test/src/fetch.spec.ts index 8fcabaca3d4..63c4b3e0aa1 100644 --- a/packages/browsers/test/src/fetch.spec.ts +++ b/packages/browsers/test/src/fetch.spec.ts @@ -30,8 +30,8 @@ import {fetch, canFetch} from '../../lib/cjs/fetch.js'; */ describe('fetch', () => { let tmpDir = '/tmp/puppeteer-browsers-test'; - const testChromeRevision = '1083080'; - const testFirefoxRevision = '111.0a1'; + const testChromeBuildId = '1083080'; + const testFirefoxBuildId = '111.0a1'; beforeEach(() => { tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'puppeteer-browsers-test')); @@ -41,42 +41,42 @@ describe('fetch', () => { fs.rmSync(tmpDir, {recursive: true}); }); - it('should check if a revision can be downloaded', async () => { + it('should check if a buildId can be downloaded', async () => { assert.ok( await canFetch({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: testChromeRevision, + buildId: testChromeBuildId, }) ); }); - it('should report if a revision is not downloadable', async () => { + it('should report if a buildId is not downloadable', async () => { assert.strictEqual( await canFetch({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: 'unknown', + buildId: 'unknown', }), false ); }); - it('should download a revision that is a zip archive', async function () { + it('should download a buildId that is a zip archive', async function () { this.timeout(60000); const expectedOutputPath = path.join( tmpDir, 'chrome', - `${BrowserPlatform.LINUX}-${testChromeRevision}` + `${BrowserPlatform.LINUX}-${testChromeBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); let browser = await fetch({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: testChromeRevision, + buildId: testChromeBuildId, }); assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); @@ -85,25 +85,25 @@ describe('fetch', () => { cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: testChromeRevision, + buildId: testChromeBuildId, }); assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); }); - it('should download a revision that is a bzip2 archive', async function () { + it('should download a buildId that is a bzip2 archive', async function () { this.timeout(60000); const expectedOutputPath = path.join( tmpDir, 'firefox', - `${BrowserPlatform.LINUX}-${testFirefoxRevision}` + `${BrowserPlatform.LINUX}-${testFirefoxBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); const browser = await fetch({ cacheDir: tmpDir, browser: Browser.FIREFOX, platform: BrowserPlatform.LINUX, - revision: testFirefoxRevision, + buildId: testFirefoxBuildId, }); assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); @@ -112,20 +112,20 @@ describe('fetch', () => { // Fetch relies on the `hdiutil` utility on MacOS. // The utility is not available on other platforms. (os.platform() === 'darwin' ? it : it.skip)( - 'should download a revision that is a dmg archive', + 'should download a buildId that is a dmg archive', async function () { this.timeout(120000); const expectedOutputPath = path.join( tmpDir, 'firefox', - `${BrowserPlatform.MAC}-${testFirefoxRevision}` + `${BrowserPlatform.MAC}-${testFirefoxBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); const browser = await fetch({ cacheDir: tmpDir, browser: Browser.FIREFOX, platform: BrowserPlatform.MAC, - revision: testFirefoxRevision, + buildId: testFirefoxBuildId, }); assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); @@ -195,7 +195,7 @@ describe('fetch', () => { cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: testChromeRevision, + buildId: testChromeBuildId, }), true ); @@ -209,14 +209,14 @@ describe('fetch', () => { const expectedOutputPath = path.join( tmpDir, 'chrome', - `${BrowserPlatform.LINUX}-${testChromeRevision}` + `${BrowserPlatform.LINUX}-${testChromeBuildId}` ); assert.strictEqual(fs.existsSync(expectedOutputPath), false); const browser = await fetch({ cacheDir: tmpDir, browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: testChromeRevision, + buildId: testChromeBuildId, }); assert.strictEqual(browser.path, expectedOutputPath); assert.ok(fs.existsSync(expectedOutputPath)); diff --git a/packages/browsers/test/src/launcher.spec.ts b/packages/browsers/test/src/launcher.spec.ts index e4f66d018ce..96dedba909f 100644 --- a/packages/browsers/test/src/launcher.spec.ts +++ b/packages/browsers/test/src/launcher.spec.ts @@ -29,7 +29,7 @@ describe('launcher', () => { computeExecutablePath({ browser: Browser.CHROME, platform: BrowserPlatform.LINUX, - revision: '123', + buildId: '123', cacheDir: 'cache', }), path.join('cache', 'chrome', 'linux-123', 'chrome-linux', 'chrome') @@ -41,7 +41,7 @@ describe('launcher', () => { computeExecutablePath({ browser: Browser.FIREFOX, platform: BrowserPlatform.LINUX, - revision: '123', + buildId: '123', cacheDir: 'cache', }), path.join('cache', 'firefox', 'linux-123', 'firefox', 'firefox') @@ -52,7 +52,7 @@ describe('launcher', () => { this.timeout(60000); let tmpDir = '/tmp/puppeteer-browsers-test'; - const testChromeRevision = '1083080'; + const testChromeBuildId = '1083080'; beforeEach(async () => { tmpDir = fs.mkdtempSync( @@ -61,7 +61,7 @@ describe('launcher', () => { await fetch({ cacheDir: tmpDir, browser: Browser.CHROME, - revision: testChromeRevision, + buildId: testChromeBuildId, }); }); @@ -73,7 +73,7 @@ describe('launcher', () => { const executablePath = computeExecutablePath({ cacheDir: tmpDir, browser: Browser.CHROME, - revision: testChromeRevision, + buildId: testChromeBuildId, }); const process = launch({ executablePath, @@ -91,7 +91,7 @@ describe('launcher', () => { this.timeout(60000); let tmpDir = '/tmp/puppeteer-browsers-test'; - const testFirefoxRevision = '111.0a1'; + const testFirefoxBuildId = '111.0a1'; beforeEach(async () => { tmpDir = fs.mkdtempSync( @@ -100,7 +100,7 @@ describe('launcher', () => { await fetch({ cacheDir: tmpDir, browser: Browser.FIREFOX, - revision: testFirefoxRevision, + buildId: testFirefoxBuildId, }); }); @@ -112,7 +112,7 @@ describe('launcher', () => { const executablePath = computeExecutablePath({ cacheDir: tmpDir, browser: Browser.FIREFOX, - revision: testFirefoxRevision, + buildId: testFirefoxBuildId, }); const process = launch({ executablePath,