diff --git a/packages/autodetect/src/autodetect-plugins.d.ts b/packages/autodetect/src/autodetect-plugins.d.ts new file mode 100644 index 0000000000..5eb19dee39 --- /dev/null +++ b/packages/autodetect/src/autodetect-plugins.d.ts @@ -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; + }; + const modules: Array<{ name: string; module: Record }>; +} diff --git a/packages/autodetect/src/index.ts b/packages/autodetect/src/index.ts index 490e6f25d7..833b9bad7c 100644 --- a/packages/autodetect/src/index.ts +++ b/packages/autodetect/src/index.ts @@ -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; }; -type DetectedModule = { - name: string; - module: Record; -}; - /** * @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): obj is BackstagePlugin { typeof obj.provide !== 'undefined' ); } - -export { getAvailablePlugins }; -export type { DetectedPlugin }; diff --git a/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx b/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx index 6ed0140b96..67d34e4010 100644 --- a/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx +++ b/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx @@ -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 }) => {