From bce68adfb7c40052c0bcb51c4399c24bd6620e37 Mon Sep 17 00:00:00 2001 From: Valentin Semirulnik Date: Sun, 5 Sep 2021 19:36:28 +0300 Subject: [PATCH] feat: add support for Apple Silicon chromium builds --- src/node/BrowserFetcher.ts | 23 ++++++++++++++--------- src/node/Launcher.ts | 3 +-- src/node/install.ts | 11 +++-------- src/revisions.ts | 2 +- utils/check_availability.js | 7 +++++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/node/BrowserFetcher.ts b/src/node/BrowserFetcher.ts index 20301e2462142..5de9df1f61a86 100644 --- a/src/node/BrowserFetcher.ts +++ b/src/node/BrowserFetcher.ts @@ -41,6 +41,7 @@ const downloadURLs = { chrome: { linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip', mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip', + mac_arm: '%s/chromium-browser-snapshots/Mac_Arm/%d/%s.zip', win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip', win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip', }, @@ -67,7 +68,7 @@ const browserConfig = { * Supported platforms. * @public */ -export type Platform = 'linux' | 'mac' | 'win32' | 'win64'; +export type Platform = 'linux' | 'mac' | 'mac_arm' | 'win32' | 'win64'; function archiveName( product: Product, @@ -76,7 +77,7 @@ function archiveName( ): string { if (product === 'chrome') { if (platform === 'linux') return 'chrome-linux'; - if (platform === 'mac') return 'chrome-mac'; + if (platform === 'mac' || platform === 'mac_arm') return 'chrome-mac'; if (platform === 'win32' || platform === 'win64') { // Windows archive name changed at r591479. return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32'; @@ -198,21 +199,26 @@ export class BrowserFetcher { options.path || path.join(projectRoot, browserConfig[this._product].destination); this._downloadHost = options.host || browserConfig[this._product].host; - this.setPlatform(options.platform); + this.setPlatform(options.platform, this._product); assert( downloadURLs[this._product][this._platform], 'Unsupported platform: ' + this._platform ); } - private setPlatform(platformFromOptions?: Platform): void { + private setPlatform( + platformFromOptions?: Platform, + productFromOptions?: Product + ): void { if (platformFromOptions) { this._platform = platformFromOptions; return; } const platform = os.platform(); - if (platform === 'darwin') this._platform = 'mac'; + if (platform === 'darwin' && productFromOptions === 'chrome') + this._platform = os.arch() === 'arm64' ? 'mac_arm' : 'mac'; + else if (productFromOptions === 'firefox') this._platform = 'mac'; else if (platform === 'linux') this._platform = 'linux'; else if (platform === 'win32') this._platform = os.arch() === 'x64' ? 'win64' : 'win32'; @@ -295,8 +301,7 @@ export class BrowserFetcher { if (!(await existsAsync(this._downloadsFolder))) await mkdirAsync(this._downloadsFolder); - // Use Intel x86 builds on Apple M1 until native macOS arm64 - // Chromium builds are available. + // Use system Chromium builds on Linux ARM devices if (os.platform() !== 'darwin' && os.arch() === 'arm64') { handleArm64(); return; @@ -351,7 +356,7 @@ export class BrowserFetcher { const folderPath = this._getFolderPath(revision); let executablePath = ''; if (this._product === 'chrome') { - if (this._platform === 'mac') + if (this._platform === 'mac' || this._platform === 'mac_arm') executablePath = path.join( folderPath, archiveName(this._product, this._platform, revision), @@ -374,7 +379,7 @@ export class BrowserFetcher { ); else throw new Error('Unsupported platform: ' + this._platform); } else if (this._product === 'firefox') { - if (this._platform === 'mac') + if (this._platform === 'mac' || this._platform === 'mac_arm') executablePath = path.join( folderPath, 'Firefox Nightly.app', diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index 402ae0ad0d7f1..cf1cb72212826 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -118,8 +118,7 @@ class ChromeLauncher implements ProductLauncher { chromeExecutable = executablePathForChannel(channel); } else if (!executablePath) { - // Use Intel x86 builds on Apple M1 until native macOS arm64 - // Chromium builds are available. + // Use system Chromium builds on Linux ARM devices if (os.platform() !== 'darwin' && os.arch() === 'arm64') { chromeExecutable = '/usr/bin/chromium-browser'; } else { diff --git a/src/node/install.ts b/src/node/install.ts index d7e751f44ef87..6789c6bbd01b5 100644 --- a/src/node/install.ts +++ b/src/node/install.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import os from 'os'; import https from 'https'; import ProgressBar from 'progress'; import puppeteer from '../node.js'; @@ -90,13 +89,9 @@ export async function downloadBrowser(): Promise { if (NPM_NO_PROXY) process.env.NO_PROXY = NPM_NO_PROXY; function onSuccess(localRevisions: string[]): void { - // Use Intel x86 builds on Apple M1 until native macOS arm64 - // Chromium builds are available. - if (os.platform() !== 'darwin' && os.arch() !== 'arm64') { - logPolitely( - `${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}` - ); - } + logPolitely( + `${supportedProducts[product]} (${revisionInfo.revision}) downloaded to ${revisionInfo.folderPath}` + ); localRevisions = localRevisions.filter( (revision) => revision !== revisionInfo.revision ); diff --git a/src/revisions.ts b/src/revisions.ts index 5c4694ea39032..288ffe4bb6b39 100644 --- a/src/revisions.ts +++ b/src/revisions.ts @@ -20,6 +20,6 @@ type Revisions = Readonly<{ }>; export const PUPPETEER_REVISIONS: Revisions = { - chromium: '901912', + chromium: '916291', firefox: 'latest', }; diff --git a/utils/check_availability.js b/utils/check_availability.js index fbc115c1a53f0..faedbb6868a4f 100755 --- a/utils/check_availability.js +++ b/utils/check_availability.js @@ -21,7 +21,7 @@ const https = require('https'); const BrowserFetcher = require('../lib/cjs/puppeteer/node/BrowserFetcher.js').BrowserFetcher; -const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64']; +const SUPPORTER_PLATFORMS = ['linux', 'mac', 'mac_arm', 'win32', 'win64']; const fetchers = SUPPORTER_PLATFORMS.map( (platform) => new BrowserFetcher('', { platform }) ); @@ -139,6 +139,9 @@ async function checkOmahaProxyAvailability() { fetch( 'https://storage.googleapis.com/chromium-browser-snapshots/Mac/LAST_CHANGE' ), + fetch( + 'https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/LAST_CHANGE' + ), fetch( 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/LAST_CHANGE' ), @@ -191,7 +194,7 @@ async function checkRangeAvailability({ toRevision, stopWhenAllAvailable, }) { - const table = new Table([10, 7, 7, 7, 7]); + const table = new Table([10, 7, 7, 7, 7, 7]); table.drawRow([''].concat(SUPPORTER_PLATFORMS)); const inc = fromRevision < toRevision ? 1 : -1;