Skip to content

Commit

Permalink
fix: Fix bun version discrepancies. (#1494)
Browse files Browse the repository at this point in the history
* Make change.

* Add tests.

* Bump version.
  • Loading branch information
milesj authored Jun 7, 2024
1 parent 4fc9b31 commit 45f9b03
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .yarn/versions/5614e87e.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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ scc = "2.1.1"
schematic = { version = "0.16.3", default-features = false, features = [
"schema",
] }
serial_test = "3.1.1"
semver = "1.0.23"
serde = { version = "1.0.202", features = ["derive"] }
serde_json = "1.0.117"
Expand Down
2 changes: 1 addition & 1 deletion crates/cache-item/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ starbase_utils = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
serial_test = "3.1.1"
serial_test = { workspace = true }
starbase_sandbox = { workspace = true }

[lints]
Expand Down
1 change: 1 addition & 0 deletions crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ tracing = { workspace = true, optional = true }

[dev-dependencies]
httpmock = "0.7.0"
serial_test = { workspace = true }
starbase_sandbox = { workspace = true }

[features]
Expand Down
16 changes: 16 additions & 0 deletions crates/config/src/toolchain_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl ToolchainConfig {
is_using_tool_version!(self, bun);
is_using_tool_version!(self, deno);
is_using_tool_version!(self, node);
is_using_tool_version!(self, node, bun);
is_using_tool_version!(self, node, pnpm);
is_using_tool_version!(self, node, yarn);
is_using_tool_version!(self, rust);
Expand All @@ -192,6 +193,21 @@ impl ToolchainConfig {

if let Some(node_config) = &mut self.node {
node_config.inherit_proto(proto_config)?;

// If bun and node are both enabled, and bun is being used
// as a package manager within node, we need to keep the
// versions in sync between both tools. The bun toolchain
// version takes precedence!
match (&mut self.bun, &mut node_config.bun) {
(Some(bun_config), Some(bunpm_config)) => {
if bun_config.version.is_some() && bunpm_config.version.is_none() {
bunpm_config.version = bun_config.version.clone();
} else if bunpm_config.version.is_some() && bun_config.version.is_none() {
bun_config.version = bunpm_config.version.clone();
}
}
_ => {}
};
}

Ok(())
Expand Down
75 changes: 71 additions & 4 deletions crates/config/tests/toolchain_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod utils;
use httpmock::prelude::*;
use moon_config::{BinConfig, BinEntry, NodePackageManager, NodeVersionFormat, ToolchainConfig};
use proto_core::{Id, PluginLocator, ProtoConfig, UnresolvedVersionSpec};
use serial_test::serial;
use starbase_sandbox::{create_empty_sandbox, create_sandbox};
use std::env;
use utils::*;
Expand Down Expand Up @@ -188,6 +189,7 @@ deno: {{}}
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -214,14 +216,15 @@ bun:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_BUN_VERSION", "1.0.0");

let config = test_load_config(
FILENAME,
r"
bun:
version: 3.0.0
version: 3.0.0
",
|path| {
let mut proto = ProtoConfig::default();
Expand All @@ -241,6 +244,31 @@ bun:
UnresolvedVersionSpec::parse("1.0.0").unwrap()
);
}

#[test]
fn inherits_version_from_node_pm() {
let config = test_load_config(
FILENAME,
r"
bun: {}
node:
packageManager: bun
bun:
version: 1.0.0
",
|path| ToolchainConfig::load_from(path, &ProtoConfig::default()),
);

assert_eq!(
config.bun.unwrap().version.unwrap(),
UnresolvedVersionSpec::parse("1.0.0").unwrap()
);

assert_eq!(
config.node.unwrap().bun.unwrap().version.unwrap(),
UnresolvedVersionSpec::parse("1.0.0").unwrap()
);
}
}

mod deno {
Expand Down Expand Up @@ -341,6 +369,7 @@ deno:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -367,6 +396,7 @@ deno:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_DENO_VERSION", "1.20.0");

Expand Down Expand Up @@ -466,6 +496,7 @@ node:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -492,6 +523,7 @@ node:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_NODE_VERSION", "19.0.0");

Expand Down Expand Up @@ -524,6 +556,7 @@ node:
use super::*;

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand Down Expand Up @@ -567,6 +600,7 @@ node:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_NPM_VERSION", "10.0.0");

Expand Down Expand Up @@ -682,6 +716,7 @@ node:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -708,6 +743,7 @@ node:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_PNPM_VERSION", "10.0.0");

Expand Down Expand Up @@ -806,6 +842,7 @@ node:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -832,6 +869,7 @@ node:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_YARN_VERSION", "10.0.0");

Expand Down Expand Up @@ -930,6 +968,7 @@ node:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -956,6 +995,7 @@ node:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_BUN_VERSION", "1.0.0");

Expand Down Expand Up @@ -985,6 +1025,31 @@ node:
);
}

#[test]
#[serial]
fn inherits_version_from_bun_tool() {
let config = test_load_config(
FILENAME,
r"
bun:
version: 1.0.0
node:
packageManager: bun
",
|path| ToolchainConfig::load_from(path, &ProtoConfig::default()),
);

assert_eq!(
config.bun.unwrap().version.unwrap(),
UnresolvedVersionSpec::parse("1.0.0").unwrap()
);

assert_eq!(
config.node.unwrap().bun.unwrap().version.unwrap(),
UnresolvedVersionSpec::parse("1.0.0").unwrap()
);
}

#[test]
fn fallsback_version_format() {
let config = test_load_config(
Expand Down Expand Up @@ -1112,6 +1177,7 @@ rust:
}

#[test]
#[serial]
fn proto_version_doesnt_override() {
let config = test_load_config(
FILENAME,
Expand All @@ -1138,15 +1204,16 @@ rust:
}

#[test]
#[serial]
fn inherits_version_from_env_var() {
env::set_var("MOON_RUST_VERSION", "1.70.0");

let config = test_load_config(
FILENAME,
r"
rust:
version: 1.60.0
",
rust:
version: 1.60.0
",
|path| {
let mut proto = ProtoConfig::default();
proto.versions.insert(
Expand Down
2 changes: 1 addition & 1 deletion legacy/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ moon_notifier = { path = "../core/notifier" }
moon_task_runner = { path = "../../crates/task-runner" }
moon_test_utils = { path = "../core/test-utils" }
httpmock = "0.7.0"
serial_test = "3.1.1"
serial_test = { workspace = true }
starbase_archive = { workspace = true }

[lints]
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
- More accurately monitors signals (ctrl+c) and shutdowns.
- Tasks can now be configured with a timeout.

## Unreleased

#### 🚀 Updates

- Updated `bun.version` and `node.bun.version` to stay in sync when one is defined and the other
isn't. This helps to avoid tool discrepancies.

## 1.25.3

#### 🚀 Updates
Expand Down

0 comments on commit 45f9b03

Please sign in to comment.