fnm 1.39.0

Fast and simple Node.js version manager
1
2
3
4
5
6
7
8
9
10
11
12
use crate::config::FnmConfig;
use crate::version::Version;
use std::str::FromStr;

pub fn find_default_version(config: &FnmConfig) -> Option<Version> {
    if let Ok(version_path) = config.default_version_dir().canonicalize() {
        let file_name = version_path.parent()?.file_name()?;
        Version::from_str(file_name.to_str()?).ok()?.into()
    } else {
        Some(Version::Alias("default".into()))
    }
}