From 11cdb42b7873e9e5113361d46edd6e5b03e6bcae Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Thu, 7 Sep 2023 10:22:32 -0700 Subject: [PATCH] fix: Fix globals directory not being located. (#1045) * Add locate bins. * Update rust. * Bump version. --- .yarn/versions/4539b14a.yml | 9 +++++++++ crates/node/tool/src/node_tool.rs | 2 ++ crates/node/tool/src/npm_tool.rs | 4 ++++ crates/node/tool/src/pnpm_tool.rs | 4 ++++ crates/node/tool/src/yarn_tool.rs | 4 ++++ crates/rust/platform/src/rust_platform.rs | 22 +++++++++++----------- crates/rust/tool/src/rust_tool.rs | 2 ++ packages/cli/CHANGELOG.md | 7 +++++++ 8 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 .yarn/versions/4539b14a.yml diff --git a/.yarn/versions/4539b14a.yml b/.yarn/versions/4539b14a.yml new file mode 100644 index 00000000000..1f2a5d9c201 --- /dev/null +++ b/.yarn/versions/4539b14a.yml @@ -0,0 +1,9 @@ +releases: + "@moonrepo/cli": patch + "@moonrepo/core-linux-arm64-gnu": patch + "@moonrepo/core-linux-arm64-musl": patch + "@moonrepo/core-linux-x64-gnu": patch + "@moonrepo/core-linux-x64-musl": patch + "@moonrepo/core-macos-arm64": patch + "@moonrepo/core-macos-x64": patch + "@moonrepo/core-windows-x64-msvc": patch diff --git a/crates/node/tool/src/node_tool.rs b/crates/node/tool/src/node_tool.rs index 6067b819ffb..43d24cec5e4 100644 --- a/crates/node/tool/src/node_tool.rs +++ b/crates/node/tool/src/node_tool.rs @@ -198,6 +198,8 @@ impl Tool for NodeTool { } } + self.tool.locate_globals_dir().await?; + if let Some(npm) = &mut self.npm { installed += npm.setup(last_versions).await?; } diff --git a/crates/node/tool/src/npm_tool.rs b/crates/node/tool/src/npm_tool.rs index cd30ed631b6..aa3ae55cea2 100644 --- a/crates/node/tool/src/npm_tool.rs +++ b/crates/node/tool/src/npm_tool.rs @@ -69,6 +69,8 @@ impl Tool for NpmTool { let version_type = VersionType::parse(&version)?; if self.tool.is_setup(&version_type).await? { + self.tool.locate_globals_dir().await?; + debug!("npm has already been setup"); return Ok(count); @@ -98,6 +100,8 @@ impl Tool for NpmTool { count += 1; } + self.tool.locate_globals_dir().await?; + Ok(count) } diff --git a/crates/node/tool/src/pnpm_tool.rs b/crates/node/tool/src/pnpm_tool.rs index 87016bb4ee4..b015b71cf21 100644 --- a/crates/node/tool/src/pnpm_tool.rs +++ b/crates/node/tool/src/pnpm_tool.rs @@ -71,6 +71,8 @@ impl Tool for PnpmTool { let version_type = VersionType::parse(&version)?; if self.tool.is_setup(&version_type).await? { + self.tool.locate_globals_dir().await?; + debug!("pnpm has already been setup"); return Ok(count); @@ -100,6 +102,8 @@ impl Tool for PnpmTool { count += 1; } + self.tool.locate_globals_dir().await?; + Ok(count) } diff --git a/crates/node/tool/src/yarn_tool.rs b/crates/node/tool/src/yarn_tool.rs index b786166adb8..e979f804c93 100644 --- a/crates/node/tool/src/yarn_tool.rs +++ b/crates/node/tool/src/yarn_tool.rs @@ -119,6 +119,8 @@ impl Tool for YarnTool { let version_type = VersionType::parse(&version)?; if self.tool.is_setup(&version_type).await? { + self.tool.locate_globals_dir().await?; + debug!("yarn has already been setup"); return Ok(count); @@ -148,6 +150,8 @@ impl Tool for YarnTool { count += 1; } + self.tool.locate_globals_dir().await?; + Ok(count) } diff --git a/crates/rust/platform/src/rust_platform.rs b/crates/rust/platform/src/rust_platform.rs index cc2c7366224..b1f16509b68 100644 --- a/crates/rust/platform/src/rust_platform.rs +++ b/crates/rust/platform/src/rust_platform.rs @@ -234,13 +234,11 @@ impl Platform for RustPlatform { if !self.config.bins.is_empty() { print_checkpoint("cargo binstall", Checkpoint::Setup); + let globals_dir = tool.tool.get_globals_bin_dir(); + // Install cargo-binstall if it does not exist - if !tool - .tool - .get_globals_bin_dir() - .unwrap() - .join("cargo-binstall") - .exists() + if globals_dir.is_none() + || globals_dir.is_some_and(|p| !p.join("cargo-binstall").exists()) { debug!( target: LOG_TARGET, @@ -482,11 +480,13 @@ impl Platform for RustPlatform { } // Binary may be installed to ~/.cargo/bin _ => { - let globals_dir = if let Ok(tool) = self.toolchain.get() { - tool.tool.get_globals_bin_dir().unwrap().to_path_buf() - } else { - get_cargo_home().join("bin") - }; + let mut globals_dir = get_cargo_home().join("bin"); + + if let Ok(tool) = self.toolchain.get() { + if let Some(new_globals_dir) = tool.tool.get_globals_bin_dir() { + globals_dir = new_globals_dir.to_path_buf(); + } + } let global_bin_path = globals_dir.join(&task.command); diff --git a/crates/rust/tool/src/rust_tool.rs b/crates/rust/tool/src/rust_tool.rs index 644136ed107..ba5bff04a6f 100644 --- a/crates/rust/tool/src/rust_tool.rs +++ b/crates/rust/tool/src/rust_tool.rs @@ -111,6 +111,8 @@ impl Tool for RustTool { } } + self.tool.locate_globals_dir().await?; + Ok(installed) } diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index e1a1cbc507f..6dde8a0bc2d 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +#### 🐞 Fixes + +- Fixed an issue where tool globals directory was not being correctly located. +- Fixed a panic when using the `rust` toolchain and attempting to install `bins`. + ## 1.13.2 #### 🐞 Fixes