Skip to content

Commit ec517aa

Browse files
authored
feat: intergrate vite_task_plan and vite_task_graph in vite_task::session (#64)
# feat: integrate vite_task_plan and vite_task_graph This PR integrates the task planning and execution functionality from `vite_task_plan` and `vite_task_graph` into the main `vite_task` crate. Key changes include: - Added a new `Session` type in `vite_task` that manages task graph loading and provides methods to plan and execute tasks - Implemented CLI argument parsing with `clap` for task commands - Added `async-trait` for better async interface design - Created a path redaction feature in `vite_path` for stable serialization of absolute paths - Moved snapshot tests from `vite_task_graph` to `vite_task` - Removed the standalone `vite_task_bin` crate in favor of a binary in `vite_task` - Added proper workspace node_modules/.bin path handling for task execution The PR establishes a cleaner architecture where `vite_task` serves as the main entry point for task planning and execution, while `vite_task_graph` and `vite_task_plan` provide the underlying functionality.
1 parent dd8bd2d commit ec517aa

File tree

105 files changed

+668
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+668
-297
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ allocator-api2 = { version = "0.2.21", default-features = false, features = ["al
3636
anyhow = "1.0.98"
3737
assert2 = "0.3.16"
3838
assertables = "9.8.1"
39+
async-trait = "0.1.89"
3940
base64 = "0.22.1"
4041
bincode = "2.0.1"
4142
bindgen = "0.72.1"
@@ -122,6 +123,7 @@ vite_path = { path = "crates/vite_path" }
122123
vite_shell = { path = "crates/vite_shell" }
123124
vite_str = { path = "crates/vite_str" }
124125
vite_task_graph = { path = "crates/vite_task_graph" }
126+
vite_task_plan = { path = "crates/vite_task_plan" }
125127
vite_workspace = { path = "crates/vite_workspace" }
126128
wax = "0.6.0"
127129
which = "8.0.0"

crates/vite_path/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ serde = { workspace = true, features = ["derive", "rc"] }
1414
thiserror = { workspace = true }
1515
vite_str = { workspace = true }
1616

17+
[features]
18+
absolute-redaction = []
19+
1720
[lints]
1821
workspace = true
1922

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#[cfg(feature = "absolute-redaction")]
2+
pub mod redaction;
3+
14
use std::{
25
ffi::OsStr,
36
fmt::Display,
@@ -8,6 +11,7 @@ use std::{
811
};
912

1013
use ref_cast::{RefCastCustom, ref_cast_custom};
14+
use serde::Serialize;
1115

1216
use crate::relative::{FromPathError, InvalidPathDataError, RelativePathBuf};
1317

@@ -21,6 +25,35 @@ impl AsRef<Self> for AbsolutePath {
2125
}
2226
}
2327

28+
impl Serialize for AbsolutePath {
29+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
30+
where
31+
S: serde::Serializer,
32+
{
33+
#[cfg(feature = "absolute-redaction")]
34+
{
35+
use redaction::REDACTION_PREFIX;
36+
37+
if let Some(redaction_prefix) = REDACTION_PREFIX
38+
.with(|redaction_prefix| redaction_prefix.borrow().as_ref().map(Arc::clone))
39+
{
40+
match self.strip_prefix(redaction_prefix) {
41+
Ok(Some(stripped_path)) => return stripped_path.serialize(serializer),
42+
Err(strip_error) => {
43+
return Err(serde::ser::Error::custom(format!(
44+
"Failed to redact absolute path '{}': {}",
45+
self.as_path().display(),
46+
strip_error
47+
)));
48+
}
49+
Ok(None) => { /* continue to serialize full path */ }
50+
}
51+
}
52+
}
53+
self.as_path().serialize(serializer)
54+
}
55+
}
56+
2457
impl PartialEq<AbsolutePathBuf> for AbsolutePath {
2558
fn eq(&self, other: &AbsolutePathBuf) -> bool {
2659
self.0 == other.0
@@ -46,6 +79,14 @@ impl From<&AbsolutePath> for Arc<AbsolutePath> {
4679
}
4780
}
4881

82+
impl From<&AbsolutePath> for Box<AbsolutePath> {
83+
fn from(path: &AbsolutePath) -> Self {
84+
let path_box: Box<Path> = path.0.into();
85+
let path_box_raw = Box::into_raw(path_box) as *mut AbsolutePath;
86+
unsafe { Self::from_raw(path_box_raw) }
87+
}
88+
}
89+
4990
impl AbsolutePath {
5091
/// Creates a [`AbsolutePath`] if the give path is absolute.
5192
pub fn new<P: AsRef<Path> + ?Sized>(path: &P) -> Option<&Self> {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::sync::Arc;
2+
3+
use super::AbsolutePath;
4+
5+
thread_local! {
6+
pub(crate) static REDACTION_PREFIX: std::cell::RefCell<Option<Arc<AbsolutePath>>> = std::cell::RefCell::new(None);
7+
}
8+
9+
#[derive(Debug)]
10+
pub struct RedactionGuard(());
11+
12+
impl Drop for RedactionGuard {
13+
fn drop(&mut self) {
14+
REDACTION_PREFIX.set(None);
15+
}
16+
}
17+
18+
pub fn redact_absolute_paths(prefix: &Arc<AbsolutePath>) -> RedactionGuard {
19+
REDACTION_PREFIX.with(|redaction_prefix| {
20+
let mut redaction_prefix = redaction_prefix.borrow_mut();
21+
assert!(redaction_prefix.is_none(), "RedactionGuard already active");
22+
*redaction_prefix = Some(Arc::clone(&prefix));
23+
});
24+
RedactionGuard(())
25+
}

crates/vite_path/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ pub mod relative;
33

44
use std::io;
55

6+
#[cfg(feature = "absolute-redaction")]
7+
pub use absolute::redaction;
68
pub use absolute::{AbsolutePath, AbsolutePathBuf};
79
pub use relative::{RelativePath, RelativePathBuf};
810

crates/vite_task/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ workspace = true
1313

1414
[dependencies]
1515
anyhow = { workspace = true }
16+
async-trait = { workspace = true }
1617
bincode = { workspace = true, features = ["derive"] }
1718
bstr = { workspace = true }
19+
clap = { workspace = true, features = ["derive"] }
1820
compact_str = { workspace = true, features = ["serde"] }
1921
dashmap = { workspace = true }
22+
derive_more = { workspace = true }
2023
diff-struct = { workspace = true }
2124
fspy = { workspace = true }
2225
futures-core = { workspace = true }
@@ -41,11 +44,17 @@ vite_glob = { workspace = true }
4144
vite_path = { workspace = true }
4245
vite_shell = { workspace = true }
4346
vite_str = { workspace = true }
47+
vite_task_graph = { workspace = true }
48+
vite_task_plan = { workspace = true }
4449
vite_workspace = { workspace = true }
4550
wax = { workspace = true }
4651

4752
[target.'cfg(unix)'.dependencies]
4853
nix = { workspace = true }
4954

5055
[dev-dependencies]
56+
copy_dir = { workspace = true }
57+
insta = { workspace = true, features = ["glob", "json", "redactions"] }
5158
tempfile = { workspace = true }
59+
toml = { workspace = true }
60+
vite_path = { workspace = true, features = ["absolute-redaction"] }

crates/vite_task/src/bin/vite.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use clap::Parser;
2+
use vite_str::Str;
3+
use vite_task::CLIArgs;
4+
5+
#[derive(Debug, Parser)]
6+
enum CustomTaskSubCommand {
7+
/// oxlint
8+
Lint { args: Vec<Str> },
9+
}
10+
11+
fn main() {
12+
let _subcommand = CLIArgs::<CustomTaskSubCommand>::parse();
13+
}

0 commit comments

Comments
 (0)