From 1b27c4d4349e122d92ec9ad5822c47beea48ea71 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 6 Apr 2025 11:49:06 +0200 Subject: [PATCH] cli: add repo start fallback for running plugins if app/backend are missing Signed-off-by: Patrik Oldsberg --- .../src/modules/start/commands/repo/start.ts | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/modules/start/commands/repo/start.ts b/packages/cli/src/modules/start/commands/repo/start.ts index 54d53c51d6..fc1b87d3ac 100644 --- a/packages/cli/src/modules/start/commands/repo/start.ts +++ b/packages/cli/src/modules/start/commands/repo/start.ts @@ -95,7 +95,7 @@ async function findTargetPackages(packageNames: string[], pluginIds: string[]) { return targetPackages; } - // If on package names are provided, default to expect a single frontend and/or backend package + // If no package names are provided, default to expect a single frontend and/or backend package for (const role of ['frontend', 'backend']) { const matchingPackages = packages.filter( pkg => pkg.packageJson.backstage?.role === role, @@ -122,12 +122,31 @@ async function findTargetPackages(packageNames: string[], pluginIds: string[]) { targetPackages.push(...matchingPackages); } - if (targetPackages.length === 0) { - throw new Error( - `Unable to find any packages with role 'frontend' or 'backend'`, - ); + if (targetPackages.length > 0) { + return targetPackages; } - return targetPackages; + + // If no app or backend packages are found, fall back to expecting single plugin packages + for (const role of ['frontend-plugin', 'backend-plugin']) { + const matchingPackages = packages.filter( + pkg => pkg.packageJson.backstage?.role === role, + ); + if (matchingPackages.length > 1) { + throw new Error( + `Found multiple packages with role '${role}', please choose which packages you want` + + `to run by passing the package names explicitly as arguments, for example ` + + `'yarn backstage-cli repo start my-plugin my-plugin-backend'.`, + ); + } + targetPackages.push(...matchingPackages); + } + if (targetPackages.length > 0) { + return targetPackages; + } + + throw new Error( + `Unable to find any packages with role 'frontend', 'backend', 'frontend-plugin', or 'backend-plugin'.`, + ); } async function resolvePackageOptions(