diff --git a/crates/turborepo-lib/src/shim/local_turbo_config.rs b/crates/turborepo-lib/src/shim/local_turbo_config.rs index 179ca3195bdc1..735559d2a19ac 100644 --- a/crates/turborepo-lib/src/shim/local_turbo_config.rs +++ b/crates/turborepo-lib/src/shim/local_turbo_config.rs @@ -3,7 +3,7 @@ use std::env; use tracing::debug; use turborepo_repository::{inference::RepoState, package_manager::PackageManager}; -const TURBO_DOWNLOAD_LOCAL_DISABLED: &str = "TURBO_DOWNLOAD_LOCAL_DISABLED"; +const TURBO_DOWNLOAD_LOCAL_ENABLED: &str = "TURBO_DOWNLOAD_LOCAL_ENABLED"; /// Struct containing information about the desired local turbo version /// according to lockfiles, package.jsons, and if all else fails turbo.json @@ -12,13 +12,26 @@ pub struct LocalTurboConfig { turbo_version: String, } +fn is_env_var_truthy(env_var: &str) -> Option { + let value = env::var(env_var).ok()?; + match value.as_str() { + "1" | "true" => Some(true), + "0" | "false" => Some(false), + _ => None, + } +} + impl LocalTurboConfig { pub fn infer(repo_state: &RepoState) -> Option { - // Don't attempt a download if user has opted out - if env::var(TURBO_DOWNLOAD_LOCAL_DISABLED) - .map_or(false, |disable| matches!(disable.as_str(), "1" | "true")) - { - debug!("downloading correct local version disabled"); + Self::infer_internal(repo_state, is_env_var_truthy(TURBO_DOWNLOAD_LOCAL_ENABLED)) + } + + // Used for testing when we want to manually set the controlling env var + fn infer_internal(repo_state: &RepoState, is_enabled: Option) -> Option { + // TODO: once we have properly communicated this functionality we should make + // this opt-out. + if !is_enabled.unwrap_or(false) { + debug!("downloading correct local version not enabled"); return None; } let turbo_version = Self::turbo_version_from_lockfile(repo_state)?; @@ -78,7 +91,7 @@ mod test { .unwrap(); assert_eq!( - LocalTurboConfig::infer(&repo), + LocalTurboConfig::infer_internal(&repo, Some(true)), Some(LocalTurboConfig { turbo_version: "2.0.3".into() }) @@ -103,7 +116,7 @@ mod test { .unwrap(); assert_eq!( - LocalTurboConfig::infer(&repo), + LocalTurboConfig::infer_internal(&repo, Some(true)), Some(LocalTurboConfig { turbo_version: "2.0.3".into() }) @@ -128,7 +141,7 @@ mod test { package_manager: Err(Error::MissingPackageManager), }; - assert_eq!(LocalTurboConfig::infer(&repo), None,); + assert_eq!(LocalTurboConfig::infer_internal(&repo, Some(true)), None,); } #[test] @@ -149,7 +162,7 @@ mod test { package_manager: Err(Error::MissingPackageManager), }; - assert_eq!(LocalTurboConfig::infer(&repo), None); + assert_eq!(LocalTurboConfig::infer_internal(&repo, Some(true)), None); } #[test] @@ -166,7 +179,7 @@ mod test { turbo_json .create_with_contents(include_bytes!("../../fixtures/local_config/turbo.v1.json")) .unwrap(); - assert_eq!(LocalTurboConfig::infer(&repo), None); + assert_eq!(LocalTurboConfig::infer_internal(&repo, Some(true)), None); } #[test] @@ -183,7 +196,7 @@ mod test { turbo_json .create_with_contents(include_bytes!("../../fixtures/local_config/turbo.v2.json")) .unwrap(); - assert_eq!(LocalTurboConfig::infer(&repo), None,); + assert_eq!(LocalTurboConfig::infer_internal(&repo, Some(true)), None,); } #[test] @@ -196,6 +209,6 @@ mod test { root_package_json: PackageJson::default(), package_manager: Err(Error::MissingPackageManager), }; - assert_eq!(LocalTurboConfig::infer(&repo), None,); + assert_eq!(LocalTurboConfig::infer_internal(&repo, Some(true)), None,); } } diff --git a/turborepo-tests/helpers/setup.sh b/turborepo-tests/helpers/setup.sh index 9e15edfa48032..c8580cd5ac7cb 100755 --- a/turborepo-tests/helpers/setup.sh +++ b/turborepo-tests/helpers/setup.sh @@ -12,5 +12,5 @@ fi # disable the first-run telemetry message export TURBO_TELEMETRY_MESSAGE_DISABLED=1 export TURBO_GLOBAL_WARNING_DISABLED=1 -export TURBO_DOWNLOAD_LOCAL_DISABLED=1 +export TURBO_DOWNLOAD_LOCAL_ENABLED=0 TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT} diff --git a/turborepo-tests/helpers/setup_example_test.sh b/turborepo-tests/helpers/setup_example_test.sh index f4fd970947d9b..f7445c0097a45 100644 --- a/turborepo-tests/helpers/setup_example_test.sh +++ b/turborepo-tests/helpers/setup_example_test.sh @@ -3,7 +3,7 @@ set -eo pipefail export TURBO_TELEMETRY_MESSAGE_DISABLED=1 -export TURBO_DOWNLOAD_LOCAL_DISABLED=1 +export TURBO_DOWNLOAD_LOCAL_ENABLED=0 # Start by figuring out which example we're testing and its package manager example_path=$1 diff --git a/turborepo-tests/integration/tests/find-turbo/setup.sh b/turborepo-tests/integration/tests/find-turbo/setup.sh index bafa637cf0d21..387b9c37e14d4 100644 --- a/turborepo-tests/integration/tests/find-turbo/setup.sh +++ b/turborepo-tests/integration/tests/find-turbo/setup.sh @@ -1,6 +1,6 @@ #!/bin/bash -export TURBO_DOWNLOAD_LOCAL_DISABLED=1 +export TURBO_DOWNLOAD_LOCAL_ENABLED=0 SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) TARGET_DIR=$1 FIXTURE_DIR=$2 diff --git a/turborepo-tests/integration/tests/lockfile-aware-caching/setup.sh b/turborepo-tests/integration/tests/lockfile-aware-caching/setup.sh index 3280fe5e03e09..9a2f9ddd05cd8 100755 --- a/turborepo-tests/integration/tests/lockfile-aware-caching/setup.sh +++ b/turborepo-tests/integration/tests/lockfile-aware-caching/setup.sh @@ -1,7 +1,7 @@ #!/bin/bash export TURBO_GLOBAL_WARNING_DISABLED=1 -export TURBO_DOWNLOAD_LOCAL_DISABLED=1 +export TURBO_DOWNLOAD_LOCAL_ENABLED=0 SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) TARGET_DIR=$1 FIXTURE_DIR=$2