@@ -28,6 +28,7 @@ interface ResolutionResult {
2828
2929class ResolutionContext {
3030 private noResolvePaths : picomatch . Matcher [ ] ;
31+ private pathsBase : string | undefined ;
3132
3233 public diagnostics : ts . Diagnostic [ ] = [ ] ;
3334 public resolvedFiles = new Map < string , ProcessedFile > ( ) ;
@@ -40,6 +41,8 @@ class ResolutionContext {
4041 ) {
4142 const unique = [ ...new Set ( options . noResolvePaths ) ] ;
4243 this . noResolvePaths = unique . map ( x => picomatch ( x ) ) ;
44+ this . pathsBase =
45+ options . baseUrl ?? ( options . configFilePath ? path . dirname ( options . configFilePath ) : undefined ) ;
4346 }
4447
4548 public addAndResolveDependencies ( file : ProcessedFile ) : void {
@@ -209,36 +212,18 @@ class ResolutionContext {
209212 if ( resolvedNodeModulesFile ) return resolvedNodeModulesFile ;
210213 }
211214
212- const isRelativeDependency = ts . isExternalModuleNameRelative ( dependencyPath ) ;
213-
214- if ( ! isRelativeDependency && this . options . paths ) {
215- // Bare specifiers: check paths mappings first, matching TypeScript's resolution order.
216- // When baseUrl is not set, resolve paths relative to the tsconfig directory (TS 6.0+ behavior)
217- const pathsBase =
218- this . options . baseUrl ??
219- ( this . options . configFilePath ? path . dirname ( this . options . configFilePath ) : undefined ) ;
220- if ( pathsBase ) {
221- const fileFromPaths = this . tryGetModuleNameFromPaths ( dependencyPath , this . options . paths , pathsBase ) ;
222- if ( fileFromPaths ) return fileFromPaths ;
223- }
215+ // Bare specifiers: check paths mappings first, matching TypeScript's resolution order.
216+ // TS never applies paths to relative imports, so skip for those.
217+ if ( ! ts . isExternalModuleNameRelative ( dependencyPath ) && this . options . paths && this . pathsBase ) {
218+ const fileFromPaths = this . tryGetModuleNameFromPaths ( dependencyPath , this . options . paths , this . pathsBase ) ;
219+ if ( fileFromPaths ) return fileFromPaths ;
224220 }
225221
226222 // Check if file is a file in the project
227223 const resolvedPath = this . formatPathToFile ( dependencyPath , requiringFile ) ;
228224 const fileFromPath = this . getFileFromPath ( resolvedPath ) ;
229225 if ( fileFromPath ) return fileFromPath ;
230226
231- if ( isRelativeDependency && this . options . paths ) {
232- // Relative imports are still file-relative first; fall back to paths afterwards.
233- const pathsBase =
234- this . options . baseUrl ??
235- ( this . options . configFilePath ? path . dirname ( this . options . configFilePath ) : undefined ) ;
236- if ( pathsBase ) {
237- const fileFromPaths = this . tryGetModuleNameFromPaths ( dependencyPath , this . options . paths , pathsBase ) ;
238- if ( fileFromPaths ) return fileFromPaths ;
239- }
240- }
241-
242227 // Not a TS file in our project sources, use resolver to check if we can find dependency
243228 try {
244229 const resolveResult = resolver . resolveSync ( { } , fileDirectory , dependencyPath ) ;
0 commit comments