From 6db8fea28e5ded114b1e19a7a58af6977c2be3ce Mon Sep 17 00:00:00 2001 From: Spencer Date: Thu, 12 Apr 2018 15:28:30 -0700 Subject: [PATCH] [eslint-import-resolver] support mapping plugins to directories (#17667) * [eslint-import-resolver] support mapping plugins to directories * use shorthand syntax --- .../README.md | 7 ++++++ .../lib/get_plugins.js | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/kbn-eslint-import-resolver-kibana/README.md b/packages/kbn-eslint-import-resolver-kibana/README.md index 65b28cd07bf7..2cd1dc9e9b83 100755 --- a/packages/kbn-eslint-import-resolver-kibana/README.md +++ b/packages/kbn-eslint-import-resolver-kibana/README.md @@ -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. diff --git a/packages/kbn-eslint-import-resolver-kibana/lib/get_plugins.js b/packages/kbn-eslint-import-resolver-kibana/lib/get_plugins.js index 12477987f353..155e95876dc7 100755 --- a/packages/kbn-eslint-import-resolver-kibana/lib/get_plugins.js +++ b/packages/kbn-eslint-import-resolver-kibana/lib/get_plugins.js @@ -23,13 +23,24 @@ module.exports = function getPlugins(config, kibanaPath, projectRoot) { ...pluginPaths.map(path => resolve(path, 'package.json')), ]; - return glob.sync(globPatterns).map(pkgJsonPath => { - const path = dirname(pkgJsonPath); - const pkg = require(pkgJsonPath); + const pluginsFromMap = Object.keys(config.pluginMap || {}).map(name => { + const directory = resolveToRoot(config.pluginMap[name]); return { - name: pkg.name, - directory: path, - publicDirectory: resolve(path, 'public'), + name, + directory, + publicDirectory: resolve(directory, 'public'), }; }); + + return pluginsFromMap.concat( + glob.sync(globPatterns).map(pkgJsonPath => { + const path = dirname(pkgJsonPath); + const pkg = require(pkgJsonPath); + return { + name: pkg.name, + directory: path, + publicDirectory: resolve(path, 'public'), + }; + }) + ); };