Skip to content

Commit c580878

Browse files
Addition of Boa to esvu (#53)
1 parent 12829e0 commit c580878

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ installing engines to make eshost automatically find the installed engines.
3636

3737
| Engine | Binary Names | `darwin-x64` | `darwin-arm64` | `linux-ia32` | `linux-x64` | `linux-arm64` | `win32-ia32` | `win32-x64` |
3838
| ------------------ | -------------------------------- | ------------ | -------------- | ------------ | ----------- | ------------- | ------------ | ----------- |
39-
| [Chakra][] | `ch`, `chakra` || | || |||
40-
| [engine262][] | `engine262` ||||||||
41-
| [GraalJS][] | `graaljs` ||| ||| ||
39+
| [Boa][] | `boa`, || | || | ||
40+
| [Chakra][] | `ch`, `chakra` || | || |||
41+
| [engine262][] | `engine262` ||||||||
42+
| [GraalJS][] | `graaljs` ||| ||| ||
4243
| [Hermes][] | `hermes` ||| | | | ||
4344
| [LibJS][] | `serenity-js` ||| || | | |
4445
| [JavaScriptCore][] | `jsc`, `javascriptcore` ||| || | ||
@@ -50,6 +51,7 @@ installing engines to make eshost automatically find the installed engines.
5051
Some binaries may be exposed as batch/shell scripts to properly handling shared library loading. Some binaries on
5152
64-bit systems may be natively 32-bit.
5253

54+
[Boa]: https://boajs.dev/
5355
[eshost-cli]: https://github.com/bterlson/eshost-cli
5456
[Chakra]: https://github.com/microsoft/chakracore
5557
[engine262]: https://engine262.js.org

src/engines/boa.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const execa = require('execa');
5+
const { join } = require('path');
6+
const fetch = require('node-fetch');
7+
const { copyFileSync, chmodSync, existsSync, mkdirSync } = require('fs');
8+
const Installer = require('../installer');
9+
const { platform } = require('../common');
10+
11+
const binaryName = platform.startsWith('win') ? 'boa.exe' : 'boa';
12+
13+
function getFilename() {
14+
switch (platform) {
15+
case 'darwin-x64':
16+
return 'boa-macos-amd64';
17+
case 'linux-x64':
18+
return 'boa-linux-amd64';
19+
case 'win32-x64':
20+
return 'boa-windows-amd64';
21+
default:
22+
throw new Error(`No Boa builds available for ${platform}`);
23+
}
24+
}
25+
26+
class BoaInstaller extends Installer {
27+
constructor(...args) {
28+
super(...args);
29+
this.binPath = undefined;
30+
}
31+
32+
static resolveVersion(version) {
33+
if (version === 'latest') {
34+
return fetch('https://api.github.com/repos/boa-dev/boa/releases/latest')
35+
.then((r) => r.json())
36+
.then((r) => r.tag_name);
37+
}
38+
return version;
39+
}
40+
41+
getDownloadURL(version) {
42+
return `https://github.com/boa-dev/boa/releases/download/${version}/${getFilename()}`;
43+
}
44+
45+
async extract() {
46+
// The file is not zipped so we don't need to do any extraction here
47+
// The file doesn't seem to be executable so we need to set it manually
48+
chmodSync(this.downloadPath, '755');
49+
// Windows will fail if the extractedPath doesn't exist
50+
if (!existsSync(this.extractedPath)) {
51+
mkdirSync(this.extractedPath);
52+
}
53+
return copyFileSync(this.downloadPath, join(this.extractedPath, binaryName));
54+
}
55+
56+
async install() {
57+
this.binPath = await this.registerBinary(binaryName);
58+
}
59+
60+
async test() {
61+
const program = 'console.log("42");';
62+
const output = '42\nundefined';
63+
64+
assert.strictEqual(
65+
(await execa(this.binPath, [], { input: program })).stdout,
66+
output,
67+
);
68+
}
69+
}
70+
71+
BoaInstaller.config = {
72+
name: 'Boa',
73+
id: 'boa',
74+
supported: [
75+
'linux-x64',
76+
'win32-x64',
77+
'darwin-x64',
78+
],
79+
};
80+
81+
module.exports = BoaInstaller;

0 commit comments

Comments
 (0)