Skip to content

Commit d1824f2

Browse files
authored
feat: config types (#128)
# Add TypeScript type definitions for task configuration This PR adds TypeScript type definitions for the task configuration schema used in `vite.config.*` files. The types are generated using the `ts-rs` crate and are included as a static file in the repository. Key changes: - Add `ts-rs` dependency with feature flags to make it optional - Implement `TS` trait for `Str` and `RelativePathBuf` (both map to TypeScript's `string`) - Add TypeScript type annotations to all user config structs - Convert `UserConfigTasks` to a newtype pattern for better TS support - Include generated TypeScript definition file at `crates/vite_task_graph/task-config.ts` - Add test to verify generated TypeScript matches the committed file The TypeScript definitions provide better editor support when users are editing their task configurations in TypeScript/JavaScript-based config files.
1 parent b6805fa commit d1824f2

File tree

18 files changed

+416
-54
lines changed

18 files changed

+416
-54
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ jobs:
100100
tools: dprint,cargo-shear
101101
components: clippy rust-docs rustfmt
102102

103-
- run: |
104-
dprint check
105-
cargo shear
106-
cargo fmt --check
107-
# cargo clippy --all-targets --all-features -- -D warnings
108-
RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --document-private-items
103+
- run: dprint check
104+
- run: cargo shear
105+
- run: cargo fmt --check
106+
# - run: cargo clippy --all-targets --all-features -- -D warnings
107+
- run: RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --document-private-items
109108

110109
- uses: crate-ci/typos@85f62a8a84f939ae994ab3763f01a0296d61a7ee # v1.36.2
111110
with:

Cargo.lock

Lines changed: 46 additions & 1 deletion
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
@@ -88,6 +88,7 @@ passfd = { git = "https://github.com/polachok/passfd", rev = "d55881752c16aced1a
8888
petgraph = "0.8.2"
8989
phf = { version = "0.11.3", features = ["macros"] }
9090
portable-pty = "0.9.0"
91+
pretty_assertions = "1.4.1"
9192
rand = "0.9.1"
9293
ratatui = "0.29.0"
9394
rayon = "1.10.0"
@@ -116,6 +117,7 @@ toml = "0.9.5"
116117
tracing = "0.1.43"
117118
tracing-error = "0.2.1"
118119
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "serde"] }
120+
ts-rs = { version = "11.1.0" }
119121
tui-term = "0.2.0"
120122
twox-hash = "2.1.1"
121123
uuid = "1.18.1"

crates/vite_path/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ diff-struct = { workspace = true }
1212
ref-cast = { workspace = true }
1313
serde = { workspace = true, features = ["derive", "rc"] }
1414
thiserror = { workspace = true }
15+
ts-rs = { workspace = true, optional = true }
1516
vite_str = { workspace = true }
1617

1718
[features]
1819
absolute-redaction = []
20+
ts-rs = ["dep:ts-rs", "vite_str/ts-rs"]
1921

2022
[lints]
2123
workspace = true

crates/vite_path/src/relative.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,38 @@ pub enum FromPathError {
263263
InvalidPathData(#[from] InvalidPathDataError),
264264
}
265265

266+
#[cfg(feature = "ts-rs")]
267+
mod ts_impl {
268+
use ts_rs::TS;
269+
270+
use super::RelativePathBuf;
271+
272+
impl TS for RelativePathBuf {
273+
type OptionInnerType = Self;
274+
type WithoutGenerics = Self;
275+
276+
fn name() -> String {
277+
"string".to_owned()
278+
}
279+
280+
fn inline() -> String {
281+
"string".to_owned()
282+
}
283+
284+
fn inline_flattened() -> String {
285+
panic!("RelativePathBuf cannot be flattened")
286+
}
287+
288+
fn decl() -> String {
289+
panic!("RelativePathBuf is a primitive type")
290+
}
291+
292+
fn decl_concrete() -> String {
293+
panic!("RelativePathBuf is a primitive type")
294+
}
295+
}
296+
}
297+
266298
#[cfg(test)]
267299
mod tests {
268300

crates/vite_str/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ bincode = { workspace = true }
1111
compact_str = { workspace = true, features = ["serde"] }
1212
diff-struct = { workspace = true }
1313
serde = { workspace = true, features = ["derive"] }
14+
ts-rs = { workspace = true, optional = true }
15+
16+
[features]
17+
ts-rs = ["dep:ts-rs"]
1418

1519
[lints]
1620
workspace = true

crates/vite_str/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,38 @@ impl PartialEq<str> for Str {
176176
}
177177
}
178178

179+
#[cfg(feature = "ts-rs")]
180+
mod ts_impl {
181+
use ts_rs::TS;
182+
183+
use super::Str;
184+
185+
impl TS for Str {
186+
type OptionInnerType = Self;
187+
type WithoutGenerics = Self;
188+
189+
fn name() -> String {
190+
"string".to_owned()
191+
}
192+
193+
fn inline() -> String {
194+
"string".to_owned()
195+
}
196+
197+
fn inline_flattened() -> String {
198+
panic!("Str cannot be flattened")
199+
}
200+
201+
fn decl() -> String {
202+
panic!("Str is a primitive type")
203+
}
204+
205+
fn decl_concrete() -> String {
206+
panic!("Str is a primitive type")
207+
}
208+
}
209+
}
210+
179211
#[cfg(test)]
180212
mod tests {
181213
use bincode::{config::standard, decode_from_slice, encode_to_vec};

crates/vite_task_bin/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ path = "src/main.rs"
1414
anyhow = { workspace = true }
1515
async-trait = { workspace = true }
1616
clap = { workspace = true, features = ["derive"] }
17-
monostate = { workspace = true }
1817
tokio = { workspace = true, features = ["full"] }
1918
vite_path = { workspace = true }
2019
vite_str = { workspace = true }

crates/vite_task_bin/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
};
99

1010
use clap::Subcommand;
11-
use monostate::MustBe;
1211
use vite_path::AbsolutePath;
1312
use vite_str::Str;
1413
use vite_task::{
@@ -120,10 +119,10 @@ impl vite_task::TaskSynthesizer<CustomTaskSubcommand> for TaskSynthesizer {
120119
args: [name.clone()].into(),
121120
task_options: UserTaskOptions {
122121
cache_config: UserCacheConfig::Enabled {
123-
cache: MustBe!(true),
122+
cache: None,
124123
enabled_cache_config: EnabledCacheConfig {
125-
envs: Box::new([]),
126-
pass_through_envs: vec![name],
124+
envs: None,
125+
pass_through_envs: Some(vec![name]),
127126
},
128127
},
129128
..Default::default()

crates/vite_task_graph/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ vite_str = { workspace = true }
2323
vite_workspace = { workspace = true }
2424

2525
[dev-dependencies]
26+
pretty_assertions = { workspace = true }
2627
tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
28+
ts-rs = { workspace = true }
29+
vite_path = { workspace = true, features = ["ts-rs"] }
30+
vite_str = { workspace = true, features = ["ts-rs"] }
31+
which = { workspace = true }
2732

2833
[lints]
2934
workspace = true

0 commit comments

Comments
 (0)