-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck-build.mjs
More file actions
55 lines (49 loc) · 1.37 KB
/
check-build.mjs
File metadata and controls
55 lines (49 loc) · 1.37 KB
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
import * as child_process from 'node:child_process';
import * as fs from 'node:fs';
import { createRequire } from 'node:module';
import * as binaries from './binaries.mjs';
const require = createRequire(import.meta.url);
function clean(err) {
return err.toString().trim();
}
async function recompileFromSource() {
console.log('Compiling from source...');
let spawn = child_process.spawnSync('node-gyp', ['configure'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true,
});
if (spawn.status !== 0) {
console.log('Failed to configure gyp');
console.log(clean(spawn.stderr));
return;
}
spawn = child_process.spawnSync('node-gyp', ['build'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true,
});
if (spawn.status !== 0) {
console.log('Failed to build bindings');
console.log(clean(spawn.stderr));
return;
}
await import('./copy-target.mjs');
}
if (fs.existsSync(binaries.target)) {
try {
require(binaries.target);
console.log('Precompiled binary found, skipping build from source.');
} catch (e) {
console.log('Precompiled binary found but failed loading');
if (process.env.ALWAYS_THROW) {
throw e;
} else {
console.log(e);
}
await recompileFromSource();
}
} else {
console.log('No precompiled binary found');
await recompileFromSource();
}