mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-11-07 09:45:36 +00:00
fix(npm): install the binary on first run when postinstall was skipped
npm 12 blocks install scripts of unapproved packages under `npx` and `npm install -g` (its allow-scripts policy). The postinstall download never ran, so `npx -y idx-mcp` exited with "installed binary not found" and MCP clients saw only "Connection closed". Hermes Agent hits this by default: it runs a bare `npx` with its own npm 12. The launcher now runs the installer itself when the binary is missing, logging to stderr so the idx-mcp stdout channel stays clean. This also covers pnpm 10+ and bun, which skip dependency scripts by default. npm-smoke installs idx-mcp with --ignore-scripts and checks that the first run still starts cleanly. Fixes #41 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WB13omP6h7YeyJx7GNtUnF
This commit is contained in:
parent
a047112737
commit
bdbcf62a7b
5 changed files with 44 additions and 15 deletions
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const { spawn } = require("node:child_process");
|
||||
const { spawn, spawnSync } = require("node:child_process");
|
||||
|
||||
const packageManifest = JSON.parse(
|
||||
fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"),
|
||||
|
|
@ -13,6 +13,15 @@ const packageName = packageManifest.name;
|
|||
const binaryName = process.platform === "win32" ? `${nativeBinary}.exe` : nativeBinary;
|
||||
const binaryPath = path.join(__dirname, "..", "bin", binaryName);
|
||||
|
||||
// postinstall never ran (ignore-scripts) or its download failed: install now.
|
||||
// Its log goes to stderr, since stdout is the MCP channel for idx-mcp.
|
||||
if (!fs.existsSync(binaryPath)) {
|
||||
console.error(`${packageName}: binary not installed; running the installer`);
|
||||
spawnSync(process.execPath, [path.join(__dirname, "install.js")], {
|
||||
stdio: ["ignore", 2, 2],
|
||||
});
|
||||
}
|
||||
|
||||
if (!fs.existsSync(binaryPath)) {
|
||||
console.error(`${packageName}: installed binary not found at ${binaryPath}`);
|
||||
console.error(`${packageName}: rerun npm install or set IDX_BINARY_URL for a local binary`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue