-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathboa.js
More file actions
98 lines (84 loc) · 2.73 KB
/
boa.js
File metadata and controls
98 lines (84 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
const assert = require('assert');
const execa = require('execa');
const { join } = require('path');
const fetch = require('node-fetch');
const { copyFileSync, chmodSync, existsSync, mkdirSync } = require('fs');
const Installer = require('../installer');
const { platform } = require('../common');
const binaryName = platform.startsWith('win') ? 'boa.exe' : 'boa';
function isNightly(version) {
return version.startsWith('nightly');
}
function getReleaseTag(version) {
return isNightly(version) ? 'nightly' : version;
}
function getFilename(version) {
switch (platform) {
case 'darwin-x64':
return isNightly(version) ? 'boa-x86_64-apple-darwin' : 'boa-macos-amd64';
case 'linux-x64':
return isNightly(version) ? 'boa-x86_64-unknown-linux-gnu' : 'boa-linux-amd64';
case 'win32-x64':
return isNightly(version) ? 'boa-x86_64-pc-windows-msvc.exe' : 'boa-windows-amd64.exe';
case 'darwin-arm64':
if (isNightly(version)) {
return 'boa-aarch64-apple-darwin';
}
// fall through
default:
throw new Error(`No Boa builds available for ${platform}`);
}
}
class BoaInstaller extends Installer {
constructor(...args) {
super(...args);
this.binPath = undefined;
}
static resolveVersion(version) {
if (version === 'latest') {
// Boa has nightly releases under the 'nightly' tag on GitHub, which are
// updated instead of making a new release for each one. Tag the version
// with the time the tag was last updated.
return fetch('https://api.github.com/repos/boa-dev/boa/releases/tags/nightly')
.then((r) => r.json())
.then((r) => `nightly-${r.updated_at}`);
}
return version;
}
getDownloadURL(version) {
return `https://github.com/boa-dev/boa/releases/download/${getReleaseTag(version)}/${getFilename(version)}`;
}
async extract() {
// The file is not zipped so we don't need to do any extraction here
// The file doesn't seem to be executable so we need to set it manually
chmodSync(this.downloadPath, '755');
// Windows will fail if the extractedPath doesn't exist
if (!existsSync(this.extractedPath)) {
mkdirSync(this.extractedPath);
}
return copyFileSync(this.downloadPath, join(this.extractedPath, binaryName));
}
async install() {
this.binPath = await this.registerBinary(binaryName);
}
async test() {
const program = 'console.log("42");';
const output = '42\nundefined';
assert.strictEqual(
(await execa(this.binPath, [], { input: program })).stdout,
output,
);
}
}
BoaInstaller.config = {
name: 'Boa',
id: 'boa',
supported: [
'linux-x64',
'win32-x64',
'darwin-x64',
'darwin-arm64',
],
};
module.exports = BoaInstaller;