From b9f81c945c8ec169f737e6ff7be4d8a9bcadd394 Mon Sep 17 00:00:00 2001 From: Philipp Hugenroth Date: Mon, 17 Jul 2023 15:49:45 +0200 Subject: [PATCH] Allow explicit package list & add UI Co-authored-by: Vincenzo Scamporlino Signed-off-by: Philipp Hugenroth --- packages/cli/src/lib/bundler/config.ts | 2 +- packages/cli/src/lib/bundler/server.ts | 19 +++++++++- .../Content/InfoContent/InfoContent.tsx | 35 +++++++++++++++++-- .../InfoContent/InfoDependenciesTable.tsx | 4 ++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/lib/bundler/config.ts b/packages/cli/src/lib/bundler/config.ts index 6ebfeae99e..df3f440fa5 100644 --- a/packages/cli/src/lib/bundler/config.ts +++ b/packages/cli/src/lib/bundler/config.ts @@ -131,7 +131,7 @@ export async function createConfig( if (extraPackages.length > 0) { const requirePackageScript = extraPackages - ?.map(pkg => `require('${pkg}')`) + ?.map(pkg => `{name: '${pkg}', module: require('${pkg}')}`) .join(','); plugins.push( diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index d51ab7dc30..db046e1e18 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -42,7 +42,7 @@ export async function serveBundle(options: ServeOptions) { // TODO: proper // Assumption for config string based on https://github.com/backstage/backstage/issues/18372 ^ - const packageDetectionMode = options.fullConfig.getOptionalString( + const packageDetectionMode = options.fullConfig.getOptional( 'app.experimental.packages', ); const extraPackages = []; @@ -60,6 +60,23 @@ export async function serveBundle(options: ServeOptions) { extraPackages.push(depName); } } + } else { + const packagesList = Array.isArray(packageDetectionMode) + ? packageDetectionMode + : []; + for (const depName of packagesList ?? []) { + const depPackageJson: BackstagePackageJson = require(require.resolve( + `${depName}/package.json`, + { paths: [paths.targetPath] }, + )); + if ( + ['frontend-plugin', 'frontend-plugin-module'].includes( + depPackageJson.backstage?.role || '', + ) + ) { + extraPackages.push(depName); + } + } } if (options.verifyVersions) { const lockfile = await Lockfile.load( diff --git a/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx b/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx index 0ed43d2fee..d9301ea6ec 100644 --- a/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx +++ b/plugins/devtools/src/components/Content/InfoContent/InfoContent.tsx @@ -37,7 +37,12 @@ import MemoryIcon from '@material-ui/icons/Memory'; import DeveloperBoardIcon from '@material-ui/icons/DeveloperBoard'; import { BackstageLogoIcon } from './BackstageLogoIcon'; import FileCopyIcon from '@material-ui/icons/FileCopy'; -import { DevToolsInfo } from '@backstage/plugin-devtools-common'; +import { + DevToolsInfo, + PackageDependency, +} from '@backstage/plugin-devtools-common'; + +const PACKAGES_GLOBAL = '__backstage_detected_packages__'; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -74,6 +79,21 @@ export const InfoContent = () => { const classes = useStyles(); const { about, loading, error } = useInfo(); + const availablePlugins: PackageDependency[] = (window as any)[PACKAGES_GLOBAL] + ? ( + (window as any)[PACKAGES_GLOBAL].modules as Array> + ).map(({ name, module }) => { + const pluginImpl: any = Object.values(module).find( + (v: any) => !!v?.getId, + ); + + return { + name, + versions: (pluginImpl?.getId() as string) || '', + }; + }) + : []; + if (loading) { return ; } else if (error) { @@ -144,7 +164,18 @@ export const InfoContent = () => { - + + + + + + ); }; diff --git a/plugins/devtools/src/components/Content/InfoContent/InfoDependenciesTable.tsx b/plugins/devtools/src/components/Content/InfoContent/InfoDependenciesTable.tsx index e1ab59f279..ac54e2ebaa 100644 --- a/plugins/devtools/src/components/Content/InfoContent/InfoDependenciesTable.tsx +++ b/plugins/devtools/src/components/Content/InfoContent/InfoDependenciesTable.tsx @@ -35,12 +35,14 @@ const columns: TableColumn[] = [ export const InfoDependenciesTable = ({ infoDependencies, + title, }: { + title: string; infoDependencies: PackageDependency[] | undefined; }) => { return (