From 3437a3c0e68c908c9b691cf13483524e769dc112 Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Thu, 1 Aug 2024 06:31:35 -0600 Subject: [PATCH] feat(tui): Set TURBO_IS_TUI environment variable when using TUI. (#8897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Description Tools being used inside Turborepo tasks may want to know if they are being ran in our multiplexer, similar to the way other terminal tooling set environment variables that other programs can read (e.g. `ZSH`,`TMUX`, `ALACRITTY_WINDOW_ID`). In this PR, we're exposing a `TURBO_IS_TUI` variable for this purpose. ### Testing Instructions Using the `with-shell-commands` example, I edited one of the `build` scripts to echo the value. With TUI: ``` TURBO_UI devturbo build --force --skip-infer ┌ pkg-b#build > cache bypass, force executing 33b029c222753bd2 │ │ │ > pkg-b@ prebuild /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b │ > echo "Executing pre-build step..." │ │ Executing pre-build step... │ │ > pkg-b@ build /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b │ > echo $TURBO_IS_TUI │ │ true └────> ``` Without TUI: ``` TURBO_UI=0 devturbo build --force --skip-infer --filter=pkg-b turbo 2.0.11 • Packages in scope: pkg-b • Running build in 1 packages • Remote caching disabled pkg-b:prebuild: > echo "Executing pre-build step..." pkg-b:prebuild: pkg-b:prebuild: Executing pre-build step... pkg-b:build: cache bypass, force executing 33b029c222753bd2 pkg-b:build: pkg-b:build: pkg-b:build: > pkg-b@ prebuild /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b pkg-b:build: > echo "Executing pre-build step..." pkg-b:build: pkg-b:build: Executing pre-build step... pkg-b:build: pkg-b:build: > pkg-b@ build /Users/anthonyshew/projects/debugs/with-shell-commands/packages/pkg-b pkg-b:build: > echo $TURBO_IS_TUI pkg-b:build: pkg-b:build: ``` --- crates/turborepo-lib/src/task_graph/visitor.rs | 6 ++++++ docs/repo-docs/reference/system-environment-variables.mdx | 7 ++++--- grep | 0 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 grep diff --git a/crates/turborepo-lib/src/task_graph/visitor.rs b/crates/turborepo-lib/src/task_graph/visitor.rs index 27f301ca42c3b..e34f35548c277 100644 --- a/crates/turborepo-lib/src/task_graph/visitor.rs +++ b/crates/turborepo-lib/src/task_graph/visitor.rs @@ -912,6 +912,12 @@ impl ExecContext { cmd.envs(self.execution_env.iter()); // Always last to make sure it overwrites any user configured env var. cmd.env("TURBO_HASH", &self.task_hash); + + // Allow downstream tools to detect if the task is being ran with TUI + if self.experimental_ui { + cmd.env("TURBO_IS_TUI", "true"); + } + // enable task access tracing // set the trace file env var - frameworks that support this can use it to diff --git a/docs/repo-docs/reference/system-environment-variables.mdx b/docs/repo-docs/reference/system-environment-variables.mdx index 2ebb267f09ba7..255a6ad45f25b 100644 --- a/docs/repo-docs/reference/system-environment-variables.mdx +++ b/docs/repo-docs/reference/system-environment-variables.mdx @@ -39,6 +39,7 @@ System environment variables are always overridden by flag values provided direc Turborepo will make the following environment variables available within your tasks while they are executing: -| Variable | Description | -| ------------ | --------------------------------------- | -| `TURBO_HASH` | The hash of the currently running task. | +| Variable | Description | +| -------------- | -------------------------------------------------------------------------------------------- | +| `TURBO_HASH` | The hash of the currently running task. | +| `TURBO_IS_TUI` | When using the [TUI](/repo/docs/reference/configuration#ui), this variable is set to `true`. | diff --git a/grep b/grep new file mode 100644 index 0000000000000..e69de29bb2d1d