Skip to content

Commit 73a4b74

Browse files
authored
fix(cli.rs/info): don't show outdated text for latest versions (#3829)
1 parent 7c7d854 commit 73a4b74

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

.changes/cli-info-outdated.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": "patch"
3+
"cli.js": "patch"
4+
---
5+
6+
Fix `info` command showing outdated text for latest versions.

tooling/cli/src/info.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,7 @@ fn crate_version(
441441
}
442442

443443
fn indent(spaces: usize) {
444-
print!(
445-
"{}",
446-
vec![0; spaces].iter().map(|_| " ").collect::<String>()
447-
);
444+
print!("{}", " ".repeat(spaces));
448445
}
449446

450447
struct Section(&'static str);
@@ -460,7 +457,7 @@ struct VersionBlock {
460457
version: String,
461458
target_version: String,
462459
indentation: usize,
463-
skip_update: bool,
460+
skip_update_check: bool,
464461
}
465462

466463
impl VersionBlock {
@@ -470,12 +467,12 @@ impl VersionBlock {
470467
version: version.into(),
471468
target_version: "".into(),
472469
indentation: 2,
473-
skip_update: false,
470+
skip_update_check: false,
474471
}
475472
}
476473

477-
fn skip_update(mut self) -> Self {
478-
self.skip_update = true;
474+
fn skip_update_check(mut self) -> Self {
475+
self.skip_update_check = true;
479476
self
480477
}
481478

@@ -497,12 +494,16 @@ impl VersionBlock {
497494
self.version.clone()
498495
}
499496
);
500-
if !self.target_version.is_empty() && !self.skip_update {
501-
print!(
502-
"({}, latest: {})",
503-
"outdated".red(),
504-
self.target_version.green()
505-
);
497+
if !self.target_version.is_empty() && !self.skip_update_check {
498+
let version = semver::Version::parse(self.version.as_str()).unwrap();
499+
let target_version = semver::Version::parse(self.target_version.as_str()).unwrap();
500+
if version < target_version {
501+
print!(
502+
"({}, latest: {})",
503+
"outdated".red(),
504+
self.target_version.green()
505+
);
506+
}
506507
}
507508
println!();
508509
}
@@ -592,7 +593,7 @@ pub fn command(_options: Options) -> Result<()> {
592593
.collect::<String>(),
593594
)
594595
.target_version(metadata.js_cli.node.replace(">= ", ""))
595-
.skip_update()
596+
.skip_update_check()
596597
.display();
597598

598599
VersionBlock::new(

0 commit comments

Comments
 (0)