backend-dynamic-feature-service: expand type check
This change caters for backend dynamic plugins that have been wrapped by BackendFeatureCompatWrapper by expanding the allowed types for the default export of a dynamic plugin to also be a function. Signed-off-by: Stan Lewis <gashcrumb@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-dynamic-feature-service': patch
|
||||
---
|
||||
|
||||
Relax type check for a plugin's default export to also accept a BackendFeature defined as a function instead of an object
|
||||
@@ -246,6 +246,59 @@ describe('backend-dynamic-feature-service', () => {
|
||||
>([]);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'should successfully load a backend plugin wrapped in a BackendFeatureCompatWrapper function',
|
||||
packageManifest: {
|
||||
name: 'backend-dynamic-plugin-test',
|
||||
version: '0.0.0',
|
||||
backstage: {
|
||||
role: 'backend-plugin',
|
||||
},
|
||||
main: 'dist/index.cjs.js',
|
||||
},
|
||||
indexFile: {
|
||||
relativePath: ['dist', 'index.cjs.js'],
|
||||
content: `
|
||||
function backendFeatureCompatWrapper() {
|
||||
return backendFeatureCompatWrapper;
|
||||
}
|
||||
Object.assign(backendFeatureCompatWrapper, {
|
||||
$$type: "@backstage/BackendFeature",
|
||||
version: "v1",
|
||||
});
|
||||
const alpha = backendFeatureCompatWrapper;
|
||||
exports.default = alpha;
|
||||
`,
|
||||
},
|
||||
expectedLogs(location) {
|
||||
return {
|
||||
infos: [
|
||||
{
|
||||
message: `loaded dynamic backend plugin 'backend-dynamic-plugin-test' from '${location}'`,
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
checkLoadedPlugins(plugins) {
|
||||
expect(plugins).toMatchObject([
|
||||
{
|
||||
name: 'backend-dynamic-plugin-test',
|
||||
version: '0.0.0',
|
||||
role: 'backend-plugin',
|
||||
platform: 'node',
|
||||
installer: {
|
||||
kind: 'new',
|
||||
},
|
||||
},
|
||||
]);
|
||||
const installer: NewBackendPluginInstaller = (
|
||||
plugins[0] as BackendDynamicPlugin
|
||||
).installer as NewBackendPluginInstaller;
|
||||
expect((installer.install() as BackendFeature).$$type).toEqual(
|
||||
'@backstage/BackendFeature',
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'should fail when no index file',
|
||||
packageManifest: {
|
||||
|
||||
@@ -301,7 +301,7 @@ export const dynamicPluginsFeatureDiscoveryServiceFactory =
|
||||
function isBackendFeature(value: unknown): value is BackendFeature {
|
||||
return (
|
||||
!!value &&
|
||||
typeof value === 'object' &&
|
||||
(typeof value === 'object' || typeof value === 'function') &&
|
||||
(value as BackendFeature).$$type === '@backstage/BackendFeature'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user