Skip to content

Commit e20a9d5

Browse files
author
Guy Bedford
committed
fixup formatting
1 parent 2bf7d39 commit e20a9d5

File tree

1 file changed

+63
-62
lines changed

1 file changed

+63
-62
lines changed

npm/weval/index.js

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,89 @@
11
import { endianness } from "node:os";
2-
import { fileURLToPath } from 'node:url';
3-
import { dirname, join, parse } from 'node:path';
2+
import { fileURLToPath } from "node:url";
3+
import { dirname, join, parse } from "node:path";
44
import { platform, arch } from "node:process";
55
import { mkdir } from "node:fs/promises";
66
import { existsSync } from "node:fs";
77

8-
import decompress from 'decompress';
9-
import decompressUnzip from 'decompress-unzip';
10-
import decompressTar from 'decompress-tar';
11-
import xz from '@napi-rs/lzma/xz';
8+
import decompress from "decompress";
9+
import decompressUnzip from "decompress-unzip";
10+
import decompressTar from "decompress-tar";
11+
import xz from "@napi-rs/lzma/xz";
1212

1313
const __dirname = dirname(fileURLToPath(import.meta.url));
1414

1515
const TAG = "v0.3.2";
1616

1717
async function getWeval() {
18-
const knownPlatforms = {
19-
"win32 x64 LE": "x86_64-windows",
20-
"darwin arm64 LE": "aarch64-macos",
21-
"darwin x64 LE": "x86_64-macos",
22-
"linux x64 LE": "x86_64-linux",
23-
"linux arm64 LE": "aarch64-linux",
24-
};
18+
const knownPlatforms = {
19+
"win32 x64 LE": "x86_64-windows",
20+
"darwin arm64 LE": "aarch64-macos",
21+
"darwin x64 LE": "x86_64-macos",
22+
"linux x64 LE": "x86_64-linux",
23+
"linux arm64 LE": "aarch64-linux",
24+
};
2525

26-
function getPlatformName() {
27-
let platformKey = `${platform} ${arch} ${endianness()}`;
26+
function getPlatformName() {
27+
let platformKey = `${platform} ${arch} ${endianness()}`;
2828

29-
if (platformKey in knownPlatforms) {
30-
return knownPlatforms[platformKey];
31-
}
32-
throw new Error(`Unsupported platform: "${platformKey}". "weval does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/weval/issues to request for your platform/architecture to be included."`);
29+
if (platformKey in knownPlatforms) {
30+
return knownPlatforms[platformKey];
3331
}
32+
throw new Error(
33+
`Unsupported platform: "${platformKey}". "weval does not have a precompiled binary for the platform/architecture you are using. You can open an issue on https://github.com/bytecodealliance/weval/issues to request for your platform/architecture to be included."`
34+
);
35+
}
3436

35-
async function getJSON(url) {
36-
let resp;
37-
try {
38-
resp = await fetch(url);
39-
if (!resp.ok) {
40-
throw new Error("non 2xx response code");
41-
}
42-
return resp.json();
43-
} catch (err) {
44-
const errMsg = err?.toString() ?? 'unknown error';
45-
console.error(`failed to fetch JSON from URL [${url}] (status ${resp?.status}): ${errMsg}`);
46-
process.exit(1);
37+
async function getJSON(url) {
38+
let resp;
39+
try {
40+
resp = await fetch(url);
41+
if (!resp.ok) {
42+
throw new Error("non 2xx response code");
4743
}
44+
return resp.json();
45+
} catch (err) {
46+
const errMsg = err?.toString() ?? "unknown error";
47+
console.error(
48+
`failed to fetch JSON from URL [${url}] (status ${resp?.status}): ${errMsg}`
49+
);
50+
process.exit(1);
4851
}
52+
}
4953

50-
const platformName = getPlatformName();
51-
const assetSuffix = (platform == 'win32') ? 'zip' : 'tar.xz';
52-
const exeSuffix = (platform == 'win32') ? '.exe' : '';
54+
const platformName = getPlatformName();
55+
const assetSuffix = platform == "win32" ? "zip" : "tar.xz";
56+
const exeSuffix = platform == "win32" ? ".exe" : "";
5357

54-
const exeDir = join(__dirname, platformName);
55-
const exe = join(exeDir, `weval${exeSuffix}`);
58+
const exeDir = join(__dirname, platformName);
59+
const exe = join(exeDir, `weval${exeSuffix}`);
5660

57-
// If we already have the executable installed, then return it
58-
if (existsSync(exe)) {
59-
return exe;
60-
}
61+
// If we already have the executable installed, then return it
62+
if (existsSync(exe)) {
63+
return exe;
64+
}
6165

62-
await mkdir(exeDir, { recursive: true });
63-
const downloadUrl = `https://github.com/bytecodealliance/weval/releases/download/${TAG}/weval-${TAG}-${platformName}.${assetSuffix}`;
64-
let data = await fetch(downloadUrl);
65-
if (!data.ok) {
66-
console.error(`Error downloading ${downloadUrl}`);
67-
process.exit(1);
68-
}
69-
let buf = await data.arrayBuffer();
66+
await mkdir(exeDir, { recursive: true });
67+
const downloadUrl = `https://github.com/bytecodealliance/weval/releases/download/${TAG}/weval-${TAG}-${platformName}.${assetSuffix}`;
68+
let data = await fetch(downloadUrl);
69+
if (!data.ok) {
70+
console.error(`Error downloading ${downloadUrl}`);
71+
process.exit(1);
72+
}
73+
let buf = await data.arrayBuffer();
7074

71-
if (downloadUrl.endsWith('.xz')) {
72-
buf = await xz.decompress(new Uint8Array(buf));
73-
}
74-
await decompress(Buffer.from(buf), exeDir, {
75-
// Remove the leading directory from the extracted file.
76-
strip: 1,
77-
plugins: [
78-
decompressUnzip(),
79-
decompressTar()
80-
],
81-
// Only extract the binary file and nothing else
82-
filter: file => parse(file.path).base === `weval${exeSuffix}`,
83-
});
75+
if (downloadUrl.endsWith(".xz")) {
76+
buf = await xz.decompress(new Uint8Array(buf));
77+
}
78+
await decompress(Buffer.from(buf), exeDir, {
79+
// Remove the leading directory from the extracted file.
80+
strip: 1,
81+
plugins: [decompressUnzip(), decompressTar()],
82+
// Only extract the binary file and nothing else
83+
filter: (file) => parse(file.path).base === `weval${exeSuffix}`,
84+
});
8485

85-
return exe;
86+
return exe;
8687
}
8788

8889
export default getWeval;

0 commit comments

Comments
 (0)