MCPcopy Create free account
hub / github.com/Noumena-Network/code / attemptNpmUninstall

Function attemptNpmUninstall

src/utils/nativeInstaller/installer.ts:1626–1671  ·  view source on GitHub ↗
(
  packageName: string,
)

Source from the content-addressed store, hash-verified

1624}
1625
1626async function attemptNpmUninstall(
1627 packageName: string,
1628): Promise<{ success: boolean; error?: string; warning?: string }> {
1629 const { code, stderr } = await execFileNoThrowWithCwd(
1630 'npm',
1631 ['uninstall', '-g', packageName],
1632 // eslint-disable-next-line custom-rules/no-process-cwd -- matches original behavior
1633 { cwd: process.cwd() },
1634 )
1635
1636 if (code === 0) {
1637 logForDebugging(`Removed global npm installation of ${packageName}`)
1638 return { success: true }
1639 } else if (stderr && !stderr.includes('npm ERR! code E404')) {
1640 // Check for ENOTEMPTY error and try manual removal
1641 if (stderr.includes('npm error code ENOTEMPTY')) {
1642 logForDebugging(
1643 `Failed to uninstall global npm package ${packageName}: ${stderr}`,
1644 { level: 'error' },
1645 )
1646 logForDebugging(`Attempting manual removal due to ENOTEMPTY error`)
1647
1648 const manualResult = await manualRemoveNpmPackage(packageName)
1649 if (manualResult.success) {
1650 return { success: true, warning: manualResult.warning }
1651 } else if (manualResult.error) {
1652 return {
1653 success: false,
1654 error: `Failed to remove global npm installation of ${packageName}: ${stderr}. Manual removal also failed: ${manualResult.error}`,
1655 }
1656 }
1657 }
1658
1659 // Only report as error if it's not a "package not found" error
1660 logForDebugging(
1661 `Failed to uninstall global npm package ${packageName}: ${stderr}`,
1662 { level: 'error' },
1663 )
1664 return {
1665 success: false,
1666 error: `Failed to remove global npm installation of ${packageName}: ${stderr}`,
1667 }
1668 }
1669
1670 return { success: false } // Package not found, not an error
1671}
1672
1673export async function cleanupNpmInstallations(): Promise<{
1674 removed: number

Callers 1

cleanupNpmInstallationsFunction · 0.85

Calls 3

execFileNoThrowWithCwdFunction · 0.85
manualRemoveNpmPackageFunction · 0.85
logForDebuggingFunction · 0.50

Tested by

no test coverage detected