Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select latest lts node version #1258

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/providers/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,14 +634,18 @@ fn parse_node_version_into_pkg(node_version: &str) -> String {
eprintln!("Warning: node version {node_version} is not valid, using default node version {default_node_pkg_name}");
Range::parse(DEFAULT_NODE_VERSION.to_string()).unwrap()
});
let mut available_node_versions = AVAILABLE_NODE_VERSIONS.to_vec();
let mut available_lts_node_versions = AVAILABLE_NODE_VERSIONS
.iter()
.filter(|v| *v % 2 == 0)
.collect::<Vec<_>>();

// use newest node version first
available_node_versions.sort_by(|a, b| b.cmp(a));
for version_number in available_node_versions {
available_lts_node_versions.sort_by(|a, b| b.cmp(a));
for version_number in available_lts_node_versions {
let version_range_string = format!("{version_number}.x.x");
let version_range: Range = version_range_string.parse().unwrap();
if version_range.allows_any(&range) {
return version_number_to_pkg(version_number);
return version_number_to_pkg(*version_number);
}
}
default_node_pkg_name
Expand Down Expand Up @@ -721,6 +725,24 @@ mod test {
Ok(())
}

#[test]
fn test_latest_lts_version() -> Result<()> {
assert_eq!(
NodeProvider::get_nix_node_pkg(
&PackageJson {
name: Some(String::default()),
engines: Some(engines_node(">=18")),
..Default::default()
},
&App::new("examples/node")?,
&Environment::default()
)?,
Pkg::new(version_number_to_pkg(22).as_str())
);

Ok(())
}

#[test]
fn test_simple_engine() -> Result<()> {
assert_eq!(
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshots/generate_plan_tests__node_pnpm_corepack.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/generate_plan_tests.rs
expression: plan
snapshot_kind: text
---
{
"providers": [],
Expand Down Expand Up @@ -44,7 +43,7 @@ snapshot_kind: text
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_23",
"nodejs_22",
"pnpm-9_x"
],
"nixOverlays": [
Expand Down
3 changes: 1 addition & 2 deletions tests/snapshots/generate_plan_tests__node_turborepo.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
source: tests/generate_plan_tests.rs
expression: plan
snapshot_kind: text
---
{
"providers": [],
Expand Down Expand Up @@ -45,7 +44,7 @@ snapshot_kind: text
"setup": {
"name": "setup",
"nixPkgs": [
"nodejs_23",
"nodejs_22",
"npm-8_x"
],
"nixOverlays": [
Expand Down
Loading