fix(npm): proper npx bin

This commit is contained in:
Marc Nuri
2025-02-14 16:02:24 +01:00
parent b14d8f46bc
commit b8e9b845e9
6 changed files with 40 additions and 33 deletions

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env node
const childProcess = require("child_process");
const BINARY_MAP = {
darwin_x86: {name: "kubernetes-mcp-server-darwin-amd64", suffix: ''},
darwin_arm64: {name: "kubernetes-mcp-server-darwin-arm64", suffix: ''},
linux_x86: {name: "kubernetes-mcp-server-linux-amd64", suffix: ''},
linux_arm64: {name: "kubernetes-mcp-server-linux-arm64", suffix: ''},
win32_x86: {name: "kubernetes-mcp-server-windows-amd64", suffix: '.exe'},
win32_arm64: {name: "kubernetes-mcp-server-windows-arm64", suffix: '.exe'},
};
const binary = BINARY_MAP[`${process.platform}_${process.arch}`];
module.exports.runBinary = function (...args) {
// Resolving will fail if the optionalDependency was not installed
childProcess.execFileSync(require.resolve(`${binary.name}/bin/${binary.name}+${binary.suffix}`), args, {
stdio: "inherit",
});
};

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env node
const path = require('path')
const childProcess = require('child_process');
const BINARY_MAP = {
darwin_x64: {name: 'kubernetes-mcp-server-darwin-amd64', suffix: ''},
darwin_arm64: {name: 'kubernetes-mcp-server-darwin-arm64', suffix: ''},
linux_x64: {name: 'kubernetes-mcp-server-linux-amd64', suffix: ''},
linux_arm64: {name: 'kubernetes-mcp-server-linux-arm64', suffix: ''},
win32_x64: {name: 'kubernetes-mcp-server-windows-amd64', suffix: '.exe'},
win32_arm64: {name: 'kubernetes-mcp-server-windows-arm64', suffix: '.exe'},
};
const binary = BINARY_MAP[`${process.platform}_${process.arch}`];
const resolveBinaryPath = () => {
try {
// Resolving will fail if the optionalDependency was not installed
return require.resolve(`${binary.name}/bin/${binary.name}${binary.suffix}`)
} catch (e) {
return path.join(__dirname, '..', `${binary.name}${binary.suffix}`)
}
};
childProcess.execFileSync(resolveBinaryPath(), process.argv.slice(2), {
stdio: 'inherit',
});

View File

@@ -2,9 +2,9 @@
"name": "kubernetes-mcp-server",
"version": "0.0.0",
"description": "Model Context Protocol (MCP) server for Kubernetes and OpenShift",
"main": "./index.js",
"main": "./bin/index.js",
"bin": {
"kubernetes-mcp-server": "bin/cli"
"kubernetes-mcp-server": "bin/index.js"
},
"optionalDependencies": {
"kubernetes-mcp-server-darwin-amd64": "0.0.0",