@@ -1055,10 +1055,15 @@ impl Config {
10551055 }
10561056
10571057 pub fn get_project_root_args ( & self ) -> Vec < String > {
1058- vec ! [
1059- "-bs-project-root" . to_string( ) ,
1060- self . get_package_root( ) . to_string_lossy( ) . to_string( ) ,
1061- ]
1058+ // The parser records locations from a canonical working directory.
1059+ // Use the same representation here so GenType can strip this prefix,
1060+ // including when Windows supplied the project through an 8.3 path.
1061+ let root = self
1062+ . get_package_root ( )
1063+ . canonicalize ( )
1064+ . map ( helpers:: StrippedVerbatimPath :: to_stripped_verbatim_path)
1065+ . unwrap_or_else ( |_| self . get_package_root ( ) . to_path_buf ( ) ) ;
1066+ vec ! [ "-bs-project-root" . to_string( ) , root. to_string_lossy( ) . to_string( ) ]
10621067 }
10631068
10641069 pub fn get_warning_args ( & self , is_local_dep : bool , warn_error_override : Option < String > ) -> Vec < String > {
@@ -1655,6 +1660,31 @@ pub mod tests {
16551660 assert_eq ! ( platform_args[ suffix_idx + 1 ] , "" ) ;
16561661 }
16571662
1663+ #[ test]
1664+ fn test_compiler_project_root_is_canonicalized ( ) {
1665+ let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
1666+ let nested_dir = temp_dir. path ( ) . join ( "nested" ) ;
1667+ fs:: create_dir ( & nested_dir) . unwrap ( ) ;
1668+ let config_path = nested_dir. join ( ".." ) . join ( "rescript.json" ) ;
1669+ fs:: write (
1670+ temp_dir. path ( ) . join ( "rescript.json" ) ,
1671+ r#"{"name":"test","gentypeconfig":{}}"# ,
1672+ )
1673+ . unwrap ( ) ;
1674+
1675+ let config = Config :: new ( & config_path) . unwrap ( ) ;
1676+ let expected_root = temp_dir
1677+ . path ( )
1678+ . canonicalize ( )
1679+ . map ( helpers:: StrippedVerbatimPath :: to_stripped_verbatim_path)
1680+ . unwrap ( )
1681+ . to_string_lossy ( )
1682+ . to_string ( ) ;
1683+
1684+ let project_root_args = config. get_project_root_args ( ) ;
1685+ assert_eq ! ( project_root_args, [ "-bs-project-root" , & expected_root] ) ;
1686+ }
1687+
16581688 #[ test]
16591689 fn test_gentype_shims_object_and_array_forms ( ) {
16601690 let object_form = serde_json:: from_str :: < GenTypeShims > ( r#"{"From": "To"}"# ) . unwrap ( ) ;
0 commit comments