Skip to content

Commit 6cf9740

Browse files
committed
fix build
1 parent 86f35ff commit 6cf9740

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

npm/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
.npmrc
33
tmp.json
44

5-
# Binary files (these are built during release)
6-
*/bin/
7-
85
# Temporary files
96
*.tmp
107
*.temp

npm/istio-mcp-server/bin/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env node
2+
3+
const childProcess = require('child_process');
4+
5+
const BINARY_MAP = {
6+
darwin_x64: {name: 'istio-mcp-server-darwin-amd64', suffix: ''},
7+
darwin_arm64: {name: 'istio-mcp-server-darwin-arm64', suffix: ''},
8+
linux_x64: {name: 'istio-mcp-server-linux-amd64', suffix: ''},
9+
linux_arm64: {name: 'istio-mcp-server-linux-arm64', suffix: ''},
10+
win32_x64: {name: 'istio-mcp-server-windows-amd64', suffix: '.exe'},
11+
win32_arm64: {name: 'istio-mcp-server-windows-arm64', suffix: '.exe'},
12+
};
13+
14+
// Resolving will fail if the optionalDependency was not installed or the platform/arch is not supported
15+
const resolveBinaryPath = () => {
16+
try {
17+
const binary = BINARY_MAP[`${process.platform}_${process.arch}`];
18+
return require.resolve(`${binary.name}/bin/${binary.name}${binary.suffix}`);
19+
} catch (e) {
20+
throw new Error(`Could not resolve binary path for platform/arch: ${process.platform}/${process.arch}`);
21+
}
22+
};
23+
24+
const child = childProcess.spawn(resolveBinaryPath(), process.argv.slice(2), {
25+
stdio: 'inherit',
26+
});
27+
28+
const handleSignal = () => (signal) => {
29+
console.log(`Received ${signal}, terminating child process...`);
30+
if (child && !child.killed) {
31+
child.kill(signal);
32+
}
33+
};
34+
35+
['SIGTERM', 'SIGINT', 'SIGHUP'].forEach((signal) => {
36+
process.on(signal, handleSignal(signal));
37+
});
38+
39+
child.on('close', (code, signal) => {
40+
if (signal) {
41+
console.log(`Child process terminated by signal: ${signal}`);
42+
process.exit(128 + (signal === 'SIGTERM' ? 15 : signal === 'SIGINT' ? 2 : 1));
43+
} else {
44+
process.exit(code || 0);
45+
}
46+
});

0 commit comments

Comments
 (0)