Skip to content

Commit 8d9eb92

Browse files
authored
Clean up postinstall script (rescript-lang#5931)
* Add missing type annotation in dump script * Clean up postinstall script
1 parent 3a8cf1a commit 8d9eb92

File tree

2 files changed

+29
-45
lines changed

2 files changed

+29
-45
lines changed

scripts/rescript_dump.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ var dump_usage = `Usage: rescript dump <options> [target]
55
`;
66
var child_process = require("child_process");
77
var path = require("path");
8+
/**
9+
* @type {arg.specs}
10+
*/
811
var specs = [];
912

1013
/**

scripts/rescript_postinstall.js

+26-45
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,43 @@
11
//@ts-check
2-
var child_process = require("child_process");
3-
var fs = require("fs");
2+
const child_process = require("child_process");
3+
const fs = require("fs");
44

5-
var supported_os = ["darwin", "freebsd", "linux", "openbsd", "win32"];
6-
if (supported_os.indexOf(process.platform) < 0) {
7-
throw new Error("Not supported platform" + process.platform);
8-
}
9-
10-
var bsc_exe = require("./bin_path").bsc_exe;
11-
12-
var ninja_bin_output = require("./bin_path").ninja_exe;
5+
const bsc_exe = require("./bin_path").bsc_exe;
6+
const ninja_exe = require("./bin_path").ninja_exe;
137

148
function checkNinja() {
15-
var vendor_ninja_version = "1.9.0.git";
16-
17-
// sanity check to make sure the binary actually runs. Used for Linux. Too many variants
18-
/**
19-
*
20-
* @param {string} binary_path
21-
*/
22-
function test_ninja_compatible(binary_path) {
23-
var version;
24-
try {
25-
version = child_process
26-
.execSync(JSON.stringify(binary_path) + " --version", {
27-
encoding: "utf8",
28-
stdio: ["pipe", "pipe", "ignore"], // execSync outputs to stdout even if we catch the error. Silent it here
29-
})
30-
.trim();
31-
} catch (e) {
32-
console.log("ninja not compatible?", String(e));
33-
return false;
34-
}
35-
return version === vendor_ninja_version;
9+
if (!fs.existsSync(ninja_exe)) {
10+
throw new Error(
11+
`No ninja binary found for this platform. ${ninja_exe} does not exist.`
12+
);
3613
}
3714

38-
if (
39-
fs.existsSync(ninja_bin_output) &&
40-
test_ninja_compatible(ninja_bin_output)
41-
) {
42-
console.log(
43-
"ninja binary is already cached and installed: ",
44-
ninja_bin_output
15+
try {
16+
return String(child_process.execFileSync(ninja_exe, ["--version"])).trim();
17+
} catch (e) {
18+
throw new Error(
19+
`Error getting ninja version. The ninja binary at ${ninja_exe} may not be compatible with this platform: ${e}`
4520
);
46-
} else {
47-
throw new Error("No matching ninja binary found");
4821
}
4922
}
5023

5124
function checkCompiler() {
25+
if (!fs.existsSync(bsc_exe)) {
26+
throw new Error(
27+
`No ReScript compiler binary found for this platform. ${bsc_exe} does not exist.`
28+
);
29+
}
30+
5231
try {
53-
var version = String(child_process.execFileSync(bsc_exe, ["-v"]));
54-
console.log("ReScript compiler version:", version);
32+
return String(child_process.execFileSync(bsc_exe, ["-v"])).trim();
5533
} catch (e) {
56-
throw new Error("No working ReScript compiler");
34+
throw new Error(
35+
`Error getting ReScript compiler version. The compiler binary at ${bsc_exe} may not be compatible with this platform: ${e}`
36+
);
5737
}
5838
}
5939

60-
checkNinja();
40+
var ninjaVersion = checkNinja();
41+
var compilerVersion = checkCompiler();
6142

62-
checkCompiler();
43+
console.log(`${compilerVersion} (ninja ${ninjaVersion})`);

0 commit comments

Comments
 (0)