Skip to content

Commit

Permalink
feat: warn when no local turbo found (#8356)
Browse files Browse the repository at this point in the history
### Description

Warn a user if they do not have a local turbo install as it might be an
incorrect version for their project.

### Testing Instructions

```
[0 olszewski@Chriss-MacBook-Pro] /tmp/foo $ turbo_dev --version             
2.0.2-canary.1
[0 olszewski@Chriss-MacBook-Pro] /tmp/foo $ pnpm rm turbo
Packages: -2
--
Progress: resolved 1, reused 1, downloaded 0, added 0, done

dependencies:
- turbo 2.0.2-canary.1

Done in 366ms
[0 olszewski@Chriss-MacBook-Pro] /tmp/foo $ turbo_dev --version 
No local turbo found. Using global turbo version 2.0.2-canary.1
2.0.2-canary.1
```
Integration tests show that the disabled env flag works. (Otherwise they
would all have this warning)

---------

Co-authored-by: Anthony Shew <[email protected]>
  • Loading branch information
chris-olszewski and anthonyshew committed Jun 6, 2024
1 parent 29aeaf0 commit 4471f2d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use turborepo_ui::UI;

use crate::{cli, get_version, spawn_child, tracing::TurboSubscriber};

const TURBO_GLOBAL_WARNING_DISABLED: &str = "TURBO_GLOBAL_WARNING_DISABLED";

#[derive(Debug, Error, Diagnostic)]
#[error("cannot have multiple `--cwd` flags in command")]
#[diagnostic(code(turbo::shim::multiple_cwd))]
Expand Down Expand Up @@ -595,14 +597,20 @@ fn run_correct_turbo(
spawn_local_turbo(&repo_state, turbo_state, shim_args)
}
} else {
try_check_for_updates(&shim_args, get_version());
let version = get_version();
try_check_for_updates(&shim_args, version);
// cli::run checks for this env var, rather than an arg, so that we can support
// calling old versions without passing unknown flags.
env::set_var(
cli::INVOCATION_DIR_ENV_VAR,
shim_args.invocation_dir.as_path(),
);
debug!("Running command as global turbo");
let should_warn_on_global = env::var(TURBO_GLOBAL_WARNING_DISABLED)
.map_or(true, |disable| !matches!(disable.as_str(), "1" | "true"));
if should_warn_on_global {
eprintln!("No locally installed `turbo` found. Using version: {version}.");
}
Ok(cli::run(Some(repo_state), subscriber, ui)?)
}
}
Expand Down
1 change: 1 addition & 0 deletions turborepo-tests/helpers/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ fi

# disable the first-run telemetry message
export TURBO_TELEMETRY_MESSAGE_DISABLED=1
export TURBO_GLOBAL_WARNING_DISABLED=1
TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}
1 change: 1 addition & 0 deletions turborepo-tests/helpers/setup_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ else
fi

export TURBO_TELEMETRY_MESSAGE_DISABLED=1
export TURBO_GLOBAL_WARNING_DISABLED=1
export TURBO=${MONOREPO_ROOT_DIR}/target/debug/turbo${EXT}

# Undo the set -eo pipefail at the top of this script
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

export TURBO_GLOBAL_WARNING_DISABLED=1
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
TARGET_DIR=$1
FIXTURE_DIR=$2
Expand Down
1 change: 1 addition & 0 deletions turborepo-tests/integration/tests/prune/resolutions.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup.sh
$ . ${TESTDIR}/../../../helpers/copy_fixture.sh $(pwd) berry_resolutions ${TESTDIR}/../../fixtures
$ export TURBO_GLOBAL_WARNING_DISABLED=1

Prune a
We expect to no longer have the non-resolved is-odd descriptor and
Expand Down
1 change: 1 addition & 0 deletions turborepo-tests/integration/tests/prune/yarn-pnp.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup.sh
$ . ${TESTDIR}/../../../helpers/copy_fixture.sh $(pwd) berry_resolutions ${TESTDIR}/../../fixtures
$ export TURBO_GLOBAL_WARNING_DISABLED=1
Remove linker override
$ rm .yarnrc.yml
Prune the project
Expand Down

0 comments on commit 4471f2d

Please sign in to comment.