-
Notifications
You must be signed in to change notification settings - Fork 12
/
node-pre-gyp.js
101 lines (87 loc) · 2.66 KB
/
node-pre-gyp.js
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
91
92
93
94
95
96
97
98
99
100
101
/* eslint-disable no-console */
"use strict";
const { fork } = require("child_process");
const fs = require("fs");
const path = require("path");
const ROARING_NODE_PRE_GYP = process.env.ROARING_NODE_PRE_GYP;
if (ROARING_NODE_PRE_GYP) {
process.env.ROARING_NODE_PRE_GYP = "";
}
function roaring32NodePreGyp() {
console.time("node-pre-gyp");
process.on("exit", () => {
console.timeEnd("node-pre-gyp");
});
process.chdir(__dirname);
if (ROARING_NODE_PRE_GYP !== "custom-rebuild") {
try {
process.env.npm_config_node_gyp = require.resolve("node-gyp/bin/node-gyp.js");
} catch (_e) {}
require("@mapbox/node-pre-gyp/lib/main");
} else {
const forkAsync = (modulePath, args, options) => {
return new Promise((resolve, reject) => {
const childProcess = fork(modulePath, args, { stdio: "inherit", ...options });
childProcess.on("error", (e) => {
reject(e);
});
childProcess.on("close", (code) => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${modulePath} exited with code ${code}`));
}
});
});
};
const main = async () => {
console.log("* rebuild...");
let glibc;
try {
// eslint-disable-next-line node/no-unsupported-features/node-builtins
const header = process.report.getReport().header;
glibc = header.glibcVersionRuntime;
} catch {}
console.log("versions:", {
node: process.version,
v8: process.versions.v8,
glibc: glibc || null,
});
console.time("rebuild");
await forkAsync(__filename, ["rebuild"]);
console.log();
console.timeEnd("rebuild");
console.log();
// Clean debug info and temporary files
for (let d of fs.readdirSync("native")) {
d = path.resolve(__dirname, "native", d);
if (fs.lstatSync(d).isDirectory()) {
for (let f of fs.readdirSync(d)) {
f = path.resolve(d, f);
for (const ext of [".ipdb", ".iobj", ".pdb", ".obj", ".lib", ".exp", ".tmp"]) {
if (f.endsWith(ext)) {
console.log(`- removing file ${f}`);
fs.unlinkSync(f);
}
}
}
}
}
console.log();
console.log("* packaging...");
console.time("packaging");
await forkAsync(__filename, ["package", "testpackage"]);
console.timeEnd("packaging");
console.log();
};
main().catch((e) => {
console.error(e);
if (!process.exitCode) {
process.exitCode = 1;
}
});
}
}
if (ROARING_NODE_PRE_GYP !== "false") {
roaring32NodePreGyp();
}