Improve opencode-config install on Windows

This commit is contained in:
Shantur Rathore
2026-01-06 20:30:40 +00:00
parent ac04d5daf7
commit ac8dfcc607

View File

@@ -10,7 +10,7 @@ const cliRoot = path.resolve(__dirname, "..")
const sourceDir = path.resolve(cliRoot, "../opencode-config")
const targetDir = path.resolve(cliRoot, "dist/opencode-config")
const nodeModulesDir = path.resolve(sourceDir, "node_modules")
const npmCmd = process.platform === "win32" ? "npm.cmd" : "npm"
const npmCandidates = process.platform === "win32" ? ["npm.cmd", "npm"] : ["npm"]
if (!existsSync(sourceDir)) {
console.error(`[copy-opencode-config] Missing source directory at ${sourceDir}`)
@@ -19,24 +19,41 @@ if (!existsSync(sourceDir)) {
if (!existsSync(nodeModulesDir)) {
console.log(`[copy-opencode-config] Installing opencode-config dependencies in ${sourceDir}`)
const result = spawnSync(
npmCmd,
[
"install",
"--prefix",
sourceDir,
"--omit=dev",
"--ignore-scripts",
"--fund=false",
"--audit=false",
"--package-lock=false",
"--workspaces=false",
],
{ cwd: sourceDir, stdio: "inherit", env: { ...process.env, npm_config_workspaces: "false" } },
)
if (result.status !== 0) {
const npmArgs = [
"install",
"--omit=dev",
"--ignore-scripts",
"--fund=false",
"--audit=false",
"--package-lock=false",
"--workspaces=false",
]
let lastResult
for (const npmCmd of npmCandidates) {
const result = spawnSync(npmCmd, npmArgs, {
cwd: sourceDir,
stdio: "inherit",
env: { ...process.env, npm_config_workspaces: "false" },
})
lastResult = result
if (result.error?.code === "ENOENT") {
console.warn(`[copy-opencode-config] ${npmCmd} not found on PATH, trying next candidate`)
continue
}
break
}
if (!lastResult || lastResult.status !== 0) {
if (lastResult?.error) {
console.error("[copy-opencode-config] npm install failed to start", lastResult.error)
}
console.error("[copy-opencode-config] Failed to install opencode-config dependencies")
process.exit(result.status ?? 1)
process.exit(lastResult?.status ?? 1)
}
}