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:
chrnx committed 2026-07-11 13:52:21 -05:00
1 parent 65ecba05d1
commit 2f9b656692
10 files changed
+329 -79

No files matched your search

+14 -6
View File
@@ -12,13 +12,18 @@ fn command_for(rt: Runtime) -> (&'static str, Vec<&'static str>) {
}
pub fn run(dir: &Path) -> std::io::Result<()> {
let rt = runtime::detect(dir).ok_or_else(|| Error::new(
ErrorKind::NotFound,
"no runtime detected (need deno.json, bun.lock, or package.json)",
))?;
let rt = runtime::detect(dir).ok_or_else(|| {
Error::new(
ErrorKind::NotFound,
"no runtime detected (need deno.json, bun.lock, or package.json)",
)
})?;
let (prog, args) = command_for(rt);
println!("→ {prog} {}", args.join(" "));
let status = std::process::Command::new(prog).args(&args).current_dir(dir).status()?;
let status = std::process::Command::new(prog)
.args(&args)
.current_dir(dir)
.status()?;
std::process::exit(status.code().unwrap_or(1));
}
@@ -33,7 +38,10 @@ mod tests {
}
#[test]
fn bun_watch() {
assert_eq!(command_for(Runtime::Bun), ("bun", vec!["--watch", "run", "dev"]));
assert_eq!(
command_for(Runtime::Bun),
("bun", vec!["--watch", "run", "dev"])
);
}
#[test]
fn node_watch() {