Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support Apple M1 Chromium builds #7895

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/node/BrowserFetcher.ts
Expand Up @@ -41,12 +41,14 @@ const downloadURLs = {
chrome: {
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
macArm: '%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',
},
firefox: {
linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',
mac: '%s/firefox-%s.en-US.%s.dmg',
macArm: '%s/firefox-%s.en-US.%s.dmg',
win32: '%s/firefox-%s.en-US.%s.zip',
win64: '%s/firefox-%s.en-US.%s.zip',
},
Expand All @@ -67,7 +69,7 @@ const browserConfig = {
* Supported platforms.
* @public
*/
export type Platform = 'linux' | 'mac' | 'win32' | 'win64';
export type Platform = 'linux' | 'mac' | 'macArm' | 'win32' | 'win64';

function archiveName(
product: Product,
Expand All @@ -76,13 +78,13 @@ function archiveName(
): string {
if (product === 'chrome') {
if (platform === 'linux') return 'chrome-linux';
if (platform === 'mac') return 'chrome-mac';
if (platform === 'mac' || platform === 'macArm') return 'chrome-mac';
if (platform === 'win32' || platform === 'win64') {
// Windows archive name changed at r591479.
return parseInt(revision, 10) > 591479 ? 'chrome-win' : 'chrome-win32';
}
} else if (product === 'firefox') {
return platform;
return platform === 'macArm' ? 'mac' : platform;
}
}

Expand Down Expand Up @@ -214,7 +216,8 @@ export class BrowserFetcher {
}

const platform = os.platform();
if (platform === 'darwin') this._platform = 'mac';
if (platform === 'darwin')
this._platform = os.arch() === 'arm64' ? 'macArm' : 'mac';
else if (platform === 'linux') this._platform = 'linux';
else if (platform === 'win32')
this._platform = os.arch() === 'x64' ? 'win64' : 'win32';
Expand Down Expand Up @@ -353,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 === 'macArm')
executablePath = path.join(
folderPath,
archiveName(this._product, this._platform, revision),
Expand All @@ -376,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 === 'macArm')
executablePath = path.join(
folderPath,
'Firefox Nightly.app',
Expand Down
11 changes: 3 additions & 8 deletions src/node/install.ts
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import os from 'os';
import https, { RequestOptions } from 'https';
import ProgressBar from 'progress';
import URL from 'url';
Expand Down Expand Up @@ -95,13 +94,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