mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[plugin-discovery] move logic to a package (#128684)
This commit is contained in:
parent
1e33587b68
commit
92d65484a5
23 changed files with 225 additions and 14 deletions
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
|
@ -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
|
||||
|
|
|
@ -148,6 +148,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",
|
||||
|
@ -199,6 +200,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",
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
124
packages/kbn-plugin-discovery/BUILD.bazel
Normal file
124
packages/kbn-plugin-discovery/BUILD.bazel
Normal file
|
@ -0,0 +1,124 @@
|
|||
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,
|
||||
declaration_map = 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
packages/kbn-plugin-discovery/README.md
Normal file
3
packages/kbn-plugin-discovery/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# @kbn/plugin-discovery
|
||||
|
||||
Logic used to find plugins in the repository.
|
13
packages/kbn-plugin-discovery/jest.config.js
Normal file
13
packages/kbn-plugin-discovery/jest.config.js
Normal file
|
@ -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
packages/kbn-plugin-discovery/package.json
Normal file
7
packages/kbn-plugin-discovery/package.json
Normal file
|
@ -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"
|
||||
}
|
|
@ -7,4 +7,5 @@
|
|||
*/
|
||||
|
||||
export * from './parse_kibana_platform_plugin';
|
||||
export * from './plugin_search_paths';
|
||||
export * from './simple_kibana_platform_plugin_discovery';
|
|
@ -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[] {
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
}
|
26
packages/kbn-plugin-discovery/src/plugin_search_paths.ts
Normal file
26
packages/kbn-plugin-discovery/src/plugin_search_paths.ts
Normal file
|
@ -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'),
|
||||
];
|
||||
}
|
|
@ -11,12 +11,15 @@ import Path from 'path';
|
|||
import globby from 'globby';
|
||||
import normalize from 'normalize-path';
|
||||
|
||||
import { parseKibanaPlatformPlugin } from './parse_kibana_platform_plugin';
|
||||
import { parseKibanaPlatformPlugin, KibanaPlatformPlugin } from './parse_kibana_platform_plugin';
|
||||
|
||||
/**
|
||||
* Helper to find the new platform plugins.
|
||||
*/
|
||||
export function simpleKibanaPlatformPluginDiscovery(scanDirs: string[], pluginPaths: string[]) {
|
||||
export function simpleKibanaPlatformPluginDiscovery(
|
||||
scanDirs: string[],
|
||||
pluginPaths: string[]
|
||||
): KibanaPlatformPlugin[] {
|
||||
const patterns = Array.from(
|
||||
new Set([
|
||||
// find kibana.json files up to 5 levels within the scan dir
|
18
packages/kbn-plugin-discovery/tsconfig.json
Normal file
18
packages/kbn-plugin-discovery/tsconfig.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "../../tsconfig.bazel.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "target_types",
|
||||
"rootDir": "src",
|
||||
"stripInternal": false,
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ const TYPE_SUMMARIZER_PACKAGES = [
|
|||
'@kbn/analytics',
|
||||
'@kbn/apm-config-loader',
|
||||
'@kbn/apm-utils',
|
||||
'@kbn/plugin-discovery',
|
||||
];
|
||||
|
||||
type TypeSummarizerType = 'api-extractor' | 'type-summarizer';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 ""
|
||||
|
@ -6023,6 +6027,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 ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue