-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement import-x resolver interface v3 (#326)
* feat: implement import-x resolver interface v3 * chore: add changeset * docs: update eslint flag config usage * test: fix test ci * chore: update changeset
- Loading branch information
Showing
21 changed files
with
400 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
'eslint-import-resolver-typescript': minor | ||
--- | ||
|
||
This version has implemented the `eslint-plugin-import-x`'s v3 resolver interface. This allows you to use import/require to reference `eslint-import-resolver-typescript` directly in your ESLint flat config: | ||
|
||
**Previously** | ||
|
||
```js | ||
// eslint.config.js | ||
module.exports = { | ||
settings: { | ||
'import-x/resolver': { | ||
typescript: { | ||
alwaysTryTypes: true, | ||
}, | ||
// or | ||
require.resolve('eslint-import-resolver-typescript'): | ||
alwaysTryTypes: true, | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
**Now** | ||
|
||
```js | ||
// eslint.config.js | ||
const { | ||
createTypeScriptImportResolver, | ||
} = require('eslint-import-resolver-typescript') | ||
|
||
module.exports = { | ||
settings: { | ||
'import-x/resolver-next': [ | ||
createTypeScriptImportResolver({ | ||
alwaysTryTypes: true, | ||
}), | ||
], | ||
}, | ||
} | ||
``` | ||
|
||
Note that this only works with `eslint-plugin-import-x@>=4.5.0`. You can't use `createTypeScriptImportResolver` with the older versions of `eslint-plugin-import-x` or any existing versions of `eslint-plugin-import`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"eslint.useFlatConfig": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const path = require('path') | ||
const { createTypeScriptImportResolver } = require('../../lib/index.cjs') | ||
|
||
const globPattern = './packages/*/tsconfig.json' | ||
|
||
// in normal cases this is not needed because the __dirname would be the root | ||
const absoluteGlobPath = path.join(__dirname, globPattern) | ||
|
||
module.exports = { | ||
...require('eslint-plugin-import-x').flatConfigs.typescript, | ||
settings: { | ||
...require('eslint-plugin-import-x').flatConfigs.typescript.settings, | ||
'import-x/resolver-next': [ | ||
createTypeScriptImportResolver({ | ||
project: absoluteGlobPath, | ||
alwaysTryTypes: true, | ||
}), | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// import relative | ||
import './tsImportee' | ||
import './tsxImportee' | ||
import './subfolder/tsImportee' | ||
import './subfolder/tsxImportee' | ||
|
||
// import using tsconfig.json path mapping | ||
import 'folder/tsImportee' | ||
import 'folder/tsxImportee' | ||
import 'folder/subfolder/tsImportee' | ||
import 'folder/subfolder/tsxImportee' | ||
|
||
// import from node_module | ||
import 'typescript' | ||
import 'dummy.js' |
1 change: 1 addition & 0 deletions
1
tests/importXResolverV3/packages/module-a/subfolder/tsImportee.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'yes' |
1 change: 1 addition & 0 deletions
1
tests/importXResolverV3/packages/module-a/subfolder/tsxImportee.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'React Component' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'yes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"jsx": "react", | ||
"paths": { | ||
"folder/*": ["*"], | ||
"*": ["../../../../node_modules/*"] | ||
} | ||
}, | ||
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'React Component' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// import relative | ||
import './tsImportee' | ||
import './tsxImportee' | ||
import './subfolder/tsImportee' | ||
import './subfolder/tsxImportee' | ||
|
||
// import using tsconfig.json path mapping | ||
import 'folder/tsImportee' | ||
import 'folder/tsxImportee' | ||
import 'folder/subfolder/tsImportee' | ||
import 'folder/subfolder/tsxImportee' | ||
|
||
// import from node_module | ||
import 'typescript' | ||
import 'dummy.js' |
1 change: 1 addition & 0 deletions
1
tests/importXResolverV3/packages/module-b/subfolder/tsImportee.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'yes' |
1 change: 1 addition & 0 deletions
1
tests/importXResolverV3/packages/module-b/subfolder/tsxImportee.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'React Component' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'yes' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"jsx": "react", | ||
"paths": { | ||
"folder/*": ["*"], | ||
"*": ["../../../../node_modules/*"] | ||
} | ||
}, | ||
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default 'React Component' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.