Skip to content

Commit

Permalink
feat: change values of "ui" in turbo.json (#8289)
Browse files Browse the repository at this point in the history
### Description

It was mentioned that `"ui": false` doesn't make much sense. We replace
that in this PR with `"tui"` for the rich terminal output and `"stream"`
for the non-TTY behavior.

### Testing Instructions

Updated migration and unit tests. Quick manual check on a test repo.
<img width="798" alt="Screenshot 2024-06-04 at 8 51 53 AM"
src="https://github.com/vercel/turbo/assets/4131117/ed8aa9a0-bb04-4618-a782-5af02e5867e2">
  • Loading branch information
chris-olszewski committed Jun 4, 2024
1 parent ec7db77 commit 9a45c86
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl ResolvedConfigurationOptions for RawTurboJson {
.experimental_spaces
.and_then(|spaces| spaces.id)
.map(|spaces_id| spaces_id.into());
opts.ui = self.ui;
opts.ui = self.ui.map(|ui| ui.use_tui());
Ok(opts)
}
}
Expand Down
28 changes: 23 additions & 5 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub struct RawTurboJson {
#[serde(skip_serializing_if = "Option::is_none")]
pub(crate) remote_cache: Option<RawRemoteCacheOptions>,
#[serde(skip_serializing_if = "Option::is_none", rename = "ui")]
pub ui: Option<bool>,
pub ui: Option<UI>,

#[deserializable(rename = "//")]
#[serde(skip)]
Expand Down Expand Up @@ -159,6 +159,24 @@ impl DerefMut for Pipeline {
}
}

#[derive(Serialize, Debug, Copy, Clone, Deserializable, PartialEq, Eq)]
pub enum UI {
Tui,
Stream,
}

impl Default for UI {
fn default() -> Self {
Self::Tui
}
}

impl UI {
pub fn use_tui(&self) -> bool {
matches!(self, Self::Tui)
}
}

#[derive(Serialize, Default, Debug, PartialEq, Clone, Iterable, Deserializable)]
#[serde(rename_all = "camelCase")]
#[deserializable(unknown_fields = "deny")]
Expand Down Expand Up @@ -717,7 +735,7 @@ mod tests {
use turbopath::{AbsoluteSystemPath, AnchoredSystemPath};
use turborepo_repository::package_json::PackageJson;

use super::{Pipeline, RawTurboJson, Spanned};
use super::{Pipeline, RawTurboJson, Spanned, UI};
use crate::{
cli::OutputLogsMode,
run::task_id::TaskName,
Expand Down Expand Up @@ -1048,10 +1066,10 @@ mod tests {
assert_eq!(actual, expected);
}

#[test_case(r#"{ "ui": false }"#, Some(false) ; "f")]
#[test_case(r#"{ "ui": true }"#, Some(true) ; "t")]
#[test_case(r#"{ "ui": "tui" }"#, Some(UI::Tui) ; "tui")]
#[test_case(r#"{ "ui": "stream" }"#, Some(UI::Stream) ; "stream")]
#[test_case(r#"{}"#, None ; "missing")]
fn test_ui(json: &str, expected: Option<bool>) {
fn test_ui(json: &str, expected: Option<UI>) {
let json = RawTurboJson::parse(json, AnchoredSystemPath::new("").unwrap()).unwrap();
assert_eq!(json.ui, expected);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-codemod/__tests__/stabilize-ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("stabilize-ui", () => {
outputs: ["dist"],
},
},
ui: false,
ui: "stream",
});

expect(result.fatalError).toBeUndefined();
Expand Down
2 changes: 1 addition & 1 deletion packages/turbo-codemod/src/transforms/stabilize-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function migrateConfig(config: ExperimentalSchema): RootSchema {
delete config.experimentalUI;
// If UI is enabled we can just remove the config now that it's enabled by default
if (ui !== undefined && !ui) {
config.ui = ui;
config.ui = "stream";
}
return config;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/turbo-types/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ export interface RootSchema extends BaseSchema {
*
* Documentation: https://turbo.build/repo/docs/reference/configuration#experimentalui
*
* @defaultValue `true`
* @defaultValue `"tui"`
*/
ui?: boolean;
ui?: UI;
}

export type LegacyRootSchema = RootSchema & LegacyBaseSchema;
Expand Down Expand Up @@ -320,5 +320,7 @@ export type OutputMode =
| "errors-only"
| "none";

export type UI = "tui" | "stream";

export type AnchoredUnixPath = string;
export type EnvWildcard = string;

0 comments on commit 9a45c86

Please sign in to comment.