Skip to content

Commit 5c74fe9

Browse files
chore(env): add VERCEL_ENV into default global env map (#9635)
### Description Include `VERCEL_ENV` as an environment variable that affects the global hash. Can be opted out by specifying `!VERCEL_ENV` in `globalEnv`. ### Testing Instructions Unit test, quick manual test as a smoke test: ``` [0 olszewski@chriss-mbp] /tmp/env-var $ VERCEL_ENV=dev turbo_dev --skip-infer build --output-logs=hash-only --ui=stream turbo 2.3.4-canary.4 • Packages in scope: @repo/eslint-config, @repo/typescript-config, @repo/ui, docs, web • Running build in 5 packages • Remote caching disabled web:build: cache miss, executing 7a2bad92132801df docs:build: cache miss, executing 744d362ee9e1eb1b Tasks: 2 successful, 2 total Cached: 0 cached, 2 total Time: 13.166s [0 olszewski@chriss-mbp] /tmp/env-var $ VERCEL_ENV=dev turbo_dev --skip-infer build --output-logs=hash-only --ui=stream turbo 2.3.4-canary.4 • Packages in scope: @repo/eslint-config, @repo/typescript-config, @repo/ui, docs, web • Running build in 5 packages • Remote caching disabled docs:build: cache hit, suppressing logs 744d362ee9e1eb1b web:build: cache hit, suppressing logs 7a2bad92132801df Tasks: 2 successful, 2 total Cached: 2 cached, 2 total Time: 108ms >>> FULL TURBO [0 olszewski@chriss-mbp] /tmp/env-var $ VERCEL_ENV=prod turbo_dev --skip-infer build --output-logs=hash-only --ui=stream turbo 2.3.4-canary.4 • Packages in scope: @repo/eslint-config, @repo/typescript-config, @repo/ui, docs, web • Running build in 5 packages • Remote caching disabled web:build: cache miss, executing b138cc0b45044f36 docs:build: cache miss, executing 0149788cd6331b71 Tasks: 2 successful, 2 total Cached: 0 cached, 2 total Time: 9.355s ```
1 parent 0cd0490 commit 5c74fe9

File tree

1 file changed

+26
-3
lines changed
  • crates/turborepo-env/src

1 file changed

+26
-3
lines changed

crates/turborepo-env/src/lib.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use thiserror::Error;
1313

1414
pub mod platform;
1515

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

1818
#[derive(Clone, Debug, Error)]
1919
pub enum Error {
@@ -22,7 +22,7 @@ pub enum Error {
2222
}
2323

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

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

283283
let user_env_var_set =
284284
env_at_execution_start.wildcard_map_from_wildcards_unresolved(global_env)?;
@@ -335,4 +335,27 @@ mod tests {
335335
assert_eq!(actual.get("Turbo"), None);
336336
}
337337
}
338+
339+
#[test_case(&[], &["VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "defaults")]
340+
#[test_case(&["!VERCEL*"], &[] ; "removing defaults")]
341+
#[test_case(&["FOO*", "!FOOD"], &["FOO", "FOOBAR", "VERCEL_ANALYTICS_ID", "VERCEL_ENV"] ; "intersecting globs")]
342+
fn test_global_env(inputs: &[&str], expected: &[&str]) {
343+
let env_at_start = EnvironmentVariableMap(
344+
vec![
345+
("VERCEL_ENV", "prod"),
346+
("VERCEL_ANALYTICS_ID", "1"),
347+
("FOO", "bar"),
348+
("FOOBAR", "baz"),
349+
("FOOD", "cheese"),
350+
]
351+
.into_iter()
352+
.map(|(k, v)| (k.to_owned(), v.to_owned()))
353+
.collect(),
354+
);
355+
let inputs = inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>();
356+
let actual = get_global_hashable_env_vars(&env_at_start, &inputs).unwrap();
357+
let mut actual = actual.all.keys().map(|s| s.as_str()).collect::<Vec<_>>();
358+
actual.sort();
359+
assert_eq!(actual, expected);
360+
}
338361
}

0 commit comments

Comments
 (0)