Skip to content

Commit fe0aa6f

Browse files
committed
feat: add alwaysTryTypes option, add tests
1 parent 4f9c6dc commit fe0aa6f

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ function resolveFile(source, file, config) {
6363
}
6464

6565
// naive attempt at @types/* resolution,
66-
// iff path is neither absolute nor relative
66+
// if path is neither absolute nor relative
6767
if (
68-
/\.jsx?$/.test(foundNodePath) &&
68+
(config.alwaysTryTypes || /\.jsx?$/.test(foundNodePath)) &&
6969
!/^@types[/\\]/.test(source) &&
7070
!path.isAbsolute(source) &&
7171
source[0] !== '.'

package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"eslint-plugin-import": "*"
3030
},
3131
"devDependencies": {
32+
"@types/unist": "^2.0.3",
3233
"dummy.js": "file:dummy.js",
3334
"eslint": "^5.6.1",
3435
"eslint-plugin-import": "^2.14.0",

tests/baseEslintConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = dirname => ({
2626
'import/resolver': {
2727
[path.resolve(`${__dirname}/../index.js`)]: {
2828
directory: dirname,
29+
alwaysTryTypes: true
2930
},
3031
},
3132
},

tests/withoutPaths/dtsImportee.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare const content : 'yes';
2+
3+
export default content;

tests/withoutPaths/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// import relative
22
import './tsImportee'
33
import './tsxImportee'
4+
import './dtsImportee'
5+
import './subfolder/dtsImportee'
46
import './subfolder/tsImportee'
57
import './subfolder/tsxImportee'
68

79
// import from node_module
810
import 'typescript'
911
import 'dummy.js'
12+
13+
// import from `@types/`
14+
import 'json5'
15+
16+
// enable alwaysTryTypes
17+
import 'unist'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare const content : 'yes';
2+
3+
export default content;

0 commit comments

Comments
 (0)