summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Golden <8162045+tbjgolden@users.noreply.github.com>2021-04-29 14:06:25 -0500
committerGitHub <noreply@github.com>2021-04-29 15:06:25 -0400
commitc2e84e1802931197acb3eba957b78134e33cc7e8 (patch)
tree8bffaa9d7d07533f2f8ed5b9d03519279560fe91
parent8a8dca71a68d0d84167a5c0071d0a21dca5651c2 (diff)
feat: abbreviate package.json semantic versions (#2271)
-rw-r--r--src/modules/package.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/modules/package.rs b/src/modules/package.rs
index 909998d7b..bd7372ca6 100644
--- a/src/modules/package.rs
+++ b/src/modules/package.rs
@@ -68,6 +68,11 @@ fn extract_package_version(file_contents: &str, display_private: bool) -> Option
};
let formatted_version = format_version(raw_version);
+ if formatted_version == "v0.0.0-development" || formatted_version.starts_with("v0.0.0-semantic")
+ {
+ return Some("semantic".to_string());
+ };
+
Some(formatted_version)
}
@@ -344,6 +349,51 @@ mod tests {
}
#[test]
+ fn test_package_version_semantic_development_version() -> io::Result<()> {
+ let config_name = "package.json";
+ let config_content = json::json!({
+ "name": "starship",
+ "version": "0.0.0-development"
+ })
+ .to_string();
+
+ let project_dir = create_project_dir()?;
+ fill_config(&project_dir, config_name, Some(&config_content))?;
+ expect_output(&project_dir, Some("semantic"), None);
+ project_dir.close()
+ }
+
+ #[test]
+ fn test_package_version_with_semantic_other_version() -> io::Result<()> {
+ let config_name = "package.json";
+ let config_content = json::json!({
+ "name": "starship",
+ "version": "v0.0.0-semantically-released"
+ })
+ .to_string();
+
+ let project_dir = create_project_dir()?;
+ fill_config(&project_dir, config_name, Some(&config_content))?;
+ expect_output(&project_dir, Some("semantic"), None);
+ project_dir.close()
+ }
+
+ #[test]
+ fn test_package_version_with_non_semantic_tag() -> io::Result<()> {
+ let config_name = "package.json";
+ let config_content = json::json!({
+ "name": "starship",
+ "version": "v0.0.0-alpha"
+ })
+ .to_string();
+
+ let project_dir = create_project_dir()?;
+ fill_config(&project_dir, config_name, Some(&config_content))?;
+ expect_output(&project_dir, Some("v0.0.0-alpha"), None);
+ project_dir.close()
+ }
+
+ #[test]
fn test_extract_poetry_version() -> io::Result<()> {
let config_name = "pyproject.toml";
let config_content = toml::toml! {