fix(add): merge imports into existing brace + capability idempotency; fmt
- wire::add_import now merges a new symbol into an already-present
`import { ... } from '<from>';` brace instead of appending a second,
colliding import line for the same module (a duplicate ESM binding
is a hard SyntaxError/TS2300, not a harmless dupe as previously
assumed). Falls back to appending a new line when the module isn't
imported yet, or if the brace-merge edit fails the parses_clean
guard.
- cmd_add::run gains a capability-level idempotency guard, keyed on
each capability's unique route-path literal, so `matcha add <cap>`
run twice no longer appends a duplicate handler + route.
- cargo fmt --all across the crate; drop the stale #[allow(dead_code)]
on wire::parses_clean now that it's demonstrably live.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
10 files changed
+329
-79
No files matched your search
+12
-6
@@ -6,8 +6,10 @@ use crate::template;
|
||||
pub fn run(name: &str, template_url: Option<&str>) -> std::io::Result<()> {
|
||||
let dest = Path::new(name);
|
||||
if dest.exists() {
|
||||
return Err(Error::new(ErrorKind::AlreadyExists,
|
||||
format!("'{name}' already exists")));
|
||||
return Err(Error::new(
|
||||
ErrorKind::AlreadyExists,
|
||||
format!("'{name}' already exists"),
|
||||
));
|
||||
}
|
||||
|
||||
match template_url {
|
||||
@@ -46,12 +48,16 @@ mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn gh_shorthand_expands() {
|
||||
assert_eq!(resolve_url("gh:green-tea/tmpl"),
|
||||
"https://github.com/green-tea/tmpl");
|
||||
assert_eq!(
|
||||
resolve_url("gh:green-tea/tmpl"),
|
||||
"https://github.com/green-tea/tmpl"
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn full_url_passes_through() {
|
||||
assert_eq!(resolve_url("https://example.com/x.git"),
|
||||
"https://example.com/x.git");
|
||||
assert_eq!(
|
||||
resolve_url("https://example.com/x.git"),
|
||||
"https://example.com/x.git"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user