File tree 1 file changed +25
-3
lines changed
1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,27 @@ export class TrieNode<T> {
79
79
prefix : alias . replace ( / \* $ / , '' ) ,
80
80
// Normalize paths.
81
81
paths : paths [ alias ] . map ( ( path ) => {
82
- path = path
83
- . replace ( / \* $ / , '' )
84
- . replace ( / \. ( [ m c ] ) ? t s ( x ) ? $ / , '.$1js$2' ) ;
82
+ path = path . replace ( / \* $ / , '' ) ;
83
+
84
+ const dotIndex = path . lastIndexOf ( '.' ) ;
85
+ const beforeDot = path . slice ( 0 , dotIndex ) ;
86
+ const afterDot = path . slice ( dotIndex ) ;
87
+
88
+ // Refuse to normalize extensions for paths that look like "a.b/c" or "a.b\c".
89
+ // Even if the current system is Linux the original author could've written a Windows path.
90
+ if ( ! afterDot . includes ( '/' ) && ! afterDot . includes ( '\\' ) ) {
91
+ const extension = afterDot ;
92
+ let normalizedExtension = afterDot ;
93
+ if ( ! isDTS ( extension ) ) {
94
+ normalizedExtension = extension . replace (
95
+ / \. ( [ m c ] ) ? t s ( x ) ? $ / ,
96
+ '.$1js$2'
97
+ ) ;
98
+ }
99
+
100
+ path = beforeDot + normalizedExtension ;
101
+ }
102
+
85
103
if ( isAbsolute ( path ) ) {
86
104
path = relative (
87
105
resolve ( config . configDir , config . baseUrl ) ,
@@ -114,3 +132,7 @@ export class TrieNode<T> {
114
132
return aliasTrie ;
115
133
}
116
134
}
135
+
136
+ function isDTS ( extension : string ) : boolean {
137
+ return / \. d ( \. .* ) ? \. [ m c ] ? t s ( x ) ? $ / . test ( extension ) ;
138
+ }
You can’t perform that action at this time.
0 commit comments