这是indexloc提供的服务,不要输入任何密码
Skip to content

fix(watch): correctly derive opts from watch mode args #9761

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

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions crates/turborepo-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub struct CacheHitMetadata {
pub time_saved: u64,
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize)]
pub struct CacheActions {
pub read: bool,
pub write: bool,
Expand All @@ -134,7 +134,7 @@ impl CacheActions {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, Serialize)]
pub struct CacheConfig {
pub local: CacheActions,
pub remote: CacheActions,
Expand Down Expand Up @@ -172,7 +172,7 @@ impl Default for CacheActions {
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
pub struct CacheOpts {
pub cache_dir: Utf8PathBuf,
pub cache: CacheConfig,
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl LogOrder {
}
}

#[derive(Copy, Clone, Debug, PartialEq, ValueEnum)]
#[derive(Copy, Clone, Debug, PartialEq, ValueEnum, Serialize)]
pub enum DryRunMode {
Text,
Json,
Expand Down Expand Up @@ -399,7 +399,7 @@ impl Args {
clap_args
}

fn parse(os_args: Vec<OsString>) -> Result<Self, clap::Error> {
pub(crate) fn parse(os_args: Vec<OsString>) -> Result<Self, clap::Error> {
let (is_single_package, single_package_free) = Self::remove_single_package(os_args);
let mut args = Args::try_parse_from(single_package_free)?;
// And then only add them back in when we're in `run`.
Expand Down
55 changes: 46 additions & 9 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::backtrace;

use camino::Utf8PathBuf;
use serde::Serialize;
use thiserror::Error;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPathBuf};
use turborepo_api_client::APIAuth;
Expand Down Expand Up @@ -43,7 +44,7 @@ pub enum Error {
Config(#[from] crate::config::Error),
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct APIClientOpts {
pub api_url: String,
pub timeout: u64,
Expand All @@ -55,7 +56,7 @@ pub struct APIClientOpts {
pub preflight: bool,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct RepoOpts {
pub root_turbo_json_path: AbsoluteSystemPathBuf,
pub allow_no_package_manager: bool,
Expand All @@ -65,7 +66,7 @@ pub struct RepoOpts {
/// The fully resolved options for Turborepo. This is the combination of config,
/// including all the layers (env, args, defaults, etc.), and the command line
/// arguments.
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize)]
pub struct Opts {
pub repo_opts: RepoOpts,
pub api_client_opts: APIClientOpts,
Expand Down Expand Up @@ -135,6 +136,7 @@ impl Opts {
run_args,
execution_args,
}) => (execution_args, run_args),
Some(Command::Watch(execution_args)) => (execution_args, &Box::default()),
Some(Command::Ls {
affected, filter, ..
}) => {
Expand Down Expand Up @@ -191,7 +193,7 @@ struct OptsInputs<'a> {
api_auth: &'a Option<APIAuth>,
}

#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug, Default, Serialize)]
pub struct RunCacheOpts {
pub(crate) task_output_logs_override: Option<OutputLogsMode>,
}
Expand All @@ -204,7 +206,7 @@ impl<'a> From<OptsInputs<'a>> for RunCacheOpts {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct RunOpts {
pub(crate) tasks: Vec<String>,
pub(crate) concurrency: u32,
Expand Down Expand Up @@ -261,19 +263,19 @@ impl<'a> TaskArgs<'a> {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub enum GraphOpts {
Stdout,
File(String),
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize)]
pub enum ResolvedLogOrder {
Stream,
Grouped,
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize)]
pub enum ResolvedLogPrefix {
Task,
None,
Expand Down Expand Up @@ -395,7 +397,7 @@ impl From<LogPrefix> for ResolvedLogPrefix {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize)]
pub struct ScopeOpts {
pub pkg_inference_root: Option<AnchoredSystemPathBuf>,
pub global_deps: Vec<String>,
Expand Down Expand Up @@ -537,6 +539,9 @@ impl ScopeOpts {

#[cfg(test)]
mod test {
use clap::Parser;
use itertools::Itertools;
use serde_json::json;
use tempfile::TempDir;
use test_case::test_case;
use turbopath::AbsoluteSystemPathBuf;
Expand Down Expand Up @@ -826,4 +831,36 @@ mod test {

Ok(())
}

#[test_case(
vec!["turbo", "watch", "build"];
"watch"
)]
#[test_case(
vec!["turbo", "run", "build"];
"run"
)]
#[test_case(
vec!["turbo", "ls", "--filter", "foo"];
"ls"
)]
#[test_case(
vec!["turbo", "boundaries", "--filter", "foo"];
"boundaries"
)]
fn test_derive_opts_from_args(args_str: Vec<&str>) -> Result<(), anyhow::Error> {
let args = Args::try_parse_from(&args_str)?;
let opts = Opts::new(
&AbsoluteSystemPathBuf::default(),
&args,
ConfigurationOptions::default(),
)?;

insta::assert_json_snapshot!(
args_str.iter().join("_"),
json!({ "tasks": opts.run_opts.tasks, "filter_patterns": opts.scope_opts.filter_patterns })
);

Ok(())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/turborepo-lib/src/opts.rs
expression: "json!({\n \"tasks\": opts.run_opts.tasks, \"filter_patterns\":\n opts.scope_opts.filter_patterns\n})"
---
{
"tasks": [],
"filter_patterns": [
"foo"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/turborepo-lib/src/opts.rs
expression: "json!({\n \"tasks\": opts.run_opts.tasks, \"filter_patterns\":\n opts.scope_opts.filter_patterns\n})"
---
{
"tasks": [],
"filter_patterns": [
"foo"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/turborepo-lib/src/opts.rs
expression: "json!({\n \"tasks\": opts.run_opts.tasks, \"filter_patterns\":\n opts.scope_opts.filter_patterns\n})"
---
{
"tasks": [
"build"
],
"filter_patterns": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: crates/turborepo-lib/src/opts.rs
expression: "json!({\n \"tasks\": opts.run_opts.tasks, \"filter_patterns\":\n opts.scope_opts.filter_patterns\n})"
---
{
"tasks": [
"build"
],
"filter_patterns": []
}

This file was deleted.

3 changes: 0 additions & 3 deletions crates/turborepo-microfrontends/src/.lib.rs.pending-snap

This file was deleted.

Loading