@@ -18,28 +18,16 @@ use vite_task::{
1818} ;
1919
2020use crate :: commands:: {
21- add:: AddCommand ,
22- dedupe:: DedupeCommand ,
23- doc:: doc as doc_cmd,
24- fmt:: { FmtConfig , fmt} ,
25- install:: InstallCommand ,
26- lib_cmd:: lib,
27- link:: LinkCommand ,
28- lint:: { LintConfig , lint} ,
29- outdated:: OutdatedCommand ,
30- pm:: PmCommand ,
31- remove:: RemoveCommand ,
32- test:: test,
33- unlink:: UnlinkCommand ,
34- update:: UpdateCommand ,
35- vite:: vite as vite_cmd,
36- why:: WhyCommand ,
21+ add:: AddCommand , dedupe:: DedupeCommand , doc:: doc as doc_cmd, fmt:: fmt, install:: InstallCommand ,
22+ lib_cmd:: lib, link:: LinkCommand , lint:: lint, outdated:: OutdatedCommand , pm:: PmCommand ,
23+ remove:: RemoveCommand , test:: test, unlink:: UnlinkCommand , update:: UpdateCommand ,
24+ vite:: vite as vite_cmd, why:: WhyCommand ,
3725} ;
3826
3927#[ derive( Debug , Clone , Serialize , Deserialize ) ]
4028pub struct ResolvedUniversalViteConfig {
41- pub lint : Option < LintConfig > ,
42- pub fmt : Option < FmtConfig > ,
29+ pub lint : Option < serde_json :: Value > ,
30+ pub fmt : Option < serde_json :: Value > ,
4331}
4432
4533#[ derive( Parser , Debug ) ]
@@ -993,9 +981,29 @@ pub async fn main<
993981 }
994982 Commands :: Fmt { args } => {
995983 let workspace = Workspace :: partial_load ( cwd) ?;
984+ let vite_config = read_vite_config_from_workspace_root (
985+ workspace. root_dir ( ) ,
986+ options. as_ref ( ) . map ( |o| & o. resolve_universal_vite_config ) ,
987+ )
988+ . await ?;
996989 let fmt_fn =
997990 options. map ( |o| o. fmt ) . expect ( "fmt command requires CliOptions to be provided" ) ;
998-
991+ let resolved_vite_config: Option < ResolvedUniversalViteConfig > = vite_config
992+ . map ( |vite_config| {
993+ serde_json:: from_str ( & vite_config) . inspect_err ( |_| {
994+ tracing:: error!( "Failed to parse vite config: {vite_config}" ) ;
995+ } )
996+ } )
997+ . transpose ( ) ?;
998+ let fmt_config = resolved_vite_config. and_then ( |c| c. fmt ) ;
999+ if let Some ( fmt_config) = fmt_config {
1000+ let oxfmt_config_path = workspace. cache_path ( ) . join ( ".oxfmtrc.json" ) ;
1001+ write ( & oxfmt_config_path, serde_json:: to_string ( & fmt_config) ?) . await ?;
1002+ args. extend_from_slice ( & [
1003+ "--config" . to_string ( ) ,
1004+ oxfmt_config_path. as_path ( ) . to_string_lossy ( ) . into_owned ( ) ,
1005+ ] ) ;
1006+ }
9991007 let summary = fmt ( fmt_fn, & workspace, args) . await ?;
10001008 workspace. unload ( ) . await ?;
10011009 summary
0 commit comments