Skip to content

Commit

Permalink
chore(env): add VERCEL_ENV into default global env map
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Dec 19, 2024
1 parent 0cd0490 commit 85ae7dc
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions crates/turborepo-env/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use thiserror::Error;

pub mod platform;

const DEFAULT_ENV_VARS: [&str; 1] = ["VERCEL_ANALYTICS_ID"];
const DEFAULT_ENV_VARS: &[&str] = ["VERCEL_ANALYTICS_ID", "VERCEL_ENV"].as_slice();

#[derive(Clone, Debug, Error)]
pub enum Error {
Expand All @@ -22,7 +22,7 @@ pub enum Error {
}

// TODO: Consider using immutable data structures here
#[derive(Clone, Debug, Default, Serialize)]
#[derive(Clone, Debug, Default, Serialize, PartialEq)]
#[serde(transparent)]
pub struct EnvironmentVariableMap(HashMap<String, String>);

Expand Down Expand Up @@ -278,7 +278,7 @@ pub fn get_global_hashable_env_vars(
env_at_execution_start: &EnvironmentVariableMap,
global_env: &[String],
) -> Result<DetailedMap, Error> {
let default_env_var_map = env_at_execution_start.from_wildcards(&DEFAULT_ENV_VARS[..])?;
let default_env_var_map = env_at_execution_start.from_wildcards(DEFAULT_ENV_VARS)?;

let user_env_var_set =
env_at_execution_start.wildcard_map_from_wildcards_unresolved(global_env)?;
Expand Down Expand Up @@ -335,4 +335,27 @@ mod tests {
assert_eq!(actual.get("Turbo"), None);
}
}

#[test_case(&[], &["VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "defaults")]
#[test_case(&["!VERCEL*"], &[] ; "removing defaults")]
#[test_case(&["FOO*", "!FOOD"], &["FOO", "FOOBAR", "VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "intersecting globs")]
fn test_global_env(inputs: &[&str], expected: &[&str]) {
let env_at_start = EnvironmentVariableMap(
vec![
("VERCEL_ENV", "prod"),
("VERCEL_ANALYTICS_ID", "1"),
("FOO", "bar"),
("FOOBAR", "baz"),
("FOOD", "cheese"),
]
.into_iter()
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect(),
);
let inputs = inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>();
let actual = get_global_hashable_env_vars(&env_at_start, &inputs).unwrap();
let mut actual = actual.all.keys().map(|s| s.as_str()).collect::<Vec<_>>();
actual.sort();
assert_eq!(actual, expected);
}
}

0 comments on commit 85ae7dc

Please sign in to comment.