Skip to content

Commit

Permalink
Fix dependency meta settings
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnymac committed Jul 30, 2024
1 parent 831b773 commit 95f3cf1
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions crates/turborepo-lockfiles/src/berry/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,31 +147,34 @@ where
let mut string = String::new();
let mut first = true;

let mut add_line = |dependency: &str, field: &str, setting: bool| {
let mut add_line = |dependency: &str, settings: &[(Option<bool>, &str)]| {
if !first {
string.push('\n');
}

string.push_str(&format!(
" {}:\n {}: {}",
wrap_string(dependency),
wrap_string(field),
setting,
));
string.push_str(&format!(" {}:\n", wrap_string(dependency)));

for (i, (setting, field)) in settings.iter().enumerate() {
if let Some(value) = setting {
string.push_str(&format!(" {}: {}", wrap_string(field), value));
}
if i < settings.len() - 1 {
string.push('\n');
}
}

first = false;
};

for (dependency, meta) in metadata {
let dependency = dependency.as_ref();
if let Some(built) = meta.built {
add_line(dependency, "built", built);
}
if let Some(optional) = meta.optional {
add_line(dependency, "optional", optional);
}
if let Some(unplugged) = meta.unplugged {
add_line(dependency, "unplugged", unplugged);
let settings = [
(meta.built, "built"),
(meta.optional, "optional"),
(meta.unplugged, "unplugged"),
];
if settings.iter().any(|&(setting, _)| setting.is_some()) {
add_line(dependency, &settings);
}
}

Expand Down

0 comments on commit 95f3cf1

Please sign in to comment.