`matcha new --runtime edge` scaffolds a Worker: `nodejs_compat`, `edgeHandler` as the default export, and wrangler's `[assets]` serving `./public` so `/` is the same page as on the other three runtimes and `/zen` the same stream from the worker. `matcha run` is `wrangler dev`, which is real workerd, so edge stops being a deploy-only target. Runtime detection puts `wrangler.toml` ahead of `package.json`, since an edge project has both, and the graph resolves under node — `src/app.ts` imports core, never `edgeHandler`. Getting there turned up a core defect, filed as Green-Tea/core#93: the npm ESM build cannot load on workerd at all. tsup's `createRequire(import.meta.url)` banner runs at module scope and `import.meta.url` is undefined there, so `@green-tea/core/edge` throws before any of its own code runs — while `src/node-require.ts` is written precisely to make that lazy and survivable. core's own edge test cannot see it: it bundles `src/`, so `dist/` is the one artifact users install and the one nothing exercises. The scaffold installs from JSR, which publishes source with no banner and boots clean; the `.npmrc` says why and links the issue, and both it and the alias can go once it is fixed. `matcha doctor` reports the misconfigurations that fail confusingly rather than loudly: `experimentalDecorators` missing, which turns every `@Route` into a syntax error blaming the decorator; a core pin that cannot resolve or that does not match what is installed; an entry that does not export `app`; and `@Ws` or multipart routes whose lazy-loaded peer dependency is absent, which compile and then fail at the first request. Every check is a file read — no runtime spawned, nothing fetched — so it works before the project installs. It reads the installed version from the package's own manifest rather than core's exported `VERSION`, which is stale in the published artifact (Green-Tea/core#92) and would give the wrong answer to the one check that exists to catch a wrong version. The starter smoke and the CI matrix gained edge as a fourth runtime. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012x1UPw987zNSxjH2DxHy2C
55 lines
1.6 KiB
Rust
55 lines
1.6 KiB
Rust
use std::io::{Error, ErrorKind};
|
|
use std::path::Path;
|
|
|
|
use crate::runtime::{self, Runtime};
|
|
|
|
fn command_for(rt: Runtime) -> (&'static str, Vec<&'static str>) {
|
|
match rt {
|
|
Runtime::Deno => ("deno", vec!["task", "dev"]),
|
|
Runtime::Bun => ("bun", vec!["run", "dev"]),
|
|
Runtime::Node => ("npm", vec!["run", "dev"]),
|
|
// The scaffold's `dev` script is `wrangler dev`, which boots real
|
|
// workerd locally — so edge is a `matcha run` target after all.
|
|
Runtime::Edge => ("npm", vec!["run", "dev"]),
|
|
}
|
|
}
|
|
|
|
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 (prog, args) = command_for(rt);
|
|
println!("→ {prog} {}", args.join(" "));
|
|
let status = std::process::Command::new(prog)
|
|
.args(&args)
|
|
.current_dir(dir)
|
|
.status()?;
|
|
std::process::exit(status.code().unwrap_or(1));
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::runtime::Runtime;
|
|
|
|
#[test]
|
|
fn deno_uses_task_dev() {
|
|
assert_eq!(command_for(Runtime::Deno), ("deno", vec!["task", "dev"]));
|
|
}
|
|
#[test]
|
|
fn bun_watch() {
|
|
assert_eq!(command_for(Runtime::Bun), ("bun", vec!["run", "dev"]));
|
|
}
|
|
#[test]
|
|
fn edge_runs_wrangler_through_the_dev_script() {
|
|
assert_eq!(command_for(Runtime::Edge), ("npm", vec!["run", "dev"]));
|
|
}
|
|
#[test]
|
|
fn node_watch() {
|
|
assert_eq!(command_for(Runtime::Node), ("npm", vec!["run", "dev"]));
|
|
}
|
|
}
|