use std::path::{Path, PathBuf};
pub(crate) fn normalize_host_visible_path_text(rendered: &str) -> String {
#[cfg(windows)]
{
if let Some(stripped) = rendered.strip_prefix(r"\\?\UNC\") {
return format!(r"\\{}", stripped);
}
if let Some(stripped) = rendered.strip_prefix(r"\\?\") {
return stripped.to_string();
}
}
rendered.to_string()
}
pub fn render_host_visible_path(path: &Path) -> String {
normalize_host_visible_path_text(&path.to_string_lossy())
}
pub(crate) fn host_process_path_argument(path: &Path) -> PathBuf {
#[cfg(windows)]
{
PathBuf::from(normalize_host_visible_path_text(&path.to_string_lossy()))
}
#[cfg(not(windows))]
{
path.to_path_buf()
}
}
#[cfg(test)]
mod tests {
use super::host_process_path_argument;
use std::path::Path;
#[test]
fn host_process_path_argument_uses_runtime_compatible_path() {
#[cfg(windows)]
assert_eq!(
host_process_path_argument(Path::new(r"\\?\C:\runtime\pnpm.cjs")),
Path::new(r"C:\runtime\pnpm.cjs")
);
#[cfg(not(windows))]
assert_eq!(
host_process_path_argument(Path::new("/runtime/pnpm.cjs")),
Path::new("/runtime/pnpm.cjs")
);
}
}