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
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ fspy_test_utils = { path = "crates/fspy_test_utils" }
futures = "0.3.31"
futures-util = "0.3.31"
insta = "1.44.3"
jsonc-parser = { version = "0.29.0", features = ["serde"] }
libc = "0.2.172"
memmap2 = "0.9.7"
monostate = "1.0.2"
Expand Down
2 changes: 2 additions & 0 deletions crates/vite_task_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ path = "src/main.rs"
anyhow = { workspace = true }
async-trait = { workspace = true }
clap = { workspace = true, features = ["derive"] }
jsonc-parser = { workspace = true }
serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] }
vite_path = { workspace = true }
vite_str = { workspace = true }
Expand Down
29 changes: 28 additions & 1 deletion crates/vite_task_bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,37 @@ impl vite_task::TaskSynthesizer<CustomTaskSubcommand> for TaskSynthesizer {
}
}

/// A `UserConfigLoader` implementation that only loads `vite-task.json`.
///
/// This is mainly for examples and testing as it does not require Node.js environment.
#[derive(Default, Debug)]
pub struct JsonUserConfigLoader(());

#[async_trait::async_trait(?Send)]
impl vite_task::loader::UserConfigLoader for JsonUserConfigLoader {
async fn load_user_config_file(
&self,
package_path: &AbsolutePath,
) -> anyhow::Result<Option<vite_task::config::UserRunConfig>> {
let config_path = package_path.join("vite-task.json");
let config_content = match tokio::fs::read_to_string(&config_path).await {
Ok(content) => content,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Ok(None);
}
Err(err) => return Err(err.into()),
};
let json_value = jsonc_parser::parse_to_serde_value(&config_content, &Default::default())?
.unwrap_or_default();
let user_config: vite_task::config::UserRunConfig = serde_json::from_value(json_value)?;
Ok(Some(user_config))
}
}

#[derive(Default)]
pub struct OwnedSessionCallbacks {
task_synthesizer: TaskSynthesizer,
user_config_loader: vite_task::loader::JsonUserConfigLoader,
user_config_loader: JsonUserConfigLoader,
}

impl OwnedSessionCallbacks {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
// Smoke test: enables caching for all package.json scripts.
"cacheScripts": true
}
2 changes: 0 additions & 2 deletions crates/vite_task_graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ petgraph = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["fs"] }
vec1 = { workspace = true, features = ["smallvec-v1"] }
vite_graph_ser = { workspace = true }
vite_path = { workspace = true }
Expand All @@ -24,7 +23,6 @@ vite_workspace = { workspace = true }

[dev-dependencies]
pretty_assertions = { workspace = true }
tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
ts-rs = { workspace = true }
vite_path = { workspace = true, features = ["ts-rs"] }
vite_str = { workspace = true, features = ["ts-rs"] }
Expand Down
25 changes: 0 additions & 25 deletions crates/vite_task_graph/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,3 @@ pub trait UserConfigLoader: Debug + Send + Sync {
package_path: &AbsolutePath,
) -> anyhow::Result<Option<UserRunConfig>>;
}

/// A `UserConfigLoader` implementation that only loads `vite-task.json`.
///
/// This is mainly for examples and testing as it does not require Node.js environment.
#[derive(Default, Debug)]
pub struct JsonUserConfigLoader(());

#[async_trait::async_trait(?Send)]
impl UserConfigLoader for JsonUserConfigLoader {
async fn load_user_config_file(
&self,
package_path: &AbsolutePath,
) -> anyhow::Result<Option<UserRunConfig>> {
let config_path = package_path.join("vite-task.json");
let config_content = match tokio::fs::read_to_string(&config_path).await {
Ok(content) => content,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
return Ok(None);
}
Err(err) => return Err(err.into()),
};
let user_config: UserRunConfig = serde_json::from_str(&config_content)?;
Ok(Some(user_config))
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
// Enables caching for all package.json scripts in the workspace.
"cacheScripts": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
// Enables caching for all package.json scripts in the workspace.
"cacheScripts": true
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
// This workspace root has no package.json — only pnpm-workspace.yaml.
// vite-task.json should still be loaded and applied.
"cacheScripts": true,
"tasks": {
"deploy": {
Expand Down