Skip to content

Commit

Permalink
chore(turbo)! hard error on env vars in task and global dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulkar committed Apr 23, 2024
1 parent af03a0d commit 790a451
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap::{
use clap_complete::{generate, Shell};
pub use error::Error;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, warn};
use tracing::{debug, error};
use turbopath::AbsoluteSystemPathBuf;
use turborepo_api_client::AnonAPIClient;
use turborepo_repository::inference::{RepoMode, RepoState};
Expand Down
8 changes: 8 additions & 0 deletions crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ pub enum Error {
#[source_code]
text: NamedSource,
},
#[error("`{field}` cannot contain an environment variable")]
InvalidDependsOnValue {
field: &'static str,
#[label("environment variable found here")]
span: Option<SourceSpan>,
#[source_code]
text: NamedSource,
},
#[error("`{field}` cannot contain an absolute path")]
AbsolutePathInConfig {
field: &'static str,
Expand Down
53 changes: 24 additions & 29 deletions crates/turborepo-lib/src/turbo_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,21 @@ impl TryFrom<RawTaskDefinition> for TaskDefinition {
let mut task_dependencies: Vec<Spanned<TaskName>> = Vec::new();
if let Some(depends_on) = raw_task.depends_on {
for dependency in depends_on.into_inner() {
let (dependency, span) = dependency.split();
let (span, text) = dependency.span_and_text("turbo.json");
let (dependency, depspan) = dependency.split();
let dependency: String = dependency.into();
if let Some(dependency) = dependency.strip_prefix(ENV_PIPELINE_DELIMITER) {
println!(
"[DEPRECATED] Declaring an environment variable in \"dependsOn\" is \
deprecated, found {}. Use the \"env\" key or use `npx @turbo/codemod \
migrate-env-var-dependencies`.\n",
dependency
);
env_var_dependencies.insert(dependency.to_string());
if let Some(_) = dependency.strip_prefix(ENV_PIPELINE_DELIMITER) {

Check failure on line 298 in crates/turborepo-lib/src/turbo_json/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

redundant pattern matching, consider using `is_some()`
return Err(Error::InvalidDependsOnValue {
field: "dependsOn",
span,
text,
});
} else if let Some(topo_dependency) =
dependency.strip_prefix(TOPOLOGICAL_PIPELINE_DELIMITER)
{
topological_dependencies.push(span.to(topo_dependency.to_string().into()));
topological_dependencies.push(depspan.to(topo_dependency.to_string().into()));
} else {
task_dependencies.push(span.to(dependency.into()));
task_dependencies.push(depspan.to(dependency.into()));
}
}
}
Expand Down Expand Up @@ -465,25 +464,21 @@ impl TryFrom<RawTurboJson> for TurboJson {
}

for global_dep in raw_turbo.global_dependencies.into_iter().flatten() {
if let Some(env_var) = global_dep.strip_prefix(ENV_PIPELINE_DELIMITER) {
println!(
"[DEPRECATED] Declaring an environment variable in \"dependsOn\" is \
deprecated, found {}. Use the \"env\" key or use `npx @turbo/codemod \
migrate-env-var-dependencies`.\n",
env_var
);

global_env.insert(env_var.to_string());
if let Some(_) = global_dep.strip_prefix(ENV_PIPELINE_DELIMITER) {

Check failure on line 467 in crates/turborepo-lib/src/turbo_json/mod.rs

View workflow job for this annotation

GitHub Actions / Turborepo rust clippy

redundant pattern matching, consider using `is_some()`
let (span, text) = global_dep.span_and_text("turbo.json");
return Err(Error::InvalidDependsOnValue {
field: "globalDependencies",
span,
text,
});
} else if Utf8Path::new(&global_dep.value).is_absolute() {
let (span, text) = global_dep.span_and_text("turbo.json");
return Err(Error::AbsolutePathInConfig {
field: "globalDependencies",
span,
text,
});
} else {
if Utf8Path::new(&global_dep.value).is_absolute() {
let (span, text) = global_dep.span_and_text("turbo.json");
return Err(Error::AbsolutePathInConfig {
field: "globalDependencies",
span,
text,
});
}

global_file_dependencies.insert(global_dep.into_inner().into());
}
}
Expand Down

0 comments on commit 790a451

Please sign in to comment.