Skip to content

Commit 4bd60c3

Browse files
authored
docs: document options from enhanced-resolve (#156)
1 parent 42f2dd6 commit 4bd60c3

File tree

4 files changed

+144
-39
lines changed

4 files changed

+144
-39
lines changed

.changeset/twenty-ways-yell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": patch
3+
---
4+
5+
docs: document options from `enhanced-resolve`

README.md

+108-8
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,28 @@
1212
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
1313
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets)
1414

15-
This plugin adds TypeScript support to [`eslint-plugin-import`](https://www.npmjs.com/package/eslint-plugin-import).
15+
This plugin adds [`TypeScript`][] support to [`eslint-plugin-import`][]
1616

1717
This means you can:
1818

19-
- `import`/`require` files with extension `.cts`/`.mts`/`.ts`/`.tsx`!
20-
- Use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in `tsconfig.json`.
21-
- Prefer resolve `@types/*` definitions over plain `.js`.
22-
- Multiple tsconfigs support just like normal.
23-
- `exports` fields support in `package.json`
19+
- `import`/`require` files with extension `.cts`/`.mts`/`.ts`/`.tsx`/`.d.cts`/`.d.mts`/`.d.ts`
20+
- Use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in `tsconfig.json`
21+
- Prefer resolving `@types/*` definitions over plain `.js`/`.jsx`
22+
- Multiple tsconfigs support just like normal
23+
- `imports/exports` fields support in `package.json`
2424

2525
## TOC <!-- omit in toc -->
2626

2727
- [Notice](#notice)
2828
- [Installation](#installation)
2929
- [Configuration](#configuration)
30+
- [Options from `enhanced-resolve`](#options-from-enhanced-resolve)
31+
- [`conditionNames`](#conditionnames)
32+
- [`extensions`](#extensions)
33+
- [`extensionAlias`](#extensionalias)
34+
- [`mainFields`](#mainfields)
35+
- [Other options](#other-options)
36+
- [Default options](#default-options)
3037
- [Contributing](#contributing)
3138
- [Sponsors](#sponsors)
3239
- [Backers](#backers)
@@ -35,9 +42,9 @@ This means you can:
3542

3643
## Notice
3744

38-
After version 2.0.0, `.d.ts` will take higher priority then normal `.js` files on resolving `node_modules` packages in favor of `@types/*` definitions.
45+
After version 2.0.0, `.d.ts` will take higher priority then normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition.
3946

40-
If you're facing some problems on rules `import/default` or `import/named` from [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import), do not post any issue here, because they are just working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take <https://github.com/benmosher/eslint-plugin-import/issues/1525> as reference or post a new issue to [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) instead.
47+
If you're facing some problems on rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are just working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take [import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue to [`eslint-plugin-import`][] instead.
4148

4249
## Installation
4350

@@ -98,6 +105,96 @@ Add the following to your `.eslintrc` config:
98105
}
99106
```
100107

108+
## Options from [`enhanced-resolve`][]
109+
110+
### `conditionNames`
111+
112+
Default:
113+
114+
```jsonc
115+
[
116+
"types",
117+
"import",
118+
119+
// APF: https://angular.io/guide/angular-package-format
120+
"esm2020",
121+
"es2020",
122+
"es2015",
123+
124+
"require",
125+
"node",
126+
"node-addons",
127+
"browser",
128+
"default"
129+
]
130+
```
131+
132+
### `extensions`
133+
134+
Default:
135+
136+
```jsonc
137+
[
138+
// `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly
139+
".ts",
140+
".tsx",
141+
".d.ts",
142+
".js",
143+
".jsx",
144+
".json",
145+
".node"
146+
]
147+
```
148+
149+
### `extensionAlias`
150+
151+
Default:
152+
153+
```jsonc
154+
{
155+
".js": [
156+
".ts",
157+
// `.tsx` can also be compiled as `.js`
158+
".tsx",
159+
".d.ts",
160+
".js"
161+
],
162+
".jsx": [".tsx", ".d.ts", ".jsx"],
163+
".cjs": [".cts", ".d.cts", ".cjs"],
164+
".mjs": [".mts", ".d.mts", ".mjs"]
165+
}
166+
```
167+
168+
### `mainFields`
169+
170+
Default:
171+
172+
```jsonc
173+
[
174+
"types",
175+
"typings",
176+
177+
// APF: https://angular.io/guide/angular-package-format
178+
"fesm2020",
179+
"fesm2015",
180+
"esm2020",
181+
"es2020",
182+
183+
"module",
184+
"jsnext:main",
185+
186+
"main"
187+
]
188+
```
189+
190+
### Other options
191+
192+
You can pass through other options of [`enhanced-resolve`] directly
193+
194+
### Default options
195+
196+
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias` and `defaultMainFields` by `require/import` them directly
197+
101198
## Contributing
102199

103200
- Make sure your change is covered by a test import.
@@ -129,4 +226,7 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
129226

130227
[ISC][]
131228

229+
[`eslint-plugin-import`]: https://www.npmjs.com/package/eslint-plugin-import
230+
[`enhanced-resolve`]: https://github.com/webpack/enhanced-resolve
231+
[`typescript`]: https://www.typescriptlang.org
132232
[isc]: https://opensource.org/licenses/ISC

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "eslint-import-resolver-typescript",
33
"version": "3.2.7",
44
"type": "module",
5-
"description": "TypeScript `.cts`, `.mts`, `.ts`, `.tsx` module resolver for `eslint-plugin-import`",
5+
"description": "TypeScript `.cts`/`.mts`/`.ts`/`.tsx`/`.d.cts`/`.d.mts`/`.d.ts` module resolver for `eslint-plugin-import`",
66
"repository": "git+https://github.com/import-js/eslint-import-resolver-typescript",
77
"author": "Alex Gorbatchev <[email protected]>",
88
"contributors": [

src/index.ts

+30-30
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,11 @@ export const globSync = createSyncFn<typeof import('globby').globby>(
2727
path.resolve(_dirname, 'worker.mjs'),
2828
)
2929

30-
/**
31-
* .mts, .cts, .d.mts, .d.cts, .mjs, .cjs are not included because .cjs and .mjs must be used explicitly.
32-
*/
33-
export const defaultExtensions = [
34-
'.ts',
35-
'.tsx',
36-
'.d.ts',
37-
'.js',
38-
'.jsx',
39-
'.json',
40-
'.node',
41-
]
42-
43-
export const defaultMainFields = [
44-
'types',
45-
'typings',
46-
47-
// APF: https://angular.io/guide/angular-package-format
48-
'fesm2020',
49-
'fesm2015',
50-
'esm2020',
51-
'es2020',
52-
53-
'module',
54-
'jsnext:main',
55-
56-
'main',
57-
]
58-
5930
export const defaultConditionNames = [
6031
'types',
6132
'import',
6233

63-
// APF
34+
// APF: https://angular.io/guide/angular-package-format
6435
'esm2020',
6536
'es2020',
6637
'es2015',
@@ -72,6 +43,19 @@ export const defaultConditionNames = [
7243
'default',
7344
]
7445

46+
/**
47+
* `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly
48+
*/
49+
export const defaultExtensions = [
50+
'.ts',
51+
'.tsx',
52+
'.d.ts',
53+
'.js',
54+
'.jsx',
55+
'.json',
56+
'.node',
57+
]
58+
7559
export const defaultExtensionAlias = {
7660
'.js': [
7761
'.ts',
@@ -85,6 +69,22 @@ export const defaultExtensionAlias = {
8569
'.mjs': ['.mts', '.d.mts', '.mjs'],
8670
}
8771

72+
export const defaultMainFields = [
73+
'types',
74+
'typings',
75+
76+
// APF: https://angular.io/guide/angular-package-format
77+
'fesm2020',
78+
'fesm2015',
79+
'esm2020',
80+
'es2020',
81+
82+
'module',
83+
'jsnext:main',
84+
85+
'main',
86+
]
87+
8888
export const interfaceVersion = 2
8989

9090
export interface TsResolverOptions

0 commit comments

Comments
 (0)