Fix dev CI build tool resolution and Windows npm spawning

This commit is contained in:
Shantur Rathore
2026-01-06 20:45:40 +00:00
parent fa308696b4
commit f5682ea246
3 changed files with 24 additions and 24 deletions

View File

@@ -243,7 +243,7 @@ jobs:
run: npm install @rollup/rollup-darwin-arm64 --no-save
- name: Ensure tauri native binary
run: npm install @tauri-apps/cli-darwin-arm64 @tauri-apps/cli-darwin-universal --no-save
run: npm install @tauri-apps/cli-darwin-arm64 --no-save
- name: Build macOS bundle (Tauri, arm64)
run: npm run build --workspace @codenomad/tauri-app

View File

@@ -2,7 +2,7 @@
import { spawn } from "child_process"
import { existsSync } from "fs"
import { join } from "path"
import path, { join } from "path"
import { fileURLToPath } from "url"
const __dirname = fileURLToPath(new URL(".", import.meta.url))
@@ -55,12 +55,22 @@ const platforms = {
function run(command, args, options = {}) {
return new Promise((resolve, reject) => {
const env = { ...process.env, NODE_PATH: nodeModulesPath, ...(options.env || {}) }
const pathKey = Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH"
const binPaths = [
join(nodeModulesPath, ".bin"),
join(workspaceNodeModulesPath, ".bin"),
]
env[pathKey] = `${binPaths.join(path.delimiter)}${path.delimiter}${env[pathKey] ?? ""}`
const spawnOptions = {
cwd: appDir,
stdio: "inherit",
shell: process.platform === "win32",
...options,
env: { ...process.env, NODE_PATH: nodeModulesPath, ...(options.env || {}) },
env,
}
const child = spawn(command, args, spawnOptions)

View File

@@ -10,7 +10,8 @@ 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 npmCandidates = process.platform === "win32" ? ["npm.cmd", "npm"] : ["npm"]
const npmExecPath = process.env.npm_execpath
const npmNodeExecPath = process.env.npm_node_execpath
if (!existsSync(sourceDir)) {
console.error(`[copy-opencode-config] Missing source directory at ${sourceDir}`)
@@ -30,30 +31,19 @@ if (!existsSync(nodeModulesDir)) {
"--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" },
})
const env = { ...process.env, npm_config_workspaces: "false" }
lastResult = result
const npmCli = npmExecPath && npmNodeExecPath ? [npmNodeExecPath, [npmExecPath, ...npmArgs]] : null
const result = npmCli
? spawnSync(npmCli[0], npmCli[1], { cwd: sourceDir, stdio: "inherit", env })
: spawnSync("npm", npmArgs, { cwd: sourceDir, stdio: "inherit", env, shell: process.platform === "win32" })
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)
if (result.status !== 0) {
if (result.error) {
console.error("[copy-opencode-config] npm install failed to start", result.error)
}
console.error("[copy-opencode-config] Failed to install opencode-config dependencies")
process.exit(lastResult?.status ?? 1)
process.exit(result.status ?? 1)
}
}