Merge pull request #16207 from backstage/rugvip/pluginId

backend-plugin-api: switch createBackendPlugin id -> pluginId
This commit is contained in:
Patrik Oldsberg
2023-02-06 23:32:33 +01:00
committed by GitHub
27 changed files with 78 additions and 51 deletions
@@ -33,7 +33,7 @@ describe('createExtensionPoint', () => {
describe('createBackendPlugin', () => {
it('should create a BackendPlugin', () => {
const plugin = createBackendPlugin((_options: { a: string }) => ({
id: 'x',
pluginId: 'x',
register() {},
}));
expect(plugin).toBeDefined();
@@ -47,7 +47,7 @@ describe('createBackendPlugin', () => {
it('should create plugins with optional options', () => {
const plugin = createBackendPlugin((_options?: { a: string }) => ({
id: 'x',
pluginId: 'x',
register() {},
}));
expect(plugin).toBeDefined();
@@ -59,7 +59,7 @@ describe('createBackendPlugin', () => {
it('should create plugins without options', () => {
const plugin = createBackendPlugin({
id: 'x',
pluginId: 'x',
register() {},
});
expect(plugin).toBeDefined();
@@ -74,7 +74,7 @@ describe('createBackendPlugin', () => {
a: string;
}
const plugin = createBackendPlugin((_options: TestOptions) => ({
id: 'x',
pluginId: 'x',
register() {},
}));
expect(plugin).toBeDefined();
@@ -91,7 +91,7 @@ describe('createBackendPlugin', () => {
a: string;
}
const plugin = createBackendPlugin((_options?: TestOptions) => ({
id: 'x',
pluginId: 'x',
register() {},
}));
expect(plugin).toBeDefined();
@@ -72,7 +72,7 @@ export interface BackendPluginConfig {
*
* @see {@link https://backstage.io/docs/backend-system/architecture/naming-patterns | Recommended naming patterns}
*/
id: string;
pluginId: string;
register(reg: BackendPluginRegistrationPoints): void;
}
@@ -87,10 +87,18 @@ export function createBackendPlugin<TOptions extends [options?: object] = []>(
config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig),
): (...params: TOptions) => BackendFeature {
if (typeof config === 'function') {
return config;
return (...options: TOptions) => {
const c = config(...options);
return {
...c,
id: c.pluginId,
};
};
}
return () => config;
return () => ({
...config,
id: config.pluginId,
});
}
/**