Use plugin version in its publicPath (#95945)
* Use plugin version in its publicPath * remove useless comment * fix types * update generated doc
This commit is contained in:
parent
ea03eb1bab
commit
95e45ddebc
|
@ -10,7 +10,7 @@ import { registerRouteForBundleMock } from './register_bundle_routes.test.mocks'
|
||||||
|
|
||||||
import { PackageInfo } from '@kbn/config';
|
import { PackageInfo } from '@kbn/config';
|
||||||
import { httpServiceMock } from '../../http/http_service.mock';
|
import { httpServiceMock } from '../../http/http_service.mock';
|
||||||
import { UiPlugins } from '../../plugins';
|
import { InternalPluginInfo, UiPlugins } from '../../plugins';
|
||||||
import { registerBundleRoutes } from './register_bundle_routes';
|
import { registerBundleRoutes } from './register_bundle_routes';
|
||||||
import { FileHashCache } from './file_hash_cache';
|
import { FileHashCache } from './file_hash_cache';
|
||||||
|
|
||||||
|
@ -29,9 +29,12 @@ const createUiPlugins = (...ids: string[]): UiPlugins => ({
|
||||||
internal: ids.reduce((map, id) => {
|
internal: ids.reduce((map, id) => {
|
||||||
map.set(id, {
|
map.set(id, {
|
||||||
publicTargetDir: `/plugins/${id}/public-target-dir`,
|
publicTargetDir: `/plugins/${id}/public-target-dir`,
|
||||||
|
publicAssetsDir: `/plugins/${id}/public-assets-dir`,
|
||||||
|
version: '8.0.0',
|
||||||
|
requiredBundles: [],
|
||||||
});
|
});
|
||||||
return map;
|
return map;
|
||||||
}, new Map()),
|
}, new Map<string, InternalPluginInfo>()),
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('registerBundleRoutes', () => {
|
describe('registerBundleRoutes', () => {
|
||||||
|
@ -86,16 +89,16 @@ describe('registerBundleRoutes', () => {
|
||||||
fileHashCache: expect.any(FileHashCache),
|
fileHashCache: expect.any(FileHashCache),
|
||||||
isDist: true,
|
isDist: true,
|
||||||
bundlesPath: '/plugins/plugin-a/public-target-dir',
|
bundlesPath: '/plugins/plugin-a/public-target-dir',
|
||||||
publicPath: '/server-base-path/42/bundles/plugin/plugin-a/',
|
publicPath: '/server-base-path/42/bundles/plugin/plugin-a/8.0.0/',
|
||||||
routePath: '/42/bundles/plugin/plugin-a/',
|
routePath: '/42/bundles/plugin/plugin-a/8.0.0/',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(registerRouteForBundleMock).toHaveBeenCalledWith(router, {
|
expect(registerRouteForBundleMock).toHaveBeenCalledWith(router, {
|
||||||
fileHashCache: expect.any(FileHashCache),
|
fileHashCache: expect.any(FileHashCache),
|
||||||
isDist: true,
|
isDist: true,
|
||||||
bundlesPath: '/plugins/plugin-b/public-target-dir',
|
bundlesPath: '/plugins/plugin-b/public-target-dir',
|
||||||
publicPath: '/server-base-path/42/bundles/plugin/plugin-b/',
|
publicPath: '/server-base-path/42/bundles/plugin/plugin-b/8.0.0/',
|
||||||
routePath: '/42/bundles/plugin/plugin-b/',
|
routePath: '/42/bundles/plugin/plugin-b/8.0.0/',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,7 +27,7 @@ import { registerRouteForBundle } from './bundles_route';
|
||||||
*/
|
*/
|
||||||
export function registerBundleRoutes({
|
export function registerBundleRoutes({
|
||||||
router,
|
router,
|
||||||
serverBasePath, // serverBasePath
|
serverBasePath,
|
||||||
uiPlugins,
|
uiPlugins,
|
||||||
packageInfo,
|
packageInfo,
|
||||||
}: {
|
}: {
|
||||||
|
@ -57,10 +57,10 @@ export function registerBundleRoutes({
|
||||||
isDist,
|
isDist,
|
||||||
});
|
});
|
||||||
|
|
||||||
[...uiPlugins.internal.entries()].forEach(([id, { publicTargetDir }]) => {
|
[...uiPlugins.internal.entries()].forEach(([id, { publicTargetDir, version }]) => {
|
||||||
registerRouteForBundle(router, {
|
registerRouteForBundle(router, {
|
||||||
publicPath: `${serverBasePath}/${buildNum}/bundles/plugin/${id}/`,
|
publicPath: `${serverBasePath}/${buildNum}/bundles/plugin/${id}/${version}/`,
|
||||||
routePath: `/${buildNum}/bundles/plugin/${id}/`,
|
routePath: `/${buildNum}/bundles/plugin/${id}/${version}/`,
|
||||||
bundlesPath: publicTargetDir,
|
bundlesPath: publicTargetDir,
|
||||||
fileHashCache,
|
fileHashCache,
|
||||||
isDist,
|
isDist,
|
||||||
|
|
|
@ -91,6 +91,7 @@ beforeEach(() => {
|
||||||
'plugin-id',
|
'plugin-id',
|
||||||
{
|
{
|
||||||
requiredBundles: [],
|
requiredBundles: [],
|
||||||
|
version: '8.0.0',
|
||||||
publicTargetDir: 'path/to/target/public',
|
publicTargetDir: 'path/to/target/public',
|
||||||
publicAssetsDir: '/plugins/name/assets/',
|
publicAssetsDir: '/plugins/name/assets/',
|
||||||
},
|
},
|
||||||
|
|
|
@ -562,12 +562,12 @@ describe('PluginsService', () => {
|
||||||
plugin$: from([
|
plugin$: from([
|
||||||
createPlugin('plugin-1', {
|
createPlugin('plugin-1', {
|
||||||
path: 'path-1',
|
path: 'path-1',
|
||||||
version: 'some-version',
|
version: 'version-1',
|
||||||
configPath: 'plugin1',
|
configPath: 'plugin1',
|
||||||
}),
|
}),
|
||||||
createPlugin('plugin-2', {
|
createPlugin('plugin-2', {
|
||||||
path: 'path-2',
|
path: 'path-2',
|
||||||
version: 'some-version',
|
version: 'version-2',
|
||||||
configPath: 'plugin2',
|
configPath: 'plugin2',
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
|
@ -577,7 +577,7 @@ describe('PluginsService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('uiPlugins.internal', () => {
|
describe('uiPlugins.internal', () => {
|
||||||
it('includes disabled plugins', async () => {
|
it('contains internal properties for plugins', async () => {
|
||||||
config$.next({ plugins: { initialize: true }, plugin1: { enabled: false } });
|
config$.next({ plugins: { initialize: true }, plugin1: { enabled: false } });
|
||||||
const { uiPlugins } = await pluginsService.discover({ environment: environmentSetup });
|
const { uiPlugins } = await pluginsService.discover({ environment: environmentSetup });
|
||||||
expect(uiPlugins.internal).toMatchInlineSnapshot(`
|
expect(uiPlugins.internal).toMatchInlineSnapshot(`
|
||||||
|
@ -586,15 +586,23 @@ describe('PluginsService', () => {
|
||||||
"publicAssetsDir": <absolute path>/path-1/public/assets,
|
"publicAssetsDir": <absolute path>/path-1/public/assets,
|
||||||
"publicTargetDir": <absolute path>/path-1/target/public,
|
"publicTargetDir": <absolute path>/path-1/target/public,
|
||||||
"requiredBundles": Array [],
|
"requiredBundles": Array [],
|
||||||
|
"version": "version-1",
|
||||||
},
|
},
|
||||||
"plugin-2" => Object {
|
"plugin-2" => Object {
|
||||||
"publicAssetsDir": <absolute path>/path-2/public/assets,
|
"publicAssetsDir": <absolute path>/path-2/public/assets,
|
||||||
"publicTargetDir": <absolute path>/path-2/target/public,
|
"publicTargetDir": <absolute path>/path-2/target/public,
|
||||||
"requiredBundles": Array [],
|
"requiredBundles": Array [],
|
||||||
|
"version": "version-2",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes disabled plugins', async () => {
|
||||||
|
config$.next({ plugins: { initialize: true }, plugin1: { enabled: false } });
|
||||||
|
const { uiPlugins } = await pluginsService.discover({ environment: environmentSetup });
|
||||||
|
expect([...uiPlugins.internal.keys()].sort()).toEqual(['plugin-1', 'plugin-2']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('plugin initialization', () => {
|
describe('plugin initialization', () => {
|
||||||
|
|
|
@ -222,6 +222,7 @@ export class PluginsService implements CoreService<PluginsServiceSetup, PluginsS
|
||||||
if (plugin.includesUiPlugin) {
|
if (plugin.includesUiPlugin) {
|
||||||
this.uiPluginInternalInfo.set(plugin.name, {
|
this.uiPluginInternalInfo.set(plugin.name, {
|
||||||
requiredBundles: plugin.requiredBundles,
|
requiredBundles: plugin.requiredBundles,
|
||||||
|
version: plugin.manifest.version,
|
||||||
publicTargetDir: Path.resolve(plugin.path, 'target/public'),
|
publicTargetDir: Path.resolve(plugin.path, 'target/public'),
|
||||||
publicAssetsDir: Path.resolve(plugin.path, 'public/assets'),
|
publicAssetsDir: Path.resolve(plugin.path, 'public/assets'),
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { PluginsServiceSetupDeps, PluginsServiceStartDeps } from './plugins_serv
|
||||||
import { PluginDependencies } from '.';
|
import { PluginDependencies } from '.';
|
||||||
|
|
||||||
const Sec = 1000;
|
const Sec = 1000;
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export class PluginsSystem {
|
export class PluginsSystem {
|
||||||
private readonly plugins = new Map<PluginName, PluginWrapper>();
|
private readonly plugins = new Map<PluginName, PluginWrapper>();
|
||||||
|
|
|
@ -224,12 +224,15 @@ export interface DiscoveredPlugin {
|
||||||
*/
|
*/
|
||||||
export interface InternalPluginInfo {
|
export interface InternalPluginInfo {
|
||||||
/**
|
/**
|
||||||
* Bundles that must be loaded for this plugoin
|
* Version of the plugin
|
||||||
|
*/
|
||||||
|
readonly version: string;
|
||||||
|
/**
|
||||||
|
* Bundles that must be loaded for this plugin
|
||||||
*/
|
*/
|
||||||
readonly requiredBundles: readonly string[];
|
readonly requiredBundles: readonly string[];
|
||||||
/**
|
/**
|
||||||
* Path to the target/public directory of the plugin which should be
|
* Path to the target/public directory of the plugin which should be served
|
||||||
* served
|
|
||||||
*/
|
*/
|
||||||
readonly publicTargetDir: string;
|
readonly publicTargetDir: string;
|
||||||
/**
|
/**
|
||||||
|
@ -250,7 +253,9 @@ export interface Plugin<
|
||||||
TPluginsStart extends object = object
|
TPluginsStart extends object = object
|
||||||
> {
|
> {
|
||||||
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup;
|
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup;
|
||||||
|
|
||||||
start(core: CoreStart, plugins: TPluginsStart): TStart;
|
start(core: CoreStart, plugins: TPluginsStart): TStart;
|
||||||
|
|
||||||
stop?(): void;
|
stop?(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +272,9 @@ export interface AsyncPlugin<
|
||||||
TPluginsStart extends object = object
|
TPluginsStart extends object = object
|
||||||
> {
|
> {
|
||||||
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
|
setup(core: CoreSetup, plugins: TPluginsSetup): TSetup | Promise<TSetup>;
|
||||||
|
|
||||||
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
|
start(core: CoreStart, plugins: TPluginsStart): TStart | Promise<TStart>;
|
||||||
|
|
||||||
stop?(): void;
|
stop?(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Side Public License, v 1.
|
* Side Public License, v 1.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { UiPlugins } from '../../plugins';
|
import { InternalPluginInfo, UiPlugins } from '../../plugins';
|
||||||
import { getPluginsBundlePaths } from './get_plugin_bundle_paths';
|
import { getPluginsBundlePaths } from './get_plugin_bundle_paths';
|
||||||
|
|
||||||
const createUiPlugins = (pluginDeps: Record<string, string[]>) => {
|
const createUiPlugins = (pluginDeps: Record<string, string[]>) => {
|
||||||
|
@ -16,12 +16,13 @@ const createUiPlugins = (pluginDeps: Record<string, string[]>) => {
|
||||||
browserConfigs: new Map(),
|
browserConfigs: new Map(),
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.entries(pluginDeps).forEach(([pluginId, deps]) => {
|
const addPlugin = (pluginId: string, deps: string[]) => {
|
||||||
uiPlugins.internal.set(pluginId, {
|
uiPlugins.internal.set(pluginId, {
|
||||||
requiredBundles: deps,
|
requiredBundles: deps,
|
||||||
|
version: '8.0.0',
|
||||||
publicTargetDir: '',
|
publicTargetDir: '',
|
||||||
publicAssetsDir: '',
|
publicAssetsDir: '',
|
||||||
} as any);
|
} as InternalPluginInfo);
|
||||||
uiPlugins.public.set(pluginId, {
|
uiPlugins.public.set(pluginId, {
|
||||||
id: pluginId,
|
id: pluginId,
|
||||||
configPath: 'config-path',
|
configPath: 'config-path',
|
||||||
|
@ -29,6 +30,12 @@ const createUiPlugins = (pluginDeps: Record<string, string[]>) => {
|
||||||
requiredPlugins: [],
|
requiredPlugins: [],
|
||||||
requiredBundles: deps,
|
requiredBundles: deps,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
deps.forEach((dep) => addPlugin(dep, []));
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.entries(pluginDeps).forEach(([pluginId, deps]) => {
|
||||||
|
addPlugin(pluginId, deps);
|
||||||
});
|
});
|
||||||
|
|
||||||
return uiPlugins;
|
return uiPlugins;
|
||||||
|
@ -56,13 +63,13 @@ describe('getPluginsBundlePaths', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(pluginBundlePaths.get('a')).toEqual({
|
expect(pluginBundlePaths.get('a')).toEqual({
|
||||||
bundlePath: '/regular-bundle-path/plugin/a/a.plugin.js',
|
bundlePath: '/regular-bundle-path/plugin/a/8.0.0/a.plugin.js',
|
||||||
publicPath: '/regular-bundle-path/plugin/a/',
|
publicPath: '/regular-bundle-path/plugin/a/8.0.0/',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(pluginBundlePaths.get('b')).toEqual({
|
expect(pluginBundlePaths.get('b')).toEqual({
|
||||||
bundlePath: '/regular-bundle-path/plugin/b/b.plugin.js',
|
bundlePath: '/regular-bundle-path/plugin/b/8.0.0/b.plugin.js',
|
||||||
publicPath: '/regular-bundle-path/plugin/b/',
|
publicPath: '/regular-bundle-path/plugin/b/8.0.0/',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,9 +25,15 @@ export const getPluginsBundlePaths = ({
|
||||||
|
|
||||||
while (pluginsToProcess.length > 0) {
|
while (pluginsToProcess.length > 0) {
|
||||||
const pluginId = pluginsToProcess.pop() as string;
|
const pluginId = pluginsToProcess.pop() as string;
|
||||||
|
const plugin = uiPlugins.internal.get(pluginId);
|
||||||
|
if (!plugin) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const { version } = plugin;
|
||||||
|
|
||||||
pluginBundlePaths.set(pluginId, {
|
pluginBundlePaths.set(pluginId, {
|
||||||
publicPath: `${regularBundlePath}/plugin/${pluginId}/`,
|
publicPath: `${regularBundlePath}/plugin/${pluginId}/${version}/`,
|
||||||
bundlePath: `${regularBundlePath}/plugin/${pluginId}/${pluginId}.plugin.js`,
|
bundlePath: `${regularBundlePath}/plugin/${pluginId}/${version}/${pluginId}.plugin.js`,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pluginBundleIds = uiPlugins.internal.get(pluginId)?.requiredBundles ?? [];
|
const pluginBundleIds = uiPlugins.internal.get(pluginId)?.requiredBundles ?? [];
|
||||||
|
|
|
@ -3259,9 +3259,9 @@ export const validBodyOutput: readonly ["data", "stream"];
|
||||||
//
|
//
|
||||||
// src/core/server/elasticsearch/client/types.ts:94:7 - (ae-forgotten-export) The symbol "Explanation" needs to be exported by the entry point index.d.ts
|
// src/core/server/elasticsearch/client/types.ts:94:7 - (ae-forgotten-export) The symbol "Explanation" needs to be exported by the entry point index.d.ts
|
||||||
// src/core/server/http/router/response.ts:297:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts
|
// src/core/server/http/router/response.ts:297:3 - (ae-forgotten-export) The symbol "KibanaResponse" needs to be exported by the entry point index.d.ts
|
||||||
// src/core/server/plugins/types.ts:286:3 - (ae-forgotten-export) The symbol "KibanaConfigType" needs to be exported by the entry point index.d.ts
|
// src/core/server/plugins/types.ts:293:3 - (ae-forgotten-export) The symbol "KibanaConfigType" needs to be exported by the entry point index.d.ts
|
||||||
// src/core/server/plugins/types.ts:286:3 - (ae-forgotten-export) The symbol "SharedGlobalConfigKeys" needs to be exported by the entry point index.d.ts
|
// src/core/server/plugins/types.ts:293:3 - (ae-forgotten-export) The symbol "SharedGlobalConfigKeys" needs to be exported by the entry point index.d.ts
|
||||||
// src/core/server/plugins/types.ts:289:3 - (ae-forgotten-export) The symbol "SavedObjectsConfigType" needs to be exported by the entry point index.d.ts
|
// src/core/server/plugins/types.ts:296:3 - (ae-forgotten-export) The symbol "SavedObjectsConfigType" needs to be exported by the entry point index.d.ts
|
||||||
// src/core/server/plugins/types.ts:394:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "create"
|
// src/core/server/plugins/types.ts:401:5 - (ae-unresolved-link) The @link reference could not be resolved: The package "kibana" does not have an export "create"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue