Skip to content

Commit

Permalink
feat: add alwaysTryTypes option, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jul 25, 2019
1 parent 4f9c6dc commit fe0aa6f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ function resolveFile(source, file, config) {
}

// naive attempt at @types/* resolution,
// iff path is neither absolute nor relative
// if path is neither absolute nor relative
if (
/\.jsx?$/.test(foundNodePath) &&
(config.alwaysTryTypes || /\.jsx?$/.test(foundNodePath)) &&
!/^@types[/\\]/.test(source) &&
!path.isAbsolute(source) &&
source[0] !== '.'
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"eslint-plugin-import": "*"
},
"devDependencies": {
"@types/unist": "^2.0.3",
"dummy.js": "file:dummy.js",
"eslint": "^5.6.1",
"eslint-plugin-import": "^2.14.0",
Expand Down
1 change: 1 addition & 0 deletions tests/baseEslintConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = dirname => ({
'import/resolver': {
[path.resolve(`${__dirname}/../index.js`)]: {
directory: dirname,
alwaysTryTypes: true
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions tests/withoutPaths/dtsImportee.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const content : 'yes';

export default content;
8 changes: 8 additions & 0 deletions tests/withoutPaths/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// import relative
import './tsImportee'
import './tsxImportee'
import './dtsImportee'
import './subfolder/dtsImportee'
import './subfolder/tsImportee'
import './subfolder/tsxImportee'

// import from node_module
import 'typescript'
import 'dummy.js'

// import from `@types/`
import 'json5'

// enable alwaysTryTypes
import 'unist'
3 changes: 3 additions & 0 deletions tests/withoutPaths/subfolder/dtsImportee.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare const content : 'yes';

export default content;

0 comments on commit fe0aa6f

Please sign in to comment.