@@ -5,18 +5,23 @@ use std::process::Command;
55use  std:: io:: { self ,  Read ,  Write } ; 
66use  std:: fs; 
77use  rayon:: prelude:: * ; 
8+ use  crate :: helpers; 
89use  num_cpus; 
910
1011pub  fn  run ( 
1112    stdin_path :  Option < String > , 
1213    all :  bool , 
1314    check :  bool , 
1415    files :  Vec < String > , 
15-     bsc_path_arg :  Option < PathBuf > , 
16+     bsc_path :  Option < PathBuf > , 
17+     path :  PathBuf , 
1618)  -> Result < ( ) >  { 
17-     let  bsc_exe = match  bsc_path_arg { 
18-         Some ( path)  => path, 
19-         None  => find_bsc_exe ( ) ?, 
19+     let  project_root = helpers:: get_abs_path ( & path) ; 
20+     let  workspace_root = helpers:: get_workspace_root ( & project_root) ; 
21+ 
22+     let  bsc_exe = match  bsc_path { 
23+         Some ( path)  => helpers:: get_abs_path ( & path) , 
24+         None  => helpers:: get_bsc ( & project_root,  & workspace_root) , 
2025    } ; 
2126
2227    if  check && stdin_path. is_some ( )  { 
@@ -37,34 +42,7 @@ pub fn run(
3742    Ok ( ( ) ) 
3843} 
3944
40- fn  find_bsc_exe ( )  -> Result < PathBuf >  { 
41-     let  current_exe = std:: env:: current_exe ( ) ?; 
42-     let  mut  current_dir = current_exe. parent ( ) . unwrap_or_else ( || Path :: new ( "/" ) ) ; 
43- 
44-     // Traverse up to find node_modules 
45-     let  node_modules_path = loop  { 
46-         let  potential_path = current_dir. join ( "node_modules" ) ; 
47-         if  potential_path. exists ( )  { 
48-             break  Some ( potential_path) ; 
49-         } 
50-         if  current_dir. parent ( ) . is_none ( )  { 
51-             break  None ; 
52-         } 
53-         current_dir = current_dir. parent ( ) . unwrap ( ) ; 
54-     } 
55-     . ok_or_else ( || anyhow:: anyhow!( "Could not find node_modules directory" ) ) ?; 
56- 
57-     let  target = format ! ( "{}-{}" ,  std:: env:: consts:: OS ,  std:: env:: consts:: ARCH ) ; 
58-     let  bsc_path = node_modules_path
59-         . join ( "@rescript" ) 
60-         . join ( target) 
61-         . join ( "bsc.exe" ) ; 
6245
63-     if  !bsc_path. exists ( )  { 
64-         bail ! ( "bsc executable not found at {}" ,  bsc_path. display( ) ) ; 
65-     } 
66-     Ok ( bsc_path) 
67- } 
6846
6947fn  format_all ( bsc_exe :  & Path ,  check :  bool )  -> Result < ( ) >  { 
7048    let  output = Command :: new ( std:: env:: current_exe ( ) ?) 
0 commit comments