| 58 | } |
| 59 | |
| 60 | export async function method() { |
| 61 | if (process.execPath.includes(path.join(".arctic", "bin"))) return "curl" |
| 62 | if (process.execPath.includes(path.join(".local", "bin"))) return "curl" |
| 63 | const exec = process.execPath.toLowerCase() |
| 64 | |
| 65 | const checks = [ |
| 66 | { |
| 67 | name: "npm" as const, |
| 68 | command: () => $`npm list -g --depth=0`.throws(false).text(), |
| 69 | }, |
| 70 | { |
| 71 | name: "yarn" as const, |
| 72 | command: () => $`yarn global list`.throws(false).text(), |
| 73 | }, |
| 74 | { |
| 75 | name: "pnpm" as const, |
| 76 | command: () => $`pnpm list -g --depth=0`.throws(false).text(), |
| 77 | }, |
| 78 | { |
| 79 | name: "bun" as const, |
| 80 | command: () => $`bun pm ls -g`.throws(false).text(), |
| 81 | }, |
| 82 | // TODO: brew is not there yet |
| 83 | { |
| 84 | name: "brew" as const, |
| 85 | command: () => $`brew list --formula arctic`.throws(false).text(), |
| 86 | }, |
| 87 | ] |
| 88 | |
| 89 | checks.sort((a, b) => { |
| 90 | const aMatches = exec.includes(a.name) |
| 91 | const bMatches = exec.includes(b.name) |
| 92 | if (aMatches && !bMatches) return -1 |
| 93 | if (!aMatches && bMatches) return 1 |
| 94 | return 0 |
| 95 | }) |
| 96 | |
| 97 | for (const check of checks) { |
| 98 | const output = await check.command() |
| 99 | if (output.includes(check.name === "brew" ? "arctic" : "@arctic-cli/arctic")) { |
| 100 | return check.name |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return "unknown" |
| 105 | } |
| 106 | |
| 107 | export const UpgradeFailedError = NamedError.create( |
| 108 | "UpgradeFailedError", |