@@ -36,6 +36,53 @@ pub mod emojis {
3636 pub static LINE_CLEAR : & str = "\x1b [2K\r " ;
3737}
3838
39+ /// This trait is used to strip the verbatim prefix from a Windows path.
40+ /// On non-Windows systems, it simply returns the original path.
41+ /// This is needed until the rescript compiler can handle such paths.
42+ pub trait StrippedVerbatimPath {
43+ fn to_stripped_verbatim_path ( self ) -> PathBuf ;
44+ }
45+
46+ impl StrippedVerbatimPath for PathBuf {
47+ fn to_stripped_verbatim_path ( self ) -> PathBuf {
48+ if cfg ! ( not( target_os = "windows" ) ) {
49+ return self ;
50+ }
51+
52+ let mut stripped = PathBuf :: new ( ) ;
53+ for component in self . components ( ) {
54+ match component {
55+ Component :: Prefix ( prefix_component) => {
56+ if prefix_component. kind ( ) . is_verbatim ( ) {
57+ stripped. push (
58+ prefix_component
59+ . as_os_str ( )
60+ . to_string_lossy ( )
61+ . strip_prefix ( "\\ \\ ?\\ " )
62+ . unwrap ( ) ,
63+ ) ;
64+ } else {
65+ stripped. push ( prefix_component. as_os_str ( ) ) ;
66+ }
67+ }
68+ Component :: RootDir => {
69+ stripped. push ( Component :: RootDir ) ;
70+ }
71+ Component :: CurDir => {
72+ stripped. push ( Component :: CurDir ) ;
73+ }
74+ Component :: ParentDir => {
75+ stripped. push ( Component :: ParentDir ) ;
76+ }
77+ Component :: Normal ( os_str) => {
78+ stripped. push ( os_str) ;
79+ }
80+ }
81+ }
82+ stripped
83+ }
84+ }
85+
3986pub trait LexicalAbsolute {
4087 fn to_lexical_absolute ( & self ) -> std:: io:: Result < PathBuf > ;
4188}
@@ -152,7 +199,8 @@ pub fn get_bsc(root_path: &Path, workspace_root: &Option<PathBuf>) -> PathBuf {
152199 . join ( subfolder)
153200 . join ( "bin" )
154201 . join ( "bsc.exe" )
155- . canonicalize ( ) ,
202+ . canonicalize ( )
203+ . map ( StrippedVerbatimPath :: to_stripped_verbatim_path) ,
156204 workspace_root. as_ref ( ) . map ( |workspace_root| {
157205 workspace_root
158206 . join ( "node_modules" )
@@ -161,6 +209,7 @@ pub fn get_bsc(root_path: &Path, workspace_root: &Option<PathBuf>) -> PathBuf {
161209 . join ( "bin" )
162210 . join ( "bsc.exe" )
163211 . canonicalize ( )
212+ . map ( StrippedVerbatimPath :: to_stripped_verbatim_path)
164213 } ) ,
165214 ) {
166215 ( Ok ( path) , _) => path,
@@ -212,7 +261,10 @@ pub fn get_compiler_asset(
212261}
213262
214263pub fn canonicalize_string_path ( path : & str ) -> Option < PathBuf > {
215- return Path :: new ( path) . canonicalize ( ) . ok ( ) ;
264+ return Path :: new ( path)
265+ . canonicalize ( )
266+ . map ( StrippedVerbatimPath :: to_stripped_verbatim_path)
267+ . ok ( ) ;
216268}
217269
218270pub fn get_bs_compiler_asset (
0 commit comments