Skip to content

Commit 5a8817f

Browse files
branchseerclaude
andcommitted
chore: move JsonUserConfigLoader from vite_task_graph to vite_task_bin
JsonUserConfigLoader is only instantiated in vite_task_bin, so it belongs there rather than in the core graph crate. This also removes the tokio dependency from vite_task_graph. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 85ad08e commit 5a8817f

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_task_bin/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ path = "src/main.rs"
1414
anyhow = { workspace = true }
1515
async-trait = { workspace = true }
1616
clap = { workspace = true, features = ["derive"] }
17+
jsonc-parser = { workspace = true }
18+
serde_json = { workspace = true }
1719
tokio = { workspace = true, features = ["full"] }
1820
vite_path = { workspace = true }
1921
vite_str = { workspace = true }

crates/vite_task_bin/src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,38 @@ impl vite_task::TaskSynthesizer<CustomTaskSubcommand> for TaskSynthesizer {
135135
}
136136
}
137137

138+
/// A `UserConfigLoader` implementation that only loads `vite-task.json`.
139+
///
140+
/// This is mainly for examples and testing as it does not require Node.js environment.
141+
#[derive(Default, Debug)]
142+
pub struct JsonUserConfigLoader(());
143+
144+
#[async_trait::async_trait(?Send)]
145+
impl vite_task::loader::UserConfigLoader for JsonUserConfigLoader {
146+
async fn load_user_config_file(
147+
&self,
148+
package_path: &AbsolutePath,
149+
) -> anyhow::Result<Option<vite_task::config::UserRunConfig>> {
150+
let config_path = package_path.join("vite-task.json");
151+
let config_content = match tokio::fs::read_to_string(&config_path).await {
152+
Ok(content) => content,
153+
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
154+
return Ok(None);
155+
}
156+
Err(err) => return Err(err.into()),
157+
};
158+
let json_value =
159+
jsonc_parser::parse_to_serde_value(&config_content, &Default::default())?
160+
.unwrap_or_default();
161+
let user_config: vite_task::config::UserRunConfig = serde_json::from_value(json_value)?;
162+
Ok(Some(user_config))
163+
}
164+
}
165+
138166
#[derive(Default)]
139167
pub struct OwnedSessionCallbacks {
140168
task_synthesizer: TaskSynthesizer,
141-
user_config_loader: vite_task::loader::JsonUserConfigLoader,
169+
user_config_loader: JsonUserConfigLoader,
142170
}
143171

144172
impl OwnedSessionCallbacks {

crates/vite_task_graph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ petgraph = { workspace = true }
1616
serde = { workspace = true, features = ["derive"] }
1717
serde_json = { workspace = true }
1818
thiserror = { workspace = true }
19-
tokio = { workspace = true, features = ["fs"] }
2019
vec1 = { workspace = true, features = ["smallvec-v1"] }
2120
vite_graph_ser = { workspace = true }
2221
vite_path = { workspace = true }

crates/vite_task_graph/src/loader.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,3 @@ pub trait UserConfigLoader: Debug + Send + Sync {
1212
package_path: &AbsolutePath,
1313
) -> anyhow::Result<Option<UserRunConfig>>;
1414
}
15-
16-
/// A `UserConfigLoader` implementation that only loads `vite-task.json`.
17-
///
18-
/// This is mainly for examples and testing as it does not require Node.js environment.
19-
#[derive(Default, Debug)]
20-
pub struct JsonUserConfigLoader(());
21-
22-
#[async_trait::async_trait(?Send)]
23-
impl UserConfigLoader for JsonUserConfigLoader {
24-
async fn load_user_config_file(
25-
&self,
26-
package_path: &AbsolutePath,
27-
) -> anyhow::Result<Option<UserRunConfig>> {
28-
let config_path = package_path.join("vite-task.json");
29-
let config_content = match tokio::fs::read_to_string(&config_path).await {
30-
Ok(content) => content,
31-
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
32-
return Ok(None);
33-
}
34-
Err(err) => return Err(err.into()),
35-
};
36-
let json_value = jsonc_parser::parse_to_serde_value(&config_content, &Default::default())?
37-
.unwrap_or_default();
38-
let user_config: UserRunConfig = serde_json::from_value(json_value)?;
39-
Ok(Some(user_config))
40-
}
41-
}

0 commit comments

Comments
 (0)