1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00
This commit is contained in:
Luka Leer 2025-01-19 20:09:00 +00:00 committed by GitHub
commit c6e58b111f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 34 additions and 29 deletions

View file

@ -2467,12 +2467,12 @@ The executable name is inferred by default:
- If the resulting name has an <p(245)>@...</> suffix, strip it.
To change the installation root, use <c>--root</>:
<p(245)>deno install -g --allow-net --allow-read --root /usr/local jsr:@std/http/file-server</>
<p(245)>deno install -g --allow-net --allow-read --root /usr/local/bin jsr:@std/http/file-server</>
The installation root is determined, in order of precedence:
- <p(245)>--root</> option
- <p(245)>DENO_INSTALL_ROOT</> environment variable
- <p(245)>$HOME/.deno</>
- <p(245)>$HOME/.deno/bin</>
These must be added to the path manually if required."), UnstableArgsConfig::ResolutionAndRuntime)
.visible_alias("i")
@ -2643,12 +2643,12 @@ fn uninstall_subcommand() -> Command {
<p(245)>deno uninstall --global file_server</>
To change the installation root, use <c>--root</> flag:
<p(245)>deno uninstall --global --root /usr/local serve</>
<p(245)>deno uninstall --global --root /usr/local/bin serve</>
The installation root is determined, in order of precedence:
- <p(245)>--root</> option
- <p(245)>DENO_INSTALL_ROOT</> environment variable
- <p(245)>$HOME/.deno</>"),
- <p(245)>$HOME/.deno/bin</>"),
UnstableArgsConfig::None,
)
.defer(|cmd| {

View file

@ -134,6 +134,7 @@ fn get_installer_root() -> Result<PathBuf, io::Error> {
)
})?;
home_path.push(".deno");
home_path.push("bin");
Ok(home_path)
}
@ -211,12 +212,11 @@ pub async fn uninstall(
};
let cwd = std::env::current_dir().context("Unable to get CWD")?;
let root = if let Some(root) = uninstall_flags.root {
let installation_dir = if let Some(root) = uninstall_flags.root {
canonicalize_path_maybe_not_exists(&cwd.join(root))?
} else {
get_installer_root()?
};
let installation_dir = root.join("bin");
// ensure directory exists
if let Ok(metadata) = fs::metadata(&installation_dir) {
@ -472,12 +472,11 @@ async fn resolve_shim_data(
install_flags_global: &InstallFlagsGlobal,
) -> Result<ShimData, AnyError> {
let cwd = std::env::current_dir().context("Unable to get CWD")?;
let root = if let Some(root) = &install_flags_global.root {
let installation_dir = if let Some(root) = &install_flags_global.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 module_url = resolve_url_or_path(&install_flags_global.module_url, &cwd)?;
@ -870,7 +869,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_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1160,6 +1159,7 @@ mod tests {
#[tokio::test]
async fn install_npm_lockfile_default() {
let temp_dir = canonicalize_path(&env::temp_dir()).unwrap();
let bin_dir = temp_dir.join("bin");
let shim_data = resolve_shim_data(
&HttpClientProvider::new(None, None),
&Flags {
@ -1173,14 +1173,14 @@ mod tests {
module_url: "npm:cowsay".to_string(),
args: vec![],
name: None,
root: Some(temp_dir.to_string_lossy().to_string()),
root: Some(bin_dir.to_string_lossy().to_string()),
force: false,
},
)
.await
.unwrap();
let lock_path = temp_dir.join("bin").join(".cowsay.lock.json");
let lock_path = bin_dir.join(".cowsay.lock.json");
assert_eq!(
shim_data.args,
vec![
@ -1247,7 +1247,7 @@ mod tests {
module_url: local_module_str.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1277,7 +1277,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_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1298,7 +1298,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_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1320,7 +1320,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_string()),
root: Some(bin_dir.to_string()),
force: true,
},
)
@ -1351,7 +1351,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_string()),
root: Some(bin_dir.to_string()),
force: true,
},
)
@ -1381,7 +1381,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_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1422,7 +1422,7 @@ mod tests {
module_url: local_module_str.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()),
root: Some(bin_dir.to_string()),
force: false,
},
)
@ -1468,7 +1468,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_string()),
root: Some(bin_dir.to_string()),
force: true,
},
)
@ -1511,7 +1511,7 @@ mod tests {
module_url: file_module_string.to_string(),
args: vec![],
name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()),
root: Some(bin_dir.to_string()),
force: true,
},
)
@ -1568,7 +1568,7 @@ mod tests {
UninstallFlags {
kind: UninstallKind::Global(UninstallFlagsGlobal {
name: "echo_test".to_string(),
root: Some(temp_dir.path().to_string()),
root: Some(bin_dir.to_string()),
}),
},
)

View file

@ -160,6 +160,9 @@ fn install_custom_dir_env_var() {
let context = TestContext::with_http_server();
let temp_dir = context.temp_dir();
let temp_dir_str = temp_dir.path().to_string();
let bin_dir = temp_dir.path().join("custom_bin");
std::fs::create_dir(&bin_dir).unwrap();
let bin_dir_str = bin_dir.to_string();
context
.new_command()
@ -168,13 +171,13 @@ fn install_custom_dir_env_var() {
.envs([
("HOME", temp_dir_str.as_str()),
("USERPROFILE", temp_dir_str.as_str()),
("DENO_INSTALL_ROOT", temp_dir_str.as_str()),
("DENO_INSTALL_ROOT", bin_dir_str.as_str()),
])
.run()
.skip_output_check()
.assert_exit_code(0);
let mut file_path = temp_dir.path().join("bin/echo_test");
let mut file_path = bin_dir.join("echo_test");
assert!(file_path.exists());
if cfg!(windows) {
@ -200,6 +203,9 @@ fn installer_test_local_module_run() {
let context = TestContext::with_http_server();
let temp_dir = context.temp_dir();
let temp_dir_str = temp_dir.path().to_string();
let bin_dir = temp_dir.path().join("bin");
std::fs::create_dir(&bin_dir).unwrap();
let bin_dir_str = bin_dir.to_string();
let echo_ts_str = util::testdata_path().join("echo.ts").to_string();
context
@ -211,7 +217,7 @@ fn installer_test_local_module_run() {
"--name",
"echo_test",
"--root",
temp_dir_str.as_str(),
bin_dir_str.as_str(),
echo_ts_str.as_str(),
"hello",
])
@ -224,7 +230,6 @@ fn installer_test_local_module_run() {
.skip_output_check()
.assert_exit_code(0);
let bin_dir = temp_dir.path().join("bin");
let mut file_path = bin_dir.join("echo_test");
if cfg!(windows) {
file_path = file_path.with_extension("cmd");
@ -252,7 +257,7 @@ fn installer_test_remote_module_run() {
let bin_dir = root_dir.join("bin");
context
.new_command()
.args("install --name echo_test --root ./root -g http://localhost:4545/echo.ts hello")
.args("install --name echo_test --root ./root/bin -g http://localhost:4545/echo.ts hello")
.run()
.skip_output_check()
.assert_exit_code(0);
@ -274,7 +279,7 @@ fn installer_test_remote_module_run() {
// now uninstall with the relative path
context
.new_command()
.args("uninstall -g --root ./root echo_test")
.args("uninstall -g --root ./root/bin echo_test")
.run()
.skip_output_check()
.assert_exit_code(0);

View file

@ -8,7 +8,7 @@
"-n",
"echo_test",
"--root",
"$PWD",
"$PWD/bin",
"-g",
"https://localhost:5545/echo.ts"
],

View file

@ -1,4 +1,4 @@
const dirs = Deno.readDir("./bins/bin");
const dirs = Deno.readDir("./bins");
let found = false;
for await (const entry of dirs) {