Skip to content

Commit 1466bec

Browse files
feat(resolve): allow overriding enhanced-resolve's options (#384)
1 parent af4f774 commit 1466bec

20 files changed

+153
-2
lines changed

docs/rules/no-extraneous-import.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Please see the shared settings documentation for more information.
3737
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
3838
Please see the shared settings documentation for more information.
3939

40+
#### resolverConfig
41+
42+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
43+
Please see the shared settings documentation for more information.
44+
4045
#### convertPath
4146

4247
This can be configured in the rule options or as a shared setting [`settings.convertPath`](../shared-settings.md#convertpath).

docs/rules/no-extraneous-require.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Please see the shared settings documentation for more information.
3838
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
3939
Please see the shared settings documentation for more information.
4040

41+
#### resolverConfig
42+
43+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
44+
Please see the shared settings documentation for more information.
45+
4146
#### convertPath
4247

4348
This can be configured in the rule options or as a shared setting [`settings.convertPath`](../shared-settings.md#convertpath).

docs/rules/no-missing-import.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Please see the shared settings documentation for more information.
5252
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
5353
Please see the shared settings documentation for more information.
5454

55+
#### resolverConfig
56+
57+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
58+
Please see the shared settings documentation for more information.
59+
5560
#### tsconfigPath
5661

5762
This can be configured in the rule options or as a shared setting [`settings.tsconfigPath`](../shared-settings.md#tsconfigpath).

docs/rules/no-missing-require.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Please see the shared settings documentation for more information.
6060
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
6161
Please see the shared settings documentation for more information.
6262

63+
#### resolverConfig
64+
65+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
66+
Please see the shared settings documentation for more information.
67+
6368
#### tryExtensions
6469

6570
This can be configured in the rule options or as a shared setting [`settings.tryExtensions`](../shared-settings.md#tryextensions).

docs/rules/no-unpublished-import.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Please see the shared settings documentation for more information.
4141
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
4242
Please see the shared settings documentation for more information.
4343

44+
#### resolverConfig
45+
46+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
47+
Please see the shared settings documentation for more information.
48+
4449
#### convertPath
4550

4651
This can be configured in the rule options or as a shared setting [`settings.convertPath`](../shared-settings.md#convertpath).

docs/rules/no-unpublished-require.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ Please see the shared settings documentation for more information.
4343
This can be configured in the rule options or as a shared setting [`settings.resolvePaths`](../shared-settings.md#resolvepaths).
4444
Please see the shared settings documentation for more information.
4545

46+
#### resolverConfig
47+
48+
This can be configured in the rule options or as a shared setting [`settings.resolverConfig`](../shared-settings.md#resolverconfig).
49+
Please see the shared settings documentation for more information.
50+
4651
#### convertPath
4752

4853
This can be configured in the rule options or as a shared setting [`settings.convertPath`](../shared-settings.md#convertpath).

docs/shared-settings.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ If a path is relative, it will be resolved from CWD.
6060
{ "resolvePaths": [] }
6161
```
6262

63+
## resolverConfig
64+
65+
Override the options generated by this plugin for resolving require and import statements.
66+
67+
While these options are passed down to [`enhanced-resolve`](https://github.com/webpack/enhanced-resolve)'s factory method, we only support a subset of the options they allow. These are documented below.
68+
69+
The options you define here are assigned over the default options generated by the plugin.
70+
71+
Supported options:
72+
73+
- `resolverConfig.modules`: A list of directories to resolve modules from, can be absolute path or folder name
74+
75+
### Example resolverConfig
76+
77+
```json
78+
{ "resolverConfig": { "modules": ["node_modules", "bower_components"] } }
79+
```
80+
81+
### Default resolverConfig
82+
83+
```json
84+
{ "resolverConfig": {} }
85+
```
86+
6387
## convertPath
6488

6589
If we use transpilers (e.g. Babel), perhaps the file path to a source code is never published.

lib/rules/no-extraneous-import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { checkExtraneous, messages } = require("../util/check-extraneous")
88
const getAllowModules = require("../util/get-allow-modules")
99
const getConvertPath = require("../util/get-convert-path")
1010
const getResolvePaths = require("../util/get-resolve-paths")
11+
const getResolverConfig = require("../util/get-resolver-config")
1112
const visitImport = require("../util/visit-import")
1213

1314
/** @type {import('eslint').Rule.RuleModule} */
@@ -28,6 +29,7 @@ module.exports = {
2829
allowModules: getAllowModules.schema,
2930
convertPath: getConvertPath.schema,
3031
resolvePaths: getResolvePaths.schema,
32+
resolverConfig: getResolverConfig.schema,
3133
},
3234
additionalProperties: false,
3335
},

lib/rules/no-extraneous-require.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const { checkExtraneous, messages } = require("../util/check-extraneous")
88
const getAllowModules = require("../util/get-allow-modules")
99
const getConvertPath = require("../util/get-convert-path")
1010
const getResolvePaths = require("../util/get-resolve-paths")
11+
const getResolverConfig = require("../util/get-resolver-config")
1112
const getTryExtensions = require("../util/get-try-extensions")
1213
const visitRequire = require("../util/visit-require")
1314

@@ -29,6 +30,7 @@ module.exports = {
2930
allowModules: getAllowModules.schema,
3031
convertPath: getConvertPath.schema,
3132
resolvePaths: getResolvePaths.schema,
33+
resolverConfig: getResolverConfig.schema,
3234
tryExtensions: getTryExtensions.schema,
3335
},
3436
additionalProperties: false,

lib/rules/no-missing-import.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const { checkExistence, messages } = require("../util/check-existence")
88
const getAllowModules = require("../util/get-allow-modules")
99
const getResolvePaths = require("../util/get-resolve-paths")
10+
const getResolverConfig = require("../util/get-resolver-config")
1011
const getTryExtensions = require("../util/get-try-extensions")
1112
const getTSConfig = require("../util/get-tsconfig")
1213
const getTypescriptExtensionMap = require("../util/get-typescript-extension-map")
@@ -29,6 +30,7 @@ module.exports = {
2930
properties: {
3031
allowModules: getAllowModules.schema,
3132
resolvePaths: getResolvePaths.schema,
33+
resolverConfig: getResolverConfig.schema,
3234
tryExtensions: getTryExtensions.schema,
3335
ignoreTypeImport: { type: "boolean", default: false },
3436
tsconfigPath: getTSConfig.schema,

0 commit comments

Comments
 (0)