cli: enable forwarding of backend flags for repo start

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2025-04-06 12:58:19 +02:00
parent d2091c6fe0
commit fd4fddad77
8 changed files with 60 additions and 24 deletions
+7 -4
View File
@@ -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 <path> Config files to load instead of app-config.yaml (default: [])
--plugin <pluginId> Start the dev entry-point for any matching plugin package in the repo (default: [])
--link <path> Link an external workspace for module resolution
--plugin <pluginId> Start the dev entry-point for any matching plugin package in the repo (default: [])
--config <path> 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 <path...> Add a --require argument to the node process. Applies to backend package only
--link <path> Link an external workspace for module resolution
```
## repo build
+4 -1
View File
@@ -474,8 +474,11 @@ Options:
Usage: backstage-cli repo start [options] [packageName...]
Options:
--config <path>
--plugin <pluginId>
--config <path>
--inspect [host]
--inspect-brk [host]
--require <path...>
--link <path>
-h, --help
```
+2 -2
View File
@@ -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 */
+16 -4
View File
@@ -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 <pluginId>',
'Start the dev entry-point for any matching plugin package in the repo',
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
Array<string>(),
)
.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 <path...>',
'Add a --require argument to the node process. Applies to backend package only',
)
.option(
'--link <path>',
'Link an external workspace for module resolution',
@@ -84,4 +96,4 @@ export const buildPlugin = createCliPlugin({
},
});
export default buildPlugin;
export default startPlugin;
@@ -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;
}
@@ -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<void> {
@@ -32,10 +32,16 @@ const ACCEPTED_PACKAGE_ROLES: Array<PackageRole | undefined> = [
'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,
},
},
];
+13 -1
View File
@@ -25,13 +25,25 @@ export function registerRepoCommands(command: Command) {
'[packageName...]',
'Run the specified package instead of the defaults.',
)
.option(...configOption)
.option(
'--plugin <pluginId>',
'Start the dev entry-point for any matching plugin package in the repo',
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
Array<string>(),
)
.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 <path...>',
'Add a --require argument to the node process. Applies to backend package only',
)
.option('--link <path>', 'Link an external workspace for module resolution')
.action(lazy(() => import('./commands/repo/start'), 'command'));
}