Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(turbo)! hard error on env vars in task and global dependencies #8026

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/turborepo-lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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 dependency.strip_prefix(ENV_PIPELINE_DELIMITER).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 global_dep.strip_prefix(ENV_PIPELINE_DELIMITER).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
Loading