Skip to content

Commit

Permalink
fix: Only install proto if we need it. (#1227)
Browse files Browse the repository at this point in the history
* Update code.

* Bump version.
  • Loading branch information
milesj authored Dec 12, 2023
1 parent 5b40c44 commit d03be4d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 2 deletions.
9 changes: 9 additions & 0 deletions .yarn/versions/30068a2b.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion crates/core/action-pipeline/src/actions/sync_workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async fn install_proto(workspace: &Workspace) -> miette::Result<()> {

// This causes a ton of issues when running the test suite,
// so just avoid it and assume proto exists!
if install_dir.exists() || is_test_env() {
if install_dir.exists() || is_test_env() || !workspace.toolchain_config.should_install_proto() {
return Ok(());
}

Expand Down
16 changes: 16 additions & 0 deletions nextgen/config/src/toolchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ pub use node_config::*;
pub use rust_config::*;
pub use typescript_config::*;

#[macro_export]
macro_rules! is_using_tool_version {
($self:ident, $parent_tool:ident, $tool:ident) => {
if let Some(config) = &$self.$parent_tool {
is_using_tool_version!(config, $tool);
}
};
($self:ident, $tool:ident) => {
if let Some(config) = &$self.$tool {
if config.version.is_some() {
return true;
}
}
};
}

#[macro_export]
macro_rules! inherit_tool {
($config:ident, $tool:ident, $key:expr, $method:ident) => {
Expand Down
21 changes: 20 additions & 1 deletion nextgen/config/src/toolchain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::language_platform::PlatformType;
use crate::toolchain::*;
use crate::validate::check_yml_extension;
use crate::{inherit_tool, inherit_tool_without_version};
use crate::{inherit_tool, inherit_tool_without_version, is_using_tool_version};
use moon_common::{color, consts};
use proto_core::ProtoConfig;
use schematic::{validate, Config, ConfigLoader};
Expand Down Expand Up @@ -75,6 +75,25 @@ impl ToolchainConfig {
tools
}

pub fn should_install_proto(&self) -> bool {
is_using_tool_version!(self, bun);
is_using_tool_version!(self, node);
is_using_tool_version!(self, node, pnpm);
is_using_tool_version!(self, node, yarn);
is_using_tool_version!(self, rust);

// Special case
if self
.node
.as_ref()
.is_some_and(|config| config.npm.version.is_some())
{
return true;
}

false
}

pub fn inherit_proto(&mut self, proto_config: &ProtoConfig) -> miette::Result<()> {
self.inherit_proto_bun(proto_config)?;
self.inherit_proto_deno(proto_config)?;
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- More accurately monitors signals (ctrl+c) and shutdowns.
- Tasks can now be configured with a timeout.

## Unreleased

#### 🐞 Fixes

- Fixed an issue where we would install `proto` even when not required.

## 1.18.0

#### 🚀 Updates
Expand Down

0 comments on commit d03be4d

Please sign in to comment.