-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathlibjs.js
More file actions
90 lines (77 loc) · 2.62 KB
/
libjs.js
File metadata and controls
90 lines (77 loc) · 2.62 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
'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-x64':
return 'macOS-universal2';
case 'darwin-arm64':
return 'macOS-universal2';
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.filter((a) => a.name === artifactName))
.then((x) => x[0].id)
.catch(() => {
throw new Error(`Failed to find any releases for ${artifactName} on LadybirdBrowser/ladybird`);
});
const runId = await fetch('https://api.github.com/repos/ladybirdbrowser/ladybird/actions/runs?event=push&branch=master&status=success')
.then((x) => x.json())
.then((x) => x.workflow_runs.filter((a) => a.name === 'Package the js repl as a binary artifact'))
.then((x) => x.sort((a, b) => a.check_suite_id > b.check_suite_id))
.then((x) => x[0].check_suite_id)
.catch(() => {
throw new Error('Failed to find any recent ladybird-js build');
});
return `${runId}/${artifactId}`;
}
getDownloadURL(version) {
const ids = version.split('/');
return `https://nightly.link/ladybirdbrowser/ladybird/suites/${ids[0]}/artifacts/${ids[1]}`;
}
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;