Skip to content

Commit

Permalink
feat: add support for Apple Silicon chromium builds
Browse files Browse the repository at this point in the history
  • Loading branch information
7rulnik committed Sep 5, 2021
1 parent 10e8474 commit 42bde9c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
13 changes: 7 additions & 6 deletions src/node/BrowserFetcher.ts
Expand Up @@ -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',
},
Expand All @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -212,7 +213,8 @@ export class BrowserFetcher {
}

const platform = os.platform();
if (platform === 'darwin') this._platform = 'mac';
if (platform === 'darwin')
this._platform = os.arch() === 'arm64' ? 'mac_arm' : 'mac';
else if (platform === 'linux') this._platform = 'linux';
else if (platform === 'win32')
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
Expand Down Expand Up @@ -295,8 +297,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;
Expand Down Expand Up @@ -351,7 +352,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),
Expand Down
3 changes: 1 addition & 2 deletions src/node/Launcher.ts
Expand Up @@ -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 {
Expand Down
10 changes: 3 additions & 7 deletions src/node/install.ts
Expand Up @@ -90,13 +90,9 @@ export async function downloadBrowser(): Promise<void> {
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
);
Expand Down
2 changes: 1 addition & 1 deletion src/revisions.ts
Expand Up @@ -20,6 +20,6 @@ type Revisions = Readonly<{
}>;

export const PUPPETEER_REVISIONS: Revisions = {
chromium: '901912',
chromium: '916291',
firefox: 'latest',
};
7 changes: 5 additions & 2 deletions utils/check_availability.js
Expand Up @@ -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 })
);
Expand Down Expand Up @@ -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'
),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 42bde9c

Please sign in to comment.