Skip to content

Commit 1babc37

Browse files
fix(workspace): invoke npm the way Windows exposes it
A normal Node installation on Windows exposes npm as a command shim rather than an `npm` executable, and nothing in this path spawns a shell — so "Install now" would have failed with ENOENT on the one platform where the Node gate had just told the user they were good to go. Uses the same platform split as the existing install path in `lsp/server.ts`, through `Process.run`, whose argv array also means an install spec containing spaces (an E2E tarball path) needs no quoting. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018rW3JTCesgQeuqZm9vcR9Z
1 parent 0d942e6 commit 1babc37

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-sync.ts‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { Flag as CoreFlag } from "@opencode-ai/core/flag/flag"
6161
import { which as whichBinary } from "@opencode-ai/core/util/which"
6262
import { Instance } from "@/project/instance"
6363
import { Log } from "@/altimate/util/log"
64+
import { Process } from "@/util/process"
6465
import { MCP } from "@/mcp"
6566
import { addMcpToConfig, resolveConfigPath } from "@/mcp/config"
6667
import { Config } from "@/config/config"
@@ -496,20 +497,26 @@ export function nodeMajor(): Promise<number | null> {
496497
}
497498

498499
/** Run the global install. Only ever reached from an explicit user choice —
499-
* rule 3 forbids reaching it from the attach flow itself. */
500-
export function installEngine(): Promise<InstallResult> {
500+
* rule 3 forbids reaching it from the attach flow itself.
501+
*
502+
* `npm.cmd` on Windows: a normal Node install exposes npm as a command shim,
503+
* not an `npm` executable, and nothing here spawns a shell — so the bare name
504+
* fails with ENOENT on the one platform where the Node gate has just told the
505+
* user they are good to go. Same platform split the existing install path in
506+
* `lsp/server.ts` uses. `Process.run` takes an argv array, so a spec with
507+
* spaces (an E2E tarball path) needs no quoting. */
508+
export async function installEngine(): Promise<InstallResult> {
501509
const spec = installSpec()
502510
if (syncInternals.install) return syncInternals.install(spec)
503-
return new Promise((resolve) => {
504-
execFile("npm", ["i", "-g", spec], { timeout: 300_000 }, (err, _stdout, stderr) => {
505-
if (err) {
506-
const detail = (stderr || "").trim().split(/\r?\n/).slice(-3).join(" ")
507-
resolve({ ok: false, error: detail || err.message })
508-
return
509-
}
510-
resolve({ ok: true })
511-
})
512-
})
511+
const npm = process.platform === "win32" ? "npm.cmd" : "npm"
512+
try {
513+
const result = await Process.run([npm, "i", "-g", spec], { timeout: 300_000, nothrow: true })
514+
if (result.code === 0) return { ok: true }
515+
const detail = result.stderr.toString().trim().split(/\r?\n/).slice(-3).join(" ")
516+
return { ok: false, error: detail || `npm exited with code ${result.code}` }
517+
} catch (err) {
518+
return { ok: false, error: err instanceof Error ? err.message : String(err) }
519+
}
513520
}
514521

515522
/** Hand the offer to an interactive surface. False when none is registered. */

0 commit comments

Comments
 (0)