@@ -13,7 +13,7 @@ import debug from 'debug'
13
13
14
14
const log = debug ( 'eslint-import-resolver-typescript' )
15
15
16
- const extensions = [ '.ts' , '.tsx' , '.d.ts' ] . concat (
16
+ const defaultExtensions = [ '.ts' , '.tsx' , '.d.ts' ] . concat (
17
17
// eslint-disable-next-line node/no-deprecated-api
18
18
Object . keys ( require . extensions ) ,
19
19
'.jsx' ,
@@ -24,6 +24,8 @@ export const interfaceVersion = 2
24
24
export interface TsResolverOptions {
25
25
alwaysTryTypes ?: boolean
26
26
directory ?: string | string [ ]
27
+ extensions ?: string [ ]
28
+ packageFilter ?: ( pkg : Record < string , string > ) => Record < string , string >
27
29
}
28
30
29
31
/**
@@ -62,9 +64,9 @@ export function resolve(
62
64
let foundNodePath : string | null | undefined
63
65
try {
64
66
foundNodePath = sync ( mappedPath || source , {
65
- extensions,
67
+ extensions : options . extensions || defaultExtensions ,
66
68
basedir : path . dirname ( path . resolve ( file ) ) ,
67
- packageFilter,
69
+ packageFilter : options . packageFilter || packageFilterDefault ,
68
70
} )
69
71
} catch ( err ) {
70
72
foundNodePath = null
@@ -105,7 +107,7 @@ export function resolve(
105
107
}
106
108
}
107
109
108
- function packageFilter ( pkg : Record < string , string > ) {
110
+ function packageFilterDefault ( pkg : Record < string , string > ) {
109
111
pkg . main =
110
112
pkg . types || pkg . typings || pkg . module || pkg [ 'jsnext:main' ] || pkg . main
111
113
return pkg
@@ -169,7 +171,12 @@ function initMappers(options: TsResolverOptions) {
169
171
}
170
172
171
173
// look for files based on setup tsconfig "paths"
172
- return matchPath ( source , undefined , undefined , extensions )
174
+ return matchPath (
175
+ source ,
176
+ undefined ,
177
+ undefined ,
178
+ options . extensions || defaultExtensions ,
179
+ )
173
180
}
174
181
} )
175
182
0 commit comments