From 8cd4ce7eb9fca297f1ca9d973bdc363514d1cc3e Mon Sep 17 00:00:00 2001 From: Jason Date: Sun, 12 Jun 2022 13:00:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20fix=20profile=20is=20not=20up=20to=20dat?= =?UTF-8?q?e=20and=20denobin=20will=20not=20be=20injected=20w=E2=80=A6=20(?= =?UTF-8?q?#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: fix profile is not up to date and denobin will not be injected when present before * should be good now * makes clippy happy :) --- Cargo.lock | 36 ++++++++++++++++++++++-------------- Cargo.toml | 3 ++- src/commands/doctor.rs | 11 ++++++++++- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9990d06..ebf9916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -174,9 +174,16 @@ dependencies = [ "set_env", "tempfile", "tinyget", + "which", "winapi", ] +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "fastrand" version = "1.7.0" @@ -272,9 +279,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.112" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" [[package]] name = "log" @@ -618,12 +625,11 @@ dependencies = [ [[package]] name = "set_env" -version = "1.3.1" +version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4d84a97e8068ac431f7c19ff1e5940042eac28c16e5b5130404a33a82ba1837" +checksum = "51864fb62fd09b8a7d931a11832bfbbda5297425cfc9ce04b54bc86c945c58eb" dependencies = [ "dirs", - "winreg", ] [[package]] @@ -731,6 +737,17 @@ version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +[[package]] +name = "which" +version = "4.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +dependencies = [ + "either", + "lazy_static", + "libc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -761,12 +778,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "winreg" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" -dependencies = [ - "winapi", -] diff --git a/Cargo.toml b/Cargo.toml index 35ed0e9..c9545ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,8 +31,9 @@ serde_json = "1.0.81" dirs = "4.0.0" phf = { version = "0.10.1", features = ["macros"] } colored = "2.0.0" -set_env = "1.3.1" native-tls = { version = "0.2.10", features = ["vendored"] } +set_env = "1.3.4" +which = "4.2.5" [target.'cfg(windows)'.dependencies] output_vt100 = "0.1.3" diff --git a/src/commands/doctor.rs b/src/commands/doctor.rs index aafd997..6ea84da 100644 --- a/src/commands/doctor.rs +++ b/src/commands/doctor.rs @@ -15,7 +15,16 @@ pub fn exec(meta: &mut DvmMeta) -> Result<()> { set_env::check_or_set("DVM_DIR", home_path.to_str().unwrap()).unwrap(); let path = set_env::get("PATH").unwrap(); let looking_for = deno_bin_path().parent().unwrap().to_str().unwrap().to_string(); - if !path.contains(looking_for.as_str()) { + let current = which::which("deno"); + + if let Ok(current) = current { + if current.to_str().unwrap().starts_with(&looking_for) { + println!("{}", "DVM deno bin is already set correctly.".green()); + } else { + set_env::prepend("PATH", looking_for.as_str()).unwrap(); + println!("{}", "Please restart your shell of choice to take effects.".red()); + } + } else if !path.contains(looking_for.as_str()) { set_env::prepend("PATH", looking_for.as_str()).unwrap(); println!("{}", "Please restart your shell of choice to take effects.".red()); }