forked from devsnek/esvu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibjs.js
More file actions
83 lines (70 loc) · 2.24 KB
/
libjs.js
File metadata and controls
83 lines (70 loc) · 2.24 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
'use strict';
const assert = require('assert');
const execa = require('execa');
const fetch = require('node-fetch');
const path = require('path');
const Installer = require('../installer');
const { platform, unzip, untar } = require('../common');
function getFilename() {
switch (platform) {
case 'linux-x64':
return 'Linux-x86_64';
case 'darwin-arm64':
return 'macOS-arm64';
default:
throw new Error(`LibJS does not have binary builds for ${platform}`);
}
}
class LibJSInstaller extends Installer {
constructor(...args) {
super(...args);
this.binPath = undefined;
}
static async resolveVersion(version) {
const artifactName = `ladybird-js-${getFilename()}`;
if (version !== 'latest') {
throw new Error('LibJS only provides binary builds for \'latest\'');
}
const artifactId = await fetch('https://api.github.com/repos/ladybirdbrowser/ladybird/actions/artifacts')
.then((x) => x.json())
.then((x) => x.artifacts.find((a) => a.name === artifactName))
.then((x) => x.id)
.catch(() => {
throw new Error(`Failed to find any releases for ${artifactName} on LadybirdBrowser/ladybird`);
});
return `gh-actions-artifact-${artifactId}`;
}
getDownloadURL(version) {
if (version.startsWith('gh-actions-artifact-')) {
const artifactId = version.slice('gh-actions-artifact-'.length);
return `https://nightly.link/ladybirdbrowser/ladybird/actions/artifacts/${artifactId}.zip`;
}
throw new Error(`Unexpected version format for ${version}`);
}
async extract() {
await unzip(this.downloadPath, `${this.extractedPath}zip`);
await untar(path.join(`${this.extractedPath}zip`, `ladybird-js-${getFilename()}.tar.gz`), this.extractedPath);
}
async install() {
const js = await this.registerAsset('bin/js');
this.binPath = await this.registerScript('ladybird-js', `"${js}"`);
}
async test() {
const program = 'console.log("42")';
const output = '"42"';
assert.strictEqual(
(await execa(this.binPath, ['-c', program])).stdout,
output,
);
}
}
LibJSInstaller.config = {
name: 'LibJS',
id: 'libjs',
supported: [
'linux-x64',
'darwin-x64',
'darwin-arm64',
],
};
module.exports = LibJSInstaller;