(method: Installation.Method, targets: RemovalTargets)
| 142 | } |
| 143 | |
| 144 | async function executeUninstall(method: Installation.Method, targets: RemovalTargets) { |
| 145 | const spinner = prompts.spinner() |
| 146 | const errors: string[] = [] |
| 147 | |
| 148 | for (const dir of targets.directories) { |
| 149 | if (dir.keep) { |
| 150 | prompts.log.step(`Skipping ${dir.label} (--keep-${dir.label.toLowerCase()})`) |
| 151 | continue |
| 152 | } |
| 153 | |
| 154 | const exists = await fs |
| 155 | .access(dir.path) |
| 156 | .then(() => true) |
| 157 | .catch(() => false) |
| 158 | if (!exists) continue |
| 159 | |
| 160 | spinner.start(`Removing ${dir.label}...`) |
| 161 | const err = await fs.rm(dir.path, { recursive: true, force: true }).catch((e) => e) |
| 162 | if (err) { |
| 163 | spinner.stop(`Failed to remove ${dir.label}`, 1) |
| 164 | errors.push(`${dir.label}: ${err.message}`) |
| 165 | continue |
| 166 | } |
| 167 | spinner.stop(`Removed ${dir.label}`) |
| 168 | } |
| 169 | |
| 170 | if (targets.shellConfig) { |
| 171 | spinner.start("Cleaning shell config...") |
| 172 | const err = await cleanShellConfig(targets.shellConfig).catch((e) => e) |
| 173 | if (err) { |
| 174 | spinner.stop("Failed to clean shell config", 1) |
| 175 | errors.push(`Shell config: ${err.message}`) |
| 176 | } else { |
| 177 | spinner.stop("Cleaned shell config") |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (method !== "curl" && method !== "unknown") { |
| 182 | const cmds: Record<string, string[]> = { |
| 183 | npm: ["npm", "uninstall", "-g", "opencode-ai"], |
| 184 | pnpm: ["pnpm", "uninstall", "-g", "opencode-ai"], |
| 185 | bun: ["bun", "remove", "-g", "opencode-ai"], |
| 186 | yarn: ["yarn", "global", "remove", "opencode-ai"], |
| 187 | brew: ["brew", "uninstall", "opencode"], |
| 188 | choco: ["choco", "uninstall", "opencode"], |
| 189 | scoop: ["scoop", "uninstall", "opencode"], |
| 190 | } |
| 191 | |
| 192 | const cmd = cmds[method] |
| 193 | if (cmd) { |
| 194 | spinner.start(`Running ${cmd.join(" ")}...`) |
| 195 | const result = await Process.run(method === "choco" ? ["choco", "uninstall", "opencode", "-y", "-r"] : cmd, { |
| 196 | nothrow: true, |
| 197 | }) |
| 198 | if (result.code !== 0) { |
| 199 | spinner.stop(`Package manager uninstall failed: exit code ${result.code}`, 1) |
| 200 | const text = `${result.stdout.toString("utf8")}\n${result.stderr.toString("utf8")}` |
| 201 | if (method === "choco" && text.includes("not running from an elevated command shell")) { |
no test coverage detected