@@ -76,23 +76,39 @@ const relateNormalPathSet = (exports.relateNormalPathSet = function relateNormal
76
76
*
77
77
*/
78
78
79
+ // Cache whether we need to replace path.sep because contextNormalPath is called _very_ frequently
80
+ const resolveRelativeCompilerContext =
81
+ '/' === path . sep
82
+ ? function ( context , key ) {
83
+ return path . resolve ( context , key ) ;
84
+ }
85
+ : function ( context , key ) {
86
+ return path . resolve ( context , key ) . replace ( / \/ / g, path . sep ) ;
87
+ } ;
88
+
79
89
const contextNormalPath = ( exports . contextNormalPath = function contextNormalPath (
80
90
compiler ,
81
91
key ,
82
92
) {
83
- if ( typeof key !== 'string' ) {
93
+ if ( typeof key !== 'string' || key === '' ) {
84
94
return key ;
85
95
}
96
+
97
+ const context = compilerContext ( compiler ) ;
86
98
if ( key === '.' ) {
87
- return compilerContext ( compiler ) ;
99
+ return context ;
88
100
}
89
- if ( key === '' ) {
90
- return '' ;
101
+
102
+ const markIndex = key . indexOf ( '?' ) ;
103
+ if ( markIndex === - 1 ) {
104
+ return resolveRelativeCompilerContext ( context , key ) ;
91
105
}
92
- const abs = path . resolve ( compilerContext ( compiler ) , key . split ( '?' ) [ 0 ] ) ;
93
- return [ abs . replace ( / \/ / g, path . sep ) ]
94
- . concat ( key . split ( '?' ) . slice ( 1 ) )
95
- . join ( '?' ) ;
106
+
107
+ const abs = resolveRelativeCompilerContext (
108
+ context ,
109
+ key . substring ( 0 , markIndex ) ,
110
+ ) ;
111
+ return abs + '?' + key . substring ( markIndex + 1 ) ;
96
112
} ) ;
97
113
98
114
const contextNormalRequest = ( exports . contextNormalRequest = function contextNormalRequest (
0 commit comments