diff --git a/crates/vite_task_graph/run-config.ts b/crates/vite_task_graph/run-config.ts index 4b0c4c48..0ab58364 100644 --- a/crates/vite_task_graph/run-config.ts +++ b/crates/vite_task_graph/run-config.ts @@ -1,3 +1,5 @@ +// This file is auto-generated by `cargo test`. Do not edit manually. + export type Task = { /** * The command to run for the task. diff --git a/crates/vite_task_graph/src/config/user.rs b/crates/vite_task_graph/src/config/user.rs index d8d784d6..60feb652 100644 --- a/crates/vite_task_graph/src/config/user.rs +++ b/crates/vite_task_graph/src/config/user.rs @@ -204,37 +204,52 @@ impl UserRunConfig { #[expect(clippy::disallowed_types, reason = "test code uses std types for convenience")] pub fn generate_ts_definition() -> String { use std::{ + any::TypeId, + collections::HashSet, io::Write, process::{Command, Stdio}, }; use ts_rs::TypeVisitor; - struct DeclCollector(Vec); + struct DeclCollector { + decls: Vec, + visited: HashSet, + } impl TypeVisitor for DeclCollector { fn visit(&mut self) { + if !self.visited.insert(TypeId::of::()) { + return; + } // Only collect declarations from types that are exportable // (i.e., have an output path - built-in types like HashMap don't) if T::output_path().is_some() { - self.0.push(T::decl()); + self.decls.push(T::decl()); } + // Recursively visit dependencies of T + T::visit_dependencies(self); } } - let mut collector = DeclCollector(Vec::new()); + let mut collector = DeclCollector { decls: Vec::new(), visited: HashSet::new() }; Self::visit_dependencies(&mut collector); // Sort declarations for deterministic output order - collector.0.sort(); + collector.decls.sort(); + + // Header + let mut types: String = + "// This file is auto-generated by `cargo test`. Do not edit manually.\n\n".into(); // Export all types - let mut types: String = collector - .0 + let dep_types: String = collector + .decls .iter() .map(|decl| vite_str::format!("export {decl}")) .collect::>() .join("\n\n"); + types.push_str(&dep_types); // Export the main type types.push_str("\n\nexport ");