@@ -5,18 +5,23 @@ use std::process::Command;
5
5
use std:: io:: { self , Read , Write } ;
6
6
use std:: fs;
7
7
use rayon:: prelude:: * ;
8
+ use crate :: helpers;
8
9
use num_cpus;
9
10
10
11
pub fn run (
11
12
stdin_path : Option < String > ,
12
13
all : bool ,
13
14
check : bool ,
14
15
files : Vec < String > ,
15
- bsc_path_arg : Option < PathBuf > ,
16
+ bsc_path : Option < PathBuf > ,
17
+ path : PathBuf ,
16
18
) -> 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) ,
20
25
} ;
21
26
22
27
if check && stdin_path. is_some ( ) {
@@ -37,34 +42,7 @@ pub fn run(
37
42
Ok ( ( ) )
38
43
}
39
44
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" ) ;
62
45
63
- if !bsc_path. exists ( ) {
64
- bail ! ( "bsc executable not found at {}" , bsc_path. display( ) ) ;
65
- }
66
- Ok ( bsc_path)
67
- }
68
46
69
47
fn format_all ( bsc_exe : & Path , check : bool ) -> Result < ( ) > {
70
48
let output = Command :: new ( std:: env:: current_exe ( ) ?)
0 commit comments