Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renames kbn-eslint-import-resolver-kibana to osd-eslint-import-resolver-opensearch-dashboards (#37) #45

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# @kbn/eslint-import-resolver-kibana
# @osd/eslint-import-resolver-opensearch-dashboards

Resolver for Kibana imports, meant to be used with [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import).
Resolver for OpenSearch Dashboards imports, meant to be used with [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import).

## Installation

To install this utility use `yarn` to link to the package from the Kibana project:
To install this utility use `yarn` to link to the package from the OpenSearch Dashboards project:

```sh
yarn add --dev link:../../kibana/packages/kbn-eslint-import-resolver-kibana
yarn add --dev link:../../opensearchDashboards/packages/osd-eslint-import-resolver-opensearch-dashboards
```

## Usage
Expand All @@ -17,7 +17,7 @@ Specify this resolver with the `import/resolver` setting in your eslint config f
```yml
# .eslintrc.yml
settings:
import/resolver: "@kbn/eslint-import-resolver-kibana"
import/resolver: "@osd/eslint-import-resolver-opensearch-dashboards"
```

## Settings
Expand All @@ -27,9 +27,9 @@ settings:
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.
pluginPaths | `[]` if `rootPackageName` is set, otherwise `[.]` | Array of relative paths which contain a OpenSearch Dashboards plugin. Plugins must contain a `package.json` file to be valid.
pluginDirs | `[]` | Array of relative paths pointing to directories which contain OpenSearch Dashboards 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 OpenSearch Dashboards 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:
Expand All @@ -38,7 +38,7 @@ To specify additional config add a `:` after the resolver name and specify the a
# .eslintrc.yml
settings:
import/resolver:
"@kbn/eslint-import-resolver-kibana":
"@osd/eslint-import-resolver-opensearch-dashboards":
# if your project has multiple package.json files
rootPackageName: my-project

Expand All @@ -51,7 +51,7 @@ settings:
# if all of your plugins have the same parent directory you can specify
# that directory and we will look for plugins there
pluginDirs:
- ./kibana-plugins
- ./opensearch-dashboards-plugins

# if you have some other special configuration supply a map of plugin
# ids to the directory containing their code
Expand All @@ -64,6 +64,6 @@ See [the resolvers docs](https://github.com/benmosher/eslint-plugin-import#resol

## Debugging

For debugging output from this resolver, run your linter with `DEBUG=eslint-plugin-import:resolver:kibana`.
For debugging output from this resolver, run your linter with `DEBUG=eslint-plugin-import:resolver:opensearchDashboards`.

This resolver defers to [*eslint-import-resolver-node*](https://www.npmjs.com/package/eslint-import-resolver-node) and [*eslint-import-resolver-webpack*](https://www.npmjs.com/package/eslint-import-resolver-webpack) for all of it's actual resolution logic. To get debugging output from all resolvers use `DEBUG=eslint-plugin-import:resolver:*`.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const webpackResolver = require('eslint-import-resolver-webpack');
const nodeResolver = require('eslint-import-resolver-node');

const {
getKibanaPath,
getOpenSearchDashboardsPath,
getProjectRoot,
getWebpackConfig,
isFile,
Expand All @@ -39,8 +39,8 @@ function initContext(file, config) {
}

const projectRoot = getProjectRoot(file, config);
const kibanaPath = getKibanaPath(config, projectRoot);
const webpackConfig = getWebpackConfig(kibanaPath, projectRoot, config);
const opensearchDashboardsPath = getOpenSearchDashboardsPath(config, projectRoot);
const webpackConfig = getWebpackConfig(opensearchDashboardsPath, projectRoot, config);
const aliasEntries = Object.entries(webpackConfig.resolve.alias || {});

context = {
Expand All @@ -65,7 +65,7 @@ function tryNodeResolver(importRequest, file, config) {
);
}

exports.resolve = function resolveKibanaPath(importRequest, file, config) {
exports.resolve = function resolveOpenSearchDashboardsPath(importRequest, file, config) {
config = config || {};

if (config.forceNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

exports.debug = require('debug')('eslint-plugin-import:resolver:kibana');
exports.debug = require('debug')('eslint-plugin-import:resolver:opensearchDashboards');
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ const { debug } = require('./debug');
const DEFAULT_PLUGIN_PATH = '../..';

/*
* Resolves the path to Kibana, either from default setting or config
* Resolves the path to OpenSearch Dashboards, either from default setting or config
*/
exports.getKibanaPath = function (config, projectRoot) {
const inConfig = config != null && config.kibanaPath;
exports.getOpenSearchDashboardsPath = function (config, projectRoot) {
const inConfig = config != null && config.opensearchDashboardsPath;

// We only allow `.` in the config as we need it for Kibana itself
if (inConfig && config.kibanaPath !== '.') {
// We only allow `.` in the config as we need it for OpenSearch Dashboards itself
if (inConfig && config.opensearchDashboardsPath !== '.') {
throw new Error(
'The `kibanaPath` option has been removed from `eslint-import-resolver-kibana`. ' +
'During development your plugin must live in `./plugins/{pluginName}` ' +
'inside the Kibana folder or `../kibana-extra/{pluginName}` ' +
'relative to the Kibana folder to work with this package.'
'The `opensearchDashboardsPath` option has been removed from `eslint-import-resolver-opensearch-dashboards`. ' +
'During development your plugin must live in `./plugins/{pluginName}` ' +
'inside the OpenSearch Dashboards folder or `../opensearch-dashboards-extra/{pluginName}` ' +
'relative to the OpenSearch Dashboards folder to work with this package.'
);
}

const kibanaPath = inConfig
? resolve(projectRoot, config.kibanaPath)
const opensearchDashboardsPath = inConfig
? resolve(projectRoot, config.opensearchDashboardsPath)
: resolve(projectRoot, DEFAULT_PLUGIN_PATH);

debug(`Resolved Kibana path: ${kibanaPath}`);
return kibanaPath;
debug(`Resolved OpenSearch Dashboards path: ${opensearchDashboardsPath}`);
return opensearchDashboardsPath;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const LRU = require('lru-cache');

const DIR = Symbol('dir');
const FILE = Symbol('file');
const cache = process.env.KIBANA_RESOLVER_HARD_CACHE ? new Map() : new LRU({ maxAge: 1000 });
const cache = process.env.OPENSEARCH_DASHBOARDS_RESOLVER_HARD_CACHE ? new Map() : new LRU({ maxAge: 1000 });

function getPathType(path) {
const cached = cache.get(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@

const { resolve } = require('path');

exports.getWebpackConfig = function (kibanaPath) {
exports.getWebpackConfig = function (opensearchDashboardsPath) {
return {
context: kibanaPath,
context: opensearchDashboardsPath,
resolve: {
extensions: ['.js', '.json', '.ts', '.tsx'],
mainFields: ['browser', 'main'],
modules: ['node_modules', resolve(kibanaPath, 'node_modules')],
modules: ['node_modules', resolve(opensearchDashboardsPath, 'node_modules')],
alias: {
// Dev defaults for test bundle https://github.com/elastic/kibana/blob/6998f074542e8c7b32955db159d15661aca253d7/src/core_plugins/tests_bundle/index.js#L73-L78
fixtures: resolve(kibanaPath, 'src/fixtures'),
test_utils: resolve(kibanaPath, 'src/test_utils/public'),
fixtures: resolve(opensearchDashboardsPath, 'src/fixtures'),
test_utils: resolve(opensearchDashboardsPath, 'src/test_utils/public'),
},
unsafeCache: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

module.exports = Object.assign(
{},
require('./get_kibana_path'),
require('./get_opensearch_dashboards_path'),
require('./get_project_root'),
require('./get_webpack_config'),
require('./get_path_type'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably actually change the repo url right??

"name": "@kbn/eslint-import-resolver-kibana",
"description": "eslint-plugin-import resolver for Kibana",
"name": "@osd/eslint-import-resolver-opensearch-dashboards",
"description": "eslint-plugin-import resolver for OpenSearch Dashboards",
"private": true,
"version": "2.0.0",
"main": "import_resolver_kibana.js",
"main": "import_resolver_opensearch_dashboards.js",
"license": "Apache-2.0",
"kibana": {
"opensearchDashboards": {
"devOnly": true
},
"repository": {
Expand Down