Skip to content

Commit

Permalink
adds daemon flag for env var and turbo.json
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Jul 18, 2024
1 parent 8de0996 commit 60e9a54
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct InfoConfig {
timeout: Option<u64>,
enabled: Option<bool>,
spaces_id: Option<String>,
daemon: Option<bool>,
}

impl<'a> From<&'a ConfigurationOptions> for InfoConfig {
Expand All @@ -42,6 +43,7 @@ impl<'a> From<&'a ConfigurationOptions> for InfoConfig {
timeout: config.timeout,
enabled: config.enabled,
spaces_id: config.spaces_id.clone(),
daemon: config.daemon,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl CommandBase {
.dangerously_disable_package_manager_check
.then_some(true),
)
.with_daemon(self.args.run_args.as_ref().and_then(|args| args.daemon()))
.build()
}

Expand Down
24 changes: 24 additions & 0 deletions crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ pub struct ConfigurationOptions {
pub(crate) ui: Option<bool>,
#[serde(rename = "dangerouslyDisablePackageManagerCheck")]
pub(crate) allow_no_package_manager: Option<bool>,
pub(crate) daemon: Option<bool>,
}

#[derive(Default)]
Expand Down Expand Up @@ -280,6 +281,10 @@ impl ConfigurationOptions {
pub fn allow_no_package_manager(&self) -> bool {
self.allow_no_package_manager.unwrap_or_default()
}

pub fn daemon(&self) -> Option<bool> {
self.daemon
}
}

// Maps Some("") to None to emulate how Go handles empty strings
Expand Down Expand Up @@ -314,6 +319,7 @@ impl ResolvedConfigurationOptions for RawTurboJson {
.map(|spaces_id| spaces_id.into());
opts.ui = self.ui.map(|ui| ui.use_tui());
opts.allow_no_package_manager = self.allow_no_package_manager;
opts.daemon = self.daemon.map(|daemon| *daemon.as_inner());
Ok(opts)
}
}
Expand Down Expand Up @@ -350,6 +356,7 @@ fn get_env_var_config(
OsString::from("turbo_dangerously_disable_package_manager_check"),
"allow_no_package_manager",
);
turbo_mapping.insert(OsString::from("turbo_daemon"), "daemon");
turbo_mapping.insert(OsString::from("turbo_preflight"), "preflight");

// We do not enable new config sources:
Expand Down Expand Up @@ -441,6 +448,13 @@ fn get_env_var_config(
.map(|s| s.as_str())
.and_then(truth_env_var);

// Process daemon
let daemon = output_map.get("daemon").and_then(|val| match val.as_str() {
"1" | "true" => Some(true),
"0" | "false" => Some(false),
_ => None,
});

// We currently don't pick up a Spaces ID via env var, we likely won't
// continue using the Spaces name, we can add an env var when we have the
// name we want to stick with.
Expand All @@ -459,6 +473,7 @@ fn get_env_var_config(
enabled,
ui,
allow_no_package_manager,
daemon,

// Processed numbers
timeout,
Expand Down Expand Up @@ -519,6 +534,7 @@ fn get_override_env_var_config(
preflight: None,
enabled: None,
ui,
daemon: None,
timeout: None,
upload_timeout: None,
spaces_id: None,
Expand Down Expand Up @@ -663,6 +679,7 @@ impl TurborepoConfigBuilder {
allow_no_package_manager,
Option<bool>
);
create_builder!(with_daemon, daemon, Option<bool>);

pub fn build(&self) -> Result<ConfigurationOptions, Error> {
// Priority, from least significant to most significant:
Expand Down Expand Up @@ -745,6 +762,9 @@ impl TurborepoConfigBuilder {
{
acc.allow_no_package_manager = Some(allow_no_package_manager);
}
if let Some(daemon) = current_source_config.daemon {
acc.daemon = Some(daemon);
}

acc
})
Expand Down Expand Up @@ -806,6 +826,7 @@ mod test {
"turbo_dangerously_disable_package_manager_check".into(),
"true".into(),
);
env.insert("turbo_daemon".into(), "true".into());
env.insert("turbo_preflight".into(), "true".into());

let config = get_env_var_config(&env).unwrap();
Expand All @@ -818,6 +839,7 @@ mod test {
assert_eq!(turbo_remote_cache_timeout, config.timeout.unwrap());
assert_eq!(Some(true), config.ui);
assert_eq!(Some(true), config.allow_no_package_manager);
assert_eq!(Some(true), config.daemon);
}

#[test]
Expand All @@ -829,6 +851,7 @@ mod test {
env.insert("turbo_teamid".into(), "".into());
env.insert("turbo_token".into(), "".into());
env.insert("turbo_ui".into(), "".into());
env.insert("turbo_daemon".into(), "".into());
env.insert("turbo_preflight".into(), "".into());

let config = get_env_var_config(&env).unwrap();
Expand All @@ -838,6 +861,7 @@ mod test {
assert_eq!(config.team_id(), None);
assert_eq!(config.token(), None);
assert_eq!(config.ui, None);
assert_eq!(config.daemon, None);
assert!(!config.preflight());
}

Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl<'a> TryFrom<OptsInputs<'a>> for RunOpts {
continue_on_error: inputs.execution_args.continue_execution,
pass_through_args: inputs.execution_args.pass_through_args.clone(),
only: inputs.execution_args.only,
daemon: inputs.run_args.daemon(),
daemon: inputs.config.daemon(),
single_package: inputs.execution_args.single_package,
graph,
dry_run: inputs.run_args.dry_run,
Expand Down Expand Up @@ -465,13 +465,13 @@ mod test {
only: opts_input.only,
dry_run: opts_input.dry_run,
graph: None,
daemon: None,
single_package: false,
log_prefix: crate::opts::ResolvedLogPrefix::Task,
log_order: crate::opts::ResolvedLogOrder::Stream,
summarize: None,
experimental_space_id: None,
is_github_actions: false,
daemon: None,
};
let cache_opts = CacheOpts::default();
let runcache_opts = RunCacheOpts::default();
Expand Down
10 changes: 10 additions & 0 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub struct RawTurboJson {
rename = "dangerouslyDisablePackageManagerCheck"
)]
pub allow_no_package_manager: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub daemon: Option<Spanned<bool>>,

#[deserializable(rename = "//")]
#[serde(skip)]
Expand Down Expand Up @@ -1083,6 +1085,14 @@ mod tests {
assert_eq!(json.ui, expected);
}

#[test_case(r#"{ "daemon": true }"#, r#"{"daemon":true}"# ; "daemon_on")]
#[test_case(r#"{ "daemon": false }"#, r#"{"daemon":false}"# ; "daemon_off")]
fn test_daemon(json: &str, expected: &str) {
let parsed = RawTurboJson::parse(json, AnchoredSystemPath::new("").unwrap()).unwrap();
let actual = serde_json::to_string(&parsed).unwrap();
assert_eq!(actual, expected);
}

#[test_case(r#"{ "ui": "tui" }"#, r#"{"ui":"tui"}"# ; "tui")]
#[test_case(r#"{ "ui": "stream" }"#, r#"{"ui":"stream"}"# ; "stream")]
fn test_ui_serialization(input: &str, expected: &str) {
Expand Down
3 changes: 2 additions & 1 deletion turborepo-tests/integration/tests/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Run test run
"preflight": null,
"timeout": null,
"enabled": null,
"spacesId": null
"spacesId": null,
"daemon": null
}

Run test run with api overloaded
Expand Down

0 comments on commit 60e9a54

Please sign in to comment.