From 8a94a6b8769dc6229ab61606cad1361ce19a4e32 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 12 Feb 2025 09:48:05 -0500 Subject: [PATCH 1/2] chore(mfe): add failing test for loading versionless --- crates/turborepo-microfrontends/src/lib.rs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crates/turborepo-microfrontends/src/lib.rs b/crates/turborepo-microfrontends/src/lib.rs index 846d006a56cde..d3b761ebafbcd 100644 --- a/crates/turborepo-microfrontends/src/lib.rs +++ b/crates/turborepo-microfrontends/src/lib.rs @@ -180,6 +180,14 @@ mod test { path.create_with_contents(r#"{"version": "1", "applications": {"web": {"development": {"task": "serve"}}, "docs": {}}}"#) } + fn add_no_version_config(dir: &AbsoluteSystemPath) -> Result<(), std::io::Error> { + let path = dir.join_component(DEFAULT_MICROFRONTENDS_CONFIG_V1); + path.ensure_dir()?; + path.create_with_contents( + r#"{"applications": {"web": {"development": {"task": "serve"}}, "docs": {}}}"#, + ) + } + fn add_v2_config(dir: &AbsoluteSystemPath) -> Result<(), std::io::Error> { let path = dir.join_component(DEFAULT_MICROFRONTENDS_CONFIG_V1); path.ensure_dir()?; @@ -195,6 +203,7 @@ mod test { struct LoadDirTest { has_v1: bool, has_alt_v1: bool, + has_versionless: bool, pkg_dir: &'static str, expected_version: Option, expected_filename: Option<&'static str>, @@ -211,6 +220,7 @@ mod test { pkg_dir, has_v1: false, has_alt_v1: false, + has_versionless: false, expected_version: None, expected_filename: None, } @@ -226,6 +236,11 @@ mod test { self } + pub const fn has_versionless(mut self) -> Self { + self.has_versionless = true; + self + } + pub const fn expects_v1(mut self) -> Self { self.expected_version = Some(FoundConfig::V1); self @@ -257,9 +272,16 @@ mod test { .with_filename(DEFAULT_MICROFRONTENDS_CONFIG_V1_ALT); const LOAD_NONE: LoadDirTest = LoadDirTest::new("web"); + + const LOAD_VERSIONLESS: LoadDirTest = LoadDirTest::new("web") + .has_versionless() + .expects_v1() + .with_filename(DEFAULT_MICROFRONTENDS_CONFIG_V1); + #[test_case(LOAD_V1)] #[test_case(LOAD_V1_ALT)] #[test_case(LOAD_NONE)] + #[test_case(LOAD_VERSIONLESS)] fn test_load_dir(case: LoadDirTest) { let dir = TempDir::new().unwrap(); let repo_root = AbsoluteSystemPath::new(dir.path().to_str().unwrap()).unwrap(); @@ -271,6 +293,9 @@ mod test { if case.has_alt_v1 { add_v1_alt_config(&pkg_path).unwrap(); } + if case.has_versionless { + add_no_version_config(&pkg_path).unwrap(); + } let config = Config::load_from_dir(repo_root, pkg_dir).unwrap(); let actual_version = config.as_ref().map(|config| match &config.inner { From 3fea2cbdd45c3e39e9f6e5b4237db94d45b093e4 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 12 Feb 2025 09:49:18 -0500 Subject: [PATCH 2/2] fix(mfe): properly handle versionless configurations --- crates/turborepo-microfrontends/src/lib.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/turborepo-microfrontends/src/lib.rs b/crates/turborepo-microfrontends/src/lib.rs index d3b761ebafbcd..66fe896024304 100644 --- a/crates/turborepo-microfrontends/src/lib.rs +++ b/crates/turborepo-microfrontends/src/lib.rs @@ -70,7 +70,7 @@ impl Config { pub fn from_str(input: &str, source: &str) -> Result { #[derive(Deserializable, Default)] struct VersionOnly { - version: String, + version: Option, } let (version_only, _errs) = biome_deserialize::json::deserialize_from_json_str( input, @@ -80,9 +80,11 @@ impl Config { .consume(); let version = match version_only { - Some(VersionOnly { version }) => version, + Some(VersionOnly { + version: Some(version), + }) => version, // Default to version 1 if no version found - None => "1".to_string(), + Some(VersionOnly { version: None }) | None => "1".to_string(), }; let inner = match version.as_str() {