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

feat(turborepo-lib): no update alert on some args #3126

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ pub struct Args {
/// verbosity
#[clap(flatten)]
pub verbosity: Verbosity,
#[clap(long, global = true, hide = true)]
/// Force a check for a new version of turbo
pub check_for_update: bool,
Comment on lines +93 to +95
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a hidden flag to bypass the cached file and force a new check

#[clap(long = "__test-run", global = true, hide = true)]
pub test_run: bool,
#[clap(flatten, next_help_heading = "Run Arguments")]
Expand Down
33 changes: 29 additions & 4 deletions crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
process,
process::Stdio,
str::FromStr,
time::Duration,
};

use anyhow::{anyhow, Result};
Expand All @@ -33,12 +34,14 @@ static TURBO_PURE_OUTPUT_ARGS: [&str; 6] = [
"--dry-run=json",
];

static TURBO_SKIP_NOTIFIER_ARGS: [&str; 4] = ["--help", "--h", "--version", "--v"];
static SUPPORTS_SKIP_INFER_SEMVER: &str = ">=1.7.0-canary.0";

#[derive(Debug)]
struct ShimArgs {
cwd: PathBuf,
skip_infer: bool,
force_update_check: bool,
remaining_turbo_args: Vec<String>,
forwarded_args: Vec<String>,
}
Expand All @@ -48,6 +51,7 @@ impl ShimArgs {
let mut found_cwd_flag = false;
let mut cwd: Option<PathBuf> = None;
let mut skip_infer = false;
let mut force_update_check = false;
let mut remaining_turbo_args = Vec::new();
let mut forwarded_args = Vec::new();
let mut is_forwarded_args = false;
Expand All @@ -58,6 +62,8 @@ impl ShimArgs {
forwarded_args.push(arg);
} else if arg == "--skip-infer" {
skip_infer = true;
} else if arg == "--check-for-update" {
force_update_check = true;
} else if arg == "--" {
// If we've hit `--` we've reached the args forwarded to tasks.
is_forwarded_args = true;
Expand Down Expand Up @@ -95,18 +101,30 @@ impl ShimArgs {
Ok(ShimArgs {
cwd,
skip_infer,
force_update_check,
remaining_turbo_args,
forwarded_args,
})
}
}

// returns true if any flags result in pure json output to stdout
pub fn has_json_flags(&self) -> bool {
fn has_json_flags(&self) -> bool {
self.remaining_turbo_args
.iter()
.any(|arg| TURBO_PURE_OUTPUT_ARGS.contains(&arg.as_str()))
}

// returns true if any flags should bypass the update notifier
fn has_notifier_skip_flags(&self) -> bool {
self.remaining_turbo_args
.iter()
.any(|arg| TURBO_SKIP_NOTIFIER_ARGS.contains(&arg.as_str()))
}

pub fn should_skip_updater(&self) -> bool {
!self.force_update_check && (self.has_json_flags() || self.has_notifier_skip_flags())
tknickman marked this conversation as resolved.
Show resolved Hide resolved
}
}

#[derive(Debug, Clone, PartialEq, Serialize)]
Expand Down Expand Up @@ -305,23 +323,30 @@ pub fn run() -> Result<Payload> {
// global turbo having handled the inference. We can run without any
// concerns.

if !args.has_json_flags() {
if !args.should_skip_updater() {
tknickman marked this conversation as resolved.
Show resolved Hide resolved
// custom footer for update message
let footer = format!(
"Follow {username} for updates: {url}",
username = "@turborepo".gradient([RGB::new(0, 153, 247), RGB::new(241, 23, 18)]),
url = "https://twitter.com/turborepo"
);

let interval = if args.force_update_check {
// force update check
Some(Duration::ZERO)
} else {
// use default (24 hours)
None
};
// check for updates
let _ = check_for_updates(
"turbo",
"https://github.com/vercel/turbo",
Some(&footer),
get_version(),
// use defaults for timeout and refresh interval (800ms and 1 day respectively)
None,
// use default for timeout (800ms)
None,
interval,
);
}

Expand Down