Repository navigation
Expand file tree
/
Copy pathrun.js
More file actions
50 lines (43 loc) · 1.56 KB
/
Copy pathrun.js
File metadata and controls
50 lines (43 loc) · 1.56 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
#!/usr/bin/env node
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
const binaryName = os.platform() === 'win32' ? 'preflight.exe' : 'preflight';
const binaryPath = path.join(__dirname, binaryName);
if (!fs.existsSync(binaryPath)) {
// pnpm 10, Bun and --ignore-scripts skip the postinstall that downloads it.
console.error(`preflight: the binary is missing (${binaryPath}).`);
console.error("The package's install script did not run. Run it with:");
console.error(` node "${path.join(__dirname, 'install.js')}"`);
console.error('or allow install scripts for @preflightsh/preflight and reinstall.');
process.exit(127);
}
const child = spawn(binaryPath, process.argv.slice(2), {
stdio: 'inherit'
});
// The child shares the terminal, so Ctrl-C already reaches it; forward the
// signals a supervisor (CI, a container runtime) sends only to this process.
const forward = ['SIGINT', 'SIGTERM', 'SIGHUP'];
for (const sig of forward) {
process.on(sig, () => {
if (child.exitCode === null && child.signalCode === null) {
child.kill(sig);
}
});
}
child.on('error', (err) => {
console.error(`preflight: could not start ${binaryPath}: ${err.message}`);
process.exit(127);
});
child.on('exit', (code, signal) => {
if (signal) {
// Die the same way, so the caller sees a killed process, not success.
for (const sig of forward) {
process.removeAllListeners(sig);
}
process.kill(process.pid, signal);
return;
}
process.exit(code === null ? 1 : code);
});