-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcheck-build.js
56 lines (51 loc) · 1.78 KB
/
check-build.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
// This is a build script, so some logging is desirable as it allows
// us to follow the code path that triggered the error.
/* eslint-disable no-console */
const fs = require('fs');
const child_process = require('child_process');
const binaries = require('./binaries.js');
function clean(err) {
return err.toString().trim();
}
function recompileFromSource() {
console.log('@sentry/profiling-node: Compiling from source...');
let spawn = child_process.spawnSync('npm', ['run', 'build:bindings:configure'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true,
});
if (spawn.status !== 0) {
console.log('@sentry/profiling-node: Failed to configure gyp');
console.log('@sentry/profiling-node:', clean(spawn.stderr));
return;
}
spawn = child_process.spawnSync('npm', ['run', 'build:bindings'], {
stdio: ['inherit', 'inherit', 'pipe'],
env: process.env,
shell: true,
});
if (spawn.status !== 0) {
console.log('@sentry/profiling-node: Failed to build bindings');
console.log('@sentry/profiling-node:', clean(spawn.stderr));
return;
}
}
if (fs.existsSync(binaries.target)) {
try {
console.log(`@sentry/profiling-node: Precompiled binary found, attempting to load ${binaries.target}`);
require(binaries.target);
console.log('@sentry/profiling-node: Precompiled binary found, skipping build from source.');
} catch (e) {
console.log('@sentry/profiling-node: Precompiled binary found but failed loading');
console.log('@sentry/profiling-node:', e);
try {
recompileFromSource();
} catch (e) {
console.log('@sentry/profiling-node: Failed to compile from source');
throw e;
}
}
} else {
console.log('@sentry/profiling-node: No precompiled binary found');
recompileFromSource();
}