diff --git a/Cargo.lock b/Cargo.lock index 26bdde29..6fefe022 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2798,7 +2798,7 @@ dependencies = [ [[package]] name = "workspace-node-tools" -version = "1.0.17" +version = "1.0.18" dependencies = [ "chrono", "execute", diff --git a/Cargo.toml b/Cargo.toml index f84f1f5b..db0b00c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "workspace-node-tools" -version = "1.0.17" +version = "1.0.18" edition = "2021" description = "Node workspace version tools" repository = "https://github.com/websublime/workspace-node-tools" diff --git a/src/changes.rs b/src/changes.rs index 1c5a874d..57bd0b87 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -329,11 +329,26 @@ pub fn change_exist(branch: String, packages_name: Vec, cwd: Option>(); + + let package_names_diff = packages_name + .iter() + .filter_map(|p| { + if existing_packages_changes.contains(&p) { + None + } else { + Some(p.to_string()) + } + }) + .collect::>(); + + match package_names_diff.len() { + 0 => return true, + _ => return false, + }; } } @@ -578,6 +593,59 @@ mod tests { remove_dir_all(&monorepo_dir).unwrap(); } + #[test] + fn test_change_exist_with_new_package() -> Result<(), Box> { + let ref monorepo_dir = create_test_monorepo(&PackageManager::Npm)?; + let project_root = get_project_root_path(Some(monorepo_dir.to_path_buf())); + + let ref root = project_root.unwrap().to_string(); + + let change = Change { + package: String::from("test-package"), + release_as: Bump::Major, + deploy: vec![String::from("production")], + }; + + init_changes(Some(root.to_string()), &None); + + let ref changes_path = monorepo_dir.join(String::from(".changes.json")); + add_change(&change, Some(root.to_string())); + + let result = change_exist( + String::from("main"), + vec!["test-package".to_string(), "@scope/package-a".to_string()], + Some(root.to_string()), + ); + + assert_eq!(result, false); + assert_eq!(changes_path.is_file(), true); + remove_dir_all(&monorepo_dir)?; + Ok(()) + } + + #[test] + fn test_change_exist_with_empty_packages() -> Result<(), Box> { + let ref monorepo_dir = create_test_monorepo(&PackageManager::Npm)?; + let project_root = get_project_root_path(Some(monorepo_dir.to_path_buf())); + + let ref root = project_root.unwrap().to_string(); + + init_changes(Some(root.to_string()), &None); + + let ref changes_path = monorepo_dir.join(String::from(".changes.json")); + + let result = change_exist( + String::from("main"), + vec!["test-package".to_string(), "@scope/package-a".to_string()], + Some(root.to_string()), + ); + + assert_eq!(result, false); + assert_eq!(changes_path.is_file(), true); + remove_dir_all(&monorepo_dir)?; + Ok(()) + } + #[test] fn test_changes_file_exist() -> Result<(), Box> { let ref monorepo_dir = create_test_monorepo(&PackageManager::Npm)?;