0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

Compare commits

...

2 commits

Author SHA1 Message Date
Luka Leer
77c02d60ef
Merge 64b3a2d9f8 into 57dd66ec3d 2025-01-17 22:45:32 +01:00
Luka Leer
64b3a2d9f8
fix(cli): do not create bin folder within DENO_INSTALL_ROOT
As can be seen in the documentation, `DENO_INSTALL_ROOT` is meant to be the folder wherein Deno will install executables, with the default being `$HOME/.deno/bin`.

However, the current behaviour of the `install` and `uninstall` commands, if `DENO_INSTALL_ROOT` is set, is to still append "bin" to the path. This leads to executables being installed in a folder like `$HOME/.deno/bin/bin`, which is obviously not the intended behaviour.

This commit removes this appending. Do note that this is a breaking change in the behaviour of the `--root` flag, as previously it referred to a folder wherein the `bin` folder was located, but now it refers to the `bin` folder itself. For example: `deno install --root /foo/bar test.ts` would previously install the executable in `/foo/bar/bin/test`, but now it will install it in `/foo/bar/test`.
2024-12-26 16:13:26 +01:00
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. - If the resulting name has an <p(245)>@...</> suffix, strip it.
To change the installation root, use <c>--root</>: 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: The installation root is determined, in order of precedence:
- <p(245)>--root</> option - <p(245)>--root</> option
- <p(245)>DENO_INSTALL_ROOT</> environment variable - <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) These must be added to the path manually if required."), UnstableArgsConfig::ResolutionAndRuntime)
.visible_alias("i") .visible_alias("i")
@ -2643,12 +2643,12 @@ fn uninstall_subcommand() -> Command {
<p(245)>deno uninstall --global file_server</> <p(245)>deno uninstall --global file_server</>
To change the installation root, use <c>--root</> flag: 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: The installation root is determined, in order of precedence:
- <p(245)>--root</> option - <p(245)>--root</> option
- <p(245)>DENO_INSTALL_ROOT</> environment variable - <p(245)>DENO_INSTALL_ROOT</> environment variable
- <p(245)>$HOME/.deno</>"), - <p(245)>$HOME/.deno/bin</>"),
UnstableArgsConfig::None, UnstableArgsConfig::None,
) )
.defer(|cmd| { .defer(|cmd| {

View file

@ -134,6 +134,7 @@ fn get_installer_root() -> Result<PathBuf, io::Error> {
) )
})?; })?;
home_path.push(".deno"); home_path.push(".deno");
home_path.push("bin");
Ok(home_path) Ok(home_path)
} }
@ -211,12 +212,11 @@ pub async fn uninstall(
}; };
let cwd = std::env::current_dir().context("Unable to get CWD")?; 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))? canonicalize_path_maybe_not_exists(&cwd.join(root))?
} else { } else {
get_installer_root()? get_installer_root()?
}; };
let installation_dir = root.join("bin");
// ensure directory exists // ensure directory exists
if let Ok(metadata) = fs::metadata(&installation_dir) { if let Ok(metadata) = fs::metadata(&installation_dir) {
@ -472,12 +472,11 @@ async fn resolve_shim_data(
install_flags_global: &InstallFlagsGlobal, install_flags_global: &InstallFlagsGlobal,
) -> Result<ShimData, AnyError> { ) -> Result<ShimData, AnyError> {
let cwd = std::env::current_dir().context("Unable to get CWD")?; 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))? canonicalize_path_maybe_not_exists(&cwd.join(root))?
} else { } else {
get_installer_root()? get_installer_root()?
}; };
let installation_dir = root.join("bin");
// Check if module_url is remote // Check if module_url is remote
let module_url = resolve_url_or_path(&install_flags_global.module_url, &cwd)?; 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(), module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1160,6 +1159,7 @@ mod tests {
#[tokio::test] #[tokio::test]
async fn install_npm_lockfile_default() { async fn install_npm_lockfile_default() {
let temp_dir = canonicalize_path(&env::temp_dir()).unwrap(); let temp_dir = canonicalize_path(&env::temp_dir()).unwrap();
let bin_dir = temp_dir.join("bin");
let shim_data = resolve_shim_data( let shim_data = resolve_shim_data(
&HttpClientProvider::new(None, None), &HttpClientProvider::new(None, None),
&Flags { &Flags {
@ -1173,14 +1173,14 @@ mod tests {
module_url: "npm:cowsay".to_string(), module_url: "npm:cowsay".to_string(),
args: vec![], args: vec![],
name: None, name: None,
root: Some(temp_dir.to_string_lossy().to_string()), root: Some(bin_dir.to_string_lossy().to_string()),
force: false, force: false,
}, },
) )
.await .await
.unwrap(); .unwrap();
let lock_path = temp_dir.join("bin").join(".cowsay.lock.json"); let lock_path = bin_dir.join(".cowsay.lock.json");
assert_eq!( assert_eq!(
shim_data.args, shim_data.args,
vec![ vec![
@ -1247,7 +1247,7 @@ mod tests {
module_url: local_module_str.to_string(), module_url: local_module_str.to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1277,7 +1277,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(), module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1298,7 +1298,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1320,7 +1320,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL module_url: "http://localhost:4545/cat.ts".to_string(), // using a different URL
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: true, force: true,
}, },
) )
@ -1351,7 +1351,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), module_url: "http://localhost:4545/cat.ts".to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: true, force: true,
}, },
) )
@ -1381,7 +1381,7 @@ mod tests {
module_url: "http://localhost:4545/echo_server.ts".to_string(), module_url: "http://localhost:4545/echo_server.ts".to_string(),
args: vec!["\"".to_string()], args: vec!["\"".to_string()],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1422,7 +1422,7 @@ mod tests {
module_url: local_module_str.to_string(), module_url: local_module_str.to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: false, force: false,
}, },
) )
@ -1468,7 +1468,7 @@ mod tests {
module_url: "http://localhost:4545/cat.ts".to_string(), module_url: "http://localhost:4545/cat.ts".to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: true, force: true,
}, },
) )
@ -1511,7 +1511,7 @@ mod tests {
module_url: file_module_string.to_string(), module_url: file_module_string.to_string(),
args: vec![], args: vec![],
name: Some("echo_test".to_string()), name: Some("echo_test".to_string()),
root: Some(temp_dir.path().to_string()), root: Some(bin_dir.to_string()),
force: true, force: true,
}, },
) )
@ -1568,7 +1568,7 @@ mod tests {
UninstallFlags { UninstallFlags {
kind: UninstallKind::Global(UninstallFlagsGlobal { kind: UninstallKind::Global(UninstallFlagsGlobal {
name: "echo_test".to_string(), 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 context = TestContext::with_http_server();
let temp_dir = context.temp_dir(); let temp_dir = context.temp_dir();
let temp_dir_str = temp_dir.path().to_string(); 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 context
.new_command() .new_command()
@ -168,13 +171,13 @@ fn install_custom_dir_env_var() {
.envs([ .envs([
("HOME", temp_dir_str.as_str()), ("HOME", temp_dir_str.as_str()),
("USERPROFILE", 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() .run()
.skip_output_check() .skip_output_check()
.assert_exit_code(0); .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()); assert!(file_path.exists());
if cfg!(windows) { if cfg!(windows) {
@ -200,6 +203,9 @@ fn installer_test_local_module_run() {
let context = TestContext::with_http_server(); let context = TestContext::with_http_server();
let temp_dir = context.temp_dir(); let temp_dir = context.temp_dir();
let temp_dir_str = temp_dir.path().to_string(); 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(); let echo_ts_str = util::testdata_path().join("echo.ts").to_string();
context context
@ -211,7 +217,7 @@ fn installer_test_local_module_run() {
"--name", "--name",
"echo_test", "echo_test",
"--root", "--root",
temp_dir_str.as_str(), bin_dir_str.as_str(),
echo_ts_str.as_str(), echo_ts_str.as_str(),
"hello", "hello",
]) ])
@ -224,7 +230,6 @@ fn installer_test_local_module_run() {
.skip_output_check() .skip_output_check()
.assert_exit_code(0); .assert_exit_code(0);
let bin_dir = temp_dir.path().join("bin");
let mut file_path = bin_dir.join("echo_test"); let mut file_path = bin_dir.join("echo_test");
if cfg!(windows) { if cfg!(windows) {
file_path = file_path.with_extension("cmd"); file_path = file_path.with_extension("cmd");
@ -252,7 +257,7 @@ fn installer_test_remote_module_run() {
let bin_dir = root_dir.join("bin"); let bin_dir = root_dir.join("bin");
context context
.new_command() .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() .run()
.skip_output_check() .skip_output_check()
.assert_exit_code(0); .assert_exit_code(0);
@ -274,7 +279,7 @@ fn installer_test_remote_module_run() {
// now uninstall with the relative path // now uninstall with the relative path
context context
.new_command() .new_command()
.args("uninstall -g --root ./root echo_test") .args("uninstall -g --root ./root/bin echo_test")
.run() .run()
.skip_output_check() .skip_output_check()
.assert_exit_code(0); .assert_exit_code(0);

View file

@ -8,7 +8,7 @@
"-n", "-n",
"echo_test", "echo_test",
"--root", "--root",
"$PWD", "$PWD/bin",
"-g", "-g",
"https://localhost:5545/echo.ts" "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; let found = false;
for await (const entry of dirs) { for await (const entry of dirs) {