diff --git a/Cargo.lock b/Cargo.lock index f672b45..f8d0c28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,7 +398,7 @@ dependencies = [ [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=2d824dded159efc862d2c6266c27c015542baa96#2d824dded159efc862d2c6266c27c015542baa96" +source = "git+https://github.com/ComlineProject/generation?rev=350bbce6e88caf65e60449e3ebd0e1d45eb19179#350bbce6e88caf65e60449e3ebd0e1d45eb19179" dependencies = [ "comline-core", "eyre", @@ -408,7 +408,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=8f7e0baa81e1cf6350582148ace7c4fe86be830c#8f7e0baa81e1cf6350582148ace7c4fe86be830c" +source = "git+https://github.com/ComlineProject/comline-rust?rev=bc1c4af956bfad9e110583620e6f85255a0dda42#bc1c4af956bfad9e110583620e6f85255a0dda42" dependencies = [ "comline-codegen", "comline-core", @@ -418,7 +418,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=62bbf796eff54c2bd304004b7d29e854074d4396#62bbf796eff54c2bd304004b7d29e854074d4396" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=4ad1c3574a342d974e83a94570d51d903ea32bbe#4ad1c3574a342d974e83a94570d51d903ea32bbe" dependencies = [ "comline-codegen", "comline-core", @@ -428,7 +428,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=ad2b3f582dabb4a27d616741e425699299fc84de#ad2b3f582dabb4a27d616741e425699299fc84de" +source = "git+https://github.com/ComlineProject/core?rev=622500a39a49ad4118cdce9344531cf6f0f5978d#622500a39a49ad4118cdce9344531cf6f0f5978d" dependencies = [ "ariadne", "blake3", @@ -455,7 +455,7 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=ad2b3f582dabb4a27d616741e425699299fc84de#ad2b3f582dabb4a27d616741e425699299fc84de" +source = "git+https://github.com/ComlineProject/core?rev=622500a39a49ad4118cdce9344531cf6f0f5978d#622500a39a49ad4118cdce9344531cf6f0f5978d" [[package]] name = "concolor" diff --git a/Cargo.toml b/Cargo.toml index 7643183..84b7ab3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,15 +30,15 @@ toml = "0.8" # needs real I/O (git fetch, filesystem), so it's off by default for # `comline-core`'s wasm32 consumers (the playground editor, the language # server); the CLI is the one consumer that actually runs `comline build`. -comline-core = { git = "https://github.com/ComlineProject/core", rev = "ad2b3f582dabb4a27d616741e425699299fc84de", features = ["deps"] } +comline-core = { git = "https://github.com/ComlineProject/core", rev = "622500a39a49ad4118cdce9344531cf6f0f5978d", features = ["deps"] } # All three pinned to revs that agree on one `comline-codegen`, and bumped # together: comline-rust and comline-typescript's codegen crates consume # `comline-codegen`'s types, so the rev below must be byte-identical to the # one *they* pin - Cargo only unifies a git dependency across identical rev # strings, and two copies of `GenRequest` are two incompatible types. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "2d824dded159efc862d2c6266c27c015542baa96" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "8f7e0baa81e1cf6350582148ace7c4fe86be830c", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "62bbf796eff54c2bd304004b7d29e854074d4396", optional = true } +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "350bbce6e88caf65e60449e3ebd0e1d45eb19179" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "bc1c4af956bfad9e110583620e6f85255a0dda42", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "4ad1c3574a342d974e83a94570d51d903ea32bbe", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole diff --git a/src/changes.rs b/src/changes.rs index 3618ef8..d0b6a28 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -118,9 +118,116 @@ fn breaking_line(change: &BreakingChange) -> String { mark("❌", "-", format!("Removed protocol `{name}`")) } BreakingChange::RemovedError { name } => mark("❌", "-", format!("Removed error `{name}`")), + BreakingChange::ChangedFieldOptionality { + type_name, + field_name, + now_optional, + } => { + let now = if *now_optional { + "optional" + } else { + "required" + }; + mark( + "🔄", + "~", + format!("Made field `{type_name}.{field_name}` {now}"), + ) + } + BreakingChange::RenamedEnumVariant { + enum_name, + old_name, + new_name, + } => mark( + "🔄", + "~", + format!( + "Renamed `{enum_name}::{old_name}` {} `{enum_name}::{new_name}`", + ui::arrow() + ), + ), + BreakingChange::RemovedThrownError { + protocol_name, + function_name, + error, + } => mark( + "❌", + "-", + format!("`{protocol_name}.{function_name}` no longer declares `! {error}`"), + ), + BreakingChange::ChangedErrorOrdinal { + name, + old_ordinal, + new_ordinal, + } => mark( + "🔄", + "~", + format!( + "Error `{name}`'s ordinal moved: {old_ordinal} {} {new_ordinal}", + ui::arrow() + ), + ), + BreakingChange::RemovedConstant { name } => { + mark("❌", "-", format!("Removed constant `{name}`")) + } + BreakingChange::ChangedConstantType { + name, + old_type, + new_type, + } => mark( + "🔄", + "~", + format!( + "Changed constant `{name}`: {old_type} {} {new_type}", + ui::arrow() + ), + ), + BreakingChange::RemovedTypeAlias { name } => { + mark("❌", "-", format!("Removed type alias `{name}`")) + } + BreakingChange::ChangedTypeAliasTarget { + name, + old_target, + new_target, + } => mark( + "🔄", + "~", + format!( + "Changed type alias `{name}`: {old_target} {} {new_target}", + ui::arrow() + ), + ), + BreakingChange::RemovedValidator { name } => { + mark("❌", "-", format!("Removed validator `{name}`")) + } + BreakingChange::ChangedValidator { name } => { + mark("🔄", "~", format!("Changed validator `{name}`")) + } + BreakingChange::ValidationTightened { target } => { + mark("🔄", "~", format!("Validation tightened on `{target}`")) + } + BreakingChange::ChangedWireAnnotation { + target, + key, + old_value, + new_value, + } => mark( + "🔄", + "~", + format!( + "Changed `@{key}` on `{target}`: {}", + value_change(old_value, new_value) + ), + ), } } +/// `old → new`, with `(none)` for a side that has no value. +fn value_change(old: &Option, new: &Option) -> String { + let show = |v: &Option| v.clone().unwrap_or_else(|| "(none)".to_string()); + format!("{} {} {}", show(old), ui::arrow(), show(new)) +} + fn feature_line(feature: &NewFeature) -> String { match feature { NewFeature::AddedStruct { name, field_count } => mark( @@ -177,21 +284,69 @@ fn feature_line(feature: &NewFeature) -> String { "+", format!("Added error `{name}` ({})", count(*field_count, "field")), ), + NewFeature::AddedThrownError { + protocol_name, + function_name, + error, + } => mark( + "➕", + "+", + format!("`{protocol_name}.{function_name}` now declares `! {error}`"), + ), + NewFeature::AddedConstant { name, ty } => { + mark("➕", "+", format!("Added constant `{name}`: {ty}")) + } + NewFeature::ChangedConstantValue { + name, + old_value, + new_value, + } => mark( + "🔧", + "~", + format!( + "Changed constant `{name}`'s value: {}", + value_change(old_value, new_value) + ), + ), + NewFeature::AddedTypeAlias { name, target } => { + mark("➕", "+", format!("Added type alias `{name}` = {target}")) + } + NewFeature::AddedValidator { name } => mark("➕", "+", format!("Added validator `{name}`")), + NewFeature::ValidationLoosened { target } => { + mark("🔧", "~", format!("Validation loosened on `{target}`")) + } + NewFeature::Deprecated { target } => mark("⚠️", "!", format!("Deprecated `{target}`")), } } fn modification_line(modification: &Modification) -> String { match modification { - Modification::FieldMadeOptional { + Modification::DocstringChanged { name } => { + mark("📝", "~", format!("Docstring changed on `{name}`")) + } + Modification::ChangedFieldDefault { type_name, field_name, } => mark( "🔧", "~", - format!("Made field `{type_name}.{field_name}` optional"), + format!("Changed the default of `{type_name}.{field_name}`"), ), - Modification::DocstringChanged { name } => { - mark("📝", "~", format!("Docstring changed on `{name}`")) + Modification::ChangedErrorMessage { name } => { + mark("📝", "~", format!("Changed error `{name}`'s message")) } + Modification::ChangedAnnotation { + target, + key, + old_value, + new_value, + } => mark( + "🔧", + "~", + format!( + "Changed `@{key}` on `{target}`: {}", + value_change(old_value, new_value) + ), + ), } } diff --git a/src/commands/build.rs b/src/commands/build.rs index 5fefd34..13ecf15 100644 --- a/src/commands/build.rs +++ b/src/commands/build.rs @@ -46,7 +46,8 @@ fn build_once(work_dir: &Path, release: bool) -> Result<()> { .schema_changes .as_ref() .map(|c| !c.is_empty()) - .unwrap_or(false); + .unwrap_or(false) + || !result.dependency_changes.is_empty(); if !has_changes { ui::detail(pkg(format!( @@ -62,6 +63,10 @@ fn build_once(work_dir: &Path, release: bool) -> Result<()> { if let Some(changes) = &result.schema_changes { changes::render(changes); } + for dependency in &result.dependency_changes { + ui::group(format!("In dependency `{}`:", dependency.name)); + changes::render(&dependency.changes); + } ui::detail(bump_line(result.version_bump)); Ok(()) diff --git a/src/commands/diff.rs b/src/commands/diff.rs index 9843cc7..eed1223 100644 --- a/src/commands/diff.rs +++ b/src/commands/diff.rs @@ -4,8 +4,7 @@ use std::path::Path; use comline_core::package::build::cas::objects::Commit; use comline_core::package::build::cas::ObjectStore; -use comline_core::schema::ir::diff::{analyze_schema_changes, SchemaChanges}; -use comline_core::schema::ir::frozen::unit::FrozenUnit; +use comline_core::schema::ir::diff::analyze_package_changes; use miette::Result; use crate::commands::ensure_project; @@ -34,34 +33,10 @@ pub fn run(work_dir: &Path, old: &str, new: &str) -> Result<()> { let old_schemas = history::load_schemas(&store, old_commit)?; let new_schemas = history::load_schemas(&store, new_commit)?; - changes::render(&aggregate(&old_schemas, &new_schemas)); + changes::render(&analyze_package_changes(&old_schemas, &new_schemas)); Ok(()) } -/// Diff schema-by-schema (paired by position) and merge the results, treating -/// added/removed schema files as wholesale additions/removals. -fn aggregate(old: &[Vec], new: &[Vec]) -> SchemaChanges { - let mut merged = SchemaChanges::default(); - let common = old.len().min(new.len()); - - for i in 0..common { - extend(&mut merged, analyze_schema_changes(&old[i], &new[i])); - } - for schema in &new[common..] { - extend(&mut merged, analyze_schema_changes(&[], schema)); - } - for schema in &old[common..] { - extend(&mut merged, analyze_schema_changes(schema, &[])); - } - merged -} - -fn extend(into: &mut SchemaChanges, from: SchemaChanges) { - into.breaking_changes.extend(from.breaking_changes); - into.new_features.extend(from.new_features); - into.modifications.extend(from.modifications); -} - fn label(spec: &str, commit: &Commit) -> String { if spec.eq_ignore_ascii_case("HEAD") { format!("HEAD ({})", commit.version) diff --git a/src/history.rs b/src/history.rs index 69b4ddf..0159f8c 100644 --- a/src/history.rs +++ b/src/history.rs @@ -78,7 +78,9 @@ pub fn resolve<'a>(history: &'a [Entry], spec: &str) -> Result<&'a Commit> { )) } -/// Load every schema's frozen units from a commit's root tree, in tree order. +/// Load every local schema's frozen units from a commit's root tree, in tree +/// order. Vendored dependencies (`dep_` trees) aren't this package's +/// schemas and are skipped. pub fn load_schemas(store: &ObjectStore, commit: &Commit) -> Result>> { let root_bytes = store .read(&commit.tree) @@ -88,7 +90,7 @@ pub fn load_schemas(store: &ObjectStore, commit: &Commit) -> Result