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
@@ -0,0 +1,56 @@
|
||||
//! Where the application graph is composed: the file holding the `createApp`
|
||||
//! call and exporting the `app` it returns.
|
||||
//!
|
||||
//! `src/app.ts` is what `matcha new` scaffolds, and it exists as its own file
|
||||
//! precisely so the graph can be imported without binding a port. Projects
|
||||
//! scaffolded before that split — and hand-written ones that never took it —
|
||||
//! keep the whole thing in `src/main.ts`, so that stays a candidate.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Candidate entry files, most specific first.
|
||||
const CANDIDATES: [&str; 2] = ["src/app.ts", "src/main.ts"];
|
||||
|
||||
/// The first candidate that exists under `dir`, or `None` when neither does.
|
||||
pub fn find(dir: &Path) -> Option<PathBuf> {
|
||||
CANDIDATES.iter().map(|c| dir.join(c)).find(|p| p.exists())
|
||||
}
|
||||
|
||||
/// The candidate list as prose, for the error a caller prints when `find`
|
||||
/// returns `None`.
|
||||
pub fn candidates() -> String {
|
||||
CANDIDATES.join(" or ")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
fn touch(dir: &Path, rel: &str) {
|
||||
let p = dir.join(rel);
|
||||
std::fs::create_dir_all(p.parent().unwrap()).unwrap();
|
||||
std::fs::write(p, "").unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prefers_app_over_main() {
|
||||
let d = tempdir().unwrap();
|
||||
touch(d.path(), "src/main.ts");
|
||||
touch(d.path(), "src/app.ts");
|
||||
assert_eq!(find(d.path()), Some(d.path().join("src/app.ts")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn falls_back_to_main() {
|
||||
let d = tempdir().unwrap();
|
||||
touch(d.path(), "src/main.ts");
|
||||
assert_eq!(find(d.path()), Some(d.path().join("src/main.ts")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn none_when_neither_exists() {
|
||||
let d = tempdir().unwrap();
|
||||
assert_eq!(find(d.path()), None);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user