volta icon indicating copy to clipboard operation
volta copied to clipboard

poc: Enable `volta uninstall [email protected]`

Open morishin opened this issue 1 year ago • 0 comments

This pull request is for a PoC.

As per https://github.com/volta-cli/volta/issues/327, the volta uninstall command does not allow you to uninstall node or yarn. However, I have many patch versions of node installed on my machine, and I wanted to delete older versions to free up unnecessary disk space. Therefore, it is inconvenient that volta uninstall [email protected] is not possible.

I looked through the issues and Discord but couldn't understand why this has not been implemented for so many years, so I created a simple implementation for discussion. I would like to know whether this approach is acceptable or if there are any concerns.

(The core of the implementation is here. The rest of the changes are not significant.)

fn uninstall(self: Box<Self>, _session: &mut Session) -> Fallible<()> {
    let home = volta_home()?;
    // Acquire a lock on the Volta directory, if possible, to prevent concurrent changes
    let _lock: Result<VoltaLock, crate::error::VoltaError> = VoltaLock::acquire();

    let node_dir = home.node_image_root_dir().join(self.version.to_string());
    if node_dir.exists() {
        remove_dir_if_exists(&node_dir)?;
        info!("{} 'node@{}' uninstalled", success_prefix(), self.version);
    } else {
        warn!("No version 'node@{}' found to uninstall", self.version);
    }

    Ok(())
}

morishin avatar Jan 20 '24 07:01 morishin