You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It essentially just uses the current file to get a reference base directory (`basedir`)
139
-
and then passes through any explicit config from the `.eslintrc`; things like
140
-
non-standard file extensions, module directories, etc.
102
+
In the interest of supporting both of these, v0.11 introduces resolvers.
141
103
142
104
Currently [Node] and [Webpack] resolution have been implemented, but the
143
-
resolvers are just npm packages, so third party packages are supported (and encouraged!).
105
+
resolvers are just npm packages, so [third party packages are supported](https://github.com/benmosher/eslint-plugin-import/wiki/Resolvers) (and encouraged!).
144
106
145
107
Just install a resolver as `eslint-import-resolver-foo` and reference it as such:
146
108
@@ -157,6 +119,8 @@ settings:
157
119
foo: { someConfigKey: value }
158
120
```
159
121
122
+
If you are interesting in writing a resolver, see the [spec](./resolvers/README.md) for more details.
This document currently describes version 2 of the resolver interface. As such, a resolver implementing this version should
8
+
9
+
```js
10
+
exportconstinterfaceVersion=2
11
+
```
12
+
or
13
+
```js
14
+
exports.interfaceVersion=2
15
+
```
16
+
17
+
To the extent it is feasible, trailing versions of the resolvers will continue to be supported, at least until a major version bump on the plugin proper.
18
+
19
+
Currently, version 1 is assumed if no `interfaceVersion` is available. (didn't think to define it until v2, heh. 😅)
the absolute path to the file making the import (`/some/path/to/module.js`)
49
+
50
+
##### `config`
51
+
52
+
an object provided via the `import/resolver` setting.`my-cool-resolver` will get `["some", "stuff"]` as its `config`, while
53
+
`node` will get `{ "paths": ["a", "b", "c"] }` provided as `config`.
54
+
55
+
#### Return value
56
+
57
+
The first resolver to return `{found: true}` is considered the source of truth. The returned object has:
58
+
59
+
- `found`: `true`if the `source` module can be resolved relative to `file`, else `false`
60
+
- `path`: an absolute path `String` if the module can be located on the filesystem; else, `null`.
61
+
62
+
An example of a `null` path is a Node core module, such as `fs` or `crypto`. These modules can always be resolved, but the path need not be provided as the plugin will not attempt to parse core modules at this time.
63
+
64
+
If the resolver cannot resolve `source` relative to `file`, it should just return `{ found: false }`. No `path` key is needed in this case.
65
+
66
+
## Example
67
+
68
+
Here is most of the [Node resolver] at the time of this writing. It is just a wrapper around substack/Browserify's synchronous [`resolve`]:
69
+
70
+
```js
71
+
var resolve = require('resolve')
72
+
73
+
exports.resolve = function (source, file, config) {
74
+
if (resolve.isCore(source)) return { found: true, path: null }
0 commit comments