diff --git a/crates/turborepo-microfrontends/src/lib.rs b/crates/turborepo-microfrontends/src/lib.rs index 846d006a56cde..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() { @@ -180,6 +182,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 +205,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 +222,7 @@ mod test { pkg_dir, has_v1: false, has_alt_v1: false, + has_versionless: false, expected_version: None, expected_filename: None, } @@ -226,6 +238,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 +274,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 +295,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 {