Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/vite_task_graph/run-config.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
27 changes: 21 additions & 6 deletions crates/vite_task_graph/src/config/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>);
struct DeclCollector {
decls: Vec<String>,
visited: HashSet<TypeId>,
}

impl TypeVisitor for DeclCollector {
fn visit<T: TS + 'static + ?Sized>(&mut self) {
if !self.visited.insert(TypeId::of::<T>()) {
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::<Vec<_>>()
.join("\n\n");
types.push_str(&dep_types);

// Export the main type
types.push_str("\n\nexport ");
Expand Down