diff --git a/Cargo.lock b/Cargo.lock index 15e76943541f0..eeb28361a5a20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11052,6 +11052,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "turborepo-dirs" +version = "0.1.0" +dependencies = [ + "dirs-next", +] + [[package]] name = "turborepo-env" version = "0.1.0" diff --git a/crates/turborepo-dirs/Cargo.toml b/crates/turborepo-dirs/Cargo.toml new file mode 100644 index 0000000000000..2fe47fff69ff7 --- /dev/null +++ b/crates/turborepo-dirs/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "turborepo-dirs" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dirs-next = "2.0.0" + +[lints] +workspace = true diff --git a/crates/turborepo-dirs/src/lib.rs b/crates/turborepo-dirs/src/lib.rs new file mode 100644 index 0000000000000..a87fac533bb9a --- /dev/null +++ b/crates/turborepo-dirs/src/lib.rs @@ -0,0 +1,14 @@ +use std::path::PathBuf; + +use dirs_next::config_dir as dirs_config_dir; + +/// Returns the path to the user's configuration directory. This is a wrapper +/// around `dirs_next::config_dir` that also checks the `TURBO_CONFIG_DIR_PATH` +/// environment variable. If the environment variable is set, it will return +/// that path instead of `dirs_next::config_dir`. +pub fn config_dir() -> Option { + if let Ok(dir) = std::env::var("TURBO_CONFIG_DIR_PATH") { + return Some(PathBuf::from(dir)); + } + dirs_config_dir() +}