Skip to content

Commit

Permalink
feat(turbo-updater): notifications per tag (vercel#2957)
Browse files Browse the repository at this point in the history
  • Loading branch information
tknickman authored Dec 8, 2022
1 parent cd4a9f2 commit b5975df
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/turbo-updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ serde = { version = "1.0.126", features = ["derive"] }
strip-ansi-escapes = "0.1.1"
terminal_size = "0.2"
thiserror = "1.0"
update-informer = "0.5.0"
update-informer = "0.6.0"
ureq = { version = "2.3.0" }
24 changes: 19 additions & 5 deletions crates/turbo-updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use std::time::Duration;
use colored::*;
use serde::Deserialize;
use thiserror::Error as ThisError;
use update_informer::{Check, Package, Registry, Result as UpdateResult};
use update_informer::{Check, Package, Registry, Result as UpdateResult, Version};

mod ui;

// 800ms
const DEFAULT_TIMEOUT: Duration = Duration::from_millis(800);
// 1 day
const DEFAULT_INTERVAL: Duration = Duration::from_secs(60 * 60 * 24);

#[derive(ThisError, Debug)]
Expand All @@ -25,12 +27,24 @@ struct NPMRegistry;

impl Registry for NPMRegistry {
const NAME: &'static str = "npm_registry";
fn get_latest_version(pkg: &Package, _timeout: Duration) -> UpdateResult<Option<String>> {
fn get_latest_version(
pkg: &Package,
version: &Version,
timeout: Duration,
) -> UpdateResult<Option<String>> {
// determine tag to request
let tag = match &version.get().pre {
t if t.contains("canary") => "canary",
t if t.contains("next") => "next",
_ => "latest",
};

let url = format!(
"https://turbo.build/api/binaries/version?name={name}",
name = pkg
"https://turbo.build/api/binaries/version?name={name}&tag={tag}",
name = pkg,
tag = tag
);
let resp = ureq::get(&url).timeout(_timeout).call()?;
let resp = ureq::get(&url).timeout(timeout).call()?;
let result = resp.into_json::<NpmVersionData>().unwrap();
Ok(Some(result.version))
}
Expand Down
1 change: 1 addition & 0 deletions shim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ fn main() -> Result<()> {
"https://github.com/vercel/turbo",
Some(&footer),
get_version(),
// use defaults for timeout and refresh interval (800ms and 1 day respectively)
None,
None,
);
Expand Down

0 comments on commit b5975df

Please sign in to comment.