Skip to content

Commit

Permalink
fix some engines (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek authored Oct 27, 2023
1 parent f5b6067 commit 5386860
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ installing engines to make eshost automatically find the installed engines.
| [Chakra][] | `ch`, `chakra` || | || |||
| [engine262][] | `engine262` ||||||||
| [GraalJS][] | `graaljs` ||| ||| ||
| [Hermes][] | `hermes` || | | | | ||
| [Hermes][] | `hermes` || | | | | ||
| [LibJS][] | `serenity-js` ||| || | | |
| [JavaScriptCore][] | `jsc`, `javascriptcore` ||| || | ||
| [QuickJS][] | `quickjs`, `quickjs-run-test262` || ||| |||
Expand Down
21 changes: 19 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"extract-zip": "^2.0.1",
"glob": "^7.1.6",
"inquirer": "^7.3.3",
"macos-release": "^3.2.0",
"node-fetch": "^2.6.1",
"ora": "^4.1.1",
"rimraf": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions src/engines/hermes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function getFilename() {
case 'linux-x64':
return 'linux';
case 'darwin-x64':
case 'darwin-arm64':
return 'darwin';
case 'win32-x64':
return 'windows';
Expand Down
53 changes: 32 additions & 21 deletions src/engines/javascriptcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,26 @@ const execa = require('execa');
const Installer = require('../installer');
const { platform, unzip } = require('../common');

function buildURL(builder) {
return `https://build.webkit.org/api/v2/builders/${builder}/builds?limit=1&order=-number&property=got_revision&complete=true`;
async function macName() {
const { default: macosRelease } = await import('macos-release');
return macosRelease().name.toLowerCase();
}

async function getVersionFromBuilder(builder) {
const url = `https://build.webkit.org/api/v2/builders/${builder}/builds?limit=1&order=-number&property=archive_revision&complete=true`;
const body = await fetch(url).then((r) => r.json());
return body.builds[0].properties.archive_revision[0].split('@')[0];
}

async function getMacBuilder() {
switch (await macName()) {
case 'ventura':
return 706;
case 'monterey':
return 368;
default:
throw new Error(`Unknown macOS release: ${macName()}`);
}
}

class JavaScriptCoreInstaller extends Installer {
Expand All @@ -44,40 +62,33 @@ class JavaScriptCoreInstaller extends Installer {
if (version === 'latest') {
switch (platform) {
case 'linux-x64':
case 'linux-ia32':
return fetch('https://webkitgtk.org/jsc-built-products/x86_64/release/LAST-IS')
.then((r) => r.text())
.then((n) => n.trim().replace('.zip', ''));
case 'win32-x64': {
const body = await fetch(buildURL(27)).then((r) => r.json());
return body.builds[0].properties.got_revision[0];
}
case 'darwin-x64': {
const body = await fetch(buildURL(54)).then((r) => r.json());
return body.builds[0].properties.got_revision[0];
}
case 'darwin-arm64': {
const body = await fetch(buildURL(29)).then((r) => r.json());
return body.builds[0].properties.got_revision[0];
}
.then((n) => n.trim().replace('.zip', '').split('@')[0]);
case 'win32-x64':
return getVersionFromBuilder(27);
case 'darwin-x64':
case 'darwin-arm64':
return getVersionFromBuilder(await getMacBuilder());
default:
throw new RangeError(`Unknown platform ${platform}`);
}
}
return version;
}

getDownloadURL(version) {
async getDownloadURL(version) {
switch (platform) {
case 'darwin-x64':
return `https://s3-us-west-2.amazonaws.com/minified-archives.webkit.org/mac-catalina-x86_64-release/${version}.zip`;
case 'darwin-arm64':
return `https://s3-us-west-2.amazonaws.com/minified-archives.webkit.org/mac-bigsur-x86_64%20arm64-release/${version}.zip`;
return `https://s3-us-west-2.amazonaws.com/minified-archives.webkit.org/mac-${await macName()}-x86_64%20arm64-release/${version}@main.zip`;
case 'linux-ia32':
return `https://webkitgtk.org/jsc-built-products/x86_32/release/${version}.zip`;
return `https://webkitgtk.org/jsc-built-products/x86_32/release/${version}@main.zip`;
case 'linux-x64':
return `https://webkitgtk.org/jsc-built-products/x86_64/release/${version}.zip`;
return `https://webkitgtk.org/jsc-built-products/x86_64/release/${version}@main.zip`;
case 'win32-x64':
return `https://s3-us-west-2.amazonaws.com/archives.webkit.org/wincairo-x86_64-release/${version}.zip`;
return `https://s3-us-west-2.amazonaws.com/archives.webkit.org/wincairo-x86_64-release/${version}@main.zip`;
default:
throw new RangeError(`Unknown platform ${platform}`);
}
Expand Down
33 changes: 9 additions & 24 deletions src/engines/spidermonkey.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,15 @@ class SpiderMonkeyInstaller extends Installer {

static async resolveVersion(version) {
if (version === 'latest') {
// Build a request for buildhub2: https://buildhub2.readthedocs.io/en/latest/project.html
const body = {
size: 1,
sort: { 'build.id': 'desc' },
query: {
bool: {
must: [
{ term: { 'source.product': 'firefox' } },
{ term: { 'source.tree': 'mozilla-central' } },
{ term: { 'target.channel': 'nightly' } },
{ term: { 'target.platform': getFilename() } },
],
},
},
};

const data = await fetch('https://buildhub.moz.tools/api/search', {
method: 'post',
body: JSON.stringify(body),
}).then((r) => r.json());

const source = data.hits.hits[0]._source;

return `${source.target.version}#${source.build.id}`;
const result = await fetch('https://product-details.mozilla.org/1.0/firefox_history_development_releases.json')
.then((r) => r.json());
const entries = Object.entries(result);
entries.sort(([, a], [, b]) => {
const aTime = new Date(a).getTime();
const bTime = new Date(b).getTime();
return bTime - aTime;
});
return entries[0][0];
}
return version;
}
Expand Down

0 comments on commit 5386860

Please sign in to comment.