From fd4fddad77b0e651eede3af7542632502f39562a Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 6 Apr 2025 12:58:19 +0200 Subject: [PATCH] cli: enable forwarding of backend flags for repo start Signed-off-by: Patrik Oldsberg --- docs/tooling/cli/03-commands.md | 11 ++++++---- packages/cli/cli-report.backstage-cli.md | 5 ++++- packages/cli/src/lib/runner/runBackend.ts | 4 ++-- packages/cli/src/modules/start/alpha.ts | 20 +++++++++++++---- .../commands/package/start/startBackend.ts | 4 ++-- .../commands/package/start/startPackage.ts | 4 ++-- .../src/modules/start/commands/repo/start.ts | 22 ++++++++++++------- packages/cli/src/modules/start/index.ts | 14 +++++++++++- 8 files changed, 60 insertions(+), 24 deletions(-) diff --git a/docs/tooling/cli/03-commands.md b/docs/tooling/cli/03-commands.md index 5fa01f931b..6ca63da44e 100644 --- a/docs/tooling/cli/03-commands.md +++ b/docs/tooling/cli/03-commands.md @@ -83,12 +83,15 @@ Usage: backstage-cli repo start [options] [packageName...] Starts packages in the repo for local development Arguments: - packageName Run the specified package instead of the defaults. + packageName Run the specified package instead of the defaults. Options: - --config Config files to load instead of app-config.yaml (default: []) - --plugin Start the dev entry-point for any matching plugin package in the repo (default: []) - --link Link an external workspace for module resolution + --plugin Start the dev entry-point for any matching plugin package in the repo (default: []) + --config Config files to load instead of app-config.yaml (default: []) + --inspect [host] Enable debugger in Node.js environments. Applies to backend package only + --inspect-brk [host] Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only + --require Add a --require argument to the node process. Applies to backend package only + --link Link an external workspace for module resolution ``` ## repo build diff --git a/packages/cli/cli-report.backstage-cli.md b/packages/cli/cli-report.backstage-cli.md index 2e6b34850e..3747d6acc4 100644 --- a/packages/cli/cli-report.backstage-cli.md +++ b/packages/cli/cli-report.backstage-cli.md @@ -474,8 +474,11 @@ Options: Usage: backstage-cli repo start [options] [packageName...] Options: - --config --plugin + --config + --inspect [host] + --inspect-brk [host] + --require --link -h, --help ``` diff --git a/packages/cli/src/lib/runner/runBackend.ts b/packages/cli/src/lib/runner/runBackend.ts index 9f52968067..ebb1d535b3 100644 --- a/packages/cli/src/lib/runner/runBackend.ts +++ b/packages/cli/src/lib/runner/runBackend.ts @@ -37,9 +37,9 @@ export type RunBackendOptions = { /** relative entry point path without extension, e.g. 'src/index' */ entry: string; /** Whether to forward the --inspect flag to the node process */ - inspectEnabled: boolean; + inspectEnabled?: boolean | string; /** Whether to forward the --inspect-brk flag to the node process */ - inspectBrkEnabled: boolean; + inspectBrkEnabled?: boolean | string; /** Additional module to require via the --require flag to the node process */ require?: string | string[]; /** An external linked workspace to override module resolution towards */ diff --git a/packages/cli/src/modules/start/alpha.ts b/packages/cli/src/modules/start/alpha.ts index 860753fb85..0d2b6f661e 100644 --- a/packages/cli/src/modules/start/alpha.ts +++ b/packages/cli/src/modules/start/alpha.ts @@ -19,8 +19,8 @@ import { createCliPlugin } from '../../wiring/factory'; import { lazy } from '../../lib/lazy'; import { configOption } from '../config'; -export const buildPlugin = createCliPlugin({ - pluginId: 'build', +export const startPlugin = createCliPlugin({ + pluginId: 'start', init: async reg => { reg.addCommand({ path: ['package', 'start'], @@ -65,13 +65,25 @@ export const buildPlugin = createCliPlugin({ '[...packageName]', 'Run the specified package instead of the defaults.', ) - .option(...configOption) .option( '--plugin ', 'Start the dev entry-point for any matching plugin package in the repo', (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), Array(), ) + .option(...configOption) + .option( + '--inspect [host]', + 'Enable debugger in Node.js environments. Applies to backend package only', + ) + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', + ) + .option( + '--require ', + 'Add a --require argument to the node process. Applies to backend package only', + ) .option( '--link ', 'Link an external workspace for module resolution', @@ -84,4 +96,4 @@ export const buildPlugin = createCliPlugin({ }, }); -export default buildPlugin; +export default startPlugin; diff --git a/packages/cli/src/modules/start/commands/package/start/startBackend.ts b/packages/cli/src/modules/start/commands/package/start/startBackend.ts index 16b47d309a..417398e9f9 100644 --- a/packages/cli/src/modules/start/commands/package/start/startBackend.ts +++ b/packages/cli/src/modules/start/commands/package/start/startBackend.ts @@ -22,8 +22,8 @@ import { runBackend } from '../../../../../lib/runner'; interface StartBackendOptions { targetDir: string; checksEnabled: boolean; - inspectEnabled: boolean; - inspectBrkEnabled: boolean; + inspectEnabled?: boolean | string; + inspectBrkEnabled?: boolean | string; linkedWorkspace?: string; require?: string; } diff --git a/packages/cli/src/modules/start/commands/package/start/startPackage.ts b/packages/cli/src/modules/start/commands/package/start/startPackage.ts index d6ca3c068f..10f705ba4d 100644 --- a/packages/cli/src/modules/start/commands/package/start/startPackage.ts +++ b/packages/cli/src/modules/start/commands/package/start/startPackage.ts @@ -23,8 +23,8 @@ export async function startPackage(options: { targetDir: string; configPaths: string[]; checksEnabled: boolean; - inspectEnabled: boolean; - inspectBrkEnabled: boolean; + inspectEnabled?: boolean | string; + inspectBrkEnabled?: boolean | string; linkedWorkspace?: string; require?: string; }): Promise { diff --git a/packages/cli/src/modules/start/commands/repo/start.ts b/packages/cli/src/modules/start/commands/repo/start.ts index fc1b87d3ac..7a4704ea3e 100644 --- a/packages/cli/src/modules/start/commands/repo/start.ts +++ b/packages/cli/src/modules/start/commands/repo/start.ts @@ -32,10 +32,16 @@ const ACCEPTED_PACKAGE_ROLES: Array = [ 'backend-plugin', ]; -export async function command( - packageNames: string[], - options: { plugin: string[]; config: string[]; link?: string }, -) { +type CommandOptions = { + plugin: string[]; + config: string[]; + inspect?: boolean | string; + inspectBrk?: boolean | string; + require?: string; + link?: string; +}; + +export async function command(packageNames: string[], options: CommandOptions) { const targetPackages = await findTargetPackages(packageNames, options.plugin); const packageOptions = await resolvePackageOptions(targetPackages, options); @@ -151,7 +157,7 @@ async function findTargetPackages(packageNames: string[], pluginIds: string[]) { async function resolvePackageOptions( targetPackages: BackstagePackage[], - options: { plugin: string[]; config: string[]; link?: string }, + options: CommandOptions, ) { const linkedWorkspace = await resolveLinkedWorkspace(options.link); @@ -194,9 +200,9 @@ async function resolvePackageOptions( options.config.length > 0 ? options.config : parsedConfig, checksEnabled: false, linkedWorkspace, - inspectEnabled: false, - inspectBrkEnabled: false, - require: parsedRequire, + inspectEnabled: options.inspect, + inspectBrkEnabled: options.inspectBrk, + require: options.require ?? parsedRequire, }, }, ]; diff --git a/packages/cli/src/modules/start/index.ts b/packages/cli/src/modules/start/index.ts index 627336e3f4..f1dd1eeb71 100644 --- a/packages/cli/src/modules/start/index.ts +++ b/packages/cli/src/modules/start/index.ts @@ -25,13 +25,25 @@ export function registerRepoCommands(command: Command) { '[packageName...]', 'Run the specified package instead of the defaults.', ) - .option(...configOption) .option( '--plugin ', 'Start the dev entry-point for any matching plugin package in the repo', (opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]), Array(), ) + .option(...configOption) + .option( + '--inspect [host]', + 'Enable debugger in Node.js environments. Applies to backend package only', + ) + .option( + '--inspect-brk [host]', + 'Enable debugger in Node.js environments, breaking before code starts. Applies to backend package only', + ) + .option( + '--require ', + 'Add a --require argument to the node process. Applies to backend package only', + ) .option('--link ', 'Link an external workspace for module resolution') .action(lazy(() => import('./commands/repo/start'), 'command')); }