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

Migrate server-side preboot service to packages #136060

Merged
Merged
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@
"@kbn/core-node-server": "link:bazel-bin/packages/core/node/core-node-server",
"@kbn/core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal",
"@kbn/core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks",
"@kbn/core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server",
"@kbn/core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal",
"@kbn/core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks",
"@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser",
"@kbn/core-theme-browser-internal": "link:bazel-bin/packages/core/theme/core-theme-browser-internal",
"@kbn/core-theme-browser-mocks": "link:bazel-bin/packages/core/theme/core-theme-browser-mocks",
Expand Down Expand Up @@ -744,6 +747,9 @@
"@types/kbn__core-node-server": "link:bazel-bin/packages/core/node/core-node-server/npm_module_types",
"@types/kbn__core-node-server-internal": "link:bazel-bin/packages/core/node/core-node-server-internal/npm_module_types",
"@types/kbn__core-node-server-mocks": "link:bazel-bin/packages/core/node/core-node-server-mocks/npm_module_types",
"@types/kbn__core-preboot-server": "link:bazel-bin/packages/core/preboot/core-preboot-server/npm_module_types",
"@types/kbn__core-preboot-server-internal": "link:bazel-bin/packages/core/preboot/core-preboot-server-internal/npm_module_types",
"@types/kbn__core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks/npm_module_types",
"@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types",
"@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types",
"@types/kbn__core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser/npm_module_types",
Expand Down
6 changes: 6 additions & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ filegroup(
"//packages/core/node/core-node-server-internal:build",
"//packages/core/node/core-node-server-mocks:build",
"//packages/core/node/core-node-server:build",
"//packages/core/preboot/core-preboot-server-internal:build",
"//packages/core/preboot/core-preboot-server-mocks:build",
"//packages/core/preboot/core-preboot-server:build",
"//packages/core/theme/core-theme-browser-internal:build",
"//packages/core/theme/core-theme-browser-mocks:build",
"//packages/core/theme/core-theme-browser:build",
Expand Down Expand Up @@ -238,6 +241,9 @@ filegroup(
"//packages/core/node/core-node-server-internal:build_types",
"//packages/core/node/core-node-server-mocks:build_types",
"//packages/core/node/core-node-server:build_types",
"//packages/core/preboot/core-preboot-server-internal:build_types",
"//packages/core/preboot/core-preboot-server-mocks:build_types",
"//packages/core/preboot/core-preboot-server:build_types",
"//packages/core/theme/core-theme-browser-internal:build_types",
"//packages/core/theme/core-theme-browser-mocks:build_types",
"//packages/core/theme/core-theme-browser:build_types",
Expand Down
111 changes: 111 additions & 0 deletions packages/core/preboot/core-preboot-server-internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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 = "core-preboot-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-preboot-server-internal"

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

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"//packages/kbn-logging",
"//packages/core/base/core-base-server-internal",
"//packages/core/base/core-base-common",
"//packages/kbn-utils",
"//packages/kbn-config",
"//packages/kbn-config-mocks",
"//packages/core/logging/core-logging-server-mocks",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/kbn-logging:npm_module_types",
"//packages/core/base/core-base-server-internal:npm_module_types",
"//packages/core/base/core-base-common:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-config:npm_module_types",
"//packages/kbn-config-mocks:npm_module_types",
"//packages/core/logging/core-logging-server-mocks:npm_module_types",
]

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"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/core-preboot-server-internal

This package contains the internal types and implementation for Core's server-side preboot service.
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/core/preboot/core-preboot-server-internal'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/core-preboot-server-internal",
"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 @@ -6,5 +6,5 @@
* Side Public License, v 1.
*/

export type { InternalPrebootServicePreboot } from './types';
export { PrebootService } from './preboot_service';
export type { InternalPrebootServicePreboot, PrebootServicePreboot } from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import { REPO_ROOT } from '@kbn/utils';
import { LoggerFactory } from '@kbn/logging';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import { configServiceMock, loggingSystemMock } from '../mocks';
import { configServiceMock, getEnvOptions } from '@kbn/config-mocks';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';

import { PrebootService } from './preboot_service';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import type { Logger } from '@kbn/logging';
import type { CoreContext } from '@kbn/core-base-server-internal';
import { InternalPrebootServicePreboot } from './types';
import type { InternalPrebootServicePreboot } from './types';

/** @internal */
export class PrebootService {
Expand Down
40 changes: 40 additions & 0 deletions packages/core/preboot/core-preboot-server-internal/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 type { PluginName } from '@kbn/core-base-common';

/** @internal */
export interface InternalPrebootServicePreboot {
/**
* Indicates whether Kibana is currently on hold and cannot proceed to `setup` yet.
*/
readonly isSetupOnHold: () => boolean;

/**
* Registers a `Promise` as a precondition before Kibana can proceed to `setup`. This method can be invoked multiple
* times and from multiple `preboot` plugins. Kibana will proceed to `setup` only when all registered `Promise` are
* resolved, or it will shut down if any of them are rejected.
* @param pluginName Name of the plugin that needs to hold `setup`.
* @param reason A string that explains the reason why this promise should hold `setup`. It's supposed to be a human
* readable string that will be recorded in the logs or standard output.
* @param promise A `Promise` that should resolved before Kibana can proceed to `setup`.
*/
readonly holdSetupUntilResolved: (
pluginName: PluginName,
reason: string,
promise: Promise<{ shouldReloadConfig: boolean } | undefined>
) => void;

/**
* Returns a `Promise` that is resolved only when all `Promise` instances registered with {@link holdSetupUntilResolved}
* are resolved, or rejected if any of them are rejected. If the supplied `Promise` resolves to an object with the
* `shouldReloadConfig` property set to `true`, it indicates that Kibana configuration might have changed and Kibana
* needs to reload it from the disk.
*/
readonly waitUntilCanSetup: () => Promise<{ shouldReloadConfig: boolean }>;
}
Original file line number Diff line number Diff line change
@@ -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/**/*"
]
}
102 changes: 102 additions & 0 deletions packages/core/preboot/core-preboot-server-mocks/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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 = "core-preboot-server-mocks"
PKG_REQUIRE_NAME = "@kbn/core-preboot-server-mocks"

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

SRCS = SOURCE_FILES

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

NPM_MODULE_EXTRA_FILES = [
"package.json",
]

RUNTIME_DEPS = [
"//packages/kbn-utility-types",
"//packages/core/preboot/core-preboot-server-internal",
]

TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/kbn-utility-types:npm_module_types",
"//packages/core/preboot/core-preboot-server-internal:npm_module_types",
"//packages/core/preboot/core-preboot-server:npm_module_types"
]

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 changes: 3 additions & 0 deletions packages/core/preboot/core-preboot-server-mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/core-preboot-server-mocks

This package contains the mocks for Core's server-side preboot service.
13 changes: 13 additions & 0 deletions packages/core/preboot/core-preboot-server-mocks/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/core/preboot/core-preboot-server-mocks'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/core-preboot-server-mocks",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Loading