Skip to content

Commit 7865584

Browse files
committed
Close...
1 parent 63fe984 commit 7865584

File tree

1 file changed

+32
-21
lines changed
  • crates/turborepo-lib/src/turbo_json

1 file changed

+32
-21
lines changed

crates/turborepo-lib/src/turbo_json/mod.rs

+32-21
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,18 @@ impl TurboJson {
575575
}
576576
}
577577

578-
if let Some(tasks_from_turbo) = raw_turbo.tasks {
579-
for (task_name, task_def) in tasks_from_turbo {
580-
task_def
581-
.inputs
578+
let mut tasks = raw_turbo.tasks.clone().unwrap_or_default();
579+
for (_, task_def) in tasks.iter_mut() {
580+
if let Some(inputs) = &task_def.inputs {
581+
let updated_inputs = inputs
582582
.iter()
583-
.map(|glob| replace_turbo_root_token(&mut task_def, path_to_repo_root))
584-
.collect()
583+
.map(|glob| {
584+
let updated_value =
585+
replace_turbo_root_token_in_string(&glob.value, path_to_repo_root);
586+
Spanned::new(UnescapedString::from(updated_value))
587+
})
588+
.collect();
589+
task_def.inputs = Some(updated_inputs);
585590
}
586591
}
587592

@@ -611,7 +616,7 @@ impl TurboJson {
611616

612617
global_deps
613618
},
614-
tasks: raw_turbo.tasks.unwrap_or_default(),
619+
tasks,
615620
// copy these over, we don't need any changes here.
616621
extends: raw_turbo
617622
.extends
@@ -783,27 +788,33 @@ fn gather_env_vars(
783788
Ok(())
784789
}
785790

791+
fn replace_turbo_root_token_in_string(
792+
input: &str,
793+
path_to_repo_root: &AnchoredSystemPath,
794+
) -> String {
795+
input.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1)
796+
}
797+
786798
fn replace_turbo_root_token(
787799
task_definition: &mut TaskDefinition,
788800
path_to_repo_root: &AnchoredSystemPath,
789-
) {
790-
for input in task_definition.inputs.iter_mut() {
791-
let _ = input.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1);
801+
) -> TaskDefinition {
802+
let mut new_task = task_definition.clone();
803+
804+
for input in &mut new_task.inputs {
805+
*input = input.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1);
792806
}
793807

794-
for output in task_definition.outputs.validated_exclusions().iter_mut() {
795-
let _ = output.iter().map(|glob| {
796-
glob.as_str()
797-
.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1)
798-
});
808+
let outputs = &mut new_task.outputs;
809+
for output in &mut outputs.exclusions {
810+
*output = output.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1);
799811
}
800812

801-
for output in task_definition.outputs.validated_inclusions().iter_mut() {
802-
let _ = output.iter().map(|glob| {
803-
glob.as_str()
804-
.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1)
805-
});
813+
for output in &mut outputs.inclusions {
814+
*output = output.replacen(TURBO_ROOT, path_to_repo_root.as_str(), 1);
806815
}
816+
817+
new_task
807818
}
808819

809820
#[cfg(test)]
@@ -828,7 +839,7 @@ mod tests {
828839
#[test_case("{}", "empty boundaries")]
829840
#[test_case(r#"{"tags": {} }"#, "empty tags")]
830841
#[test_case(
831-
r#"{"tags": { "my-tag": { "dependencies": { "allow": ["my-package"] } } } }"#,
842+
r#"{"tags": { "my-tag": { "dependencies": { "allow": ["my-package"] } } }"#,
832843
"tags and dependencies"
833844
)]
834845
#[test_case(

0 commit comments

Comments
 (0)