From fe39eb51b3316ae1bfaf859925cd230af64e162b Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Thu, 31 Oct 2024 23:30:11 -0600 Subject: [PATCH 1/6] Start working on . --- crates/turborepo-lib/src/cli/mod.rs | 19 ++++++-- crates/turborepo-lib/src/commands/info.rs | 58 +++++++++++++++++++++++ crates/turborepo-lib/src/commands/mod.rs | 1 + 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 crates/turborepo-lib/src/commands/info.rs diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 136cfa7154d0d..23cbeba7da067 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -22,8 +22,8 @@ use turborepo_ui::{ColorConfig, GREY}; use crate::{ cli::error::print_potential_tasks, commands::{ - bin, config, daemon, generate, link, login, logout, ls, prune, query, run, scan, telemetry, - unlink, CommandBase, + bin, config, daemon, generate, info, link, login, logout, ls, prune, query, run, scan, + telemetry, unlink, CommandBase, }, get_version, run::watch::WatchClient, @@ -475,9 +475,7 @@ impl Args { } } -/// Defines the subcommands for CLI. NOTE: If we change the commands in Go, -/// we must change these as well to avoid accidentally passing the -/// --single-package flag into non-build commands. +/// Defines the subcommands for CLI #[derive(Subcommand, Clone, Debug, PartialEq)] pub enum Command { /// Get the path to the Turbo binary @@ -570,6 +568,8 @@ pub enum Command { #[clap(long)] invalidate: bool, }, + /// Print debugging information + Info, /// Prepare a subset of your monorepo. Prune { #[clap(hide = true, long)] @@ -1214,6 +1214,15 @@ pub async fn run( generate::run(tag, command, &args, child_event)?; Ok(0) } + Command::Info => { + CommandEventBuilder::new("info") + .with_parent(&root_telemetry) + .track_call(); + let mut base = CommandBase::new(cli_args.clone(), repo_root, version, color_config); + info::run(base); + + Ok(0) + } Command::Telemetry { command } => { let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry); event.track_call(); diff --git a/crates/turborepo-lib/src/commands/info.rs b/crates/turborepo-lib/src/commands/info.rs new file mode 100644 index 0000000000000..3e9ad8197e3e2 --- /dev/null +++ b/crates/turborepo-lib/src/commands/info.rs @@ -0,0 +1,58 @@ +use std::{env, io}; + +use thiserror::Error; + +use super::CommandBase; +use crate::get_version; + +#[derive(Debug, Error)] +pub enum Error { + #[error("could not get path to turbo binary: {0}")] + NoCurrentExe(#[from] io::Error), +} + +pub fn run(base: CommandBase) -> Result<(), Error> { + println!("CLI:"); + println!(" Version: {}", base.version); + println!( + " Location: {}", + std::env::current_exe()?.to_string_lossy() + ); + println!(""); + + println!("Platform:"); + println!(" Architecture: {}", std::env::consts::ARCH); + println!(" Operating System: {}", std::env::consts::OS); + println!(""); + + println!("Environment:"); + println!(" CI: {:#?}", turborepo_ci::Vendor::get_name()); + println!( + " Terminal (TERM): {}", + env::var("TERM").unwrap_or_else(|_| "unknown".to_owned()) + ); + + println!( + " Terminal program (TERM_PROGRAM): {}", + env::var("TERM_PROGRAM").unwrap_or_else(|_| "unknown".to_owned()) + ); + println!( + " Terminal program version (TERM_PROGRAM_VERSION): {}", + env::var("TERM_PROGRAM_VERSION").unwrap_or_else(|_| "unknown".to_owned()) + ); + println!( + " Shell (SHELL): {}", + env::var("SHELL").unwrap_or_else(|_| "unknown".to_owned()) + ); + println!(" stdin: {}", turborepo_ci::is_ci()); + println!(""); + + println!("Turborepo System Environment Variables:"); + for (key, value) in env::vars().fil { + if key.starts_with("TURBO_") { + println!(" {}: {}", key, value); + } + } + + Ok(()) +} diff --git a/crates/turborepo-lib/src/commands/mod.rs b/crates/turborepo-lib/src/commands/mod.rs index 04f1568bc0df8..9aea38130ed10 100644 --- a/crates/turborepo-lib/src/commands/mod.rs +++ b/crates/turborepo-lib/src/commands/mod.rs @@ -15,6 +15,7 @@ pub(crate) mod bin; pub(crate) mod config; pub(crate) mod daemon; pub(crate) mod generate; +pub(crate) mod info; pub(crate) mod link; pub(crate) mod login; pub(crate) mod logout; From 125f960efc182335fe398522652fd01ddfb4540b Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Fri, 1 Nov 2024 10:29:59 -0600 Subject: [PATCH 2/6] Just need package managers now... --- crates/turborepo-lib/src/cli/mod.rs | 4 +-- crates/turborepo-lib/src/commands/info.rs | 38 ++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 23cbeba7da067..a6bfaddad8158 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -1218,8 +1218,8 @@ pub async fn run( CommandEventBuilder::new("info") .with_parent(&root_telemetry) .track_call(); - let mut base = CommandBase::new(cli_args.clone(), repo_root, version, color_config); - info::run(base); + let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config); + info::run(base).await; Ok(0) } diff --git a/crates/turborepo-lib/src/commands/info.rs b/crates/turborepo-lib/src/commands/info.rs index 3e9ad8197e3e2..d306d4e3c15c1 100644 --- a/crates/turborepo-lib/src/commands/info.rs +++ b/crates/turborepo-lib/src/commands/info.rs @@ -1,9 +1,10 @@ use std::{env, io}; +use sysinfo::{System, SystemExt}; use thiserror::Error; use super::CommandBase; -use crate::get_version; +use crate::{DaemonConnector, DaemonConnectorError}; #[derive(Debug, Error)] pub enum Error { @@ -11,18 +12,39 @@ pub enum Error { NoCurrentExe(#[from] io::Error), } -pub fn run(base: CommandBase) -> Result<(), Error> { +pub async fn run(base: CommandBase) -> Result<(), Error> { + let system = System::new_all(); + let connector = DaemonConnector::new(false, false, &base.repo_root); + let daemon_status = match connector.connect().await { + Ok(_status) => "Running", + Err(DaemonConnectorError::NotRunning) => "Not running", + Err(_e) => "Error getting status", + }; + println!("CLI:"); println!(" Version: {}", base.version); println!( " Location: {}", std::env::current_exe()?.to_string_lossy() ); + println!(" Daemon status: {}", daemon_status); + println!(""); + + println!("Package managers:"); + println!(" npm version: {}", "TODO"); + println!(" yarn version: {}", "TODO"); + println!(" pnpm version: {}", "TODO"); + println!(" bun version: {}", "TODO"); println!(""); println!("Platform:"); println!(" Architecture: {}", std::env::consts::ARCH); - println!(" Operating System: {}", std::env::consts::OS); + println!(" Operating system: {}", std::env::consts::OS); + println!( + " Available memory (MB): {}", + system.available_memory() / 1024 / 1024 + ); + println!(" Available CPU cores: {}", num_cpus::get()); println!(""); println!("Environment:"); @@ -48,7 +70,15 @@ pub fn run(base: CommandBase) -> Result<(), Error> { println!(""); println!("Turborepo System Environment Variables:"); - for (key, value) in env::vars().fil { + for (key, value) in env::vars() { + // Don't print sensitive information + if key == "TURBO_TEAM".to_string() + || key == "TURBO_TEAMID".to_string() + || key == "TURBO_TOKEN".to_string() + || key == "TURBO_API".to_string() + { + continue; + } if key.starts_with("TURBO_") { println!(" {}: {}", key, value); } From f8dbe6f6f68d09bd3a356f55c24968bd4f1510cf Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Fri, 1 Nov 2024 12:07:38 -0600 Subject: [PATCH 3/6] WIP --- crates/turborepo-lib/src/cli/mod.rs | 5 +++- crates/turborepo-lib/src/commands/info.rs | 33 +++++++++++++---------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index a6bfaddad8158..28da888117a4e 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -1219,8 +1219,11 @@ pub async fn run( .with_parent(&root_telemetry) .track_call(); let base = CommandBase::new(cli_args.clone(), repo_root, version, color_config); - info::run(base).await; + match info::run(base).await { + Ok(()) => {} + Err(e) => println!("Command failed. Please file a GitHub Issue.\n{}", e), + } Ok(0) } Command::Telemetry { command } => { diff --git a/crates/turborepo-lib/src/commands/info.rs b/crates/turborepo-lib/src/commands/info.rs index d306d4e3c15c1..9c18461dcb6b5 100644 --- a/crates/turborepo-lib/src/commands/info.rs +++ b/crates/turborepo-lib/src/commands/info.rs @@ -2,6 +2,7 @@ use std::{env, io}; use sysinfo::{System, SystemExt}; use thiserror::Error; +use turborepo_repository::{package_json::PackageJson, package_manager::PackageManager}; use super::CommandBase; use crate::{DaemonConnector, DaemonConnectorError}; @@ -21,6 +22,16 @@ pub async fn run(base: CommandBase) -> Result<(), Error> { Err(_e) => "Error getting status", }; + let package_manager = match PackageJson::load(&base.repo_root.join_component("package.json")) { + Ok(package_json) => { + match PackageManager::read_or_detect_package_manager(&package_json, &base.repo_root) { + Ok(pm) => pm.to_string(), + Err(_) => "Not found".to_owned(), + } + } + Err(_) => "Not found".to_owned(), + }; + println!("CLI:"); println!(" Version: {}", base.version); println!( @@ -28,14 +39,8 @@ pub async fn run(base: CommandBase) -> Result<(), Error> { std::env::current_exe()?.to_string_lossy() ); println!(" Daemon status: {}", daemon_status); - println!(""); - - println!("Package managers:"); - println!(" npm version: {}", "TODO"); - println!(" yarn version: {}", "TODO"); - println!(" pnpm version: {}", "TODO"); - println!(" bun version: {}", "TODO"); - println!(""); + println!(" Package manager: {}", package_manager); + println!(); println!("Platform:"); println!(" Architecture: {}", std::env::consts::ARCH); @@ -45,7 +50,7 @@ pub async fn run(base: CommandBase) -> Result<(), Error> { system.available_memory() / 1024 / 1024 ); println!(" Available CPU cores: {}", num_cpus::get()); - println!(""); + println!(); println!("Environment:"); println!(" CI: {:#?}", turborepo_ci::Vendor::get_name()); @@ -67,15 +72,15 @@ pub async fn run(base: CommandBase) -> Result<(), Error> { env::var("SHELL").unwrap_or_else(|_| "unknown".to_owned()) ); println!(" stdin: {}", turborepo_ci::is_ci()); - println!(""); + println!(); println!("Turborepo System Environment Variables:"); for (key, value) in env::vars() { // Don't print sensitive information - if key == "TURBO_TEAM".to_string() - || key == "TURBO_TEAMID".to_string() - || key == "TURBO_TOKEN".to_string() - || key == "TURBO_API".to_string() + if key == "TURBO_TEAM" + || key == "TURBO_TEAMID" + || key == "TURBO_TOKEN" + || key == "TURBO_API" { continue; } From 0c50d007698b2204677af2acfcf3e2a2a67eee39 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Fri, 1 Nov 2024 12:56:03 -0600 Subject: [PATCH 4/6] WIP --- turborepo-tests/integration/tests/no-args.t | 1 + turborepo-tests/integration/tests/turbo-help.t | 1 + 2 files changed, 2 insertions(+) diff --git a/turborepo-tests/integration/tests/no-args.t b/turborepo-tests/integration/tests/no-args.t index 72848871ce25c..c8443babd571c 100644 --- a/turborepo-tests/integration/tests/no-args.t +++ b/turborepo-tests/integration/tests/no-args.t @@ -18,6 +18,7 @@ Make sure exit code is 2 when no args are passed link Link your local directory to a Vercel organization and enable remote caching login Login to your Vercel account logout Logout to your Vercel account + info Print debugging information prune Prepare a subset of your monorepo run Run tasks across projects in your monorepo query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL diff --git a/turborepo-tests/integration/tests/turbo-help.t b/turborepo-tests/integration/tests/turbo-help.t index 0fd66d1c3d7be..893306deaf139 100644 --- a/turborepo-tests/integration/tests/turbo-help.t +++ b/turborepo-tests/integration/tests/turbo-help.t @@ -139,6 +139,7 @@ Test help flag link Link your local directory to a Vercel organization and enable remote caching login Login to your Vercel account logout Logout to your Vercel account + info Print debugging information prune Prepare a subset of your monorepo run Run tasks across projects in your monorepo query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL From c77dcc537b4f367d04abaf9c89b8e90755f55ca8 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Fri, 1 Nov 2024 13:08:04 -0600 Subject: [PATCH 5/6] WIP --- turborepo-tests/integration/tests/turbo-help.t | 1 + 1 file changed, 1 insertion(+) diff --git a/turborepo-tests/integration/tests/turbo-help.t b/turborepo-tests/integration/tests/turbo-help.t index 893306deaf139..951d2aa413550 100644 --- a/turborepo-tests/integration/tests/turbo-help.t +++ b/turborepo-tests/integration/tests/turbo-help.t @@ -18,6 +18,7 @@ Test help flag link Link your local directory to a Vercel organization and enable remote caching login Login to your Vercel account logout Logout to your Vercel account + info Print debugging information prune Prepare a subset of your monorepo run Run tasks across projects in your monorepo query Query your monorepo using GraphQL. If no query is provided, spins up a GraphQL server with GraphiQL From bbba1c4a4aa228e3f923c480b38abc47af927d4c Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Mon, 4 Nov 2024 12:44:27 -0700 Subject: [PATCH 6/6] WIP --- crates/turborepo-lib/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index 28da888117a4e..ad44349368bb0 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -1222,7 +1222,7 @@ pub async fn run( match info::run(base).await { Ok(()) => {} - Err(e) => println!("Command failed. Please file a GitHub Issue.\n{}", e), + Err(_e) => panic!("`info` command failed."), } Ok(0) }