Skip to content

Commit

Permalink
feat: allow usage of turbo without turbo.json (#9149)
Browse files Browse the repository at this point in the history
### Description

This PR adds the ability to use `turbo` in a monorepo that doesn't have
a `turbo.json`. This feature is currently gated behind
`--experimental-allow-no-turbo-json`/`TURBO_ALLOW_NO_TURBO_JSON`.

A majority of the PR is refactoring the `EngineBuilder` so that it no
longer directly loads `TurboJson`s, but delegates to a
`TurboJsonLoader`. This allows us to use different strategies for
resolving `TurboJson` loads depending on runtime options e.g. single
package mode or task access.

Reviewing this PR is best done by viewing each commit individually.

### Testing Instructions

Unit testing for `turbo.json` loading changes.

Integration test for verifying the new loader is activated with the new
env var/flag.
  • Loading branch information
chris-olszewski authored Sep 17, 2024
1 parent 826f4fe commit 8856b3b
Show file tree
Hide file tree
Showing 22 changed files with 946 additions and 399 deletions.
2 changes: 2 additions & 0 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ pub struct Args {
/// should be used.
#[clap(long, global = true)]
pub dangerously_disable_package_manager_check: bool,
#[clap(long = "experimental-allow-no-turbo-json", hide = true, global = true)]
pub allow_no_turbo_json: bool,
/// Use the `turbo.json` located at the provided path instead of one at the
/// root of the repository.
#[clap(long, global = true)]
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 @@ -108,6 +108,7 @@ impl CommandBase {
.and_then(|args| args.remote_cache_read_only()),
)
.with_run_summary(self.args.run_args().and_then(|args| args.summarize()))
.with_allow_no_turbo_json(self.args.allow_no_turbo_json.then_some(true))
.build()
}

Expand Down
7 changes: 7 additions & 0 deletions crates/turborepo-lib/src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const TURBO_MAPPING: &[(&str, &str)] = [
("turbo_remote_only", "remote_only"),
("turbo_remote_cache_read_only", "remote_cache_read_only"),
("turbo_run_summary", "run_summary"),
("turbo_allow_no_turbo_json", "allow_no_turbo_json"),
]
.as_slice();

Expand Down Expand Up @@ -86,6 +87,7 @@ impl ResolvedConfigurationOptions for EnvVars {
let remote_only = self.truthy_value("remote_only").flatten();
let remote_cache_read_only = self.truthy_value("remote_cache_read_only").flatten();
let run_summary = self.truthy_value("run_summary").flatten();
let allow_no_turbo_json = self.truthy_value("allow_no_turbo_json").flatten();

// Process timeout
let timeout = self
Expand Down Expand Up @@ -171,6 +173,7 @@ impl ResolvedConfigurationOptions for EnvVars {
remote_only,
remote_cache_read_only,
run_summary,
allow_no_turbo_json,

// Processed numbers
timeout,
Expand Down Expand Up @@ -317,6 +320,7 @@ mod test {
env.insert("turbo_remote_only".into(), "1".into());
env.insert("turbo_remote_cache_read_only".into(), "1".into());
env.insert("turbo_run_summary".into(), "true".into());
env.insert("turbo_allow_no_turbo_json".into(), "true".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -328,6 +332,7 @@ mod test {
assert!(config.remote_only());
assert!(config.remote_cache_read_only());
assert!(config.run_summary());
assert!(config.allow_no_turbo_json());
assert_eq!(turbo_api, config.api_url.unwrap());
assert_eq!(turbo_login, config.login_url.unwrap());
assert_eq!(turbo_team, config.team_slug.unwrap());
Expand Down Expand Up @@ -365,6 +370,7 @@ mod test {
env.insert("turbo_remote_only".into(), "".into());
env.insert("turbo_remote_cache_read_only".into(), "".into());
env.insert("turbo_run_summary".into(), "".into());
env.insert("turbo_allow_no_turbo_json".into(), "".into());

let config = EnvVars::new(&env)
.unwrap()
Expand All @@ -387,6 +393,7 @@ mod test {
assert!(!config.remote_only());
assert!(!config.remote_cache_read_only());
assert!(!config.run_summary());
assert!(!config.allow_no_turbo_json());
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions crates/turborepo-lib/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use thiserror::Error;
use turbo_json::TurboJsonReader;
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf};
use turborepo_errors::TURBO_SITE;
use turborepo_repository::package_graph::PackageName;

pub use crate::turbo_json::{RawTurboJson, UIMode};
use crate::{
Expand Down Expand Up @@ -179,6 +180,8 @@ pub enum Error {
#[source_code]
text: NamedSource,
},
#[error("Cannot load turbo.json for in {0} single package mode")]
InvalidTurboJsonLoad(PackageName),
}

const DEFAULT_API_URL: &str = "https://vercel.com/api";
Expand Down Expand Up @@ -239,6 +242,7 @@ pub struct ConfigurationOptions {
pub(crate) remote_only: Option<bool>,
pub(crate) remote_cache_read_only: Option<bool>,
pub(crate) run_summary: Option<bool>,
pub(crate) allow_no_turbo_json: Option<bool>,
}

#[derive(Default)]
Expand Down Expand Up @@ -367,6 +371,10 @@ impl ConfigurationOptions {
.clone()
.unwrap_or_else(|| repo_root.join_component(CONFIG_FILE))
}

pub fn allow_no_turbo_json(&self) -> bool {
self.allow_no_turbo_json.unwrap_or_default()
}
}

// Maps Some("") to None to emulate how Go handles empty strings
Expand Down
Loading

0 comments on commit 8856b3b

Please sign in to comment.