red-briq-nodes/scripts/build-tcp-keepalive.js

33 lines
836 B
JavaScript

const { spawnSync } = require("child_process");
const path = require("path");
if (process.platform !== "linux") {
process.exit(0);
}
const nativeDir = path.join(__dirname, "..", "native", "tcp_keepalive");
function runNodeGyp(command, args) {
const result = spawnSync(command, args, {
cwd: nativeDir,
stdio: "inherit"
});
return result.error ? false : result.status === 0;
}
let built = false;
try {
const nodeGyp = require.resolve("node-gyp/bin/node-gyp.js");
built = runNodeGyp(process.execPath, [nodeGyp, "rebuild"]);
} catch (err) {
built = runNodeGyp("node-gyp", ["rebuild"]);
if (!built) {
built = runNodeGyp("npx", ["node-gyp", "rebuild"]);
}
}
if (!built) {
console.warn("tcp keepalive native helper was not built; TCP_KEEPCNT override will be disabled");
}