Skip to content

Commit f984cef

Browse files
authoredJul 16, 2020
Package filter extensions options (#49)
1 parent d563eeb commit f984cef

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
lib
33
node_modules
44
*.log
5+
.eslintcache

‎src/index.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import debug from 'debug'
1313

1414
const log = debug('eslint-import-resolver-typescript')
1515

16-
const extensions = ['.ts', '.tsx', '.d.ts'].concat(
16+
const defaultExtensions = ['.ts', '.tsx', '.d.ts'].concat(
1717
// eslint-disable-next-line node/no-deprecated-api
1818
Object.keys(require.extensions),
1919
'.jsx',
@@ -24,6 +24,8 @@ export const interfaceVersion = 2
2424
export interface TsResolverOptions {
2525
alwaysTryTypes?: boolean
2626
directory?: string | string[]
27+
extensions?: string[]
28+
packageFilter?: (pkg: Record<string, string>) => Record<string, string>
2729
}
2830

2931
/**
@@ -62,9 +64,9 @@ export function resolve(
6264
let foundNodePath: string | null | undefined
6365
try {
6466
foundNodePath = sync(mappedPath || source, {
65-
extensions,
67+
extensions: options.extensions || defaultExtensions,
6668
basedir: path.dirname(path.resolve(file)),
67-
packageFilter,
69+
packageFilter: options.packageFilter || packageFilterDefault,
6870
})
6971
} catch (err) {
7072
foundNodePath = null
@@ -105,7 +107,7 @@ export function resolve(
105107
}
106108
}
107109

108-
function packageFilter(pkg: Record<string, string>) {
110+
function packageFilterDefault(pkg: Record<string, string>) {
109111
pkg.main =
110112
pkg.types || pkg.typings || pkg.module || pkg['jsnext:main'] || pkg.main
111113
return pkg
@@ -169,7 +171,12 @@ function initMappers(options: TsResolverOptions) {
169171
}
170172

171173
// 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+
)
173180
}
174181
})
175182

0 commit comments

Comments
 (0)
Please sign in to comment.