-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement "plugin" package type (#149370)
This PR updates the core discovery logic to support loading plugins from packages. This logic is additive, so that the existing plugins in the repo and third-party plugins can continue to be loaded via the existing mechanism, but with #148130 we will be automatically migrating all plugins in the repo to packages, which will use this logic. The logic is already in-use in that PR, and was developed there, but extracted here for easier review. The logic is relatively simple, where a list of packages in the repo are attached to the core `Env` and then filtered by core before converting all plugin packages to `PluginWrapper`. The `PluginWrapper` still exposes the plugin manifest to the rest of the code, and it is used in many places, so rather than making changes to the `PluginWrapper` I'm faking a legacy plugin manifest with the plugin package manifest. @elastic/kibana-core: I'm going to need some help identifying what we need to get test coverage for. This is a pretty simple addition to the core IMO, and if it didn't work then nothing would work, so I'm pretty confident in it, but would still appreciate your feedback.
- Loading branch information
Spencer
authored
Jan 30, 2023
1 parent
ad75d90
commit 376bed5
Showing
31 changed files
with
520 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...ns/core-plugins-server-internal/src/discovery/plugin_manifest_from_plugin_package.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* 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 { PluginPackageManifest } from '@kbn/repo-packages'; | ||
import { PluginType } from '@kbn/core-base-common'; | ||
import { pluginManifestFromPluginPackage } from './plugin_manifest_from_plugin_package'; | ||
|
||
const kibanaVersion = `1.${Math.round(10 * Math.random())}.1`; | ||
const minimal: PluginPackageManifest = { | ||
type: 'plugin', | ||
id: '@kbn/some-legacy-plugin', | ||
owner: ['@elastic/team-a', '@elastic/team-b'], | ||
plugin: { | ||
id: 'someLegacyPluginId', | ||
browser: true, | ||
server: true, | ||
}, | ||
}; | ||
const basic: PluginPackageManifest = { | ||
...minimal, | ||
plugin: { | ||
...minimal.plugin, | ||
type: 'preboot', | ||
configPath: ['some', 'legacy'], | ||
enabledOnAnonymousPages: false, | ||
extraPublicDirs: ['foo', 'bar'], | ||
optionalPlugins: ['someOtherPlugin'], | ||
requiredBundles: ['someRequiresBundlePlugin'], | ||
requiredPlugins: ['someRequiredPlugin'], | ||
}, | ||
serviceFolders: ['foo', 'bar'], | ||
}; | ||
|
||
describe('pluginManifestFromPluginPackage()', () => { | ||
it('consumes correct values from plugin package manifest', () => { | ||
expect(pluginManifestFromPluginPackage('static', basic)).toMatchInlineSnapshot(` | ||
Object { | ||
"configPath": Array [ | ||
"some", | ||
"legacy", | ||
], | ||
"enabledOnAnonymousPages": false, | ||
"id": "someLegacyPluginId", | ||
"kibanaVersion": "static", | ||
"optionalPlugins": Array [ | ||
"someOtherPlugin", | ||
], | ||
"owner": Object { | ||
"name": "@elastic/team-a & @elastic/team-b", | ||
}, | ||
"requiredBundles": Array [ | ||
"someRequiresBundlePlugin", | ||
], | ||
"requiredPlugins": Array [ | ||
"someRequiredPlugin", | ||
], | ||
"server": true, | ||
"serviceFolders": Array [ | ||
"foo", | ||
"bar", | ||
], | ||
"type": "preboot", | ||
"ui": true, | ||
"version": "1.0.0", | ||
} | ||
`); | ||
}); | ||
|
||
it('applies correct defaults', () => { | ||
const pm = pluginManifestFromPluginPackage(kibanaVersion, minimal); | ||
expect(pm).toHaveProperty('type', PluginType.standard); | ||
expect(pm.enabledOnAnonymousPages).toBeUndefined(); | ||
expect(pm.serviceFolders).toBeUndefined(); | ||
expect(pm).toHaveProperty('kibanaVersion', kibanaVersion); | ||
expect(pm).toHaveProperty('optionalPlugins', []); | ||
expect(pm).toHaveProperty('requiredBundles', []); | ||
expect(pm).toHaveProperty('requiredPlugins', []); | ||
expect(pm).toHaveProperty('owner', { | ||
name: '@elastic/team-a & @elastic/team-b', | ||
}); | ||
expect(pm).toHaveProperty('server', true); | ||
expect(pm).toHaveProperty('ui', true); | ||
expect(pm).toHaveProperty('configPath', 'some_legacy_plugin_id'); | ||
}); | ||
|
||
it('reflects plugin.server', () => { | ||
expect( | ||
pluginManifestFromPluginPackage(kibanaVersion, { | ||
...minimal, | ||
plugin: { ...minimal.plugin, server: false }, | ||
}) | ||
).toHaveProperty('server', false); | ||
expect( | ||
pluginManifestFromPluginPackage(kibanaVersion, { | ||
...minimal, | ||
plugin: { ...minimal.plugin, server: true }, | ||
}) | ||
).toHaveProperty('server', true); | ||
}); | ||
|
||
it('reflects plugin.browser', () => { | ||
expect( | ||
pluginManifestFromPluginPackage(kibanaVersion, { | ||
...minimal, | ||
plugin: { ...minimal.plugin, browser: false }, | ||
}) | ||
).toHaveProperty('ui', false); | ||
expect( | ||
pluginManifestFromPluginPackage(kibanaVersion, { | ||
...minimal, | ||
plugin: { ...minimal.plugin, browser: true }, | ||
}) | ||
).toHaveProperty('ui', true); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
...plugins/core-plugins-server-internal/src/discovery/plugin_manifest_from_plugin_package.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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 { snakeCase } from 'lodash'; | ||
import { PluginPackageManifest } from '@kbn/repo-packages'; | ||
import { PluginManifest } from '@kbn/core-plugins-server'; | ||
import { PluginType } from '@kbn/core-base-common'; | ||
|
||
export function pluginManifestFromPluginPackage( | ||
kibanaVersion: string, | ||
manifest: PluginPackageManifest | ||
): PluginManifest { | ||
return { | ||
type: manifest.plugin.type === 'preboot' ? PluginType.preboot : PluginType.standard, | ||
id: manifest.plugin.id, | ||
version: '1.0.0', | ||
enabledOnAnonymousPages: manifest.plugin.enabledOnAnonymousPages, | ||
serviceFolders: manifest.serviceFolders, | ||
kibanaVersion, | ||
optionalPlugins: manifest.plugin.optionalPlugins ?? [], | ||
requiredBundles: manifest.plugin.requiredBundles ?? [], | ||
requiredPlugins: manifest.plugin.requiredPlugins ?? [], | ||
owner: { | ||
name: manifest.owner.join(' & '), | ||
}, | ||
server: manifest.plugin.server, | ||
ui: manifest.plugin.browser, | ||
configPath: manifest.plugin.configPath ?? snakeCase(manifest.plugin.id), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.