Add components to available plugins

Co-authored-by: Vincenzo Scamporlino <vinzscam@users.noreply.github.com>
Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
Philipp Hugenroth
2023-07-18 16:35:17 +02:00
committed by Patrik Oldsberg
parent 12c3fadb6d
commit 1d527ae2b6
4 changed files with 65 additions and 17 deletions
+4 -1
View File
@@ -27,5 +27,8 @@
},
"files": [
"dist"
]
],
"dependencies": {
"@backstage/core-plugin-api": "workspace:^"
}
}
+52 -7
View File
@@ -14,16 +14,61 @@
* limitations under the License.
*/
type Modules = Array<{
name: string;
module: object; // Loaded Webpack Module of Backstage Plugin
}>;
import { BackstagePlugin } from '@backstage/core-plugin-api';
function getAvailablePlugins() {
const { modules }: { modules: Modules } = __webpack_require__(
/**
* @public
*/
type DetectedPlugin = {
name: string;
plugin: BackstagePlugin;
components: Record<string, any>;
};
type DetectedModule = {
name: string;
module: Record<string, any>;
};
/**
* @public
*/
function getAvailablePlugins(): DetectedPlugin[] {
const { modules } = __webpack_require__(
'./node_modules/backstage-autodetected-plugins.js',
) as { modules: DetectedModule[] };
return modules
.map(splitPluginFromComponents)
.filter((m): m is DetectedPlugin => !!m.plugin);
}
function splitPluginFromComponents({ module, name }: DetectedModule) {
return Object.entries(module).reduce(
(acc, [k, v]) => {
if (!isBackstagePlugin(v)) {
acc.components[k] = v;
} else {
acc.plugin = v;
}
return acc;
},
{ name, components: {} } as {
name: string;
plugin?: BackstagePlugin;
components: Record<string, any>;
},
);
}
function isBackstagePlugin(obj: Record<string, any>): obj is BackstagePlugin {
return (
typeof obj.getId !== 'undefined' &&
typeof obj.getApis !== 'undefined' &&
typeof obj.getFeatureFlags !== 'undefined' &&
typeof obj.provide !== 'undefined'
);
return modules;
}
export { getAvailablePlugins };
export type { DetectedPlugin };
@@ -78,16 +78,15 @@ export const InfoContent = () => {
const classes = useStyles();
const { about, loading, error } = useInfo();
const plugins = autodetect.getAvailablePlugins();
const availablePlugins: PackageDependency[] = (
plugins as Array<Record<string, any>>
).map(({ name, module }) => {
const pluginImpl: any = Object.values(module).find((v: any) => !!v?.getId);
return {
name,
versions: (pluginImpl?.getId() as string) || '',
};
});
const availablePlugins: PackageDependency[] = plugins.map(
({ name, components }) => {
return {
name,
versions: Object.keys(components).toString(),
};
},
);
if (loading) {
return <Progress />;
} else if (error) {
+1
View File
@@ -3382,6 +3382,7 @@ __metadata:
resolution: "@backstage/autodetect@workspace:packages/autodetect"
dependencies:
"@backstage/cli": "workspace:^"
"@backstage/core-plugin-api": "workspace:^"
"@testing-library/jest-dom": ^5.10.1
languageName: unknown
linkType: soft