Skip to content

Commit b4d9a34

Browse files
authored
fix graaljs engine installer (#42)
fixes #38
1 parent 8930413 commit b4d9a34

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

src/engines/graaljs.js

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,42 @@ function getArchiveExtension() {
2727
return platform.startsWith('win') ? '.zip' : '.tar.gz';
2828
}
2929

30+
class GraalJSVersion {
31+
constructor(tagName) {
32+
const match = /((\d+)(?:\.(\d+))?(?:\.(\d+))?(?:\.(\d+))?.*)$/.exec(tagName);
33+
if (match == null) {
34+
throw new Error(`Unable to parse version from tag name '${tagName}'`);
35+
}
36+
const [, fullVersion, ...parts] = match;
37+
this.fullVersion = fullVersion;
38+
this.numParts = parts.filter((s) => s !== undefined).map((s) => parseInt(s, 10));
39+
}
40+
41+
static from(a) {
42+
return a instanceof GraalJSVersion ? a : new GraalJSVersion(a);
43+
}
44+
45+
static compare(a, b) {
46+
a = GraalJSVersion.from(a);
47+
b = GraalJSVersion.from(b);
48+
for (let i = 0; i < Math.max(a.numParts.length, b.numParts.length); i += 1) {
49+
const cmp = Math.sign((a.numParts[i] || 0) - (b.numParts[i] || 0));
50+
if (cmp !== 0) {
51+
return cmp;
52+
}
53+
}
54+
return a.fullVersion.localeCompare(b.fullVersion);
55+
}
56+
57+
toString() {
58+
return this.fullVersion;
59+
}
60+
61+
get majorVersion() {
62+
return this.numParts[0];
63+
}
64+
}
65+
3066
class GraalJSInstaller extends Installer {
3167
constructor(...args) {
3268
super(...args);
@@ -38,10 +74,14 @@ class GraalJSInstaller extends Installer {
3874
if (version === 'latest') {
3975
const body = await fetch('https://api.github.com/repos/oracle/graaljs/releases')
4076
.then((r) => r.json());
41-
return body
77+
const versions = body
4278
.filter((b) => !b.prerelease)
43-
.sort((a, b) => new Date(b.published_at).getTime() - new Date(a.published_at).getTime())[0]
44-
.tag_name.slice(3);
79+
.map((b) => GraalJSVersion.from(b.tag_name))
80+
.sort((a, b) => GraalJSVersion.compare(b, a));
81+
if (versions.length === 0) {
82+
throw new Error('Could not find a release version');
83+
}
84+
return versions[0].toString();
4585
}
4686
return version;
4787
}
@@ -60,12 +100,22 @@ class GraalJSInstaller extends Installer {
60100

61101
async install() {
62102
const root = `graaljs-${this.version}-${getFilename()}`;
103+
const libjsvm = GraalJSVersion.from(this.version).majorVersion >= 22;
63104
let graaljs;
64-
if (platform === 'darwin-x64') {
65-
graaljs = await this.registerAsset(`${root}/Contents/Home/bin/js`);
66-
} else if (platform === 'win32-x64') {
105+
if (platform.startsWith('darwin')) {
106+
if (libjsvm) {
107+
await this.registerAsset(`${root}/lib/libjsvm.dylib`);
108+
}
109+
graaljs = await this.registerAsset(`${root}/bin/js`);
110+
} else if (platform.startsWith('win')) {
111+
if (libjsvm) {
112+
await this.registerAsset(`${root}/lib/jsvm.dll`);
113+
}
67114
graaljs = await this.registerAsset(`${root}/bin/js.exe`);
68115
} else {
116+
if (libjsvm) {
117+
await this.registerAsset(`${root}/lib/libjsvm.so`);
118+
}
69119
graaljs = await this.registerAsset(`${root}/bin/js`);
70120
}
71121
this.binPath = await this.registerScript('graaljs', `${graaljs}`);
@@ -85,7 +135,9 @@ class GraalJSInstaller extends Installer {
85135
GraalJSInstaller.config = {
86136
name: 'GraalJS',
87137
id: 'graaljs',
88-
supported: [],
138+
supported: [
139+
'linux-x64', 'win32-x64', 'darwin-x64', 'linux-arm64', 'darwin-arm64',
140+
],
89141
};
90142

91143
module.exports = GraalJSInstaller;

0 commit comments

Comments
 (0)