[eslint-import-resolver] support mapping plugins to directories (#17667)
* [eslint-import-resolver] support mapping plugins to directories * use shorthand syntax
This commit is contained in:
parent
977cd51f6a
commit
6db8fea28e
|
@ -29,6 +29,7 @@ Property | Default | Description
|
|||
rootPackageName | `null` | The `"name"` property of the root `package.json` file. If your project has multiple `package.json` files then specify this setting to tell the resolver which `package.json` file sits at the root of your project.
|
||||
pluginPaths | `[]` if `rootPackageName` is set, otherwise `[.]` | Array of relative paths which contain a Kibana plugin. Plugins must contain a `package.json` file to be valid.
|
||||
pluginDirs | `[]` | Array of relative paths pointing to directories which contain Kibana plugins. Plugins must contain a `package.json` file to be valid.
|
||||
pluginMap | `{}` | A map of plugin ids to relative paths, explicitly pointing to the location where Kibana should map `plugin/{pluginId}` import statements. Directories do not need to contain a `package.json` file to work.
|
||||
|
||||
## Settings Usage
|
||||
To specify additional config add a `:` after the resolver name and specify the argument as key-value pairs:
|
||||
|
@ -51,6 +52,12 @@ settings:
|
|||
# that directory and we will look for plugins there
|
||||
pluginDirs:
|
||||
- ./kibana-plugins
|
||||
|
||||
# if you have some other special configuration supply a map of plugin
|
||||
# ids to the directory containing their code
|
||||
pluginMap:
|
||||
plugin1: plugins/plugin1
|
||||
plugin2: plugins/plugin2
|
||||
```
|
||||
|
||||
See [the resolvers docs](https://github.com/benmosher/eslint-plugin-import#resolvers) or the [resolver spec](https://github.com/benmosher/eslint-plugin-import/blob/master/resolvers/README.md#resolvesource-file-config---found-boolean-path-string-) for more details.
|
||||
|
|
|
@ -23,7 +23,17 @@ module.exports = function getPlugins(config, kibanaPath, projectRoot) {
|
|||
...pluginPaths.map(path => resolve(path, 'package.json')),
|
||||
];
|
||||
|
||||
return glob.sync(globPatterns).map(pkgJsonPath => {
|
||||
const pluginsFromMap = Object.keys(config.pluginMap || {}).map(name => {
|
||||
const directory = resolveToRoot(config.pluginMap[name]);
|
||||
return {
|
||||
name,
|
||||
directory,
|
||||
publicDirectory: resolve(directory, 'public'),
|
||||
};
|
||||
});
|
||||
|
||||
return pluginsFromMap.concat(
|
||||
glob.sync(globPatterns).map(pkgJsonPath => {
|
||||
const path = dirname(pkgJsonPath);
|
||||
const pkg = require(pkgJsonPath);
|
||||
return {
|
||||
|
@ -31,5 +41,6 @@ module.exports = function getPlugins(config, kibanaPath, projectRoot) {
|
|||
directory: path,
|
||||
publicDirectory: resolve(path, 'public'),
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue