diff options
author | Bert Belder <bertbelder@gmail.com> | 2022-10-20 16:15:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-20 16:15:21 +0200 |
commit | a48d05fac779e53e92fe0e8b5668adf120f319e4 (patch) | |
tree | ff76b217ac4e5550d61ee00b36b37b07bc6542ff /cli/main.rs | |
parent | bfc1fb8d68f39b899e544eee66e3a08abfd350b0 (diff) |
feat(cli): check for updates in background (#15974)
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/cli/main.rs b/cli/main.rs index f0cac4f38..5faf9c401 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -807,6 +807,29 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<i32, AnyError> { Ok(0) } +fn check_for_upgrades(cache_dir: PathBuf) { + // Run a background task that checks for available upgrades. If an earlier + // run of this background task found a new version of Deno, the new version + // number (or commit hash for canary builds) is returned. + let maybe_upgrade_version = tools::upgrade::check_for_upgrades(cache_dir); + + // Print a message if an update is available, unless: + // * stderr is not a tty + // * we're already running the 'deno upgrade' command. + if let Some(upgrade_version) = maybe_upgrade_version { + if atty::is(atty::Stream::Stderr) { + eprint!( + "{} ", + colors::green(format!("Deno {upgrade_version} has been released.")) + ); + eprintln!( + "{}", + colors::italic_gray("Run `deno upgrade` to install it.") + ); + } + } +} + async fn run_command( flags: Flags, run_flags: RunFlags, @@ -824,6 +847,7 @@ async fn run_command( // map specified and bare specifier is used on the command line - this should // probably call `ProcState::resolve` instead let ps = ProcState::build(flags).await?; + check_for_upgrades(ps.dir.root.clone()); let main_module = if NpmPackageReference::from_str(&run_flags.script).is_ok() { ModuleSpecifier::parse(&run_flags.script)? |