Skip to content

Commit

Permalink
chore(turborepo): remove unused code (#8428)
Browse files Browse the repository at this point in the history
### Description

We don't need these serde derives anymore since we're not serializing
the args to pass to Go.

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
NicholasLYang authored Jun 11, 2024
1 parent 943d6b5 commit d79cc4f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 77 deletions.
89 changes: 16 additions & 73 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use clap::{
};
use clap_complete::{generate, Shell};
pub use error::Error;
use serde::{Deserialize, Serialize};
use serde::Serialize;
use tracing::{debug, error};
use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::AnonAPIClient;
Expand Down Expand Up @@ -45,10 +45,8 @@ const DEFAULT_NUM_WORKERS: u32 = 10;
const SUPPORTED_GRAPH_FILE_EXTENSIONS: [&str; 8] =
["svg", "png", "jpg", "pdf", "json", "html", "mermaid", "dot"];

#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, ValueEnum, Deserializable)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, Deserializable, Serialize)]
pub enum OutputLogsMode {
// biome also obeys serde rename directives,
// so the `Deserializable` derive will work properly here
#[serde(rename = "full")]
Full,
#[serde(rename = "none")]
Expand Down Expand Up @@ -113,7 +111,7 @@ impl LogOrder {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, ValueEnum)]
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)]
pub enum DryRunMode {
Text,
Json,
Expand Down Expand Up @@ -145,24 +143,21 @@ impl fmt::Display for EnvMode {
}
}

#[derive(Parser, Clone, Default, Debug, PartialEq, Serialize)]
#[derive(Parser, Clone, Default, Debug, PartialEq)]
#[clap(author, about = "The build system that makes ship happen", long_about = None)]
#[clap(disable_help_subcommand = true)]
#[clap(disable_version_flag = true)]
#[clap(arg_required_else_help = true)]
#[command(name = "turbo")]
pub struct Args {
#[clap(long, global = true)]
#[serde(skip)]
pub version: bool,
#[clap(long, global = true)]
/// Skip any attempts to infer which version of Turbo the project is
/// configured to use
#[serde(skip)]
pub skip_infer: bool,
/// Disable the turbo update notification
#[clap(long, global = true)]
#[serde(skip)]
pub no_update_notifier: bool,
/// Override the endpoint for API calls
#[clap(long, global = true, value_parser)]
Expand Down Expand Up @@ -203,12 +198,10 @@ pub struct Args {
pub verbosity: Verbosity,
/// Force a check for a new version of turbo
#[clap(long, global = true, hide = true)]
#[serde(skip)]
pub check_for_update: bool,
#[clap(long = "__test-run", global = true, hide = true)]
pub test_run: bool,
#[clap(flatten, next_help_heading = "Run Arguments")]
#[serde(skip)]
pub run_args: Option<RunArgs>,
// This should be inside `RunArgs` but clap currently has a bug
// around nested flattened optional args: https://github.com/clap-rs/clap/issues/4697
Expand All @@ -218,8 +211,7 @@ pub struct Args {
pub command: Option<Command>,
}

#[derive(Debug, Parser, Serialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(into = "u8")]
#[derive(Debug, Parser, Clone, Copy, PartialEq, Eq, Default)]
pub struct Verbosity {
#[clap(
long = "verbosity",
Expand All @@ -246,8 +238,7 @@ impl From<Verbosity> for u8 {
}
}

#[derive(Subcommand, Copy, Clone, Debug, Serialize, PartialEq)]
#[serde(tag = "command")]
#[derive(Subcommand, Copy, Clone, Debug, PartialEq)]
pub enum DaemonCommand {
/// Restarts the turbo daemon
Restart,
Expand All @@ -272,8 +263,7 @@ pub enum DaemonCommand {
Logs,
}

#[derive(Subcommand, Copy, Clone, Debug, Serialize, PartialEq)]
#[serde(tag = "command")]
#[derive(Subcommand, Copy, Clone, Debug, PartialEq)]
pub enum TelemetryCommand {
/// Enables anonymous telemetry
Enable,
Expand All @@ -283,7 +273,7 @@ pub enum TelemetryCommand {
Status,
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, ValueEnum)]
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)]
pub enum LinkTarget {
RemoteCache,
Spaces,
Expand Down Expand Up @@ -434,14 +424,11 @@ 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.
#[derive(Subcommand, Clone, Debug, Serialize, PartialEq)]
#[derive(Subcommand, Clone, Debug, PartialEq)]
pub enum Command {
// NOTE: Empty variants still have an empty struct attached so that serde serializes
// them as `{ "Bin": {} }` instead of as `"Bin"`.
/// Get the path to the Turbo binary
Bin {},
Bin,
/// Generate the autocompletion script for the specified shell
#[serde(skip)]
Completion {
shell: Shell,
},
Expand All @@ -451,13 +438,11 @@ pub enum Command {
#[clap(long, default_value_t = String::from("4h0m0s"))]
idle_time: String,
#[clap(subcommand)]
#[serde(flatten)]
command: Option<DaemonCommand>,
},
/// Generate a new app / package
#[clap(aliases = ["g", "gen"])]
Generate {
#[serde(skip)]
#[clap(long, default_value_t = String::from("latest"), hide = true)]
tag: String,
/// The name of the generator to run
Expand All @@ -474,13 +459,11 @@ pub enum Command {
args: Vec<String>,

#[clap(subcommand)]
#[serde(skip)]
command: Option<Box<GenerateCommand>>,
},
/// Enable or disable anonymous telemetry
Telemetry {
#[clap(subcommand)]
#[serde(flatten)]
command: Option<TelemetryCommand>,
},
/// Turbo your monorepo by running a number of 'repo lints' to
Expand Down Expand Up @@ -594,7 +577,7 @@ pub struct GenerateWorkspaceArgs {
pub show_all_dependencies: bool,
}

#[derive(Parser, Clone, Debug, Default, Serialize, PartialEq)]
#[derive(Parser, Clone, Debug, Default, PartialEq, Serialize)]
pub struct GeneratorCustomArgs {
/// The name of the generator to run
generator_name: Option<String>,
Expand All @@ -610,7 +593,7 @@ pub struct GeneratorCustomArgs {
args: Vec<String>,
}

#[derive(Subcommand, Clone, Debug, Serialize, PartialEq)]
#[derive(Subcommand, Clone, Debug, PartialEq)]
pub enum GenerateCommand {
/// Add a new package or app to your project
#[clap(name = "workspace", alias = "w")]
Expand Down Expand Up @@ -645,7 +628,7 @@ fn path_non_empty(s: &str) -> Result<Utf8PathBuf, String> {
}

/// Arguments used in run and watch
#[derive(Parser, Clone, Debug, Default, Serialize, PartialEq)]
#[derive(Parser, Clone, Debug, Default, PartialEq)]
#[command(groups = [
ArgGroup::new("scope-filter-group").multiple(true).required(false),
])]
Expand Down Expand Up @@ -773,7 +756,7 @@ impl ExecutionArgs {
}
}

#[derive(Parser, Clone, Debug, Serialize, PartialEq)]
#[derive(Parser, Clone, Debug, PartialEq)]
#[command(groups = [
ArgGroup::new("daemon-group").multiple(false).required(false),
])]
Expand Down Expand Up @@ -815,12 +798,10 @@ pub struct RunArgs {
pub profile: Option<String>,
/// File to write turbo's performance profile output into.
/// All identifying data omitted from the profile.
#[serde(skip)]
#[clap(long, value_parser=NonEmptyStringValueParser::new(), conflicts_with = "profile")]
pub anon_profile: Option<String>,
/// Treat remote cache as read only
#[clap(long, env = "TURBO_REMOTE_CACHE_READ_ONLY", value_name = "BOOL", action = ArgAction::Set, default_value = "false", default_missing_value = "true", num_args = 0..=1)]
#[serde(skip)]
pub remote_cache_read_only: bool,
/// Generate a summary of the turbo run
#[clap(long, env = "TURBO_RUN_SUMMARY", default_missing_value = "true")]
Expand Down Expand Up @@ -1070,7 +1051,7 @@ pub async fn run(
cli_args.track(&root_telemetry);

let cli_result = match cli_args.command.as_ref().unwrap() {
Command::Bin { .. } => {
Command::Bin => {
CommandEventBuilder::new("bin")
.with_parent(&root_telemetry)
.track_call();
Expand Down Expand Up @@ -1357,11 +1338,7 @@ mod test {
}
}

use anyhow::Result;

use crate::cli::{
Args, Command, DryRunMode, EnvMode, LogOrder, LogPrefix, OutputLogsMode, Verbosity,
};
use crate::cli::{Args, Command, DryRunMode, EnvMode, LogOrder, LogPrefix, OutputLogsMode};

#[test_case::test_case(
&["turbo", "run", "build"],
Expand Down Expand Up @@ -2092,15 +2069,6 @@ mod test {
assert_eq!(Args::try_parse_from(args).unwrap(), expected);
}

fn test_serde() {
// Test that ouput-logs is not serialized by default
assert_eq!(
serde_json::to_string(&Args::try_parse_from(["turbo", "run", "build"]).unwrap())
.unwrap()
.contains("\"output_logs\":null"),
true
);
}
#[test_case::test_case(
&["turbo", "run", "build", "--daemon", "--no-daemon"],
"cannot be used with '--no-daemon'" ;
Expand Down Expand Up @@ -2437,31 +2405,6 @@ mod test {
assert!(Args::try_parse_from(["turbo", "prune", "foo", "--scope", "bar"]).is_err(),);
}

#[test]
fn test_verbosity_serialization() -> Result<(), serde_json::Error> {
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: None,
v: 0
})?,
"0"
);
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: Some(3),
v: 0
})?,
"3"
);
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: None,
v: 3
})?,
"3"
);
Ok(())
}
#[test]
fn test_parse_gen() {
let default_gen = Command::Generate {
Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ impl ProcessManager {

#[cfg(test)]
mod test {
use std::time::Instant;

use futures::{stream::FuturesUnordered, StreamExt};
use test_case::test_case;
use time::Instant;
use tokio::{join, time::sleep};
use tracing_test::traced_test;

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/task_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl TaskOutputs {
}

// Constructed from a RawTaskDefinition
#[derive(Debug, Deserialize, PartialEq, Clone, Eq)]
#[derive(Debug, PartialEq, Clone, Eq)]
pub struct TaskDefinition {
pub outputs: TaskOutputs,
pub(crate) cache: bool,
Expand Down
3 changes: 1 addition & 2 deletions crates/turborepo-repository/src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,9 @@ impl PackageManager {

#[cfg(test)]
mod tests {
use std::{collections::HashSet, fs::File};
use std::collections::HashSet;

use pretty_assertions::assert_eq;
use tempfile::tempdir;

use super::*;

Expand Down

0 comments on commit d79cc4f

Please sign in to comment.