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

chore: fetch Firefox from json source instead of run a RegExp #5864

Merged
merged 2 commits into from May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 11 additions & 14 deletions install.js
Expand Up @@ -26,6 +26,8 @@

const compileTypeScriptIfRequired = require('./typescript-if-required');

const firefoxVersions =
'https://product-details.mozilla.org/1.0/firefox_versions.json';
const supportedProducts = {
chrome: 'Chromium',
firefox: 'Firefox Nightly',
Expand Down Expand Up @@ -160,27 +162,22 @@ async function download() {
let data = '';
logPolitely(`Requesting latest Firefox Nightly version from ${host}`);
https
.get(host + '/', (r) => {
.get(firefoxVersions, (r) => {
if (r.statusCode >= 400)
return reject(new Error(`Got status code ${r.statusCode}`));
r.on('data', (chunk) => {
data += chunk;
});
r.on('end', parseVersion);
r.on('end', () => {
try {
const versions = JSON.parse(data);
return resolve(versions.FIREFOX_NIGHTLY);
} catch {
return reject(new Error('Firefox version not found'));
}
});
})
.on('error', reject);

function parseVersion() {
const regex = /firefox\-(?<version>\d\d)\..*/gm;
let result = 0;
let match;
while ((match = regex.exec(data)) !== null) {
const version = parseInt(match.groups.version, 10);
if (version > result) result = version;
}
if (result) resolve(result.toString());
else reject(new Error('Firefox version not found'));
}
});
return promise;
}
Expand Down
8 changes: 4 additions & 4 deletions src/BrowserFetcher.ts
Expand Up @@ -40,10 +40,10 @@ const downloadURLs = {
win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
},
firefox: {
linux: '%s/firefox-%s.0a1.en-US.%s-x86_64.tar.bz2',
mac: '%s/firefox-%s.0a1.en-US.%s.dmg',
win32: '%s/firefox-%s.0a1.en-US.%s.zip',
win64: '%s/firefox-%s.0a1.en-US.%s.zip',
linux: '%s/firefox-%s.en-US.%s-x86_64.tar.bz2',
mac: '%s/firefox-%s.en-US.%s.dmg',
win32: '%s/firefox-%s.en-US.%s.zip',
win64: '%s/firefox-%s.en-US.%s.zip',
},
} as const;

Expand Down
2 changes: 1 addition & 1 deletion test/launcher.spec.js
Expand Up @@ -89,7 +89,7 @@ describe('Launcher specs', function () {
server.serveFile(
req,
res,
`/firefox-${expectedVersion}.0a1.en-US.linux-x86_64.tar.bz2`
`/firefox-${expectedVersion}.en-US.linux-x86_64.tar.bz2`
);
}
);
Expand Down