@agora-build/dialf 0.1.55 → 0.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/dialf.js +33 -5
- package/package.json +1 -1
package/bin/dialf.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Thin launcher
|
|
2
|
+
// Thin launcher for the vendored native `dialf` binary — must be TRANSPARENT, so dialf
|
|
3
|
+
// behaves identically installed via npm, curl (direct symlink), or built from source.
|
|
4
|
+
//
|
|
5
|
+
// Not spawnSync: Ctrl+C sends SIGINT to the whole foreground process group — the native
|
|
6
|
+
// binary catches it for its multi-level job-cancel flow, but spawnSync leaves this wrapper
|
|
7
|
+
// to die on the same SIGINT, which hands the shell its prompt back and orphans the binary
|
|
8
|
+
// so further Ctrl+C presses never reach it. Instead: async spawn, stay alive through
|
|
9
|
+
// SIGINT (the tty already delivers it to the child), forward direct termination signals,
|
|
10
|
+
// and mirror the child's exit code / fatal signal exactly.
|
|
3
11
|
|
|
4
|
-
const {
|
|
12
|
+
const { spawn } = require('child_process');
|
|
5
13
|
const fs = require('fs');
|
|
14
|
+
const os = require('os');
|
|
6
15
|
const path = require('path');
|
|
7
16
|
|
|
8
17
|
const vendor = path.join(__dirname, '..', 'vendor');
|
|
@@ -17,6 +26,25 @@ if (!dir) {
|
|
|
17
26
|
process.exit(1);
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
const child = spawn(path.join(vendor, dir, 'dialf'), process.argv.slice(2), { stdio: 'inherit' });
|
|
30
|
+
|
|
31
|
+
// Ctrl+C: the child already receives its own SIGINT from the tty — just don't die with it.
|
|
32
|
+
process.on('SIGINT', () => {});
|
|
33
|
+
// Signals sent to the wrapper alone (kill <wrapper-pid>) are forwarded to the child.
|
|
34
|
+
for (const sig of ['SIGTERM', 'SIGHUP']) {
|
|
35
|
+
process.on(sig, () => {
|
|
36
|
+
try {
|
|
37
|
+
child.kill(sig);
|
|
38
|
+
} catch (_) {
|
|
39
|
+
/* already gone */
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
child.on('error', (e) => {
|
|
45
|
+
console.error(`dialf: ${e.message}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
child.on('exit', (code, signal) => {
|
|
49
|
+
process.exit(signal ? 128 + (os.constants.signals[signal] || 1) : code === null ? 1 : code);
|
|
50
|
+
});
|