@@ -14,7 +14,7 @@ use typed_path::Utf8TypedPath;
14
14
use wax:: Pattern ;
15
15
16
16
/// 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 {
18
18
let typed_path = Utf8TypedPath :: derive ( path) ;
19
19
if typed_path. is_windows ( ) {
20
20
typed_path. with_unix_encoding ( ) . to_string ( )
@@ -77,9 +77,14 @@ pub fn process(program: Program, metadata: TransformPluginProgramMetadata) -> Pr
77
77
// compatible glob and the filename matches the pattern, the file will not be instrumented.
78
78
// Note that the filename is provided by swc's core, may not be the full absolute path to the file name.
79
79
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 ( ) ) ) {
81
86
Ok ( p) => {
82
- let normalized_filename = normalize_path_for_glob_matching ( filename) ;
87
+ let normalized_filename = normalize_path ( filename) ;
83
88
if p. is_match ( normalized_filename. as_str ( ) ) {
84
89
return program;
85
90
}
@@ -110,32 +115,32 @@ mod tests {
110
115
#[ test]
111
116
fn test_normalize_path_for_glob_matching ( ) {
112
117
// 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" ) ;
114
119
println ! ( "Windows path result: {}" , result) ;
115
120
// The typed-path crate converts Windows paths to Unix format, but may strip the drive letter
116
121
// The important thing is that backslashes are converted to forward slashes
117
122
assert ! ( result. contains( "/Users/project/test/index.test.ts" ) ) ;
118
123
119
124
// 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" ) ;
121
126
println ! ( "Mixed separators result: {}" , result) ;
122
127
assert ! ( result. contains( "/Users/project/test/file.js" ) ) ;
123
128
124
129
// Test Unix paths remain unchanged
125
130
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" ) ,
127
132
"/home/user/project/src/utils/helper.js"
128
133
) ;
129
134
130
135
// Test relative Unix paths remain unchanged
131
136
assert_eq ! (
132
- normalize_path_for_glob_matching ( "src/components/Button.tsx" ) ,
137
+ normalize_path ( "src/components/Button.tsx" ) ,
133
138
"src/components/Button.tsx"
134
139
) ;
135
140
136
141
// Test that backslashes are converted to forward slashes
137
142
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) ;
139
144
println ! ( "Relative Windows path result: {}" , result) ;
140
145
assert ! ( result. contains( "project/src/test/file.ts" ) ) ;
141
146
}
0 commit comments