@@ -14,7 +14,7 @@ use typed_path::Utf8TypedPath;
1414use wax:: Pattern ;
1515
1616/// Normalize a file path to use forward slashes for consistent glob matching
17- fn normalize_path_for_glob_matching ( path : & str ) -> String {
17+ fn normalize_path ( path : & str ) -> String {
1818 let typed_path = Utf8TypedPath :: derive ( path) ;
1919 if typed_path. is_windows ( ) {
2020 typed_path. with_unix_encoding ( ) . to_string ( )
@@ -77,9 +77,14 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr
7777 // compatible glob and the filename matches the pattern, the file will not be instrumented.
7878 // Note that the filename is provided by swc's core, may not be the full absolute path to the file name.
7979 if let Some ( exclude) = & instrument_options. unstable_exclude {
80- match wax:: any ( exclude. iter ( ) . map ( |s| s. as_ref ( ) ) . collect :: < Vec < & str > > ( ) ) {
80+ let normalized_patterns = exclude
81+ . iter ( )
82+ . map ( |s| normalize_path ( s) )
83+ . collect :: < Vec < _ > > ( ) ;
84+
85+ match wax:: any ( normalized_patterns. iter ( ) . map ( |s| s. as_str ( ) ) ) {
8186 Ok ( p) => {
82- let normalized_filename = normalize_path_for_glob_matching ( filename) ;
87+ let normalized_filename = normalize_path ( filename) ;
8388 if p. is_match ( normalized_filename. as_str ( ) ) {
8489 return program;
8590 }
@@ -110,32 +115,32 @@ mod tests {
110115 #[ test]
111116 fn test_normalize_path_for_glob_matching ( ) {
112117 // Test Windows paths are normalized to Unix-style
113- let result = normalize_path_for_glob_matching ( r"C:\Users\project\test\index.test.ts" ) ;
118+ let result = normalize_path ( r"C:\Users\project\test\index.test.ts" ) ;
114119 println ! ( "Windows path result: {}" , result) ;
115120 // The typed-path crate converts Windows paths to Unix format, but may strip the drive letter
116121 // The important thing is that backslashes are converted to forward slashes
117122 assert ! ( result. contains( "/Users/project/test/index.test.ts" ) ) ;
118123
119124 // Test mixed separators are normalized
120- let result = normalize_path_for_glob_matching ( r"C:\Users/project\test/file.js" ) ;
125+ let result = normalize_path ( r"C:\Users/project\test/file.js" ) ;
121126 println ! ( "Mixed separators result: {}" , result) ;
122127 assert ! ( result. contains( "/Users/project/test/file.js" ) ) ;
123128
124129 // Test Unix paths remain unchanged
125130 assert_eq ! (
126- normalize_path_for_glob_matching ( "/home/user/project/src/utils/helper.js" ) ,
131+ normalize_path ( "/home/user/project/src/utils/helper.js" ) ,
127132 "/home/user/project/src/utils/helper.js"
128133 ) ;
129134
130135 // Test relative Unix paths remain unchanged
131136 assert_eq ! (
132- normalize_path_for_glob_matching ( "src/components/Button.tsx" ) ,
137+ normalize_path ( "src/components/Button.tsx" ) ,
133138 "src/components/Button.tsx"
134139 ) ;
135140
136141 // Test that backslashes are converted to forward slashes
137142 let windows_path = r"project\src\test\file.ts" ;
138- let result = normalize_path_for_glob_matching ( windows_path) ;
143+ let result = normalize_path ( windows_path) ;
139144 println ! ( "Relative Windows path result: {}" , result) ;
140145 assert ! ( result. contains( "project/src/test/file.ts" ) ) ;
141146 }
0 commit comments