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

✨ Install the correct Chromium binary for arm Macs #486

Merged
merged 3 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/core/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ function formatProgress(prefix, total, start, progress) {
// Returns an item from the map keyed by the current platform
function selectByPlatform(map) {
let { platform, arch } = process;
return map[platform === 'win32' && arch === 'x64' ? 'win64' : platform];
if (platform === 'win32' && arch === 'x64') platform = 'win64';
if (platform === 'darwin' && arch === 'arm64') platform = 'darwinArm';
return map[platform];
}

// Installs a revision of Chromium to a local directory
Expand All @@ -63,6 +65,7 @@ function installChromium({
selectByPlatform({
linux: `Linux_x64/${revision}/chrome-linux.zip`,
darwin: `Mac/${revision}/chrome-mac.zip`,
darwinArm: `Mac_Arm/${revision}/chrome-mac.zip`,
win64: `Win_x64/${revision}/chrome-win.zip`,
win32: `Win/${revision}/chrome-win.zip`
});
Expand All @@ -71,7 +74,8 @@ function installChromium({
linux: path.join('chrome-linux', 'chrome'),
win64: path.join('chrome-win', 'chrome.exe'),
win32: path.join('chrome-win', 'chrome.exe'),
darwin: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium')
darwin: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'),
darwinArm: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium')
});

return install({
Expand All @@ -89,7 +93,8 @@ installChromium.revisions = {
linux: '885264',
win64: '885282',
win32: '885263',
darwin: '885263'
darwin: '885263',
darwinArm: '885282'
};

// Installs an executable from a url to a local directory, returning the full path to the extracted
Expand Down
22 changes: 16 additions & 6 deletions packages/core/test/unit/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,37 @@ describe('Unit / Install', () => {
linux: {
revision: install.chromium.revisions.linux,
url: jasmine.stringMatching(`Linux_x64/${install.chromium.revisions.linux}/chrome-linux.zip`),
return: path.join('chrome-linux', 'chrome')
return: path.join('chrome-linux', 'chrome'),
process: { platform: 'linux', arch: 'x64' }
},
darwin: {
revision: install.chromium.revisions.darwin,
url: jasmine.stringMatching(`Mac/${install.chromium.revisions.darwin}/chrome-mac.zip`),
return: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium')
return: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'),
process: { platform: 'darwin', arch: 'x64' }
},
darwinArm: {
revision: install.chromium.revisions.darwinArm,
url: jasmine.stringMatching(`Mac_Arm/${install.chromium.revisions.darwinArm}/chrome-mac.zip`),
return: path.join('chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium'),
process: { platform: 'darwin', arch: 'arm64' }
},
win64: {
revision: install.chromium.revisions.win64,
url: jasmine.stringMatching(`Win_x64/${install.chromium.revisions.win64}/chrome-win.zip`),
return: path.join('chrome-win', 'chrome.exe')
return: path.join('chrome-win', 'chrome.exe'),
process: { platform: 'win32', arch: 'x64' }
},
win32: {
revision: install.chromium.revisions.win32,
url: jasmine.stringMatching(`Win/${install.chromium.revisions.win32}/chrome-win.zip`),
return: path.join('chrome-win', 'chrome.exe')
return: path.join('chrome-win', 'chrome.exe'),
process: { platform: 'win32', arch: 'x32' }
}
})) {
it(`downloads the correct files for ${platform}`, async () => {
spyOnProperty(process, 'platform').and.returnValue(platform === 'win64' ? 'win32' : platform);
spyOnProperty(process, 'arch').and.returnValue(platform === 'win32' ? 'x32' : 'x64');
spyOnProperty(process, 'platform').and.returnValue(expected.process.platform);
spyOnProperty(process, 'arch').and.returnValue(expected.process.arch);

await expectAsync(install.chromium()).toBeResolvedTo(
jasmine.stringMatching(expected.return.replace(/[.\\]/g, '\\$&'))
Expand Down
6 changes: 4 additions & 2 deletions scripts/chromium-revision
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const GH_HEADERS = {
const G_STORAGE_API_URL = 'https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o';
const G_STORAGE_PREFIXES = {
darwin: 'Mac',
darwinArm: 'Mac_Arm',
linux: 'Linux_x64',
win64: 'Win_x64',
win32: 'Win'
Expand Down Expand Up @@ -95,7 +96,7 @@ async function printVersionRevisions(version) {
// 50 revisions (not all platforms release at the same time)
let revisions = await task({
state: () => ({
platforms: ['linux', 'win64', 'win32', 'darwin'],
platforms: ['linux', 'win64', 'win32', 'darwin', 'darwinArm'],
range: [revision - 50, revision],
value: {}
}),
Expand All @@ -105,8 +106,9 @@ async function printVersionRevisions(version) {
async function(state) {
let platform = state.platforms[state.i - 1];
if (!platform) return state.value;
let rev = state.range[1];

for (let rev = state.range[1]; rev >= state.range[0]; rev--) {
for (; rev >= state.range[0]; rev--) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got an error with this variable using the latest LTS node with this script. Apparently, let hoisting has changed under the hood. The change makes sense though, as we're referencing rev outside of the loop down below.

// query google's storage api for the platform revision
let { items } = await request((
`${G_STORAGE_API_URL}?fields=items(name,metadata)&` +
Expand Down