remove the backend feature compat callback pattern

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-08-15 10:00:15 +02:00
parent 4f56cc68d2
commit d425fc4dfd
95 changed files with 284 additions and 238 deletions
+2 -8
View File
@@ -64,12 +64,6 @@ export interface BackendFeature {
$$type: '@backstage/BackendFeature';
}
// @public @deprecated (undocumented)
export interface BackendFeatureCompat extends BackendFeature {
// @deprecated (undocumented)
(): this;
}
// @public @deprecated (undocumented)
export type BackendModuleConfig = CreateBackendModuleOptions;
@@ -257,7 +251,7 @@ export interface CreateBackendFeatureLoaderOptions<
// @public
export function createBackendModule(
options: CreateBackendModuleOptions,
): BackendFeatureCompat;
): BackendFeature;
// @public
export interface CreateBackendModuleOptions {
@@ -270,7 +264,7 @@ export interface CreateBackendModuleOptions {
// @public
export function createBackendPlugin(
options: CreateBackendPluginOptions,
): BackendFeatureCompat;
): BackendFeature;
// @public
export interface CreateBackendPluginOptions {
+1 -1
View File
@@ -21,6 +21,6 @@
*/
export * from './services';
export type { BackendFeature, BackendFeatureCompat } from './types';
export type { BackendFeature } from './types';
export * from './paths';
export * from './wiring';
-11
View File
@@ -27,14 +27,3 @@ export interface BackendFeature {
// NOTE: This type is opaque in order to simplify future API evolution.
$$type: '@backstage/BackendFeature';
}
/**
* @public
* @deprecated This type exists only as a helper for old code that relied on `createBackendFeature` and `createBackendPlugin` to return `() => BackendFeature` instead of `BackendFeature`. You should remove the `()` parentheses at the end of your usages. This type will be removed in a future release.
*/
export interface BackendFeatureCompat extends BackendFeature {
/**
* @deprecated You do not need to use this call signature; use the type directly instead by removing the `()` parentheses at the end. This call signature will be removed in a future release.
*/
(): this;
}
@@ -46,18 +46,18 @@ describe('createBackendFeatureLoader', () => {
createBackendPlugin({
pluginId: 'x',
register() {},
})(),
}),
createServiceFactory({
service: coreServices.pluginMetadata,
deps: {},
factory: () => ({ getId: () => 'fake-id' }),
})(),
}),
// Dynamic import format
Promise.resolve({
default: createBackendPlugin({
pluginId: 'y',
register() {},
})(),
}),
}),
];
},
@@ -79,7 +79,7 @@ describe('createBackendFeatureLoader', () => {
});
it('should support multiple output formats', async () => {
const feature = createBackendPlugin({ pluginId: 'x', register() {} })();
const feature = createBackendPlugin({ pluginId: 'x', register() {} });
const dynamicFeature = Promise.resolve({ default: feature });
async function extractResult(f: BackendFeature) {
@@ -29,13 +29,6 @@ describe('createBackendModule', () => {
},
});
// legacy form
const legacy = result() as unknown as InternalBackendRegistrations;
expect(legacy.$$type).toEqual('@backstage/BackendFeature');
expect(legacy.version).toEqual('v1');
expect(legacy.getRegistrations).toEqual(expect.any(Function));
// new form
const module = result as unknown as InternalBackendRegistrations;
expect(module.$$type).toEqual('@backstage/BackendFeature');
expect(module.version).toEqual('v1');
@@ -52,9 +45,6 @@ describe('createBackendModule', () => {
},
},
]);
// @ts-expect-error
expect(module({ a: 'a' })).toBeDefined();
});
it('should be able to depend on all types of dependencies', () => {
@@ -14,11 +14,12 @@
* limitations under the License.
*/
import { BackendFeatureCompat } from '../types';
import { BackendFeature } from '../types';
import {
BackendModuleRegistrationPoints,
InternalBackendModuleRegistration,
InternalBackendPluginRegistration,
InternalBackendRegistrations,
} from './types';
/**
@@ -52,7 +53,7 @@ export interface CreateBackendModuleOptions {
*/
export function createBackendModule(
options: CreateBackendModuleOptions,
): BackendFeatureCompat {
): BackendFeature {
function getRegistrations() {
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
[];
@@ -93,15 +94,10 @@ export function createBackendModule(
];
}
function backendFeatureCompatWrapper() {
return backendFeatureCompatWrapper;
}
Object.assign(backendFeatureCompatWrapper, {
return {
$$type: '@backstage/BackendFeature' as const,
featureType: 'registrations',
version: 'v1',
getRegistrations,
});
return backendFeatureCompatWrapper as BackendFeatureCompat;
} as InternalBackendRegistrations;
}
@@ -28,13 +28,6 @@ describe('createBackendPlugin', () => {
},
});
// legacy form
const legacy = result() as unknown as InternalBackendRegistrations;
expect(legacy.$$type).toEqual('@backstage/BackendFeature');
expect(legacy.version).toEqual('v1');
expect(legacy.getRegistrations).toEqual(expect.any(Function));
// new form
const plugin = result as unknown as InternalBackendRegistrations;
expect(plugin.$$type).toEqual('@backstage/BackendFeature');
expect(plugin.version).toEqual('v1');
@@ -50,9 +43,6 @@ describe('createBackendPlugin', () => {
},
},
]);
// @ts-expect-error
expect(plugin({ a: 'a' })).toBeDefined();
});
it('should be able to depend on all compatible dependencies', () => {
@@ -14,10 +14,11 @@
* limitations under the License.
*/
import { BackendFeatureCompat } from '../types';
import { BackendFeature } from '../types';
import {
BackendPluginRegistrationPoints,
InternalBackendPluginRegistration,
InternalBackendRegistrations,
} from './types';
/**
@@ -46,7 +47,7 @@ export interface CreateBackendPluginOptions {
*/
export function createBackendPlugin(
options: CreateBackendPluginOptions,
): BackendFeatureCompat {
): BackendFeature {
function getRegistrations() {
const extensionPoints: InternalBackendPluginRegistration['extensionPoints'] =
[];
@@ -86,15 +87,10 @@ export function createBackendPlugin(
];
}
function backendFeatureCompatWrapper() {
return backendFeatureCompatWrapper;
}
Object.assign(backendFeatureCompatWrapper, {
return {
$$type: '@backstage/BackendFeature' as const,
version: 'v1',
featureType: 'registrations',
getRegistrations,
});
return backendFeatureCompatWrapper as BackendFeatureCompat;
} as InternalBackendRegistrations;
}