Migrate server-side rendering service to packages (#141902)

* create empty packages

* moves files to packages

* adapt usages

* updating READMEs and packages jsons

* [CI] Auto-commit changed files from 'node scripts/generate codeowners'

* adapt more usages

* more import fixes

* fix mock method names

* export the `Fonts` component for security...

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* fix more usages again

* includes tsx files

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Pierre Gayvallet 2022-10-03 09:52:17 +02:00 committed by GitHub
parent de1c22a074
commit 8a298e4c8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
79 changed files with 705 additions and 86 deletions

3
.github/CODEOWNERS vendored
View file

@ -784,6 +784,7 @@ packages/core/notifications/core-notifications-browser-mocks @elastic/kibana-cor
packages/core/overlays/core-overlays-browser @elastic/kibana-core
packages/core/overlays/core-overlays-browser-internal @elastic/kibana-core
packages/core/overlays/core-overlays-browser-mocks @elastic/kibana-core
packages/core/plugins/core-plugins-base-server-internal @elastic/kibana-core
packages/core/plugins/core-plugins-browser @elastic/kibana-core
packages/core/plugins/core-plugins-browser-internal @elastic/kibana-core
packages/core/plugins/core-plugins-browser-mocks @elastic/kibana-core
@ -792,6 +793,8 @@ packages/core/preboot/core-preboot-server-internal @elastic/kibana-core
packages/core/preboot/core-preboot-server-mocks @elastic/kibana-core
packages/core/rendering/core-rendering-browser-internal @elastic/kibana-core
packages/core/rendering/core-rendering-browser-mocks @elastic/kibana-core
packages/core/rendering/core-rendering-server-internal @elastic/kibana-core
packages/core/rendering/core-rendering-server-mocks @elastic/kibana-core
packages/core/root/core-root-browser-internal @elastic/kibana-core
packages/core/saved-objects/core-saved-objects-api-browser @elastic/kibana-core
packages/core/saved-objects/core-saved-objects-api-server @elastic/kibana-core

View file

@ -254,6 +254,7 @@
"@kbn/core-overlays-browser": "link:bazel-bin/packages/core/overlays/core-overlays-browser",
"@kbn/core-overlays-browser-internal": "link:bazel-bin/packages/core/overlays/core-overlays-browser-internal",
"@kbn/core-overlays-browser-mocks": "link:bazel-bin/packages/core/overlays/core-overlays-browser-mocks",
"@kbn/core-plugins-base-server-internal": "link:bazel-bin/packages/core/plugins/core-plugins-base-server-internal",
"@kbn/core-plugins-browser": "link:bazel-bin/packages/core/plugins/core-plugins-browser",
"@kbn/core-plugins-browser-internal": "link:bazel-bin/packages/core/plugins/core-plugins-browser-internal",
"@kbn/core-plugins-browser-mocks": "link:bazel-bin/packages/core/plugins/core-plugins-browser-mocks",
@ -262,6 +263,8 @@
"@kbn/core-preboot-server-mocks": "link:bazel-bin/packages/core/preboot/core-preboot-server-mocks",
"@kbn/core-rendering-browser-internal": "link:bazel-bin/packages/core/rendering/core-rendering-browser-internal",
"@kbn/core-rendering-browser-mocks": "link:bazel-bin/packages/core/rendering/core-rendering-browser-mocks",
"@kbn/core-rendering-server-internal": "link:bazel-bin/packages/core/rendering/core-rendering-server-internal",
"@kbn/core-rendering-server-mocks": "link:bazel-bin/packages/core/rendering/core-rendering-server-mocks",
"@kbn/core-root-browser-internal": "link:bazel-bin/packages/core/root/core-root-browser-internal",
"@kbn/core-saved-objects-api-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-browser",
"@kbn/core-saved-objects-api-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-server",
@ -978,6 +981,7 @@
"@types/kbn__core-overlays-browser": "link:bazel-bin/packages/core/overlays/core-overlays-browser/npm_module_types",
"@types/kbn__core-overlays-browser-internal": "link:bazel-bin/packages/core/overlays/core-overlays-browser-internal/npm_module_types",
"@types/kbn__core-overlays-browser-mocks": "link:bazel-bin/packages/core/overlays/core-overlays-browser-mocks/npm_module_types",
"@types/kbn__core-plugins-base-server-internal": "link:bazel-bin/packages/core/plugins/core-plugins-base-server-internal/npm_module_types",
"@types/kbn__core-plugins-browser": "link:bazel-bin/packages/core/plugins/core-plugins-browser/npm_module_types",
"@types/kbn__core-plugins-browser-internal": "link:bazel-bin/packages/core/plugins/core-plugins-browser-internal/npm_module_types",
"@types/kbn__core-plugins-browser-mocks": "link:bazel-bin/packages/core/plugins/core-plugins-browser-mocks/npm_module_types",
@ -987,6 +991,8 @@
"@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types",
"@types/kbn__core-rendering-browser-internal": "link:bazel-bin/packages/core/rendering/core-rendering-browser-internal/npm_module_types",
"@types/kbn__core-rendering-browser-mocks": "link:bazel-bin/packages/core/rendering/core-rendering-browser-mocks/npm_module_types",
"@types/kbn__core-rendering-server-internal": "link:bazel-bin/packages/core/rendering/core-rendering-server-internal/npm_module_types",
"@types/kbn__core-rendering-server-mocks": "link:bazel-bin/packages/core/rendering/core-rendering-server-mocks/npm_module_types",
"@types/kbn__core-root-browser-internal": "link:bazel-bin/packages/core/root/core-root-browser-internal/npm_module_types",
"@types/kbn__core-saved-objects-api-browser": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-browser/npm_module_types",
"@types/kbn__core-saved-objects-api-server": "link:bazel-bin/packages/core/saved-objects/core-saved-objects-api-server/npm_module_types",

View file

@ -120,6 +120,7 @@ filegroup(
"//packages/core/overlays/core-overlays-browser:build",
"//packages/core/overlays/core-overlays-browser-internal:build",
"//packages/core/overlays/core-overlays-browser-mocks:build",
"//packages/core/plugins/core-plugins-base-server-internal:build",
"//packages/core/plugins/core-plugins-browser:build",
"//packages/core/plugins/core-plugins-browser-internal:build",
"//packages/core/plugins/core-plugins-browser-mocks:build",
@ -128,6 +129,8 @@ filegroup(
"//packages/core/preboot/core-preboot-server-mocks:build",
"//packages/core/rendering/core-rendering-browser-internal:build",
"//packages/core/rendering/core-rendering-browser-mocks:build",
"//packages/core/rendering/core-rendering-server-internal:build",
"//packages/core/rendering/core-rendering-server-mocks:build",
"//packages/core/root/core-root-browser-internal:build",
"//packages/core/saved-objects/core-saved-objects-api-browser:build",
"//packages/core/saved-objects/core-saved-objects-api-server:build",
@ -454,6 +457,7 @@ filegroup(
"//packages/core/overlays/core-overlays-browser:build_types",
"//packages/core/overlays/core-overlays-browser-internal:build_types",
"//packages/core/overlays/core-overlays-browser-mocks:build_types",
"//packages/core/plugins/core-plugins-base-server-internal:build_types",
"//packages/core/plugins/core-plugins-browser:build_types",
"//packages/core/plugins/core-plugins-browser-internal:build_types",
"//packages/core/plugins/core-plugins-browser-mocks:build_types",
@ -462,6 +466,8 @@ filegroup(
"//packages/core/preboot/core-preboot-server-mocks:build_types",
"//packages/core/rendering/core-rendering-browser-internal:build_types",
"//packages/core/rendering/core-rendering-browser-mocks:build_types",
"//packages/core/rendering/core-rendering-server-internal:build_types",
"//packages/core/rendering/core-rendering-server-mocks:build_types",
"//packages/core/root/core-root-browser-internal:build_types",
"//packages/core/saved-objects/core-saved-objects-api-browser:build_types",
"//packages/core/saved-objects/core-saved-objects-api-server:build_types",

View file

@ -0,0 +1,107 @@
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-plugins-base-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-plugins-base-server-internal"
SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//rxjs",
"//packages/core/base/core-base-common: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",
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"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-plugins-base-server-internal
This package contains base internal types of the `plugins` domain used across other core domains.

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export type { UiPlugins, InternalPluginInfo } from './src';

View 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/core/plugins/core-plugins-base-server-internal'],
};

View file

@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/core-plugins-base-server-internal",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-plugins-base-server-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export type { UiPlugins, InternalPluginInfo } from './types';

View file

@ -0,0 +1,51 @@
/*
* 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 { Observable } from 'rxjs';
import type { DiscoveredPlugin, PluginName } from '@kbn/core-base-common';
/** @internal */
export interface UiPlugins {
/**
* Paths to all discovered ui plugin entrypoints on the filesystem, even if
* disabled.
*/
internal: Map<PluginName, InternalPluginInfo>;
/**
* Information needed by client-side to load plugins and wire dependencies.
*/
public: Map<PluginName, DiscoveredPlugin>;
/**
* Configuration for plugins to be exposed to the client-side.
*/
browserConfigs: Map<PluginName, Observable<unknown>>;
}
/**
* @internal
*/
export interface InternalPluginInfo {
/**
* Version of the plugin
*/
readonly version: string;
/**
* Bundles that must be loaded for this plugin
*/
readonly requiredBundles: readonly string[];
/**
* Path to the target/public directory of the plugin which should be served
*/
readonly publicTargetDir: string;
/**
* Path to the plugin assets directory.
*/
readonly publicAssetsDir: string;
}

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}

View file

@ -0,0 +1,127 @@
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-rendering-server-internal"
PKG_REQUIRE_NAME = "@kbn/core-rendering-server-internal"
SOURCE_FILES = glob(
[
"**/*.ts",
"**/*.tsx",
],
exclude = [
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
"@npm//react",
"@npm//react-dom",
"@npm//rxjs",
"//packages/kbn-i18n",
"//packages/kbn-ui-shared-deps-npm",
"//packages/kbn-ui-shared-deps-src",
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//@types/react",
"@npm//@types/react-dom",
"@npm//rxjs",
"//packages/kbn-i18n:npm_module_types",
"//packages/kbn-ui-shared-deps-npm:npm_module_types",
"//packages/kbn-ui-shared-deps-src:npm_module_types",
"//packages/core/base/core-base-server-internal:npm_module_types",
"//packages/core/injected-metadata/core-injected-metadata-common-internal:npm_module_types",
"//packages/core/http/core-http-server:npm_module_types",
"//packages/core/http/core-http-server-internal:npm_module_types",
"//packages/core/elasticsearch/core-elasticsearch-server-internal:npm_module_types",
"//packages/core/status/core-status-server-internal:npm_module_types",
"//packages/core/ui-settings/core-ui-settings-common:npm_module_types",
"//packages/core/ui-settings/core-ui-settings-server:npm_module_types",
"//packages/core/plugins/core-plugins-base-server-internal: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",
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"],
)

View file

@ -0,0 +1,3 @@
# @kbn/core-rendering-server-internal
This package contains the internal types and implementation for Core's server-side rendering service.

View file

@ -0,0 +1,17 @@
/*
* 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.
*/
export { RenderingService, Fonts } from './src';
export type {
InternalRenderingServicePreboot,
InternalRenderingServiceSetup,
IRenderOptions,
RenderingMetadata,
RenderingPrebootDeps,
RenderingSetupDeps,
} from './src';

View 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/core/rendering/core-rendering-server-internal'],
};

View file

@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/core-rendering-server-internal",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-rendering-server-internal",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -15,7 +15,7 @@ import {
import { PackageInfo } from '@kbn/config';
import { AuthStatus } from '@kbn/core-http-server';
import { UiPlugins } from '../../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
import { bootstrapRendererFactory, BootstrapRenderer } from './bootstrap_renderer';

View file

@ -11,7 +11,7 @@ import { PackageInfo } from '@kbn/config';
import { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import type { KibanaRequest, HttpAuth } from '@kbn/core-http-server';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import { UiPlugins } from '../../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { getPluginsBundlePaths } from './get_plugin_bundle_paths';
import { getJsDependencyPaths } from './get_js_dependency_paths';
import { getThemeTag } from './get_theme_tag';

View file

@ -6,7 +6,8 @@
* Side Public License, v 1.
*/
import { InternalPluginInfo, PluginType, UiPlugins } from '../../plugins';
import { PluginType } from '@kbn/core-base-common';
import type { InternalPluginInfo, UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { getPluginsBundlePaths } from './get_plugin_bundle_paths';
const createUiPlugins = (pluginDeps: Record<string, string[]>) => {

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { UiPlugins } from '../../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { filterUiPlugins } from '../filter_ui_plugins';
export interface PluginInfo {

View file

@ -6,7 +6,8 @@
* Side Public License, v 1.
*/
import type { DiscoveredPlugin, PluginName, UiPlugins } from '../plugins';
import type { PluginName, DiscoveredPlugin } from '@kbn/core-base-common';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { filterUiPlugins } from './filter_ui_plugins';
function createMockPlugin(params: Partial<DiscoveredPlugin>) {

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import type { UiPlugins } from '../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
/**
* Gets the array of plugins that should be enabled on the page.

View file

@ -7,6 +7,7 @@
*/
export { RenderingService } from './rendering_service';
export { Fonts } from './views';
export type {
InternalRenderingServicePreboot,
InternalRenderingServiceSetup,

View file

@ -22,7 +22,7 @@ import {
mockRenderingServiceParams,
mockRenderingPrebootDeps,
mockRenderingSetupDeps,
} from './__mocks__/params';
} from './test_helpers/params';
import { InternalRenderingServicePreboot, InternalRenderingServiceSetup } from './types';
import { RenderingService } from './rendering_service';
import { AuthStatus } from '@kbn/core-http-server';

View file

@ -8,15 +8,15 @@
import React from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { firstValueFrom, of } from 'rxjs';
import { catchError, take, timeout } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import { firstValueFrom, of } from 'rxjs';
import type { CoreContext } from '@kbn/core-base-server-internal';
import type { KibanaRequest, HttpAuth } from '@kbn/core-http-server';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import type { UiPlugins } from '../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { Template } from './views';
import {
IRenderOptions,

View file

@ -10,7 +10,6 @@ import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { statusServiceMock } from '@kbn/core-status-server-mocks';
import { pluginServiceMock } from '../../plugins/plugins_service.mock';
const context = mockCoreContext.create();
const httpPreboot = httpServiceMock.createInternalPrebootContract();
@ -18,14 +17,22 @@ const httpSetup = httpServiceMock.createInternalSetupContract();
const status = statusServiceMock.createInternalSetupContract();
const elasticsearch = elasticsearchServiceMock.createInternalSetup();
function createUiPlugins() {
return {
browserConfigs: new Map(),
internal: new Map(),
public: new Map(),
};
}
export const mockRenderingServiceParams = context;
export const mockRenderingPrebootDeps = {
http: httpPreboot,
uiPlugins: pluginServiceMock.createUiPlugins(),
uiPlugins: createUiPlugins(),
};
export const mockRenderingSetupDeps = {
elasticsearch,
http: httpSetup,
uiPlugins: pluginServiceMock.createUiPlugins(),
uiPlugins: createUiPlugins(),
status,
};

View file

@ -17,7 +17,7 @@ import type {
import type { InternalElasticsearchServiceSetup } from '@kbn/core-elasticsearch-server-internal';
import type { InternalStatusServiceSetup } from '@kbn/core-status-server-internal';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import { UiPlugins } from '../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
/** @internal */
export interface RenderingMetadata {
@ -46,7 +46,7 @@ export interface RenderingSetupDeps {
uiPlugins: UiPlugins;
}
/** @public */
/** @internal */
export interface IRenderOptions {
/**
* Set whether the page is anonymous, which determines what plugins are enabled and whether to output user settings in the page metadata.

View file

@ -7,3 +7,4 @@
*/
export { Template } from './template';
export { Fonts } from './fonts';

View file

@ -0,0 +1,19 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node",
"react",
]
},
"include": [
"**/*.ts",
"**/*.tsx",
]
}

View file

@ -0,0 +1,106 @@
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-rendering-server-mocks"
PKG_REQUIRE_NAME = "@kbn/core-rendering-server-mocks"
SOURCE_FILES = glob(
[
"**/*.ts",
],
exclude = [
"**/*.config.js",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
RUNTIME_DEPS = [
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"//packages/kbn-utility-types:npm_module_types",
"//packages/core/rendering/core-rendering-server-internal: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",
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"],
)

View file

@ -0,0 +1,4 @@
# @kbn/core-rendering-server-mocks
This package contains mocks for Core's server-side rendering service.
- `renderingServiceMock`

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export { renderingServiceMock } from './src';

View 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/core/rendering/core-rendering-server-mocks'],
};

View file

@ -0,0 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/core-rendering-server-mocks",
"owner": "@elastic/kibana-core",
"runtimeDeps": [],
"typeDeps": [],
}

View file

@ -0,0 +1,8 @@
{
"name": "@kbn/core-rendering-server-mocks",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"author": "Kibana Core",
"license": "SSPL-1.0 OR Elastic License 2.0"
}

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export { renderingServiceMock } from './rendering_service.mock';

View file

@ -6,7 +6,14 @@
* Side Public License, v 1.
*/
import { InternalRenderingServicePreboot, InternalRenderingServiceSetup } from './types';
import type { PublicMethodsOf } from '@kbn/utility-types';
import type {
InternalRenderingServicePreboot,
InternalRenderingServiceSetup,
RenderingService,
} from '@kbn/core-rendering-server-internal';
export type RenderingServiceMock = jest.Mocked<PublicMethodsOf<RenderingService>>;
function createRenderingPreboot() {
const mocked: jest.Mocked<InternalRenderingServicePreboot> = {
@ -22,7 +29,21 @@ function createRenderingSetup() {
return mocked;
}
export const renderingMock = {
function createRenderingService() {
const mock: RenderingServiceMock = {
preboot: jest.fn(),
setup: jest.fn(),
stop: jest.fn(),
};
mock.preboot.mockResolvedValue(createRenderingPreboot());
mock.setup.mockResolvedValue(createRenderingSetup());
return mock;
}
export const renderingServiceMock = {
create: createRenderingService,
createPrebootContract: createRenderingPreboot,
createSetupContract: createRenderingSetup,
};

View file

@ -0,0 +1,17 @@
{
"extends": "../../../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
]
}

View file

@ -10,7 +10,7 @@ import { registerRouteForBundleMock } from './register_bundle_routes.test.mocks'
import { PackageInfo } from '@kbn/config';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
import { InternalPluginInfo, UiPlugins } from '../../plugins';
import type { InternalPluginInfo, UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { registerBundleRoutes } from './register_bundle_routes';
import { FileHashCache } from './file_hash_cache';

View file

@ -12,7 +12,7 @@ import { fromRoot } from '@kbn/utils';
import UiSharedDepsNpm from '@kbn/ui-shared-deps-npm';
import * as UiSharedDepsSrc from '@kbn/ui-shared-deps-src';
import type { IRouter } from '@kbn/core-http-server';
import { UiPlugins } from '../../plugins';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { FileHashCache } from './file_hash_cache';
import { registerRouteForBundle } from './bundles_route';

View file

@ -10,9 +10,9 @@ import { registerBundleRoutesMock } from './core_app.test.mocks';
import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { mockRouter } from '@kbn/core-http-router-server-mocks';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { coreMock, httpServerMock } from '../mocks';
import { httpResourcesMock } from '../http_resources/http_resources_service.mock';
import type { UiPlugins } from '../plugins';
import { PluginType } from '../plugins';
import { CoreApp } from './core_app';
import { RequestHandlerContext } from '..';

View file

@ -20,10 +20,10 @@ import type {
KibanaRequest,
IBasePath,
} from '@kbn/core-http-server';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { HttpResources, HttpResourcesServiceToolkit } from '../http_resources';
import { InternalCorePreboot, InternalCoreSetup } from '../internal_types';
import { registerBundleRoutes } from './bundle_routes';
import { UiPlugins } from '../plugins';
import type { InternalCoreAppRequestHandlerContext } from './internal_types';
/** @internal */

View file

@ -13,7 +13,7 @@ import type { RouteConfig } from '@kbn/core-http-server';
import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { coreMock } from '../mocks';
import { renderingMock } from '../rendering/rendering_service.mock';
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
import { HttpResourcesService, PrebootDeps, SetupDeps } from './http_resources_service';
import { httpResourcesMock } from './http_resources_service.mock';
import { HttpResources } from '..';
@ -37,11 +37,11 @@ describe('HttpResources service', () => {
beforeEach(() => {
prebootDeps = {
http: httpServiceMock.createInternalPrebootContract(),
rendering: renderingMock.createPrebootContract(),
rendering: renderingServiceMock.createPrebootContract(),
};
setupDeps = {
http: httpServiceMock.createInternalSetupContract(),
rendering: renderingMock.createSetupContract(),
rendering: renderingServiceMock.createSetupContract(),
};
service = new HttpResourcesService(coreContext);
router = httpServiceMock.createRouter();

View file

@ -18,8 +18,11 @@ import type {
InternalHttpServiceSetup,
InternalHttpServicePreboot,
} from '@kbn/core-http-server-internal';
import type {
InternalRenderingServicePreboot,
InternalRenderingServiceSetup,
} from '@kbn/core-rendering-server-internal';
import type { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server';
import { InternalRenderingServicePreboot, InternalRenderingServiceSetup } from '../rendering';
import {
InternalHttpResourcesSetup,
HttpResources,

View file

@ -230,7 +230,6 @@ export type {
HttpResourcesRequestHandler,
} from './http_resources';
export type { IRenderOptions } from './rendering';
export type {
LoggingServiceSetup,
LoggerContextConfigInput,

View file

@ -58,7 +58,7 @@ import type {
InternalUiSettingsServiceSetup,
InternalUiSettingsServiceStart,
} from '@kbn/core-ui-settings-server-internal';
import { InternalRenderingServiceSetup } from './rendering';
import type { InternalRenderingServiceSetup } from '@kbn/core-rendering-server-internal';
import { InternalHttpResourcesPreboot, InternalHttpResourcesSetup } from './http_resources';
/** @internal */

View file

@ -31,6 +31,7 @@ import { coreUsageDataServiceMock } from '@kbn/core-usage-data-server-mocks';
import { i18nServiceMock } from '@kbn/core-i18n-server-mocks';
import { statusServiceMock } from '@kbn/core-status-server-mocks';
import { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
import type {
PluginInitializerContext,
CoreSetup,
@ -40,7 +41,6 @@ import type {
RequestHandlerContext,
} from '.';
import { httpResourcesMock } from './http_resources/http_resources_service.mock';
import { renderingMock } from './rendering/rendering_service.mock';
import { SharedGlobalConfig } from './plugins';
export { configServiceMock, configDeprecationsMock } from '@kbn/config-mocks';
@ -57,7 +57,7 @@ export {
export { migrationMocks } from '@kbn/core-saved-objects-migration-server-mocks';
export { uiSettingsServiceMock } from '@kbn/core-ui-settings-server-mocks';
export { metricsServiceMock } from '@kbn/core-metrics-server-mocks';
export { renderingMock } from './rendering/rendering_service.mock';
export { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
export { statusServiceMock } from '@kbn/core-status-server-mocks';
export { contextServiceMock } from '@kbn/core-http-context-server-mocks';
export { capabilitiesServiceMock } from '@kbn/core-capabilities-server-mocks';
@ -237,7 +237,7 @@ function createInternalCoreSetupMock() {
environment: environmentServiceMock.createSetupContract(),
i18n: i18nServiceMock.createSetupContract(),
httpResources: httpResourcesMock.createSetupContract(),
rendering: renderingMock.createSetupContract(),
rendering: renderingServiceMock.createSetupContract(),
uiSettings: uiSettingsServiceMock.createSetupContract(),
logging: loggingServiceMock.createInternalSetupContract(),
metrics: metricsServiceMock.createInternalSetupContract(),

View file

@ -10,7 +10,6 @@ export { PluginsService } from './plugins_service';
export type {
PluginsServiceSetup,
PluginsServiceStart,
UiPlugins,
DiscoveredPlugins,
} from './plugins_service';
export { config } from './plugins_config';

View file

@ -17,15 +17,10 @@ import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import type { PluginName } from '@kbn/core-base-common';
import type { InternalEnvironmentServicePreboot } from '@kbn/core-environment-server-internal';
import type { InternalNodeServicePreboot } from '@kbn/core-node-server-internal';
import type { InternalPluginInfo, UiPlugins } from '@kbn/core-plugins-base-server-internal';
import { discover, PluginDiscoveryError, PluginDiscoveryErrorType } from './discovery';
import { PluginWrapper } from './plugin';
import {
DiscoveredPlugin,
InternalPluginInfo,
PluginConfigDescriptor,
PluginDependencies,
PluginType,
} from './types';
import { DiscoveredPlugin, PluginConfigDescriptor, PluginDependencies, PluginType } from './types';
import { PluginsConfig, PluginsConfigType } from './plugins_config';
import { PluginsSystem } from './plugins_system';
import { createBrowserConfig } from './create_browser_config';
@ -48,25 +43,6 @@ export interface PluginsServiceSetup {
contracts: Map<PluginName, unknown>;
}
/** @internal */
export interface UiPlugins {
/**
* Paths to all discovered ui plugin entrypoints on the filesystem, even if
* disabled.
*/
internal: Map<PluginName, InternalPluginInfo>;
/**
* Information needed by client-side to load plugins and wire dependencies.
*/
public: Map<PluginName, DiscoveredPlugin>;
/**
* Configuration for plugins to be exposed to the client-side.
*/
browserConfigs: Map<PluginName, Observable<unknown>>;
}
/** @internal */
export interface PluginsServiceStart {
/** Start contracts returned by plugins. */

View file

@ -254,28 +254,6 @@ export interface PluginManifest {
readonly enabledOnAnonymousPages?: boolean;
}
/**
* @internal
*/
export interface InternalPluginInfo {
/**
* Version of the plugin
*/
readonly version: string;
/**
* Bundles that must be loaded for this plugin
*/
readonly requiredBundles: readonly string[];
/**
* Path to the target/public directory of the plugin which should be served
*/
readonly publicTargetDir: string;
/**
* Path to the plugin assets directory.
*/
readonly publicAssetsDir: string;
}
/**
* The interface that should be returned by a `PluginInitializer` for a `preboot` plugin.
*

View file

@ -63,10 +63,12 @@ jest.doMock('@kbn/core-config-server-internal', () => ({
ensureValidConfiguration: mockEnsureValidConfiguration,
}));
import { RenderingService, mockRenderingService } from './rendering/__mocks__/rendering_service';
import { renderingServiceMock } from '@kbn/core-rendering-server-mocks';
export { mockRenderingService };
jest.doMock('./rendering/rendering_service', () => ({ RenderingService }));
export const mockRenderingService = renderingServiceMock.create();
jest.doMock('@kbn/core-rendering-server-internal', () => ({
RenderingService: jest.fn(() => mockRenderingService),
}));
import { environmentServiceMock } from '@kbn/core-environment-server-mocks';

View file

@ -66,10 +66,10 @@ import type {
RequestHandlerContext,
PrebootRequestHandlerContext,
} from '@kbn/core-http-request-handler-context-server';
import { RenderingService } from '@kbn/core-rendering-server-internal';
import { CoreApp } from './core_app';
import { HttpResourcesService } from './http_resources';
import { RenderingService } from './rendering';
import { PluginsService, config as pluginsConfig } from './plugins';
import { InternalCorePreboot, InternalCoreSetup, InternalCoreStart } from './internal_types';
import { DiscoveredPlugins } from './plugins';

View file

@ -12,7 +12,7 @@ import { coreMock } from '@kbn/core/server/mocks';
import { UnauthenticatedPage } from './unauthenticated_page';
jest.mock('@kbn/core/server/rendering/views/fonts', () => ({
jest.mock('@kbn/core-rendering-server-internal', () => ({
Fonts: () => <>MockedFonts</>,
}));

View file

@ -12,7 +12,7 @@ import { coreMock } from '@kbn/core/server/mocks';
import { ResetSessionPage } from './reset_session_page';
jest.mock('@kbn/core/server/rendering/views/fonts', () => ({
jest.mock('@kbn/core-rendering-server-internal', () => ({
Fonts: () => <>MockedFonts</>,
}));

View file

@ -12,7 +12,7 @@ import { coreMock } from '@kbn/core/server/mocks';
import { PromptPage } from './prompt_page';
jest.mock('@kbn/core/server/rendering/views/fonts', () => ({
jest.mock('@kbn/core-rendering-server-internal', () => ({
Fonts: () => <>MockedFonts</>,
}));

View file

@ -20,8 +20,8 @@ import createCache from '@emotion/cache';
import type { ReactNode } from 'react';
import React from 'react';
import { Fonts } from '@kbn/core-rendering-server-internal';
import type { IBasePath } from '@kbn/core/server';
import { Fonts } from '@kbn/core/server/rendering/views/fonts';
import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n-react';
import UiSharedDepsNpm from '@kbn/ui-shared-deps-npm';

View file

@ -3118,6 +3118,10 @@
version "0.0.0"
uid ""
"@kbn/core-plugins-base-server-internal@link:bazel-bin/packages/core/plugins/core-plugins-base-server-internal":
version "0.0.0"
uid ""
"@kbn/core-plugins-browser-internal@link:bazel-bin/packages/core/plugins/core-plugins-browser-internal":
version "0.0.0"
uid ""
@ -3150,6 +3154,14 @@
version "0.0.0"
uid ""
"@kbn/core-rendering-server-internal@link:bazel-bin/packages/core/rendering/core-rendering-server-internal":
version "0.0.0"
uid ""
"@kbn/core-rendering-server-mocks@link:bazel-bin/packages/core/rendering/core-rendering-server-mocks":
version "0.0.0"
uid ""
"@kbn/core-root-browser-internal@link:bazel-bin/packages/core/root/core-root-browser-internal":
version "0.0.0"
uid ""
@ -7251,6 +7263,10 @@
version "0.0.0"
uid ""
"@types/kbn__core-plugins-base-server-internal@link:bazel-bin/packages/core/plugins/core-plugins-base-server-internal/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-plugins-browser-internal@link:bazel-bin/packages/core/plugins/core-plugins-browser-internal/npm_module_types":
version "0.0.0"
uid ""
@ -7287,6 +7303,14 @@
version "0.0.0"
uid ""
"@types/kbn__core-rendering-server-internal@link:bazel-bin/packages/core/rendering/core-rendering-server-internal/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-rendering-server-mocks@link:bazel-bin/packages/core/rendering/core-rendering-server-mocks/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__core-root-browser-internal@link:bazel-bin/packages/core/root/core-root-browser-internal/npm_module_types":
version "0.0.0"
uid ""