cli: autodetect refactor typings

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-07-19 19:48:45 +02:00
committed by Patrik Oldsberg
parent 5c958a3852
commit 7b7af928ec
3 changed files with 29 additions and 17 deletions
+22
View File
@@ -0,0 +1,22 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare module 'backstage-autodetected-plugins' {
type DetectedModule = {
name: string;
module: Record<string, any>;
};
const modules: Array<{ name: string; module: Record<string, any> }>;
}
+5 -15
View File
@@ -16,29 +16,22 @@
import { BackstagePlugin } from '@backstage/core-plugin-api';
// eslint-disable-next-line @backstage/no-undeclared-imports
import { modules, DetectedModule } from 'backstage-autodetected-plugins';
/**
* @public
*/
type DetectedPlugin = {
export type DetectedPlugin = {
name: string;
plugin: BackstagePlugin;
components: Record<string, any>;
};
type DetectedModule = {
name: string;
module: Record<string, any>;
};
/**
* @public
*/
function getAvailablePlugins(): DetectedPlugin[] {
// eslint-disable-next-line @backstage/no-undeclared-imports
const { modules } = require('backstage-autodetected-plugins') as {
modules: DetectedModule[];
};
export function getAvailablePlugins(): DetectedPlugin[] {
return modules
.map(splitPluginFromComponents)
.filter((m): m is DetectedPlugin => !!m.plugin);
@@ -70,6 +63,3 @@ function isBackstagePlugin(obj: Record<string, any>): obj is BackstagePlugin {
typeof obj.provide !== 'undefined'
);
}
export { getAvailablePlugins };
export type { DetectedPlugin };
@@ -41,7 +41,7 @@ import {
DevToolsInfo,
PackageDependency,
} from '@backstage/plugin-devtools-common';
import * as autodetect from '@backstage/autodetect';
import { getAvailablePlugins } from '@backstage/autodetect';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
@@ -77,7 +77,7 @@ const copyToClipboard = ({ about }: { about: DevToolsInfo | undefined }) => {
export const InfoContent = () => {
const classes = useStyles();
const { about, loading, error } = useInfo();
const plugins = autodetect.getAvailablePlugins();
const plugins = getAvailablePlugins();
const availablePlugins: PackageDependency[] = plugins.map(
({ name, components }) => {