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

[plugin-discovery] move logic to a package #128684

Merged
merged 8 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
/packages/kbn-utils/ @elastic/kibana-operations
/packages/kbn-cli-dev-mode/ @elastic/kibana-operations
/packages/kbn-generate/ @elastic/kibana-operations
/packages/kbn-plugin-discovery/ @elastic/kibana-operations
/src/cli/keystore/ @elastic/kibana-operations
/.ci/es-snapshots/ @elastic/kibana-operations
/.github/workflows/ @elastic/kibana-operations
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"@kbn/logging-mocks": "link:bazel-bin/packages/kbn-logging-mocks",
"@kbn/mapbox-gl": "link:bazel-bin/packages/kbn-mapbox-gl",
"@kbn/monaco": "link:bazel-bin/packages/kbn-monaco",
"@kbn/plugin-discovery": "link:bazel-bin/packages/kbn-plugin-discovery",
"@kbn/react-field": "link:bazel-bin/packages/kbn-react-field",
"@kbn/rule-data-utils": "link:bazel-bin/packages/kbn-rule-data-utils",
"@kbn/securitysolution-autocomplete": "link:bazel-bin/packages/kbn-securitysolution-autocomplete",
Expand Down Expand Up @@ -200,6 +201,7 @@
"@turf/helpers": "6.0.1",
"@turf/length": "^6.0.2",
"@types/jsonwebtoken": "^8.5.6",
"@types/kbn__plugin-discovery": "link:bazel-bin/packages/kbn-plugin-discovery/npm_module_types",
"@types/kbn__shared-ux-components": "link:bazel-bin/packages/kbn-shared-ux-components/npm_module_types",
"@types/kbn__shared-ux-services": "link:bazel-bin/packages/kbn-shared-ux-services/npm_module_types",
"@types/kbn__shared-ux-storybook": "link:bazel-bin/packages/kbn-shared-ux-storybook/npm_module_types",
Expand Down
2 changes: 2 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ filegroup(
"//packages/kbn-mapbox-gl:build",
"//packages/kbn-monaco:build",
"//packages/kbn-optimizer:build",
"//packages/kbn-plugin-discovery:build",
"//packages/kbn-plugin-generator:build",
"//packages/kbn-plugin-helpers:build",
"//packages/kbn-react-field:build",
Expand Down Expand Up @@ -123,6 +124,7 @@ filegroup(
"//packages/kbn-mapbox-gl:build_types",
"//packages/kbn-monaco:build_types",
"//packages/kbn-optimizer:build_types",
"//packages/kbn-plugin-discovery:build_types",
"//packages/kbn-plugin-generator:build_types",
"//packages/kbn-plugin-helpers:build_types",
"//packages/kbn-react-field:build_types",
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-dev-utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ NPM_MODULE_EXTRA_FILES = [
RUNTIME_DEPS = [
"//packages/kbn-std",
"//packages/kbn-utils",
"//packages/kbn-plugin-discovery",
"@npm//@babel/core",
"@npm//axios",
"@npm//chalk",
Expand All @@ -54,7 +55,6 @@ RUNTIME_DEPS = [
"@npm//execa",
"@npm//exit-hook",
"@npm//getopts",
"@npm//globby",
"@npm//jest-diff",
"@npm//load-json-file",
"@npm//markdown-it",
Expand All @@ -72,6 +72,7 @@ RUNTIME_DEPS = [
TYPES_DEPS = [
"//packages/kbn-std:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-plugin-discovery:npm_module_types",
"@npm//@babel/parser",
"@npm//@babel/types",
"@npm//@types/babel__core",
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-dev-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export * from './axios';
export * from './stdio';
export * from './ci_stats_reporter';
export * from './plugin_list';
export * from './plugins';
export * from './streams';
export * from './babel';
export * from './extract';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Fs from 'fs';
import MarkdownIt from 'markdown-it';
import cheerio from 'cheerio';
import { REPO_ROOT } from '@kbn/utils';
import { simpleKibanaPlatformPluginDiscovery } from '@kbn/plugin-discovery';

import { simpleKibanaPlatformPluginDiscovery } from '../plugins';
import { extractAsciidocInfo } from './extract_asciidoc_info';

export interface Plugin {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-docs-utils/src/api_docs/find_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import globby from 'globby';
import loadJsonFile from 'load-json-file';

import { getPluginSearchPaths } from '@kbn/config';
import { simpleKibanaPlatformPluginDiscovery } from '@kbn/dev-utils';
import { simpleKibanaPlatformPluginDiscovery } from '@kbn/plugin-discovery';
import { REPO_ROOT } from '@kbn/utils';
import { ApiScope, PluginOrPackage } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { simpleKibanaPlatformPluginDiscovery } from '@kbn/dev-utils';
import { simpleKibanaPlatformPluginDiscovery } from '@kbn/plugin-discovery';

export interface KibanaPlatformPlugin {
readonly directory: string;
Expand Down
123 changes: 123 additions & 0 deletions packages/kbn-plugin-discovery/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")

PKG_DIRNAME = "kbn-plugin-discovery"
PKG_REQUIRE_NAME = "@kbn/plugin-discovery"

SOURCE_FILES = glob(
[
"src/**/*.ts",
],
exclude = [
"**/*.test.*",
],
)

SRCS = SOURCE_FILES

filegroup(
name = "srcs",
srcs = SRCS,
)

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
"@npm//globby",
"@npm//load-json-file",
"@npm//normalize-path",
"@npm//tslib",
]

# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@types/jest",
"@npm//@types/node",
"@npm//@types/normalize-path",
"@npm//globby",
"@npm//load-json-file",
"@npm//normalize-path",
"@npm//tslib",
]

jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)

ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)

js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)

pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)

filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)

pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)

filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)
3 changes: 3 additions & 0 deletions packages/kbn-plugin-discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/plugin-discovery

Logic used to find plugins in the repository.
13 changes: 13 additions & 0 deletions packages/kbn-plugin-discovery/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-plugin-discovery'],
};
7 changes: 7 additions & 0 deletions packages/kbn-plugin-discovery/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/plugin-discovery",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*/

export * from './parse_kibana_platform_plugin';
export * from './plugin_search_paths';
export * from './simple_kibana_platform_plugin_discovery';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import loadJsonFile from 'load-json-file';
export interface KibanaPlatformPlugin {
readonly directory: string;
readonly manifestPath: string;
readonly manifest: Manifest;
readonly manifest: KibanaPlatformPluginManifest;
}

function isValidDepsDeclaration(input: unknown, type: string): string[] {
Expand All @@ -23,7 +23,7 @@ function isValidDepsDeclaration(input: unknown, type: string): string[] {
throw new TypeError(`The "${type}" in plugin manifest should be an array of strings.`);
}

interface Manifest {
export interface KibanaPlatformPluginManifest {
id: string;
ui: boolean;
server: boolean;
Expand All @@ -50,7 +50,7 @@ export function parseKibanaPlatformPlugin(manifestPath: string): KibanaPlatformP
throw new TypeError('expected new platform manifest path to be absolute');
}

const manifest: Partial<Manifest> = loadJsonFile.sync(manifestPath);
const manifest: Partial<KibanaPlatformPluginManifest> = loadJsonFile.sync(manifestPath);
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) {
throw new TypeError('expected new platform plugin manifest to be a JSON encoded object');
}
Expand Down
26 changes: 26 additions & 0 deletions packages/kbn-plugin-discovery/src/plugin_search_paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { resolve } from 'path';

export interface SearchOptions {
rootDir: string;
oss: boolean;
examples: boolean;
}

export function getPluginSearchPaths({ rootDir, oss, examples }: SearchOptions) {
return [
resolve(rootDir, 'src', 'plugins'),
...(oss ? [] : [resolve(rootDir, 'x-pack', 'plugins')]),
resolve(rootDir, 'plugins'),
...(examples ? [resolve(rootDir, 'examples')] : []),
...(examples && !oss ? [resolve(rootDir, 'x-pack', 'examples')] : []),
resolve(rootDir, '..', 'kibana-extra'),
];
}
17 changes: 17 additions & 0 deletions packages/kbn-plugin-discovery/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import Path from 'path';

import { REPO_ROOT } from '@kbn/utils';
import { parseKibanaPlatformPlugin, KibanaPlatformPlugin, createFailError } from '@kbn/dev-utils';
import { parseKibanaPlatformPlugin, KibanaPlatformPlugin } from '@kbn/plugin-discovery';
import { createFailError } from '@kbn/dev-utils';

export type Plugin = KibanaPlatformPlugin;

Expand Down
2 changes: 1 addition & 1 deletion src/dev/plugin_discovery/find_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Path from 'path';
import { getPluginSearchPaths } from '@kbn/config';
import { KibanaPlatformPlugin, simpleKibanaPlatformPluginDiscovery } from '@kbn/dev-utils';
import { KibanaPlatformPlugin, simpleKibanaPlatformPluginDiscovery } from '@kbn/plugin-discovery';

import { REPO_ROOT } from '@kbn/utils';

Expand Down
2 changes: 1 addition & 1 deletion src/dev/plugin_discovery/get_plugin_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { KibanaPlatformPlugin } from '@kbn/dev-utils';
import { KibanaPlatformPlugin } from '@kbn/plugin-discovery';

interface AllOptions {
id: string;
Expand Down
3 changes: 2 additions & 1 deletion src/dev/run_find_plugins_ready_migrate_to_ts_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Path from 'path';
import Fs from 'fs';
import JSON5 from 'json5';
import { get } from 'lodash';
import { run, KibanaPlatformPlugin } from '@kbn/dev-utils';
import { run } from '@kbn/dev-utils';
import { KibanaPlatformPlugin } from '@kbn/plugin-discovery';
import { getPluginDeps, findPlugins } from './plugin_discovery';

interface AllOptions {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3033,6 +3033,10 @@
version "0.0.0"
uid ""

"@kbn/plugin-discovery@link:bazel-bin/packages/kbn-plugin-discovery":
version "0.0.0"
uid ""

"@kbn/plugin-generator@link:bazel-bin/packages/kbn-plugin-generator":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -6015,6 +6019,10 @@
version "0.0.0"
uid ""

"@types/kbn__plugin-discovery@link:bazel-bin/packages/kbn-plugin-discovery/npm_module_types":
version "0.0.0"
uid ""

"@types/kbn__plugin-generator@link:bazel-bin/packages/kbn-plugin-generator/npm_module_types":
version "0.0.0"
uid ""
Expand Down