@@ -92,28 +92,6 @@ const resolveBase: ResolveHook = async (
92
92
context ,
93
93
nextResolve ,
94
94
) => {
95
- // If directory, can be index.js, index.ts, etc.
96
-
97
- // Resolve TS alias
98
- // Bare specifier
99
- if (
100
- ! requestAcceptsQuery ( specifier )
101
- // TS path alias
102
- && tsconfigPathsMatcher
103
- && ! context . parentURL ?. includes ( '/node_modules/' )
104
- ) {
105
- const possiblePaths = tsconfigPathsMatcher ( specifier ) ;
106
- for ( const possiblePath of possiblePaths ) {
107
- try {
108
- return await resolveBase (
109
- pathToFileURL ( possiblePath ) . toString ( ) ,
110
- context ,
111
- nextResolve ,
112
- ) ;
113
- } catch { }
114
- }
115
- }
116
-
117
95
const isBarePackageName = isBarePackageNamePattern . test ( specifier ) ;
118
96
119
97
// Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions
@@ -160,11 +138,10 @@ const resolveDirectory: ResolveHook = async (
160
138
context ,
161
139
nextResolve ,
162
140
) => {
163
- const [ specifierWithoutQuery , query ] = specifier . split ( '?' ) ;
164
-
165
141
if ( isDirectoryPattern . test ( specifier ) ) {
142
+ // If directory, can be index.js, index.ts, etc.
166
143
return ( await resolveExtensions (
167
- `${ specifierWithoutQuery } index${ query ? `? ${ query } ` : '' } ` ,
144
+ `${ specifier } index` ,
168
145
context ,
169
146
nextResolve ,
170
147
true ,
@@ -181,7 +158,7 @@ const resolveDirectory: ResolveHook = async (
181
158
if ( errorPath ) {
182
159
try {
183
160
return ( await resolveExtensions (
184
- `${ errorPath } /index${ query ? `? ${ query } ` : '' } ` ,
161
+ `${ errorPath } /index` ,
185
162
context ,
186
163
nextResolve ,
187
164
true ,
@@ -201,6 +178,33 @@ const resolveDirectory: ResolveHook = async (
201
178
}
202
179
} ;
203
180
181
+ const resolveTsPaths : ResolveHook = async (
182
+ specifier ,
183
+ context ,
184
+ nextResolve ,
185
+ ) => {
186
+ if (
187
+ // Bare specifier
188
+ ! requestAcceptsQuery ( specifier )
189
+ // TS path alias
190
+ && tsconfigPathsMatcher
191
+ && ! context . parentURL ?. includes ( '/node_modules/' )
192
+ ) {
193
+ const possiblePaths = tsconfigPathsMatcher ( specifier ) ;
194
+ for ( const possiblePath of possiblePaths ) {
195
+ try {
196
+ return await resolveDirectory (
197
+ pathToFileURL ( possiblePath ) . toString ( ) ,
198
+ context ,
199
+ nextResolve ,
200
+ ) ;
201
+ } catch { }
202
+ }
203
+ }
204
+
205
+ return resolveDirectory ( specifier , context , nextResolve ) ;
206
+ } ;
207
+
204
208
export const resolve : ResolveHook = async (
205
209
specifier ,
206
210
context ,
@@ -219,8 +223,10 @@ export const resolve: ResolveHook = async (
219
223
return nextResolve ( specifier , context ) ;
220
224
}
221
225
222
- const resolved = await resolveDirectory (
223
- specifier ,
226
+ const [ cleanSpecifier , query ] = specifier . split ( '?' ) ;
227
+
228
+ const resolved = await resolveTsPaths (
229
+ cleanSpecifier ,
224
230
context ,
225
231
nextResolve ,
226
232
) ;
@@ -237,11 +243,14 @@ export const resolve: ResolveHook = async (
237
243
resolved . format = await getFormatFromFileUrl ( resolved . url ) ;
238
244
}
239
245
246
+ if ( query ) {
247
+ resolved . url += `?${ query } ` ;
248
+ }
249
+
240
250
// Inherit namespace
241
251
if (
242
252
requestNamespace
243
253
&& ! resolved . url . includes ( namespaceQuery )
244
- && requestAcceptsQuery ( resolved . url )
245
254
) {
246
255
resolved . url += ( resolved . url . includes ( '?' ) ? '&' : '?' ) + namespaceQuery + requestNamespace ;
247
256
}
0 commit comments