fix(npm): add --version fallback in wrapper

fix(npm): add --version fallback in wrapper
This commit is contained in:
GK012
2026-05-06 23:19:05 +08:00
committed by GitHub
parent 7def57203f
commit 9a7cd9f937
+22
View File
@@ -1,12 +1,34 @@
const { spawnSync } = require("child_process");
const { getBinaryPath } = require("./install");
const pkg = require("../package.json");
function isVersionFlag() {
const args = process.argv.slice(2);
return args.includes("--version") || args.includes("-v") || args.includes("-V");
}
function handleVersionFallback(binaryName) {
if (isVersionFlag()) {
const binVersion = pkg.deepseekBinaryVersion || pkg.version;
console.log(`${binaryName} (npm wrapper) v${pkg.version}`);
console.log(`binary version: v${binVersion}`);
console.log(`repo: ${pkg.repository?.url || "N/A"}`);
process.exit(0);
}
}
async function run(binaryName) {
// Intercept --version before attempting binary download/launch
handleVersionFallback(binaryName);
const binaryPath = await getBinaryPath(binaryName);
const result = spawnSync(binaryPath, process.argv.slice(2), {
stdio: "inherit",
});
if (result.error) {
// If binary fails and user asked for --version, show npm version instead
handleVersionFallback(binaryName);
throw result.error;
}
process.exit(result.status ?? 1);