()
| 1654 | } |
| 1655 | |
| 1656 | export async function cleanupNpmInstallations(): Promise<{ |
| 1657 | removed: number |
| 1658 | errors: string[] |
| 1659 | warnings: string[] |
| 1660 | }> { |
| 1661 | const errors: string[] = [] |
| 1662 | const warnings: string[] = [] |
| 1663 | let removed = 0 |
| 1664 | |
| 1665 | // Always attempt to remove @anthropic-ai/claude-code |
| 1666 | const codePackageResult = await attemptNpmUninstall( |
| 1667 | '@anthropic-ai/claude-code', |
| 1668 | ) |
| 1669 | if (codePackageResult.success) { |
| 1670 | removed++ |
| 1671 | if (codePackageResult.warning) { |
| 1672 | warnings.push(codePackageResult.warning) |
| 1673 | } |
| 1674 | } else if (codePackageResult.error) { |
| 1675 | errors.push(codePackageResult.error) |
| 1676 | } |
| 1677 | |
| 1678 | // Also attempt to remove MACRO.PACKAGE_URL if it's defined and different |
| 1679 | if (MACRO.PACKAGE_URL && MACRO.PACKAGE_URL !== '@anthropic-ai/claude-code') { |
| 1680 | const macroPackageResult = await attemptNpmUninstall(MACRO.PACKAGE_URL) |
| 1681 | if (macroPackageResult.success) { |
| 1682 | removed++ |
| 1683 | if (macroPackageResult.warning) { |
| 1684 | warnings.push(macroPackageResult.warning) |
| 1685 | } |
| 1686 | } else if (macroPackageResult.error) { |
| 1687 | errors.push(macroPackageResult.error) |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | // Check for local installation at ~/.claude/local |
| 1692 | const localInstallDir = join(homedir(), '.claude', 'local') |
| 1693 | |
| 1694 | try { |
| 1695 | await rm(localInstallDir, { recursive: true }) |
| 1696 | removed++ |
| 1697 | logForDebugging(`Removed local installation at ${localInstallDir}`) |
| 1698 | } catch (error) { |
| 1699 | if (!isENOENT(error)) { |
| 1700 | errors.push(`Failed to remove ${localInstallDir}: ${error}`) |
| 1701 | logForDebugging(`Failed to remove local installation: ${error}`, { |
| 1702 | level: 'error', |
| 1703 | }) |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | return { removed, errors, warnings } |
| 1708 | } |
| 1709 |
no test coverage detected