Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/ProcessManagement/NodeResolver/
TryFnm.rs

1//! fnm shim lookup. `FNM_MULTISHELL_PATH` (active shell) wins; otherwise
2//! probe the per-OS multishell cache directories.
3
4use std::path::PathBuf;
5
6use crate::ProcessManagement::NodeResolver::{NodeExecutableName, NodeSource, ResolvedNode};
7
8pub fn Fn() -> Option<ResolvedNode::Struct> {
9	if let Ok(Multishell) = std::env::var("FNM_MULTISHELL_PATH") {
10		let Candidate = PathBuf::from(Multishell).join("bin").join(NodeExecutableName::Fn());
11
12		if Candidate.exists() {
13			return Some(ResolvedNode::Struct { Path:Candidate, Source:NodeSource::Enum::Fnm });
14		}
15	}
16
17	let Home = std::env::var("HOME").ok()?;
18
19	for Relative in ["/.local/share/fnm/current/bin", "/Library/Caches/fnm_multishells/current/bin"] {
20		let Candidate = PathBuf::from(&Home)
21			.join(Relative.trim_start_matches('/'))
22			.join(NodeExecutableName::Fn());
23
24		if Candidate.exists() {
25			return Some(ResolvedNode::Struct { Path:Candidate, Source:NodeSource::Enum::Fnm });
26		}
27	}
28
29	None
30}