feat(graph): draw the graph, and stop scaffolding a two-month-old core
The CLI's last feature work was 12 July; core has shipped 26.8 and 26.9 since. Two consequences, fixed together because they share an entry-file convention. Every runtime overlay pinned `^26.7.0-beta.0`. Core is prerelease-only, and npm's semver excludes a prerelease from any range whose comparators carry a different major.minor.patch — so that caret is not a loose pin, it is a pin to the oldest matching prerelease that nothing can move off. Every project `matcha new` has produced since July installed 26.7.0-beta.0 and could not upgrade: no logger, no request budget, no resumable `@Sse` id, and none of the crashes 26.9 fixed. The pin is now exact, lives in one `CORE_VERSION` const, and Deno resolves through JSR — which is core's native path for Deno and the one 26.9 repaired. Nothing caught that because CI never ran JavaScript. `cargo test` proves the CLI writes the files it means to write; it cannot prove those files describe a project the current core will run. `scripts/starter-smoke.sh` scaffolds, installs, type-checks, boots, curls `/` and the `/zen` stream, and introspects a real starter per runtime; a weekly job fails when the pin falls behind the `beta` dist-tag. The smoke immediately found a second defect: the bun overlay carried no Bun types, so `tsc --noEmit` — and therefore `matcha create --check` — failed on every bun project the CLI has ever scaffolded. `matcha graph` and `matcha explain <pattern>` close the widest gap in the surface: the framework's claim is that an API is a graph rather than a middleware chain, `toMermaid`/`toDOT`/`graph`/`explain` have been exported all along, and the CLI could not draw any of it. Both reach the app through `app.ready()`, which resolves the graph and is documented as deliberately not running provider factories — asking for a diagram must not open your database connections. Formatting lives in the generated script rather than in Rust, which keeps serde out for output `console.log` already has the values for. That needed an app the CLI can import without binding a port, so the starter now composes the graph in `src/app.ts` and leaves `src/main.ts` holding only the serve call. `create module` follows, preferring `src/app.ts` and falling back to `src/main.ts` so projects scaffolded before the split keep working. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012x1UPw987zNSxjH2DxHy2C
This commit is contained in:
21 files changed
+747
-27
No files matched your search
+79
-1
@@ -3,6 +3,19 @@ use std::path::Path;
|
||||
|
||||
use crate::runtime::Runtime;
|
||||
|
||||
/// The `@green-tea/core` version `matcha new` writes into a scaffolded project,
|
||||
/// substituted for `{{core_version}}` in the runtime overlays.
|
||||
///
|
||||
/// **Pinned exactly, on purpose.** Core is prerelease-only, and npm's semver
|
||||
/// excludes a prerelease from any range whose comparators carry a different
|
||||
/// `major.minor.patch` — so `^26.7.0-beta.0` never resolves past `26.7.0-beta.0`,
|
||||
/// however many betas ship after it. A caret here is not a looser pin, it is a
|
||||
/// pin to the oldest matching prerelease that nothing can move off. When core
|
||||
/// reaches a stable major this becomes a range (`^27`) and the exactness stops
|
||||
/// mattering; until then the `core-freshness` CI job fails when this falls
|
||||
/// behind the `beta` dist-tag, which is what keeps it current.
|
||||
pub const CORE_VERSION: &str = "26.9.0-beta.1";
|
||||
|
||||
pub static SHARED: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/shared");
|
||||
pub static RUNTIME_DENO: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/runtimes/deno");
|
||||
pub static RUNTIME_NODE: Dir = include_dir!("$CARGO_MANIFEST_DIR/template/runtimes/node");
|
||||
@@ -35,7 +48,11 @@ fn write_dir(dir: &Dir, dest: &Path, name: &str) -> std::io::Result<()> {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let contents = std::str::from_utf8(f.contents())
|
||||
.map(|s| s.replace("{{project_name}}", name).into_bytes())
|
||||
.map(|s| {
|
||||
s.replace("{{project_name}}", name)
|
||||
.replace("{{core_version}}", CORE_VERSION)
|
||||
.into_bytes()
|
||||
})
|
||||
.unwrap_or_else(|_| f.contents().to_vec());
|
||||
std::fs::write(out, contents)?;
|
||||
}
|
||||
@@ -49,6 +66,60 @@ mod tests {
|
||||
use super::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
/// The graph has to be importable without binding a port, which is why the
|
||||
/// scaffold composes it in `src/app.ts` and leaves `src/main.ts` holding
|
||||
/// only the runtime's serve call. `matcha graph` and `matcha explain`
|
||||
/// import the former; breaking the split breaks both.
|
||||
#[test]
|
||||
fn every_runtime_exports_the_app_from_its_own_module() {
|
||||
for rt in [Runtime::Node, Runtime::Deno, Runtime::Bun] {
|
||||
let d = tempdir().unwrap();
|
||||
write_starter(d.path(), "my-api", rt).unwrap();
|
||||
|
||||
let app = std::fs::read_to_string(d.path().join("src/app.ts")).unwrap();
|
||||
assert!(
|
||||
app.contains("export const app = createApp("),
|
||||
"{rt:?} app.ts"
|
||||
);
|
||||
|
||||
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||
assert!(
|
||||
main.contains("import { app } from './app';"),
|
||||
"{rt:?} main.ts"
|
||||
);
|
||||
assert!(
|
||||
!main.contains("createApp("),
|
||||
"{rt:?} main.ts still composes the graph"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Core is prerelease-only, and a caret over a prerelease never resolves
|
||||
/// past its own `major.minor.patch` — `^26.7.0-beta.0` pinned every
|
||||
/// scaffold to 26.7.0-beta.0 while three later betas shipped. Nothing here
|
||||
/// may carry a range.
|
||||
#[test]
|
||||
fn no_runtime_scaffolds_a_caret_range_for_core() {
|
||||
for rt in [Runtime::Node, Runtime::Deno, Runtime::Bun] {
|
||||
let d = tempdir().unwrap();
|
||||
write_starter(d.path(), "my-api", rt).unwrap();
|
||||
|
||||
let manifest = ["package.json", "deno.json"]
|
||||
.iter()
|
||||
.map(|f| d.path().join(f))
|
||||
.find(|p| p.exists())
|
||||
.map(|p| std::fs::read_to_string(p).unwrap())
|
||||
.unwrap();
|
||||
let pin = manifest
|
||||
.lines()
|
||||
.find(|l| l.contains("@green-tea/core\":"))
|
||||
.unwrap_or_else(|| panic!("{rt:?} declares no core dependency"));
|
||||
assert!(pin.contains(CORE_VERSION), "{rt:?}: {pin}");
|
||||
assert!(!pin.contains('^'), "{rt:?} pins core with a caret: {pin}");
|
||||
assert!(!pin.contains('~'), "{rt:?} pins core with a tilde: {pin}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deno_writes_shared_and_deno_overlay() {
|
||||
let d = tempdir().unwrap();
|
||||
@@ -66,6 +137,10 @@ mod tests {
|
||||
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||
assert!(main.contains("Deno.serve"));
|
||||
assert!(!d.path().join("package.json").exists());
|
||||
|
||||
let deno_json = std::fs::read_to_string(d.path().join("deno.json")).unwrap();
|
||||
assert!(deno_json.contains(&format!("jsr:@green-tea/core@{CORE_VERSION}")));
|
||||
assert!(!deno_json.contains("{{core_version}}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -83,6 +158,9 @@ mod tests {
|
||||
let main = std::fs::read_to_string(d.path().join("src/main.ts")).unwrap();
|
||||
assert!(main.contains("app.listen"));
|
||||
assert!(!d.path().join("deno.json").exists());
|
||||
|
||||
assert!(pkg.contains(&format!("\"@green-tea/core\": \"{CORE_VERSION}\"")));
|
||||
assert!(!pkg.contains("{{core_version}}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user