summaryrefslogtreecommitdiff
path: root/cli/tools/installer.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-11-13 09:44:01 -0500
committerGitHub <noreply@github.com>2023-11-13 09:44:01 -0500
commit6e1f3aa0131f145db631d5dfb94c2b9404172194 (patch)
tree2d48695f5efb15312e7e78c1fa0d2addfd0a03f5 /cli/tools/installer.rs
parent542314a0becbba120dbee13b3f410f647b4c9cb7 (diff)
fix(install): should work with non-existent relative root (#21161)
Closes #21160
Diffstat (limited to 'cli/tools/installer.rs')
-rw-r--r--cli/tools/installer.rs49
1 files changed, 25 insertions, 24 deletions
diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs
index c221168fe..dfefb74d1 100644
--- a/cli/tools/installer.rs
+++ b/cli/tools/installer.rs
@@ -176,9 +176,10 @@ pub async fn infer_name_from_url(url: &Url) -> Option<String> {
Some(stem)
}
-pub fn uninstall(name: String, root: Option<PathBuf>) -> Result<(), AnyError> {
+pub fn uninstall(name: String, root: Option<String>) -> Result<(), AnyError> {
+ let cwd = std::env::current_dir().context("Unable to get CWD")?;
let root = if let Some(root) = root {
- canonicalize_path_maybe_not_exists(&root)?
+ canonicalize_path_maybe_not_exists(&cwd.join(root))?
} else {
get_installer_root()?
};
@@ -303,15 +304,15 @@ async fn resolve_shim_data(
flags: &Flags,
install_flags: &InstallFlags,
) -> Result<ShimData, AnyError> {
+ let cwd = std::env::current_dir().context("Unable to get CWD")?;
let root = if let Some(root) = &install_flags.root {
- canonicalize_path_maybe_not_exists(root)?
+ canonicalize_path_maybe_not_exists(&cwd.join(root))?
} else {
get_installer_root()?
};
let installation_dir = root.join("bin");
// Check if module_url is remote
- let cwd = std::env::current_dir().context("Unable to get CWD")?;
let module_url = resolve_url_or_path(&install_flags.module_url, &cwd)?;
let name = if install_flags.name.is_some() {
@@ -635,7 +636,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -669,7 +670,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: None,
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -691,7 +692,7 @@ mod tests {
module_url: "http://localhost:4545/subdir/main.ts".to_string(),
args: vec![],
name: None,
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -715,7 +716,7 @@ mod tests {
.to_string(),
args: vec![],
name: None,
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -741,7 +742,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -769,7 +770,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec!["--foobar".to_string()],
name: Some("echo_test".to_string()),
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -802,7 +803,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -831,7 +832,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -861,7 +862,7 @@ mod tests {
module_url: "npm:cowsay".to_string(),
args: vec![],
name: None,
- root: Some(temp_dir.clone()),
+ root: Some(temp_dir.to_string_lossy().to_string()),
force: false,
},
)
@@ -895,7 +896,7 @@ mod tests {
module_url: "npm:cowsay".to_string(),
args: vec![],
name: None,
- root: Some(env::temp_dir()),
+ root: Some(env::temp_dir().to_string_lossy().to_string()),
force: false,
},
)
@@ -930,7 +931,7 @@ mod tests {
module_url: local_module_str.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -959,7 +960,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -979,7 +980,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -1000,7 +1001,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: true,
},
)
@@ -1030,7 +1031,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: true,
},
)
@@ -1059,7 +1060,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec!["\"".to_string()],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -1099,7 +1100,7 @@ mod tests {
module_url: local_module_str.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: false,
},
)
@@ -1143,7 +1144,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: true,
},
)
@@ -1185,7 +1186,7 @@ mod tests {
module_url: file_module_string.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
- root: Some(temp_dir.path().to_path_buf()),
+ root: Some(temp_dir.path().to_string()),
force: true,
},
)
@@ -1237,7 +1238,7 @@ mod tests {
File::create(file_path).unwrap();
}
- uninstall("echo_test".to_string(), Some(temp_dir.path().to_path_buf()))
+ uninstall("echo_test".to_string(), Some(temp_dir.path().to_string()))
.unwrap();
assert!(!file_path.exists());