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:
1 parent
65ecba05d1
commit
2f9b656692
10 files changed
+329
-79
No files matched your search
+21
-7
@@ -1,18 +1,23 @@
|
||||
use std::path::Path;
|
||||
use crate::runtime::{self, Runtime};
|
||||
use std::path::Path;
|
||||
|
||||
fn check_command(rt: Runtime) -> (&'static str, Vec<&'static str>) {
|
||||
match rt {
|
||||
Runtime::Deno => ("deno", vec!["check", "src/app.module.ts"]),
|
||||
Runtime::Bun => ("bunx", vec!["tsc", "--noEmit"]),
|
||||
Runtime::Bun => ("bunx", vec!["tsc", "--noEmit"]),
|
||||
Runtime::Node => ("npx", vec!["tsc", "--noEmit"]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(dir: &Path) -> std::io::Result<bool> {
|
||||
let Some(rt) = runtime::detect(dir) else { return Ok(true) }; // nothing to check against
|
||||
let Some(rt) = runtime::detect(dir) else {
|
||||
return Ok(true);
|
||||
}; // nothing to check against
|
||||
let (prog, args) = check_command(rt);
|
||||
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()?;
|
||||
Ok(status.success())
|
||||
}
|
||||
|
||||
@@ -23,16 +28,25 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn deno_check_cmd() {
|
||||
assert_eq!(check_command(Runtime::Deno), ("deno", vec!["check", "src/app.module.ts"]));
|
||||
assert_eq!(
|
||||
check_command(Runtime::Deno),
|
||||
("deno", vec!["check", "src/app.module.ts"])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn node_uses_tsc_noemit() {
|
||||
assert_eq!(check_command(Runtime::Node), ("npx", vec!["tsc", "--noEmit"]));
|
||||
assert_eq!(
|
||||
check_command(Runtime::Node),
|
||||
("npx", vec!["tsc", "--noEmit"])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bun_uses_bunx_tsc_noemit() {
|
||||
assert_eq!(check_command(Runtime::Bun), ("bunx", vec!["tsc", "--noEmit"]));
|
||||
assert_eq!(
|
||||
check_command(Runtime::Bun),
|
||||
("bunx", vec!["tsc", "--noEmit"])
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user