From a395085d10f6e22a91270ebec8b821c093a2fcab Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Thu, 20 Jun 2024 12:07:45 -0400 Subject: [PATCH 1/4] fix(turborepo): add yarn berry support for built dependencies meta when pruning --- crates/turborepo-lockfiles/fixtures/berry.lock | 1 + crates/turborepo-lockfiles/src/berry/mod.rs | 1 + crates/turborepo-lockfiles/src/berry/ser.rs | 3 +++ 3 files changed, 5 insertions(+) diff --git a/crates/turborepo-lockfiles/fixtures/berry.lock b/crates/turborepo-lockfiles/fixtures/berry.lock index f4436e4aeb2f6..2ae79f564e51e 100644 --- a/crates/turborepo-lockfiles/fixtures/berry.lock +++ b/crates/turborepo-lockfiles/fixtures/berry.lock @@ -1263,6 +1263,7 @@ eslint-config-turbo@latest: debug: ^3.2.7 dependenciesMeta: debug@4.3.4: + built: false unplugged: true peerDependenciesMeta: eslint: diff --git a/crates/turborepo-lockfiles/src/berry/mod.rs b/crates/turborepo-lockfiles/src/berry/mod.rs index ae6a886159cfa..586eddfda9774 100644 --- a/crates/turborepo-lockfiles/src/berry/mod.rs +++ b/crates/turborepo-lockfiles/src/berry/mod.rs @@ -96,6 +96,7 @@ struct BerryPackage { #[derive(Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord, Clone, Copy)] struct DependencyMeta { + built: Option, optional: Option, unplugged: Option, } diff --git a/crates/turborepo-lockfiles/src/berry/ser.rs b/crates/turborepo-lockfiles/src/berry/ser.rs index 20a15c6ecb545..73f6b8fb2b6d5 100644 --- a/crates/turborepo-lockfiles/src/berry/ser.rs +++ b/crates/turborepo-lockfiles/src/berry/ser.rs @@ -163,6 +163,9 @@ where for (dependency, meta) in metadata { let dependency = dependency.as_ref(); + if meta.built.unwrap_or_default() { + add_line(dependency, "built"); + } if meta.optional.unwrap_or_default() { add_line(dependency, "optional"); } From 831b7734947de3b4ace2cfab41162cedded7a305 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Thu, 20 Jun 2024 18:43:29 -0400 Subject: [PATCH 2/4] Add false support in berry dependency meta settings --- crates/turborepo-lockfiles/src/berry/ser.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/turborepo-lockfiles/src/berry/ser.rs b/crates/turborepo-lockfiles/src/berry/ser.rs index 73f6b8fb2b6d5..dfcd278b83f9c 100644 --- a/crates/turborepo-lockfiles/src/berry/ser.rs +++ b/crates/turborepo-lockfiles/src/berry/ser.rs @@ -147,15 +147,16 @@ where let mut string = String::new(); let mut first = true; - let mut add_line = |dependency: &str, field: &str| { + let mut add_line = |dependency: &str, field: &str, setting: bool| { if !first { string.push('\n'); } string.push_str(&format!( - " {}:\n {}: true", + " {}:\n {}: {}", wrap_string(dependency), - wrap_string(field) + wrap_string(field), + setting, )); first = false; @@ -163,14 +164,14 @@ where for (dependency, meta) in metadata { let dependency = dependency.as_ref(); - if meta.built.unwrap_or_default() { - add_line(dependency, "built"); + if let Some(built) = meta.built { + add_line(dependency, "built", built); } - if meta.optional.unwrap_or_default() { - add_line(dependency, "optional"); + if let Some(optional) = meta.optional { + add_line(dependency, "optional", optional); } - if meta.unplugged.unwrap_or_default() { - add_line(dependency, "unplugged"); + if let Some(unplugged) = meta.unplugged { + add_line(dependency, "unplugged", unplugged); } } From 95f3cf1c7fd5de4eee6d1509d65e7a5621ec2608 Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Tue, 30 Jul 2024 13:33:51 -0400 Subject: [PATCH 3/4] Fix dependency meta settings --- crates/turborepo-lockfiles/src/berry/ser.rs | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/turborepo-lockfiles/src/berry/ser.rs b/crates/turborepo-lockfiles/src/berry/ser.rs index dfcd278b83f9c..886fbca4f5e28 100644 --- a/crates/turborepo-lockfiles/src/berry/ser.rs +++ b/crates/turborepo-lockfiles/src/berry/ser.rs @@ -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, &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); } } From 8186f10d44471fca37279e15cd5b4019871ef58c Mon Sep 17 00:00:00 2001 From: Vincent Taverna Date: Tue, 30 Jul 2024 14:46:18 -0400 Subject: [PATCH 4/4] Add newline only when set --- crates/turborepo-lockfiles/src/berry/ser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/turborepo-lockfiles/src/berry/ser.rs b/crates/turborepo-lockfiles/src/berry/ser.rs index 886fbca4f5e28..35327bf1d598c 100644 --- a/crates/turborepo-lockfiles/src/berry/ser.rs +++ b/crates/turborepo-lockfiles/src/berry/ser.rs @@ -157,9 +157,9 @@ where 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'); + if i < settings.len() - 1 { + string.push('\n'); + } } }